Host devices passed through as scsi-block or scsi-generic may have a compound maximum I/O limit (out of physical hardware limit, driver quirks and file system configuration, etc) that is presented in the sysfs entry. SG_IOs we issue should respect this. However the value is currently not discoverable by guest, because the vHBA (virtio-scsi) would present an fixed emulated limit, while the INQUIRY (vpd=0xb0, block limits page) response solely speaks for the LUN itself, not the host kernel. The issue is observed on scsi passthrough of host usb or dm-multipath disks, and it is not specific to certain device types.
The proposed solution is collecting the host sysfs limit in raw-posix driver when a block device is used, and intercepting INQUIRY response to clip the max xfer len field. This fixes booting a SanDisk usb-key with an upstream kernel. The usb disk reports a nonsense large value in INQUIRY, while the host (usb quirk?) only allows 120KB. Fam Zheng (2): raw-posix: Fetch max sectors for host block device from sysfs scsi-generic: Merge block max xfer len in INQUIRY response block/raw-posix.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ hw/scsi/scsi-generic.c | 12 ++++++++++++ 2 files changed, 59 insertions(+) -- 2.8.2