From 0733605bb1d9aef06ffc28a1d4fff68a1f93a34c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 25 Jun 2025 07:43:06 -0600 Subject: [PATCH] virtio: Acknowledge devices only when probed 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 --- 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 17ef47df030..19728fdbe89 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. @@ -391,7 +386,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 53414e4d3a4..4f335f966df 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));