virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "gavin.liu" <gavin.liu@jaguarmicro.com>
Cc: jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
	pbonzini@redhat.com, stefanha@redhat.com,
	virtualization@lists.linux.dev, angus.chen@jaguarmicro.com,
	yuxue.liu@jaguarmicro.com
Subject: Re: [PATCH] virtio_config: add device ready status check
Date: Fri, 15 Mar 2024 07:07:52 -0400	[thread overview]
Message-ID: <20240315070641-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20240315103125.1817-1-gavin.liu@jaguarmicro.com>

On Fri, Mar 15, 2024 at 06:31:25PM +0800, gavin.liu wrote:
> From: Yuxue Liu <yuxue.liu@jaguarmicro.com>
> 
> Under the VDPA framework, when the VDPA driver of a device sets the status
> to DRIVER OK,success is not guaranteed. The virtio driver should provide
> some protection or notification.
> 
> Signed-off-by: Yuxue Liu <yuxue.liu@jaguarmicro.com>
> ---
>  drivers/block/virtio_blk.c    |  4 +++-
>  drivers/net/virtio_net.c      |  7 ++++++-
>  include/linux/virtio_config.h | 14 ++++++++++++++
>  3 files changed, 23 insertions(+), 2 deletions(-)


And then what we are expected to change all drivers for this hack to
work? Suggest you instead have vdpa set broken flag and be done with it.

> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 42dea7601d87..14cabf662705 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -1535,7 +1535,9 @@ static int virtblk_probe(struct virtio_device *vdev)
>  		set_disk_ro(vblk->disk, 1);
>  
>  	virtblk_update_capacity(vblk, false);
> -	virtio_device_ready(vdev);
> +	err = virtio_device_ready_safe(vdev);
> +	if (err)
> +		goto out_cleanup_disk;
>  
>  	/*
>  	 * All steps that follow use the VQs therefore they need to be
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index d7ce4a1011ea..0431fc9095ae 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -4808,7 +4808,12 @@ static int virtnet_probe(struct virtio_device *vdev)
>  		goto free_failover;
>  	}
>  
> -	virtio_device_ready(vdev);
> +	err = virtio_device_ready_safe(vdev);
> +	if (err) {
> +		pr_debug("virtio_net: setting device ready failed\n");
> +		rtnl_unlock();
> +		goto free_unregister_netdev;
> +	}
>  
>  	_virtnet_set_queues(vi, vi->curr_queue_pairs);
>  
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index da9b271b54db..de4e864952ef 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -301,6 +301,20 @@ void virtio_device_ready(struct virtio_device *dev)
>  	dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK);
>  }
>  
> +static inline
> +int virtio_device_ready_safe(struct virtio_device *dev)
> +{
> +	u8 status;
> +
> +	virtio_device_ready(dev);
> +	status = dev->config->get_status(dev);
> +	if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
> +		WARN_ON(1);
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
> +
>  static inline
>  const char *virtio_bus_name(struct virtio_device *vdev)
>  {
> -- 
> 2.43.0


  reply	other threads:[~2024-03-15 11:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15 10:31 [PATCH] virtio_config: add device ready status check gavin.liu
2024-03-15 11:07 ` Michael S. Tsirkin [this message]
2024-03-18  4:21 ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240315070641-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=angus.chen@jaguarmicro.com \
    --cc=gavin.liu@jaguarmicro.com \
    --cc=jasowang@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=yuxue.liu@jaguarmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).