From 77c76392b0e3c613730ef5932348c3156c3de60f Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:52 +0200 Subject: pc-bios/s390-ccw: Remove duplicate blk_factor adjustment When using virtio-scsi, we multiply the READ(10) data_size by a block factor twice when building the I/O. This is fine, since it's only 1 for SCSI disks, but let's clean it up. Signed-off-by: Eric Farman Reviewed-by: Christian Borntraeger Message-Id: <20170510155359.32727-2-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index d850a8d..69b7a93 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -154,7 +154,7 @@ static bool scsi_read_10(VDev *vdev, VirtioCmd read_10[] = { { &req, sizeof(req), VRING_DESC_F_NEXT }, { &resp, sizeof(resp), VRING_DESC_F_WRITE | VRING_DESC_F_NEXT }, - { data, data_size * f, VRING_DESC_F_WRITE }, + { data, data_size, VRING_DESC_F_WRITE }, }; debug_print_int("read_10 sector", sector); -- cgit v1.1 From 98d3c524359fda04337c8369b617f2d5ef37bf5f Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:53 +0200 Subject: pc-bios/s390-ccw: Move SCSI block factor to outer read Simple refactoring so that the blk_factor adjustment is moved into virtio_scsi_read_many routine, in preparation for another change. Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-3-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/virtio-scsi.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index 69b7a93..6d070e2 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -142,14 +142,13 @@ static bool scsi_report_luns(VDev *vdev, void *data, uint32_t data_size) } static bool scsi_read_10(VDev *vdev, - ulong sector, int sectors, void *data) + ulong sector, int sectors, void *data, + unsigned int data_size) { - int f = vdev->blk_factor; - unsigned int data_size = sectors * virtio_get_block_size() * f; ScsiCdbRead10 cdb = { .command = 0x28, - .lba = sector * f, - .xfer_length = sectors * f, + .lba = sector, + .xfer_length = sectors, }; VirtioCmd read_10[] = { { &req, sizeof(req), VRING_DESC_F_NEXT }, @@ -255,7 +254,10 @@ static void virtio_scsi_locate_device(VDev *vdev) int virtio_scsi_read_many(VDev *vdev, ulong sector, void *load_addr, int sec_num) { - if (!scsi_read_10(vdev, sector, sec_num, load_addr)) { + int f = vdev->blk_factor; + unsigned int data_size = sec_num * virtio_get_block_size() * f; + + if (!scsi_read_10(vdev, sector * f, sec_num * f, load_addr, data_size)) { virtio_scsi_verify_response(&resp, "virtio-scsi:read_many"); } -- cgit v1.1 From 5ffd4a3c2d75db3ed31752d0936f96719ee0257b Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:54 +0200 Subject: pc-bios/s390-ccw: Break up virtio-scsi read into multiples A virtio-scsi request that goes through the host sd driver and exceeds the maximum transfer size is automatically broken up for us. But the equivalent request going to the sg driver presumes that any length requirements have already been honored. Let's use the max_sectors field on the virtio-scsi controller device, and break up all requests (both sd and sg) to avoid this problem. Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-4-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/s390-ccw.h | 7 +++++++ pc-bios/s390-ccw/virtio-scsi.c | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h index 07d8cbc..2089274 100644 --- a/pc-bios/s390-ccw/s390-ccw.h +++ b/pc-bios/s390-ccw/s390-ccw.h @@ -42,6 +42,13 @@ typedef unsigned long long __u64; #ifndef NULL #define NULL 0 #endif +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif +#ifndef MIN_NON_ZERO +#define MIN_NON_ZERO(a, b) ((a) == 0 ? (b) : \ + ((b) == 0 ? (a) : (MIN(a, b)))) +#endif #include "cio.h" #include "iplb.h" diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index 6d070e2..ff65e2e 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -202,6 +202,7 @@ static void virtio_scsi_locate_device(VDev *vdev) debug_print_int("config.scsi.max_channel", vdev->config.scsi.max_channel); debug_print_int("config.scsi.max_target ", vdev->config.scsi.max_target); debug_print_int("config.scsi.max_lun ", vdev->config.scsi.max_lun); + debug_print_int("config.scsi.max_sectors", vdev->config.scsi.max_sectors); if (vdev->scsi_device_selected) { sdev->channel = vdev->selected_scsi_device.channel; @@ -254,12 +255,21 @@ static void virtio_scsi_locate_device(VDev *vdev) int virtio_scsi_read_many(VDev *vdev, ulong sector, void *load_addr, int sec_num) { + int sector_count; int f = vdev->blk_factor; - unsigned int data_size = sec_num * virtio_get_block_size() * f; - - if (!scsi_read_10(vdev, sector * f, sec_num * f, load_addr, data_size)) { - virtio_scsi_verify_response(&resp, "virtio-scsi:read_many"); - } + unsigned int data_size; + + do { + sector_count = MIN_NON_ZERO(sec_num, vdev->config.scsi.max_sectors); + data_size = sector_count * virtio_get_block_size() * f; + if (!scsi_read_10(vdev, sector * f, sector_count * f, load_addr, + data_size)) { + virtio_scsi_verify_response(&resp, "virtio-scsi:read_many"); + } + load_addr += data_size; + sector += sector_count; + sec_num -= sector_count; + } while (sec_num > 0); return 0; } -- cgit v1.1 From 9c12359c577c61ed23f07f7f379434cab2aa1ab2 Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:55 +0200 Subject: pc-bios/s390-ccw: Refactor scsi_inquiry function If we want to issue any of the SCSI Inquiry EVPD pages, which we do, we could use this function to issue both types of commands with a little bit of refactoring. Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-5-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/scsi.h | 6 ++++++ pc-bios/s390-ccw/virtio-scsi.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/scsi.h b/pc-bios/s390-ccw/scsi.h index fc830f7..83ffaef 100644 --- a/pc-bios/s390-ccw/scsi.h +++ b/pc-bios/s390-ccw/scsi.h @@ -26,6 +26,12 @@ #define SCSI_SENSE_KEY_NO_SENSE 0 #define SCSI_SENSE_KEY_UNIT_ATTENTION 6 +/* SCSI Inquiry Types */ +#define SCSI_INQUIRY_STANDARD 0x00U + +/* SCSI Inquiry Pages */ +#define SCSI_INQUIRY_STANDARD_NONE 0x00U + union ScsiLun { uint64_t v64; /* numeric shortcut */ uint8_t v8[8]; /* generic 8 bytes representation */ diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index ff65e2e..9d2e14c 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -89,10 +89,13 @@ static void vs_run(const char *title, VirtioCmd *cmd, VDev *vdev, /* SCSI protocol implementation routines */ -static bool scsi_inquiry(VDev *vdev, void *data, uint32_t data_size) +static bool scsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page, + void *data, uint32_t data_size) { ScsiCdbInquiry cdb = { .command = 0x12, + .b1 = evpd, + .b2 = page, .alloc_len = data_size < 65535 ? data_size : 65535, }; VirtioCmd inquiry[] = { @@ -346,7 +349,10 @@ void virtio_scsi_setup(VDev *vdev) } /* read and cache SCSI INQUIRY response */ - if (!scsi_inquiry(vdev, scsi_inquiry_std_response, + if (!scsi_inquiry(vdev, + SCSI_INQUIRY_STANDARD, + SCSI_INQUIRY_STANDARD_NONE, + scsi_inquiry_std_response, sizeof(scsi_inquiry_std_response))) { virtio_scsi_verify_response(&resp, "virtio-scsi:setup:inquiry"); } -- cgit v1.1 From 8edfe85bef669d676ad17cd84b4e3dce43b110e4 Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:56 +0200 Subject: pc-bios/s390-ccw: Get list of supported VPD pages The "Supported Pages" Inquiry EVPD page is mandatory for all SCSI devices, and is used as a gateway for what VPD pages the device actually supports. Let's issue this Inquiry, and dump that list with the debug facility. Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-6-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/scsi.h | 10 ++++++++++ pc-bios/s390-ccw/virtio-scsi.c | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/scsi.h b/pc-bios/s390-ccw/scsi.h index 83ffaef..803eff8 100644 --- a/pc-bios/s390-ccw/scsi.h +++ b/pc-bios/s390-ccw/scsi.h @@ -28,9 +28,11 @@ /* SCSI Inquiry Types */ #define SCSI_INQUIRY_STANDARD 0x00U +#define SCSI_INQUIRY_EVPD 0x01U /* SCSI Inquiry Pages */ #define SCSI_INQUIRY_STANDARD_NONE 0x00U +#define SCSI_INQUIRY_EVPD_SUPPORTED_PAGES 0x00U union ScsiLun { uint64_t v64; /* numeric shortcut */ @@ -77,6 +79,14 @@ struct ScsiInquiryStd { } __attribute__((packed)); typedef struct ScsiInquiryStd ScsiInquiryStd; +struct ScsiInquiryEvpdPages { + uint8_t peripheral_qdt; /* b0, use (b0 & 0x1f) to get SCSI_INQ_RDT */ + uint8_t page_code; /* b1 */ + uint16_t page_length; /* b2..b3 length = N-3 */ + uint8_t byte[28]; /* b4..bN Supported EVPD pages (N=31 here) */ +} __attribute__((packed)); +typedef struct ScsiInquiryEvpdPages ScsiInquiryEvpdPages; + struct ScsiCdbInquiry { uint8_t command; /* b0, == 0x12 */ uint8_t b1; /* b1, |= 0x01 (evpd) */ diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index 9d2e14c..e34755c 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -19,6 +19,7 @@ static VirtioScsiCmdReq req; static VirtioScsiCmdResp resp; static uint8_t scsi_inquiry_std_response[256]; +static ScsiInquiryEvpdPages scsi_inquiry_evpd_pages_response; static inline void vs_assert(bool term, const char **msgs) { @@ -319,6 +320,8 @@ void virtio_scsi_setup(VDev *vdev) int retry_test_unit_ready = 3; uint8_t data[256]; uint32_t data_size = sizeof(data); + ScsiInquiryEvpdPages *evpd = &scsi_inquiry_evpd_pages_response; + int i; vdev->scsi_device = &default_scsi_device; virtio_scsi_locate_device(vdev); @@ -363,6 +366,20 @@ void virtio_scsi_setup(VDev *vdev) vdev->scsi_block_size = VIRTIO_ISO_BLOCK_SIZE; } + if (!scsi_inquiry(vdev, + SCSI_INQUIRY_EVPD, + SCSI_INQUIRY_EVPD_SUPPORTED_PAGES, + evpd, + sizeof(*evpd))) { + virtio_scsi_verify_response(&resp, "virtio-scsi:setup:supported_pages"); + } + + debug_print_int("EVPD length", evpd->page_length); + + for (i = 0; i <= evpd->page_length; i++) { + debug_print_int("supported EVPD page", evpd->byte[i]); + } + if (!scsi_read_capacity(vdev, data, data_size)) { virtio_scsi_verify_response(&resp, "virtio-scsi:setup:read_capacity"); } -- cgit v1.1 From fe921fc8b7e92020bb140079a9f47f14fb8e9075 Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:57 +0200 Subject: pc-bios/s390-ccw: Get Block Limits VPD device data The "Block Limits" Inquiry VPD page is optional for any SCSI device, but if it's supported it provides a hint of the maximum I/O transfer length for this particular device. If this page is supported by the disk, let's issue that Inquiry and use the minimum of it and the SCSI controller limit. That will cover this scenario: qemu-system-s390x ... -device virtio-scsi-ccw,id=scsi0,max_sectors=32768 ... -drive file=/dev/sda,if=none,id=drive0,format=raw ... -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0, drive=drive0,id=disk0,max_io_size=1048576 controller: 32768 sectors x 512 bytes/sector = 16777216 bytes disk: 1048576 bytes Now that we have a limit for a virtio-scsi disk, compare that with the limit for the virtio-scsi controller when we actually build the I/O. The minimum of these two limits should be the one we use. Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-7-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/scsi.h | 14 ++++++++++++++ pc-bios/s390-ccw/virtio-scsi.c | 21 ++++++++++++++++++++- pc-bios/s390-ccw/virtio.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/scsi.h b/pc-bios/s390-ccw/scsi.h index 803eff8..fe3fd5a 100644 --- a/pc-bios/s390-ccw/scsi.h +++ b/pc-bios/s390-ccw/scsi.h @@ -33,6 +33,7 @@ /* SCSI Inquiry Pages */ #define SCSI_INQUIRY_STANDARD_NONE 0x00U #define SCSI_INQUIRY_EVPD_SUPPORTED_PAGES 0x00U +#define SCSI_INQUIRY_EVPD_BLOCK_LIMITS 0xb0U union ScsiLun { uint64_t v64; /* numeric shortcut */ @@ -87,6 +88,19 @@ struct ScsiInquiryEvpdPages { } __attribute__((packed)); typedef struct ScsiInquiryEvpdPages ScsiInquiryEvpdPages; +struct ScsiInquiryEvpdBl { + uint8_t peripheral_qdt; /* b0, use (b0 & 0x1f) to get SCSI_INQ_RDT */ + uint8_t page_code; + uint16_t page_length; + uint8_t b4; + uint8_t b5; + uint16_t b6; + uint32_t max_transfer; /* b8 */ + uint32_t b12[7]; /* b12..b43 (defined fields) */ + uint32_t b44[5]; /* b44..b63 (reserved fields) */ +} __attribute__((packed)); +typedef struct ScsiInquiryEvpdBl ScsiInquiryEvpdBl; + struct ScsiCdbInquiry { uint8_t command; /* b0, == 0x12 */ uint8_t b1; /* b1, |= 0x01 (evpd) */ diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index e34755c..b722f25 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -20,6 +20,7 @@ static VirtioScsiCmdResp resp; static uint8_t scsi_inquiry_std_response[256]; static ScsiInquiryEvpdPages scsi_inquiry_evpd_pages_response; +static ScsiInquiryEvpdBl scsi_inquiry_evpd_bl_response; static inline void vs_assert(bool term, const char **msgs) { @@ -262,9 +263,11 @@ int virtio_scsi_read_many(VDev *vdev, int sector_count; int f = vdev->blk_factor; unsigned int data_size; + unsigned int max_transfer = MIN_NON_ZERO(vdev->config.scsi.max_sectors, + vdev->max_transfer); do { - sector_count = MIN_NON_ZERO(sec_num, vdev->config.scsi.max_sectors); + sector_count = MIN_NON_ZERO(sec_num, max_transfer); data_size = sector_count * virtio_get_block_size() * f; if (!scsi_read_10(vdev, sector * f, sector_count * f, load_addr, data_size)) { @@ -321,6 +324,7 @@ void virtio_scsi_setup(VDev *vdev) uint8_t data[256]; uint32_t data_size = sizeof(data); ScsiInquiryEvpdPages *evpd = &scsi_inquiry_evpd_pages_response; + ScsiInquiryEvpdBl *evpd_bl = &scsi_inquiry_evpd_bl_response; int i; vdev->scsi_device = &default_scsi_device; @@ -378,6 +382,21 @@ void virtio_scsi_setup(VDev *vdev) for (i = 0; i <= evpd->page_length; i++) { debug_print_int("supported EVPD page", evpd->byte[i]); + + if (evpd->byte[i] != SCSI_INQUIRY_EVPD_BLOCK_LIMITS) { + continue; + } + + if (!scsi_inquiry(vdev, + SCSI_INQUIRY_EVPD, + SCSI_INQUIRY_EVPD_BLOCK_LIMITS, + evpd_bl, + sizeof(*evpd_bl))) { + virtio_scsi_verify_response(&resp, "virtio-scsi:setup:blocklimits"); + } + + debug_print_int("max transfer", evpd_bl->max_transfer); + vdev->max_transfer = evpd_bl->max_transfer; } if (!scsi_read_capacity(vdev, data, data_size)) { diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h index 3388a42..1eaf865 100644 --- a/pc-bios/s390-ccw/virtio.h +++ b/pc-bios/s390-ccw/virtio.h @@ -277,6 +277,7 @@ struct VDev { bool scsi_device_selected; ScsiDevice selected_scsi_device; uint64_t netboot_start_addr; + uint32_t max_transfer; }; typedef struct VDev VDev; -- cgit v1.1 From de4e3ae408ad29ca820ae68e09976e14d80289a6 Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:58 +0200 Subject: pc-bios/s390-ccw: Build a reasonable max_sectors limit Now that we've read all the possible limits that have been defined for a virtio-scsi controller and the disk we're booting from, it's possible that we are STILL going to exceed the limits of the host device. For example, a "-device scsi-generic" device does not support the Block Limits VPD page. So, let's fallback to something that seems to work for most boot configurations if larger values were specified (including if nothing was explicitly specified, and we took default values). Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-8-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/virtio-scsi.c | 9 +++++++++ pc-bios/s390-ccw/virtio-scsi.h | 2 ++ 2 files changed, 11 insertions(+) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index b722f25..f61ecf0 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -399,6 +399,15 @@ void virtio_scsi_setup(VDev *vdev) vdev->max_transfer = evpd_bl->max_transfer; } + /* + * The host sg driver will often be unhappy with particularly large + * I/Os that exceed the block iovec limits. Let's enforce something + * reasonable, despite what the device configuration tells us. + */ + + vdev->max_transfer = MIN_NON_ZERO(VIRTIO_SCSI_MAX_SECTORS, + vdev->max_transfer); + if (!scsi_read_capacity(vdev, data, data_size)) { virtio_scsi_verify_response(&resp, "virtio-scsi:setup:read_capacity"); } diff --git a/pc-bios/s390-ccw/virtio-scsi.h b/pc-bios/s390-ccw/virtio-scsi.h index f50b38b..4c4f4bb 100644 --- a/pc-bios/s390-ccw/virtio-scsi.h +++ b/pc-bios/s390-ccw/virtio-scsi.h @@ -19,6 +19,8 @@ #define VIRTIO_SCSI_CDB_SIZE SCSI_DEFAULT_CDB_SIZE #define VIRTIO_SCSI_SENSE_SIZE SCSI_DEFAULT_SENSE_SIZE +#define VIRTIO_SCSI_MAX_SECTORS 2048 + /* command-specific response values */ #define VIRTIO_SCSI_S_OK 0x00 #define VIRTIO_SCSI_S_BAD_TARGET 0x03 -- cgit v1.1 From f881bbdf72178166e88fdd8cc8b40e1812efb53c Mon Sep 17 00:00:00 2001 From: Eric Farman Date: Wed, 10 May 2017 17:53:59 +0200 Subject: pc-bios/s390-ccw.img: rebuild image Contains the following commits: - pc-bios/s390-ccw: Remove duplicate blk_factor adjustment - pc-bios/s390-ccw: Move SCSI block factor to outer read - pc-bios/s390-ccw: Break up virtio-scsi read into multiples - pc-bios/s390-ccw: Refactor scsi_inquiry function - pc-bios/s390-ccw: Get list of supported EVPD pages - pc-bios/s390-ccw: Get Block Limits VPD device data - pc-bios/s390-ccw: Build a reasonable max_sectors limit Signed-off-by: Eric Farman Message-Id: <20170510155359.32727-9-farman@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw.img | Bin 26472 -> 26480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'pc-bios') diff --git a/pc-bios/s390-ccw.img b/pc-bios/s390-ccw.img index 0b01d49..5ad0564 100644 Binary files a/pc-bios/s390-ccw.img and b/pc-bios/s390-ccw.img differ -- cgit v1.1