virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio_config: add device ready status check
@ 2024-03-15 10:31 gavin.liu
  2024-03-15 11:07 ` Michael S. Tsirkin
  2024-03-18  4:21 ` Jason Wang
  0 siblings, 2 replies; 3+ messages in thread
From: gavin.liu @ 2024-03-15 10:31 UTC (permalink / raw)
  To: jasowang, mst, xuanzhuo, pbonzini
  Cc: stefanha, virtualization, angus.chen, yuxue.liu

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(-)

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-18  4:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-15 10:31 [PATCH] virtio_config: add device ready status check gavin.liu
2024-03-15 11:07 ` Michael S. Tsirkin
2024-03-18  4:21 ` Jason Wang

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).