qemu/hw
Daniel Henrique Barboza a71c775b24 hw/scsi: add VPD Block Limits emulation
The VPD Block Limits Inquiry page is optional, allowing SCSI devices
to not implement it. This is the case for devices like the MegaRAID
SAS 9361-8i and Microsemi PM8069.

In case of SCSI passthrough, the response of this request is used by
the QEMU SCSI layer to set the max_io_sectors that the guest
device will support, based on the value of the max_sectors_kb that
the device has set in the host at that time. Without this response,
the guest kernel is free to assume any value of max_io_sectors
for the SCSI device. If this value is greater than the value from
the host, SCSI Sense errors will occur because the guest will send
read/write requests that are larger than the underlying host device
is configured to support. An example of this behavior can be seen
in [1].

A workaround is to set the max_sectors_kb host value back in the guest
kernel (a process that can be automated using rc.local startup scripts
and the like), but this has several drawbacks:

- it can be troublesome if the guest has many passthrough devices that
needs this tuning;

- if a change in max_sectors_kb is made in the host side, manual change
in the guests will also be required;

- during an OS install it is difficult, and sometimes not possible, to
go to a terminal and change the max_sectors_kb prior to the installation.
This means that the disk can't be used during the install process. The
easiest alternative here is to roll back to scsi-hd, install the guest
and then go back to SCSI passthrough when the installation is done and
max_sectors_kb can be set.

An easier way would be to QEMU handle the absence of the Block Limits
VPD device response, setting max_io_sectors accordingly and allowing
the guest to use the device without the hassle.

This patch adds emulation of the Block Limits VPD response for
SCSI passthrough devices of type TYPE_DISK that doesn't support
it. The following changes were made:

- scsi_handle_inquiry_reply will now check the available VPD
pages from the Inquiry EVPD reply. In case the device does not

- a new function called scsi_generic_set_vpd_bl_emulation,
that is called during device realize,  was created to set a
new flag 'needs_vpd_bl_emulation' of the device. This function
retrieves the Inquiry EVPD response of the device to check for
VPD BL support.

- scsi_handle_inquiry_reply will now check the available VPD
pages from the Inquiry EVPD reply in case the device needs
VPD BL emulation, adding the Block Limits page (0xb0) to
the list. This will make the guest kernel aware of the
support that we're now providing by emulation.

- a new function scsi_emulate_block_limits creates the
emulated Block Limits response. This function is called
inside scsi_read_complete in case the device requires
Block Limits VPD emulation and we detected a SCSI Sense
error in the VPD Block Limits reply that was issued
from the guest kernel to the device. This error is
expected: we're reporting support from our side, but
the device isn't aware of it.

With this patch, the guest now queries the Block Limits
page during the device configuration because it is being
advertised in the Supported Pages response. It will either
receive the Block Limits page from the hardware, if it supports
it, or will receive an emulated response from QEMU. At any rate,
the guest now has the information to set the max_sectors_kb
parameter accordingly, sparing the user of SCSI sense errors
that would happen without the emulated response and in the
absence of Block Limits support from the hardware.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1566195

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1566195
Reported-by: Dac Nguyen <dacng@us.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20180627172432.11120-4-danielhb413@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-06-29 13:02:50 +02:00
..
9pfs 9p: xattr: Properly translate xattrcreate flags 2018-06-07 12:17:22 +02:00
acpi nvdimm: make persistence option symbolic 2018-06-11 22:19:57 +03:00
adc Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
alpha iommu: Add IOMMU index argument to translate method 2018-06-15 15:23:34 +01:00
arm aspeed/timer: use the APB frequency from the SCU 2018-06-26 17:50:42 +01:00
audio audio/hda: enable new timer code by default. 2018-06-25 13:57:57 +02:00
block Replace '-enable-kvm' with '-accel kvm' in docs and help texts 2018-06-28 19:05:32 +02:00
bt hw/bt: Replace fprintf(stderr, "*\n" with error_report() 2018-01-22 09:51:00 +01:00
char hw/char/serial: Only retry if qemu_chr_fe_write returns 0 2018-06-28 19:05:30 +02:00
core Revert "bus: do not unref the added child bus on realize" 2018-06-18 09:15:51 +02:00
cpu hw: use "qemu/osdep.h" as first #include in source files 2017-12-18 17:07:02 +03:00
cris hw: Do not include "sysemu/block-backend.h" if it is not necessary 2018-06-01 14:15:10 +02:00
display ramfb: fix overflow 2018-06-26 16:04:01 +02:00
dma hw/dma/omap_dma: Use qemu_log_mask(GUEST_ERROR) instead of fprintf 2018-06-26 17:50:40 +01:00
gpio hw/i2c: Use DeviceClass::realize instead of I2CSlaveClass::init 2018-06-01 15:14:31 +02:00
hppa acpi, vhost, misc: fixes, features 2018-06-04 10:15:16 +01:00
i2c hw/i2c/omap_i2c: Use qemu_log_mask(UNIMP) instead of fprintf 2018-06-26 17:50:40 +01:00
i386 hmp: obsolete "info ioapic" 2018-06-28 19:05:37 +02:00
ide ahci: fix FIS I bit and PIO Setup FIS interrupt 2018-06-25 16:50:48 -04:00
input hw/input/tsc2005: Use qemu_log_mask(GUEST_ERROR) instead of fprintf 2018-06-26 17:50:40 +01:00
intc hmp: obsolete "info ioapic" 2018-06-28 19:05:37 +02:00
ipack pci: Add INTERFACE_CONVENTIONAL_PCI_DEVICE to Conventional PCI devices 2017-10-15 05:54:43 +03:00
ipmi object: fix OBJ_PROP_LINK_UNREF_ON_RELEASE ambivalence 2018-06-12 12:07:30 +02:00
isa hw/isa/smc37c669: Change the parallel I/O base to 378H 2018-06-16 19:46:54 -10:00
lm32 hw: Do not include "sysemu/block-backend.h" if it is not necessary 2018-06-01 14:15:10 +02:00
m68k hw/m68k/mcf5206: Convert away from old_mmio 2018-06-15 15:23:34 +01:00
mem pc-dimm: get_memory_region() will not fail after realize 2018-06-28 19:05:34 +02:00
microblaze hw: Do not include "sysemu/block-backend.h" if it is not necessary 2018-06-01 14:15:10 +02:00
mips hw/mips/jazz: create ESP device directly via qdev 2018-06-28 19:05:35 +02:00
misc hostmem: drop error variable from host_memory_backend_get_memory() 2018-06-28 19:05:33 +02:00
moxie Change references to serial_hds[] to serial_hd() 2018-04-26 13:57:00 +01:00
net hw/net/smc91c111: Use qemu_log_mask(UNIMP) instead of fprintf 2018-06-26 17:50:41 +01:00
nios2 Change references to serial_hds[] to serial_hd() 2018-04-26 13:57:00 +01:00
nvram * Linux header upgrade (Peter) 2018-06-01 18:24:16 +01:00
openrisc Change references to serial_hds[] to serial_hd() 2018-04-26 13:57:00 +01:00
pci virtio,vhost,pci,pc: features, cleanups 2018-03-20 15:48:34 +00:00
pci-bridge virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
pci-host hw/pci-host/xilinx-pcie: don't make "io" region be RAM 2018-06-27 20:12:34 +02:00
pcmcia hw: Clean up includes 2016-01-29 15:07:25 +00:00
ppc pc-dimm: get_memory_region() will not fail after realize 2018-06-28 19:05:34 +02:00
rdma hw/rdma: Fix possible out of bounds access to port GID index 2018-05-03 20:52:29 +03:00
riscv hw: Do not include "exec/address-spaces.h" if it is not necessary 2018-06-01 14:15:10 +02:00
s390x s390x/ipl: Try to detect Linux vs non Linux for initial IPL PSW 2018-06-18 10:50:32 +02:00
scsi hw/scsi: add VPD Block Limits emulation 2018-06-29 13:02:50 +02:00
sd hw/sd/omap_mmc: Use qemu_log_mask(UNIMP) instead of printf 2018-06-26 17:50:40 +01:00
sh4 hw/sh/sh7750: Convert away from old_mmio 2018-06-15 15:23:34 +01:00
smbios Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
sparc hw/sparc/sun4m: Fix problems with device introspection 2018-06-17 11:12:53 +01:00
sparc64 hw/sparc64/sun4u: Fix introspection by converting prom instance_init to realize 2018-06-17 11:12:41 +01:00
ssi hw/ssi/omap_spi: Use qemu_log_mask(GUEST_ERROR) instead of fprintf 2018-06-26 17:50:40 +01:00
timer aspeed/timer: use the APB frequency from the SCU 2018-06-26 17:50:42 +01:00
tpm tpm: extend TPM TIS with state migration support 2018-05-24 12:07:04 -04:00
tricore hw: Do not include "sysemu/block-backend.h" if it is not necessary 2018-03-12 16:12:46 +01:00
unicore32 hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h 2018-03-12 16:12:48 +01:00
usb Revert "usb: release the created buses" 2018-06-18 09:15:51 +02:00
vfio vfio-ccw: add force unlimited prefetch property 2018-06-18 10:50:32 +02:00
virtio iommu: Add IOMMU index argument to notifier APIs 2018-06-15 15:23:34 +01:00
watchdog hw/watchdog/wdt_i6300esb: Convert away from old_mmio 2018-06-15 15:23:34 +01:00
xen xen: Don't use memory_region_init_ram_nomigrate() in pci_assign_dev_load_option_rom() 2018-06-22 13:28:42 +01:00
xenpv hw/xen*: Replace fprintf(stderr, "*\n" with error_report() 2018-02-06 18:29:46 +01:00
xtensa hw: Do not include "sysemu/block-backend.h" if it is not necessary 2018-06-01 14:15:10 +02:00
Makefile.objs hw: allow compiling out SCSI 2018-06-01 15:14:31 +02:00