virtio-scsi: fix hot-plug event racing device realize
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest1 patch 3 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/1 | virtio-scsi: fix hot-plug event racing device realizehw/ | +27 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/1] virtio-scsi: fix hot-plug event racing device realize
A disk or CD-ROM hot-plugged into virtio-scsi sometimes never shows up in the guest. QEMU has the device, the guest has consumed the RESCAN event, and a manual bus rescan finds the LUN at once. We see this in CI with Windows Server guests (vioscsi) and with Linux guests, always with the controller on an iothread.
The event is pushed from the plug() callback, before the device is realized, and the iothread request path does not see unrealized devices since 8ddf958e8d62. A guest that scans right away gets BAD_TARGET and does not retry. The patch moves the event to a main-loop bottom half. The alternative, letting the request path see a plugged but unrealized device, would undo what 8ddf958e8d62 protects against.
There is no test in the patch. The window lies inside a single device_add under the BQL, and a qtest or iotests client is served by the same main loop, so it cannot send a request in between. To reproduce, I booted a Linux guest with virtio-scsi on an iothread, ran QEMU under gdb in non-stop mode and stalled the main thread for 3 s in scsi_bus_set_ua(), right after the event is pushed, then hot-plugged a scsi-cd:
break scsi_bus_set_ua
commands
call (int)usleep(3000000)
continueend
Without the patch the guest never enumerated the LUN (3 of 3 runs). With the patch the same stall falls after realize and the LUN appeared every time (3 of 3). Without the stall both builds pass, which is why this only shows up on loaded hosts. tests/qtest virtio-scsi passes.
Every release since 5.2 has the bug, hence qemu-stable.
Denis V. Lunev (1):
virtio-scsi: fix hot-plug event racing device realize
hw/scsi/virtio-scsi.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
base-commit: b6c4b7e86dec12d07f5cac65265b986d38ee9002
Signature · 1 line
2.53.0