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 <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-06-25 07:43:06 -06:00
parent 4fd75b4346
commit 0733605bb1
2 changed files with 4 additions and 10 deletions

View File

@@ -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),

View File

@@ -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));