[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/20] hw/scsi: support SCSI-2 passthrough without PI
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 11/20] hw/scsi: support SCSI-2 passthrough without PI |
Date: |
Fri, 6 Apr 2018 19:11:12 +0200 |
From: Daniel Henrique Barboza <address@hidden>
QEMU SCSI code makes assumptions about how the PROTECT and BYTCHK
works in the protocol, denying support for PI (Protection
Information) in case the guest OS requests it. However, in SCSI versions 2
and older, there is no PI concept in the protocol.
This means that when dealing with such devices:
- there is no PROTECT bit in byte 5 of the standard INQUIRY response. The
whole byte is marked as "Reserved";
- there is no RDPROTECT in byte 2 of READ. We have 'Logical Unit Number'
in this field instead;
- there is no VRPROTECT in byte 2 of VERIFY. We have 'Logical Unit Number'
in this field instead. This also means that the BYTCHK bit in this case
is not related to PI.
Since QEMU does not consider these changes, a SCSI passthrough using
a SCSI-2 device will not work. It will mistake these fields with
PI information and return Illegal Request SCSI SENSE thinking
that the driver is asking for PI support.
This patch fixes it by adding a new attribute called 'scsi_version'
that is read from the standard INQUIRY response of passthrough
devices. This allows for a version verification before applying
conditions related to PI that doesn't apply for older versions.
Reported-by: Dac Nguyen <address@hidden>
Signed-off-by: Daniel Henrique Barboza <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/scsi-disk.c | 2 +-
hw/scsi/scsi-generic.c | 47 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 9400b97..ded23d3 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -3041,7 +3041,7 @@ static Property scsi_block_properties[] = {
DEFINE_PROP_BOOL("share-rw", SCSIDiskState, qdev.conf.share_rw, false),
DEFINE_PROP_UINT16("rotation_rate", SCSIDiskState, rotation_rate, 0),
DEFINE_PROP_INT32("scsi_version", SCSIDiskState, qdev.default_scsi_version,
- 5),
+ -1),
DEFINE_PROP_END_OF_LIST(),
};
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 1870085..381f04e 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -194,17 +194,40 @@ static void scsi_read_complete(void * opaque, int ret)
r->buf[3] |= 0x80;
}
}
- if (s->type == TYPE_DISK &&
- r->req.cmd.buf[0] == INQUIRY &&
- r->req.cmd.buf[2] == 0xb0) {
- uint32_t max_transfer =
- blk_get_max_transfer(s->conf.blk) / s->blocksize;
-
- assert(max_transfer);
- stl_be_p(&r->buf[8], max_transfer);
- /* Also take care of the opt xfer len. */
- stl_be_p(&r->buf[12],
- MIN_NON_ZERO(max_transfer, ldl_be_p(&r->buf[12])));
+ if (r->req.cmd.buf[0] == INQUIRY) {
+ /*
+ * EVPD set to zero returns the standard INQUIRY data.
+ *
+ * Check if scsi_version is unset (-1) to avoid re-defining it
+ * each time an INQUIRY with standard data is received.
+ * scsi_version is initialized with -1 in scsi_generic_reset
+ * and scsi_disk_reset, making sure that we'll set the
+ * scsi_version after a reset. If the version field of the
+ * INQUIRY response somehow changes after a guest reboot,
+ * we'll be able to keep track of it.
+ *
+ * On SCSI-2 and older, first 3 bits of byte 2 is the
+ * ANSI-approved version, while on later versions the
+ * whole byte 2 contains the version. Check if we're dealing
+ * with a newer version and, in that case, assign the
+ * whole byte.
+ */
+ if (s->scsi_version == -1 && !(r->req.cmd.buf[1] & 0x01)) {
+ s->scsi_version = r->buf[2] & 0x07;
+ if (s->scsi_version > 2) {
+ s->scsi_version = r->buf[2];
+ }
+ }
+ if (s->type == TYPE_DISK && r->req.cmd.buf[2] == 0xb0) {
+ uint32_t max_transfer =
+ blk_get_max_transfer(s->conf.blk) / s->blocksize;
+
+ assert(max_transfer);
+ stl_be_p(&r->buf[8], max_transfer);
+ /* Also take care of the opt xfer len. */
+ stl_be_p(&r->buf[12],
+ MIN_NON_ZERO(max_transfer, ldl_be_p(&r->buf[12])));
+ }
}
scsi_req_data(&r->req, len);
scsi_req_unref(&r->req);
@@ -550,6 +573,8 @@ static void scsi_generic_realize(SCSIDevice *s, Error
**errp)
DPRINTF("block size %d\n", s->blocksize);
+ /* Only used by scsi-block, but initialize it nevertheless to be clean. */
+ s->default_scsi_version = -1;
scsi_generic_read_device_identification(s);
}
--
1.8.3.1
- [Qemu-devel] [PULL 03/20] scripts/checkpatch.pl: Bug fix, (continued)
- [Qemu-devel] [PULL 03/20] scripts/checkpatch.pl: Bug fix, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 01/20] sys_membarrier: fix up include directives, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 04/20] memfd: fix vhost-user-test on non-memfd capable host, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 05/20] target/i386: WHPX: set CPUID_EXT_HYPERVISOR bit, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 02/20] target/i386: Fix andn instruction, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 06/20] i386/hyperv: add hv-frequencies cpu property, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 07/20] i386/hyperv: error out if features requested but unsupported, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 08/20] configure: Add missing configure options to help text, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 09/20] scsi-disk: Don't enlarge min_io_size to max_io_size, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 11/20] hw/scsi: support SCSI-2 passthrough without PI,
Paolo Bonzini <=
- [Qemu-devel] [PULL 12/20] hw/dma/i82374: Avoid double creation of the 82374 controller, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 10/20] scsi-disk: allow customizing the SCSI version, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 13/20] kvmclock: fix clock_is_reliable on migration from QEMU < 2.9, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 14/20] virtio-serial: fix heapover-flow, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 15/20] qemu-pr-helper: Daemonize before dropping privileges, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 16/20] qemu-pr-helper: Write pidfile more often, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 17/20] device-crash-test: Remove fixed isa-fdc entry, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 18/20] dump: Fix build with newer gcc, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 20/20] Add missing bit for SSE instr in VEX decoding, Paolo Bonzini, 2018/04/06
- [Qemu-devel] [PULL 19/20] maint: Add .mailmap entries for patches claiming list authorship, Paolo Bonzini, 2018/04/06