virtscsi_probe() registers the SCSI host, and scsi_add_host() adds the
class device carrying the host's write-only "scan" attribute. A write to it
reaches scsi_scan_host_selected(), which submits INQUIRY commands on a
request virtqueue, notifying the device.
virtscsi_probe() calls virtio_device_ready() only after scsi_add_host() has
returned, by which point that attribute is already writable. The virtio
spec is explicit about that ordering in 3.1 Device Initialization:
| The driver MUST NOT send any buffer available notifications to the
| device before setting DRIVER_OK.
Set DRIVER_OK before registering the host, as done for the same reason in
commit f5866db64f34 ("virtio_console: enable VQs early") and commit
1d774589f924 ("i2c: virtio: mark device ready before registering the
adapter"). scsi_add_host() can fail and now runs with DRIVER_OK set, so
reset the device on that path using the driver's existing
virtscsi_remove_vqs() helper; the core does not reset it when probe fails.
Fixes: 4fe74b1cb051 ("[SCSI] virtio-scsi: SCSI driver for QEMU based virtual
machines")
Signed-off-by: Jasper Wise <[email protected]>
---
drivers/scsi/virtio_scsi.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 5fdaa71f0652..b394de0335d8 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -976,12 +976,12 @@ static int virtscsi_probe(struct virtio_device *vdev)
}
#endif
+ virtio_device_ready(vdev);
+
err = scsi_add_host(shost, &vdev->dev);
if (err)
goto scsi_add_host_failed;
- virtio_device_ready(vdev);
-
for (int i = 0; i < VIRTIO_SCSI_EVENT_LEN; i++)
INIT_WORK(&vscsi->event_list[i].work, virtscsi_handle_event);
@@ -991,7 +991,7 @@ static int virtscsi_probe(struct virtio_device *vdev)
return 0;
scsi_add_host_failed:
- vdev->config->del_vqs(vdev);
+ virtscsi_remove_vqs(vdev);
virtscsi_init_failed:
scsi_host_put(shost);
return err;
base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff
--
2.50.1