[PATCH 08/13] virtio: Acknowledge devices only when probed
Simon Glass
sjg at chromium.org
Wed May 27 18:10:18 CEST 2026
At present virtio devices are acknowleged when bound. This results in a
call to virtio_set_status() which uses device-private data in several
cases, e.g. in virtio_pci_get_status()
This data is only allocated when the device is probed, so the access is
either ignored (on QEMU) or results in a crash (on sandbox).
Acknowledging the device so early does not seem to be necessary. Move it
to the pre-probe function instead. Update the test to match. We now have
no coverage to check that VIRTIO_CONFIG_S_ACKNOWLEDGE was actually set.
If we later find it necessary to acknowledge the device while binding,
we can update the uclass and drivers to use plat data instead of priv.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
drivers/virtio/virtio-uclass.c | 12 +++---------
test/dm/virtio_device.c | 2 +-
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c
index 927f05e2ccd..7003f30cb85 100644
--- a/drivers/virtio/virtio-uclass.c
+++ b/drivers/virtio/virtio-uclass.c
@@ -257,14 +257,6 @@ static int virtio_uclass_post_probe(struct udevice *udev)
return 0;
}
-static int virtio_uclass_child_post_bind(struct udevice *vdev)
-{
- /* Acknowledge that we've seen the device */
- virtio_add_status(vdev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
-
- return 0;
-}
-
static int virtio_uclass_child_pre_probe(struct udevice *vdev)
{
struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(vdev->parent);
@@ -278,6 +270,9 @@ static int virtio_uclass_child_pre_probe(struct udevice *vdev)
if (device_get_uclass_id(vdev) == UCLASS_BOOTDEV)
return 0;
+ /* Acknowledge that we've seen the device */
+ virtio_add_status(vdev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
+
/*
* Save the real virtio device (eg: virtio-net, virtio-blk) to
* the transport (parent) device's uclass priv for future use.
@@ -394,7 +389,6 @@ UCLASS_DRIVER(virtio) = {
.flags = DM_UC_FLAG_SEQ_ALIAS,
.pre_probe = virtio_uclass_pre_probe,
.post_probe = virtio_uclass_post_probe,
- .child_post_bind = virtio_uclass_child_post_bind,
.child_pre_probe = virtio_uclass_child_pre_probe,
.child_post_probe = virtio_uclass_child_post_probe,
.per_device_auto = sizeof(struct virtio_dev_priv),
diff --git a/test/dm/virtio_device.c b/test/dm/virtio_device.c
index c2cd0630d97..5ac7ef9d309 100644
--- a/test/dm/virtio_device.c
+++ b/test/dm/virtio_device.c
@@ -31,7 +31,7 @@ static int dm_test_virtio_base(struct unit_test_state *uts)
/* check driver status */
ut_assertok(virtio_get_status(dev, &status));
- ut_asserteq(VIRTIO_CONFIG_S_ACKNOWLEDGE, status);
+ ut_asserteq(0, status);
/* probe the virtio-rng driver */
ut_assertok(device_probe(dev));
--
2.43.0
More information about the U-Boot
mailing list