virtio-scsi: Add max_target and max_lun knobs
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest5 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | scsi: Split SCSIBusInfo structhw/ hw/ hw/ +14 more | +90 | 0 replies | |
| 2/5 | scsi: Rename SCSIBusInfo to SCSIBusOpshw/ hw/ hw/ +14 more | +61 | 0 replies | |
| 3/5 | virtio-scsi: Use errp in virtio_scsi_device_realizehw/ | +5 | 0 replies | |
| 4/5 | virtio-scsi: Make max_target parameter configurablehw/ hw/ hw/ +1 more | +34 | 1 reply | |
| 5/5 | virtio-scsi: Make max_lun parameter configurablehw/ hw/ hw/ +1 more | +9 | 1 reply |
Reviews trailers per patch
1 of 5 patches has a Reviewed-by or Acked-by.
| Patch | Raphael Norwitz |
|---|---|
| 1/5 | |
| 2/5 | |
| 3/5 | |
| 4/5 | R-b |
| 5/5 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/5] virtio-scsi: Add max_target and max_lun knobs
This series introduces an option to override the maximum number of targets and LUNs, now set to VIRTIO_SCSI_MAX_TARGET and VIRTIO_SCSI_MAX_LUN respectively, via max_target and max_lun properties in virtio-scsi and vhost-scsi devices.
When probing a device, the driver walks through all possible targets to discover what is available on the bus. In the process, it sends INQUIRY commands, including to devices that do not exist. The issue can be observed in a guest with a single scsi-hd device, with verbose SCSI logging enabled:
scsi 0:0:0:0: scsi scan: REPORT LUN scan
scsi 0:0:0:0: scsi scan: device exists on 0:0:0:0 scsi 0:0:1:0: scsi scan: INQUIRY pass 1 length 36 scsi 0:0:1:0: scsi scan: INQUIRY failed with code 0x40000 (...)
scsi 0:0:255:0: scsi scan: INQUIRY pass 1 length 36 scsi 0:0:255:0: scsi scan: INQUIRY failed with code 0x40000
The issue is more noticeable with the vhost-scsi backend. On hypervisors without the patch [2], each INQUIRY queued up for a non-existent target triggers vq_error(), registered by vhost_virtqueue_error_notifier(), resulting in a flood of "vhost vring error in virtqueue X" messages when booting a VM.
Even with [2] applied, we still send commands to phantom targets and have no way to stop the scan earlier, spending more time in virtscsi_probe() than necessary.
The fourth patch in the series addresses this issue by introducing the "max_target" property for virtio-scsi, vhost-scsi and vhost-user-scsi devices. This provides an option to specify how many targets are used by the guest, and to stop scanning before hitting VIRTIO_SCSI_MAX_TARGET.
A similar issue can be seen when scanning LUNs on existing targets. For example, the OVMF VirtioScsiDxe driver queues up INQUIRY for each 0..7 LUN, even if only LUN 0 is available. This can be easily observed when using a vhost-scsi backend, as such messages appear in the hypervisor dmesg when booting up a guest:
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000001 from naa.5001405277e02c68
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000002 from naa.5001405277e02c68
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000003 from naa.5001405277e02c68
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000004 from naa.5001405277e02c68
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000005 from naa.5001405277e02c68
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000006 from naa.5001405277e02c68
TARGET_CORE[vhost]: Detected NON_EXISTENT_LUN Access for 0x00000007 from naa.5001405277e02c68
The last patch of the series provides a way to specify how many LUNs are actually present by setting the "max_lun" property in virtio-scsi, vhost-scsi and vhost-user-scsi devices.
If neither property is specified, max_target and max_lun are set to their default values.
The series overview:
- Patches 1-2 - refactoring of SCSIBusInfo suggested by Alex Bennée in [1] that splits the struct into two: one for bus callbacks, SCSIBusOps, the other for bus configuration, SCSIBusConfig
- Patch 3 - use errp in virtio_scsi_device_realize() instead of
a local error variable
- Patch 4 - introduction of the max_target parameter
- Patch 5 - introduction of the max_lun parameter
This is a complete rewrite of the [3] series, so I decided to submit it as a new patchset, instead of labeling it v2.
Testing: In addition to running make check, I ran a guest with multiple
virtio-scsi-pci and vhost-scsi controllers using different max_target values, verified that the properties are set, and tried hotplugging virtio-scsi devices to see if the custom max_target setting is respected.
----
[1] - https://lore.kernel.org/all/[email protected]/
[2] -
https://lore.kernel.org/virtualization/[email protected]/T/#u
[3] -
https://lore.kernel.org/all/[email protected]
Karolina Stolarek (5):
scsi: Split SCSIBusInfo struct
scsi: Rename SCSIBusInfo to SCSIBusOps
virtio-scsi: Use errp in virtio_scsi_device_realize
virtio-scsi: Make max_target parameter configurable
virtio-scsi: Make max_lun parameter configurable
hw/scsi/esp-pci.c | 7 ++-- hw/scsi/esp.c | 7 ++-- hw/scsi/lasi_ncr710.c | 6 ++-- hw/scsi/lsi53c895a.c | 6 ++-- hw/scsi/megasas.c | 7 ++-- hw/scsi/mptsas.c | 9 +++-- hw/scsi/ncr53c710.c | 6 ++-- hw/scsi/scsi-bus.c | 64 +++++++++++++++++---------------- hw/scsi/scsi-disk.c | 2 +- hw/scsi/spapr_vscsi.c | 7 ++-- hw/scsi/vhost-scsi.c | 4 +++ hw/scsi/vhost-user-scsi.c | 4 +++ hw/scsi/virtio-scsi.c | 51 ++++++++++++++++++-------- hw/scsi/vmw_pvscsi.c | 7 ++-- hw/ufs/lu.c | 8 +++-- hw/usb/dev-storage-bot.c | 7 ++-- hw/usb/dev-storage-classic.c | 6 ++-- hw/usb/dev-uas.c | 7 ++-- include/hw/scsi/scsi.h | 22 ++++++++---- include/hw/virtio/virtio-scsi.h | 4 +++ scripts/checkpatch.pl | 2 +- 21 files changed, 161 insertions(+), 82 deletions(-)
Signature · 1 line
2.47.1