From nobody Sat Nov 23 22:21:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729689578; cv=none; d=zohomail.com; s=zohoarc; b=aEq55D2Wa3utU5bzhg7ZAgYp4g5PSCQwzDSenJi8WXDasG0LgQ8QS7xXoarDcRbhW4ea+cdnOao/HtAx8NVAgvVKQ5sSlxxn709mV5sTaR1eeXA41W5/2VKyOtzyYPrb/V2EPj1VqDXUP7UaLbwEUqMn4dt/7++eiNaYeE8cppo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689578; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=atR3A5VkXgm97I9Vq/CR2yJyLTLLNn3U8+9PbctvM20=; b=QfQTi2zUgAToMRFTsjfc5Hl0MZok569hl8rLxz819P9s9B7P8I4JjtfLI+d2b6/FLFgjL6xSO95la9wy4GevXbExuFZZmwZKOo55sfrAD2oGGswwI0uXKM0n+X+55DphIUqLDLPM/9dpIbPCKzIpD9pibQVijo7zy2+57ITDQLs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729689578295257.55705830926024; Wed, 23 Oct 2024 06:19:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3bFS-0006So-GG; Wed, 23 Oct 2024 09:18:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3bFA-00069I-Rp for qemu-devel@nongnu.org; Wed, 23 Oct 2024 09:17:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3bF8-0002Ak-EM for qemu-devel@nongnu.org; Wed, 23 Oct 2024 09:17:44 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-D-QKvYcWMVarJnBMZDm8RQ-1; Wed, 23 Oct 2024 09:17:38 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6B4951955D61; Wed, 23 Oct 2024 13:17:37 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.43]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BDF9D1956054; Wed, 23 Oct 2024 13:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729689461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=atR3A5VkXgm97I9Vq/CR2yJyLTLLNn3U8+9PbctvM20=; b=XmTFVAc4c3VRBwmQAIjATO9tSS1UjDw+09Q1ZLAgp8P4QQ/9Rk0YRDBek/h+AiLBBukkPq 1jah8FJhD65QlABONethm71zaU0y4R1lZ/eiDsSGCZuoRZOyHJWRqGVo9rI43NN/IY5miy MQ0go8tZmtRXrj4Bey1+kx+7z5W7XF4= X-MC-Unique: D-QKvYcWMVarJnBMZDm8RQ-1 From: Thomas Huth To: qemu-devel@nongnu.org Cc: Peter Maydell , Jared Rossi Subject: [PULL 09/23] pc-bios/s390-ccw: Remove panics from SCSI IPL path Date: Wed, 23 Oct 2024 15:16:56 +0200 Message-ID: <20241023131710.906748-10-thuth@redhat.com> In-Reply-To: <20241023131710.906748-1-thuth@redhat.com> References: <20241023131710.906748-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.263, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.697, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729689578498116600 Content-Type: text/plain; charset="utf-8" From: Jared Rossi Remove panic-on-error from virtio-scsi IPL specific functions so that error recovery may be possible in the future. Functions that would previously panic now provide a return code. Signed-off-by: Jared Rossi Reviewed-by: Thomas Huth Message-ID: <20241020012953.1380075-10-jrossi@linux.ibm.com> Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/bootmap.c | 88 ++++++++++++++----- pc-bios/s390-ccw/virtio-blkdev.c | 4 +- pc-bios/s390-ccw/virtio-scsi.c | 143 +++++++++++++++++++++---------- 3 files changed, 164 insertions(+), 71 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index b9596e28c7..652807a16a 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -595,7 +595,7 @@ static int ipl_eckd(void) * IPL a SCSI disk */ =20 -static void zipl_load_segment(ComponentEntry *entry) +static int zipl_load_segment(ComponentEntry *entry) { const int max_entries =3D (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr)); ScsiBlockPtr *bprs =3D (void *)sec; @@ -615,7 +615,10 @@ static void zipl_load_segment(ComponentEntry *entry) do { memset(bprs, FREE_SPACE_FILLER, bprs_size); fill_hex_val(blk_no, &blockno, sizeof(blockno)); - read_block(blockno, bprs, err_msg); + if (virtio_read(blockno, bprs)) { + puts(err_msg); + return -EIO; + } =20 for (i =3D 0;; i++) { uint64_t *cur_desc =3D (void *)&bprs[i]; @@ -643,23 +646,37 @@ static void zipl_load_segment(ComponentEntry *entry) } address =3D virtio_load_direct(cur_desc[0], cur_desc[1], 0, (void *)address); - IPL_assert(address !=3D -1, "zIPL load segment failed"); + if (!address) { + puts("zIPL load segment failed"); + return -EIO; + } } } while (blockno); + + return 0; } =20 /* Run a zipl program */ -static void zipl_run(ScsiBlockPtr *pte) +static int zipl_run(ScsiBlockPtr *pte) { ComponentHeader *header; ComponentEntry *entry; uint8_t tmp_sec[MAX_SECTOR_SIZE]; =20 - read_block(pte->blockno, tmp_sec, "Cannot read header"); + if (virtio_read(pte->blockno, tmp_sec)) { + puts("Cannot read header"); + return -EIO; + } header =3D (ComponentHeader *)tmp_sec; =20 - IPL_assert(magic_match(tmp_sec, ZIPL_MAGIC), "No zIPL magic in header"= ); - IPL_assert(header->type =3D=3D ZIPL_COMP_HEADER_IPL, "Bad header type"= ); + if (!magic_match(tmp_sec, ZIPL_MAGIC)) { + puts("No zIPL magic in header"); + return -EINVAL; + } + if (header->type !=3D ZIPL_COMP_HEADER_IPL) { + puts("Bad header type"); + return -EINVAL; + } =20 dputs("start loading images\n"); =20 @@ -674,22 +691,30 @@ static void zipl_run(ScsiBlockPtr *pte) continue; } =20 - zipl_load_segment(entry); + if (zipl_load_segment(entry)) { + return -1; + } =20 entry++; =20 - IPL_assert((uint8_t *)(&entry[1]) <=3D (tmp_sec + MAX_SECTOR_SIZE), - "Wrong entry value"); + if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) { + puts("Wrong entry value"); + return -EINVAL; + } } =20 - IPL_assert(entry->component_type =3D=3D ZIPL_COMP_ENTRY_EXEC, "No EXEC= entry"); + if (entry->component_type !=3D ZIPL_COMP_ENTRY_EXEC) { + puts("No EXEC entry"); + return -EINVAL; + } =20 /* should not return */ write_reset_psw(entry->compdat.load_psw); jump_to_IPL_code(0); + return -1; } =20 -static void ipl_scsi(void) +static int ipl_scsi(void) { ScsiMbr *mbr =3D (void *)sec; int program_table_entries =3D 0; @@ -700,10 +725,13 @@ static void ipl_scsi(void) =20 /* Grab the MBR */ memset(sec, FREE_SPACE_FILLER, sizeof(sec)); - read_block(0, mbr, "Cannot read block 0"); + if (virtio_read(0, mbr)) { + puts("Cannot read block 0"); + return -EIO; + } =20 if (!magic_match(mbr->magic, ZIPL_MAGIC)) { - return; + return 0; } =20 puts("Using SCSI scheme."); @@ -711,11 +739,20 @@ static void ipl_scsi(void) IPL_check(mbr->version_id =3D=3D 1, "Unknown MBR layout version, assuming version 1"); debug_print_int("program table", mbr->pt.blockno); - IPL_assert(mbr->pt.blockno, "No Program Table"); + if (!mbr->pt.blockno) { + puts("No Program Table"); + return -EINVAL; + } =20 /* Parse the program table */ - read_block(mbr->pt.blockno, sec, "Error reading Program Table"); - IPL_assert(magic_match(sec, ZIPL_MAGIC), "No zIPL magic in PT"); + if (virtio_read(mbr->pt.blockno, sec)) { + puts("Error reading Program Table"); + return -EIO; + } + if (!magic_match(sec, ZIPL_MAGIC)) { + puts("No zIPL magic in Program Table"); + return -EINVAL; + } =20 for (i =3D 0; i < MAX_BOOT_ENTRIES; i++) { if (prog_table->entry[i].scsi.blockno) { @@ -725,17 +762,22 @@ static void ipl_scsi(void) } =20 debug_print_int("program table entries", program_table_entries); - IPL_assert(program_table_entries !=3D 0, "Empty Program Table"); + if (program_table_entries =3D=3D 0) { + puts("Empty Program Table"); + return -EINVAL; + } =20 if (menu_is_enabled_enum()) { loadparm =3D menu_get_enum_boot_index(valid_entries); } =20 debug_print_int("loadparm", loadparm); - IPL_assert(loadparm < MAX_BOOT_ENTRIES, "loadparm value greater than" - " maximum number of boot entries allowed"); + if (loadparm >=3D MAX_BOOT_ENTRIES) { + puts("loadparm value greater than max number of boot entries allow= ed"); + return -EINVAL; + } =20 - zipl_run(&prog_table->entry[loadparm].scsi); /* no return */ + return zipl_run(&prog_table->entry[loadparm].scsi); } =20 /*********************************************************************** @@ -1032,7 +1074,9 @@ void zipl_load(void) netmain(); } =20 - ipl_scsi(); + if (ipl_scsi()) { + panic("\n! Cannot IPL this SCSI device !\n"); + } =20 switch (virtio_get_device_type()) { case VIRTIO_ID_BLOCK: diff --git a/pc-bios/s390-ccw/virtio-blkdev.c b/pc-bios/s390-ccw/virtio-blk= dev.c index 2666326801..1c585f034b 100644 --- a/pc-bios/s390-ccw/virtio-blkdev.c +++ b/pc-bios/s390-ccw/virtio-blkdev.c @@ -73,13 +73,13 @@ unsigned long virtio_load_direct(unsigned long rec_list= 1, unsigned long rec_list unsigned long addr =3D (unsigned long)load_addr; =20 if (sec_len !=3D virtio_get_block_size()) { - return -1; + return 0; } =20 printf("."); status =3D virtio_read_many(sec, (void *)addr, sec_num); if (status) { - panic("I/O Error"); + return 0; } addr +=3D sec_num * virtio_get_block_size(); =20 diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c index 6b4a1caf8a..71db75ce7b 100644 --- a/pc-bios/s390-ccw/virtio-scsi.c +++ b/pc-bios/s390-ccw/virtio-scsi.c @@ -26,7 +26,7 @@ static uint8_t scsi_inquiry_std_response[256]; static ScsiInquiryEvpdPages scsi_inquiry_evpd_pages_response; static ScsiInquiryEvpdBl scsi_inquiry_evpd_bl_response; =20 -static inline void vs_assert(bool term, const char **msgs) +static inline bool vs_assert(bool term, const char **msgs) { if (!term) { int i =3D 0; @@ -35,11 +35,13 @@ static inline void vs_assert(bool term, const char **ms= gs) while (msgs[i]) { printf("%s", msgs[i++]); } - panic(" !\n"); + puts(" !"); } + + return term; } =20 -static void virtio_scsi_verify_response(VirtioScsiCmdResp *resp, +static bool virtio_scsi_verify_response(VirtioScsiCmdResp *resp, const char *title) { const char *mr[] =3D { @@ -56,8 +58,8 @@ static void virtio_scsi_verify_response(VirtioScsiCmdResp= *resp, 0 }; =20 - vs_assert(resp->response =3D=3D VIRTIO_SCSI_S_OK, mr); - vs_assert(resp->status =3D=3D CDB_STATUS_GOOD, ms); + return vs_assert(resp->response =3D=3D VIRTIO_SCSI_S_OK, mr) && + vs_assert(resp->status =3D=3D CDB_STATUS_GOOD, ms); } =20 static void prepare_request(VDev *vdev, const void *cdb, int cdb_size, @@ -78,24 +80,31 @@ static void prepare_request(VDev *vdev, const void *cdb= , int cdb_size, } } =20 -static inline void vs_io_assert(bool term, const char *msg) +static inline bool vs_io_assert(bool term, const char *msg) { - if (!term) { - virtio_scsi_verify_response(&resp, msg); + if (!term && !virtio_scsi_verify_response(&resp, msg)) { + return false; } + + return true; } =20 -static void vs_run(const char *title, VirtioCmd *cmd, VDev *vdev, +static int vs_run(const char *title, VirtioCmd *cmd, VDev *vdev, const void *cdb, int cdb_size, void *data, uint32_t data_size) { prepare_request(vdev, cdb, cdb_size, data, data_size); - vs_io_assert(virtio_run(vdev, VR_REQUEST, cmd) =3D=3D 0, title); + if (!vs_io_assert(virtio_run(vdev, VR_REQUEST, cmd) =3D=3D 0, title)) { + puts(title); + return -EIO; + } + + return 0; } =20 /* SCSI protocol implementation routines */ =20 -static bool scsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page, +static int scsi_inquiry(VDev *vdev, uint8_t evpd, uint8_t page, void *data, uint32_t data_size) { ScsiCdbInquiry cdb =3D { @@ -110,12 +119,13 @@ static bool scsi_inquiry(VDev *vdev, uint8_t evpd, ui= nt8_t page, { data, data_size, VRING_DESC_F_WRITE }, }; =20 - vs_run("inquiry", inquiry, vdev, &cdb, sizeof(cdb), data, data_size); + int ret =3D vs_run("inquiry", inquiry, + vdev, &cdb, sizeof(cdb), data, data_size); =20 - return virtio_scsi_response_ok(&resp); + return ret ? ret : virtio_scsi_response_ok(&resp); } =20 -static bool scsi_test_unit_ready(VDev *vdev) +static int scsi_test_unit_ready(VDev *vdev) { ScsiCdbTestUnitReady cdb =3D { .command =3D 0x00, @@ -131,7 +141,7 @@ static bool scsi_test_unit_ready(VDev *vdev) return virtio_scsi_response_ok(&resp); } =20 -static bool scsi_report_luns(VDev *vdev, void *data, uint32_t data_size) +static int scsi_report_luns(VDev *vdev, void *data, uint32_t data_size) { ScsiCdbReportLuns cdb =3D { .command =3D 0xa0, @@ -144,13 +154,13 @@ static bool scsi_report_luns(VDev *vdev, void *data, = uint32_t data_size) { data, data_size, VRING_DESC_F_WRITE }, }; =20 - vs_run("report luns", report_luns, + int ret =3D vs_run("report luns", report_luns, vdev, &cdb, sizeof(cdb), data, data_size); =20 - return virtio_scsi_response_ok(&resp); + return ret ? ret : virtio_scsi_response_ok(&resp); } =20 -static bool scsi_read_10(VDev *vdev, +static int scsi_read_10(VDev *vdev, unsigned long sector, int sectors, void *data, unsigned int data_size) { @@ -168,12 +178,13 @@ static bool scsi_read_10(VDev *vdev, debug_print_int("read_10 sector", sector); debug_print_int("read_10 sectors", sectors); =20 - vs_run("read(10)", read_10, vdev, &cdb, sizeof(cdb), data, data_size); + int ret =3D vs_run("read(10)", read_10, + vdev, &cdb, sizeof(cdb), data, data_size); =20 - return virtio_scsi_response_ok(&resp); + return ret ? ret : virtio_scsi_response_ok(&resp); } =20 -static bool scsi_read_capacity(VDev *vdev, +static int scsi_read_capacity(VDev *vdev, void *data, uint32_t data_size) { ScsiCdbReadCapacity16 cdb =3D { @@ -187,10 +198,10 @@ static bool scsi_read_capacity(VDev *vdev, { data, data_size, VRING_DESC_F_WRITE }, }; =20 - vs_run("read capacity", read_capacity_16, + int ret =3D vs_run("read capacity", read_capacity_16, vdev, &cdb, sizeof(cdb), data, data_size); =20 - return virtio_scsi_response_ok(&resp); + return ret ? ret : virtio_scsi_response_ok(&resp); } =20 /* virtio-scsi routines */ @@ -207,7 +218,7 @@ static int virtio_scsi_locate_device(VDev *vdev) static uint8_t data[16 + 8 * 63]; ScsiLunReport *r =3D (void *) data; ScsiDevice *sdev =3D vdev->scsi_device; - int i, luns; + int i, ret, luns; =20 /* QEMU has hardcoded channel #0 in many places. * If this hardcoded value is ever changed, we'll need to add code for @@ -233,13 +244,21 @@ static int virtio_scsi_locate_device(VDev *vdev) sdev->channel =3D channel; sdev->target =3D target; sdev->lun =3D 0; /* LUN has to be 0 for REPORT LUNS */ - if (!scsi_report_luns(vdev, data, sizeof(data))) { + ret =3D scsi_report_luns(vdev, data, sizeof(data)); + if (ret < 0) { + return ret; + } + + else if (ret =3D=3D 0) { if (resp.response =3D=3D VIRTIO_SCSI_S_BAD_TARGET) { continue; } printf("target 0x%X\n", target); - virtio_scsi_verify_response(&resp, "SCSI cannot report LUNs"); + if (!virtio_scsi_verify_response(&resp, "SCSI cannot report LU= Ns")) { + return -EIO; + } } + if (r->lun_list_len =3D=3D 0) { printf("no LUNs for target 0x%X\n", target); continue; @@ -283,7 +302,9 @@ int virtio_scsi_read_many(VDev *vdev, data_size =3D 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"); + if (!virtio_scsi_verify_response(&resp, "virtio-scsi:read_many= ")) { + return -1; + } } load_addr +=3D data_size; sector +=3D sector_count; @@ -352,11 +373,16 @@ static int virtio_scsi_setup(VDev *vdev) uint8_t code =3D resp.sense[0] & SCSI_SENSE_CODE_MASK; uint8_t sense_key =3D resp.sense[2] & SCSI_SENSE_KEY_MASK; =20 - IPL_assert(resp.sense_len !=3D 0, "virtio-scsi:setup: no SENSE= data"); + if (resp.sense_len =3D=3D 0) { + puts("virtio-scsi: setup: no SENSE data"); + return -EINVAL; + } =20 - IPL_assert(retry_test_unit_ready && code =3D=3D 0x70 && - sense_key =3D=3D SCSI_SENSE_KEY_UNIT_ATTENTION, - "virtio-scsi:setup: cannot retry"); + if (!retry_test_unit_ready || code !=3D 0x70 || + sense_key !=3D SCSI_SENSE_KEY_UNIT_ATTENTION) { + puts("virtio-scsi:setup: cannot retry"); + return -EIO; + } =20 /* retry on CHECK_CONDITION/UNIT_ATTENTION as it * may not designate a real error, but it may be @@ -367,16 +393,22 @@ static int virtio_scsi_setup(VDev *vdev) continue; } =20 - virtio_scsi_verify_response(&resp, "virtio-scsi:setup"); + if (!virtio_scsi_verify_response(&resp, "virtio-scsi:setup")) { + return -1; + } } =20 /* read and cache SCSI INQUIRY response */ - if (!scsi_inquiry(vdev, + ret =3D 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"); + sizeof(scsi_inquiry_std_response)); + if (ret < 1) { + if (ret !=3D 0 || !virtio_scsi_verify_response(&resp, + "virtio-scsi:setup:inquiry")) { + return -1; + } } =20 if (virtio_scsi_inquiry_response_is_cdrom(scsi_inquiry_std_response)) { @@ -385,12 +417,16 @@ static int virtio_scsi_setup(VDev *vdev) vdev->scsi_block_size =3D VIRTIO_ISO_BLOCK_SIZE; } =20 - if (!scsi_inquiry(vdev, + ret =3D scsi_inquiry(vdev, SCSI_INQUIRY_EVPD, SCSI_INQUIRY_EVPD_SUPPORTED_PAGES, evpd, - sizeof(*evpd))) { - virtio_scsi_verify_response(&resp, "virtio-scsi:setup:supported_pa= ges"); + sizeof(*evpd)); + if (ret < 1) { + if (ret !=3D 0 || !virtio_scsi_verify_response(&resp, + "virtio-scsi:setup:supported_pages")) { + return -1; + } } =20 debug_print_int("EVPD length", evpd->page_length); @@ -402,12 +438,16 @@ static int virtio_scsi_setup(VDev *vdev) continue; } =20 - if (!scsi_inquiry(vdev, + ret =3D scsi_inquiry(vdev, SCSI_INQUIRY_EVPD, SCSI_INQUIRY_EVPD_BLOCK_LIMITS, evpd_bl, - sizeof(*evpd_bl))) { - virtio_scsi_verify_response(&resp, "virtio-scsi:setup:blocklim= its"); + sizeof(*evpd_bl)); + if (ret < 1) { + if (ret !=3D 0 || !virtio_scsi_verify_response(&resp, + "virtio-scsi:setup:blocklimits")) { + return -1; + } } =20 debug_print_int("max transfer", evpd_bl->max_transfer); @@ -423,8 +463,12 @@ static int virtio_scsi_setup(VDev *vdev) vdev->max_transfer =3D MIN_NON_ZERO(VIRTIO_SCSI_MAX_SECTORS, vdev->max_transfer); =20 - if (!scsi_read_capacity(vdev, data, data_size)) { - virtio_scsi_verify_response(&resp, "virtio-scsi:setup:read_capacit= y"); + ret =3D scsi_read_capacity(vdev, data, data_size); + if (ret < 1) { + if (ret !=3D 0 || !virtio_scsi_verify_response(&resp, + "virtio-scsi:setup:read_capacity")) { + return -1; + } } scsi_parse_capacity_report(data, &vdev->scsi_last_block, (uint32_t *) &vdev->scsi_block_size); @@ -439,10 +483,15 @@ int virtio_scsi_setup_device(SubChannelId schid) vdev->schid =3D schid; virtio_setup_ccw(vdev); =20 - IPL_assert(vdev->config.scsi.sense_size =3D=3D VIRTIO_SCSI_SENSE_SIZE, - "Config: sense size mismatch"); - IPL_assert(vdev->config.scsi.cdb_size =3D=3D VIRTIO_SCSI_CDB_SIZE, - "Config: CDB size mismatch"); + if (vdev->config.scsi.sense_size !=3D VIRTIO_SCSI_SENSE_SIZE) { + puts("Config: sense size mismatch"); + return -EINVAL; + } + + if (vdev->config.scsi.cdb_size !=3D VIRTIO_SCSI_CDB_SIZE) { + puts("Config: CDB size mismatch"); + return -EINVAL; + } =20 puts("Using virtio-scsi."); =20 --=20 2.47.0