From: Jasper Wise <jaspwise@amazon.co.uk>
To: <mst@redhat.com>, <jasowangio@gmail.com>,
<James.Bottomley@HansenPartnership.com>,
<martin.petersen@oracle.com>
Cc: <pbonzini@redhat.com>, <stefanha@redhat.com>,
<eperezma@redhat.com>, <virtualization@lists.linux.dev>,
<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<nh-open-source@amazon.com>
Subject: [PATCH] scsi: virtio_scsi: set DRIVER_OK before registering the SCSI host
Date: Thu, 13 Aug 2026 08:44:05 +0000 [thread overview]
Message-ID: <20260813084405.610322-1-jaspwise@amazon.co.uk> (raw)
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 <jaspwise@amazon.co.uk>
---
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
reply other threads:[~2026-08-13 8:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260813084405.610322-1-jaspwise@amazon.co.uk \
--to=jaspwise@amazon.co.uk \
--cc=James.Bottomley@HansenPartnership.com \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mst@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox