Hi all, We know that the seg_max of virtio-scsi respects to virtqueue size: scsiconf->seg_max is set to virtqueue size - 2.
Some of my scsi HBAs have max_segments as low as 64 in host(max_sectors_kb is 256). When I use scsi lun passthrough disk in guest, In case of default virtqueue size(256), The max_segments of the disk in guest is 254. In this scenario: host:~ # sg_vpd --page=bl /dev/sdb Block limits VPD page (SBC): Write same non-zero (WSNZ): 0 Maximum compare and write length: 0 blocks [Command not implemented] Optimal transfer length granularity: 512 blocks Maximum transfer length: 512 blocks Optimal transfer length: 512 blocks host:~ # cat /sys/block/sdb/queue/max_sectors_kb 256 host:~ # cat /sys/block/sdb/queue/max_hw_sectors_kb 256 host:~ # cat /sys/block/sdb/queue/max_segments 64 host:~ # cat /sys/block/sdb/queue/max_hw_sectors_kb 256 guest:~ # sg_vpd --page=bl /dev/sdb Block limits VPD page (SBC): Write same non-zero (WSNZ): 0 Maximum compare and write length: 0 blocks [Command not implemented] Optimal transfer length granularity: 512 blocks Maximum transfer length: 512 blocks Optimal transfer length: 512 blocks guest:~ # cat /sys/block/sdb/queue/max_sectors_kb 256 guest:~ # cat /sys/block/sdb/queue/max_hw_sectors_kb 32767 guest:~ # cat /sys/block/sdb/queue/max_segments 254 guest:~ # cat /sys/block/sdb/queue/max_segment_size 65536 Performing "mkfs.xfs -f /dev/sdb" in guest triggers I/O errors. The error message in stdout: mkfs.xfs: libxfs_device_zero write failed: Remote I/O error And the error message in dmesg: [ 887.867763] sd 6:0:0:2: [sdb] tag#147 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE [ 887.867766] sd 6:0:0:2: [sdb] tag#147 Sense Key : Illegal Request [current] [ 887.867773] sd 6:0:0:2: [sdb] tag#147 Add. Sense: Invalid field in cdb [ 887.867775] sd 6:0:0:2: [sdb] tag#147 CDB: Write(10) 2a 00 0f a3 00 40 00 02 00 00 [ 887.867778] blk_update_request: critical target error, dev sdb, sector 262340672 op 0x1:(WRITE) flags 0x8800 phys_seg 65 prio class 0 I found 2 ways to workaround the I/O error: * Reduce the max_sectors_kb value in guest. E.g: 256->255 or lower. * Modify virtio-scsi code to assign scsiconf->seg_max = max_hw_iov - 2 (in my scenario, the max_hw_iov is 64) I'm wondering that the seg_max always respects to virtqueue size, Is it reasonable? In case the max_segments of host scsi HBA is very low, say 64, Does the max_segments=254 in guest make sense? Obviously the value exceed the host limit, Does it cause I/O issue? Thanks, Lin