From patchwork Mon Jul 11 23:00:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 590001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B412CCCA480 for ; Mon, 11 Jul 2022 23:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbiGKXBA (ORCPT ); Mon, 11 Jul 2022 19:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbiGKXA7 (ORCPT ); Mon, 11 Jul 2022 19:00:59 -0400 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D1FD57260 for ; Mon, 11 Jul 2022 16:00:58 -0700 (PDT) Received: by mail-pj1-f44.google.com with SMTP id 89-20020a17090a09e200b001ef7638e536so9723290pjo.3 for ; Mon, 11 Jul 2022 16:00:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dZxOsRkLHqoOw46AFUipp3IJm8J9vVNYvBGrby4bQNY=; b=CYx7+i2ratqxhg8jYPDUB2Wy8x7OpsGPML+x5mGLrmO+hq4AbbKLxvdOBoDQOYhXvq Vjlj1+aYtXzN4Zi1LkMev0/PtnrRdxkkCdC6+2bO5k1Kk744mWJZO7SzpQjIGjnIVIyK LjppzfsaZhVCnJNAoDgWUHGqMpu9AaE9bLKjK7Rg+0Sq+Tfmw0oSthWhc+8RvUv5ekM+ OA2VPamw2IskVJhdpr9yg7jyddHIE/CUy49dMqp4w7LXw9mN/4y7neq0EGEYTF7aK5v9 86X1OkpzoFQnNA3O+2NSMNg/k+QtvnDRyK8QHSYr2LZ8pv7qdQiUyZLeV0eGImBIVnkl ohQw== X-Gm-Message-State: AJIora/McfydGXzdH+089t8e8AEjpI5/oODnWz7Tj0Z9YB8KXMM5vKrx iM/vw0iFw5A28lUbrMWBaBs= X-Google-Smtp-Source: AGRyM1ss8lZl0Oj2W+wBBCFmcsrOWxOZ2+eNrdKSqO5+10n+Bxk5CiYzjjFVsF9QKxVx384eIeTFsg== X-Received: by 2002:a17:902:c405:b0:16c:1dc:c7f8 with SMTP id k5-20020a170902c40500b0016c01dcc7f8mr20770435plk.59.1657580457491; Mon, 11 Jul 2022 16:00:57 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00411955c03e5sm4761886pgn.29.2022.07.11.16.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 16:00:56 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Damien Le Moal Subject: [PATCH 1/3] scsi_debug: Set the SAME field in the REPORT ZONES response Date: Mon, 11 Jul 2022 16:00:49 -0700 Message-Id: <20220711230051.15372-2-bvanassche@acm.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220711230051.15372-1-bvanassche@acm.org> References: <20220711230051.15372-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Provide information to the SCSI initiator about whether or not all examined zones have the same zone type and zone length. From the description of the SAME field in ZBC-1: * 0: The zone type and zone length in each zone descriptor may be different. * 1: The zone type and zone length in each zone descriptor are equal to the zone type and zone length indicated in the first zone descriptor in the zone descriptor list. Cc: Douglas Gilbert Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index b8a76b89f85a..5a8efc328fb5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4476,8 +4476,10 @@ static int resp_report_zones(struct scsi_cmnd *scp, u64 lba, zs_lba; u8 *arr = NULL, *desc; u8 *cmd = scp->cmnd; - struct sdeb_zone_state *zsp = NULL; + struct sdeb_zone_state *zsp = NULL, *first_reported_zone = NULL; struct sdeb_store_info *sip = devip2sip(devip, false); + /* 1: all zones in the response have the same type and length. */ + u8 same = 1; if (!sdebug_dev_is_zoned(devip)) { mk_sense_invalid_opcode(scp); @@ -4571,6 +4573,13 @@ static int resp_report_zones(struct scsi_cmnd *scp, goto fini; } + if (first_reported_zone) { + if (zsp->z_type != first_reported_zone->z_type || + zsp->z_size != first_reported_zone->z_size) + same = 0; + } else { + first_reported_zone = zsp; + } if (nrz < rep_max_zones) { /* Fill zone descriptor */ desc[0] = zsp->z_type; @@ -4592,6 +4601,8 @@ static int resp_report_zones(struct scsi_cmnd *scp, /* Report header */ /* Zone list length. */ put_unaligned_be32(nrz * RZONES_DESC_HD, arr + 0); + /* SAME field. */ + arr[4] = same; /* Maximum LBA */ put_unaligned_be64(sdebug_capacity - 1, arr + 8); /* Zone starting LBA granularity. */ From patchwork Mon Jul 11 23:00:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 590000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1684DC43334 for ; Mon, 11 Jul 2022 23:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbiGKXBH (ORCPT ); Mon, 11 Jul 2022 19:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbiGKXBC (ORCPT ); Mon, 11 Jul 2022 19:01:02 -0400 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52F7561B1D for ; Mon, 11 Jul 2022 16:01:01 -0700 (PDT) Received: by mail-pl1-f181.google.com with SMTP id l12so5686977plk.13 for ; Mon, 11 Jul 2022 16:01:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ie36p2rZzY5GvCYUO5UdUwYiXQgaNmEth6QGiyc7UXg=; b=DqfV1+OlH1s4KxruICRaPBklOjzUE+w9uJOL8NcsbdAahtbKWbY49r4YbSluT7EXy3 vRMWv3lL8rJgWai0Lqxg+1NXPDgkDQq5/KYU5XGbOT7mxQv8EbJoILPkVv/alXVp9Ca8 PMzuaAJlnW8BCdfGESwHFoQbBLFEGVnZorp5UGqhgAxcv5i6QMrVCwBlpcvV7uhZO5aJ KBP6AY93iswax774g4Md8u+5Lv6ZeAV+fqC/Mo4Zwy0JCGcjWXkK9+EoSt1TjBFZrxei 1jRodyem2uWaSx+3Xt42Hs77ITrOPQwI0vcv6+hKt5YqZrKDwG448RFNpCkb5l3LtohD EWDg== X-Gm-Message-State: AJIora9vH/i8cyOtSOu+Hi0e0nggyJThSro0SJcSXumj6Uexr+IfzZjp R1kgHR/inEqpLf0QeeM3bsk= X-Google-Smtp-Source: AGRyM1szUiOrROfBzh2t1n8qpt7Kc0ueKXRaSmlrJqQyqIwO6gMX32RTChTywwTxrt0sSYKpsda3wg== X-Received: by 2002:a17:902:cecb:b0:16c:40a8:88ff with SMTP id d11-20020a170902cecb00b0016c40a888ffmr9751096plg.33.1657580460588; Mon, 11 Jul 2022 16:01:00 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:feaa:14ff:fe9d:6dbd]) by smtp.gmail.com with ESMTPSA id m6-20020a637d46000000b00411955c03e5sm4761886pgn.29.2022.07.11.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 16:00:59 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Bart Van Assche , Damien Le Moal , Hannes Reinecke Subject: [PATCH 3/3] scsi: sd_zbc: Fix handling of RC BASIS Date: Mon, 11 Jul 2022 16:00:51 -0700 Message-Id: <20220711230051.15372-4-bvanassche@acm.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220711230051.15372-1-bvanassche@acm.org> References: <20220711230051.15372-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Using the RETURNED LOGICAL BLOCK ADDRESS field + 1 as the capacity (largest addressable LBA) if RC BASIS = 0 is wrong if there are sequential write required zones. Hence only use the RC BASIS = 0 capacity if there are no sequential write required zones. Cc: Damien Le Moal Cc: Hannes Reinecke Fixes: d2e428e49eec ("scsi: sd_zbc: Reduce boot device scan and revalidate time") Signed-off-by: Bart Van Assche --- drivers/scsi/sd_zbc.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 6acc4f406eb8..41ff1c0fd04b 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -699,7 +699,7 @@ static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp, * * Get the device zone size and check that the device capacity as reported * by READ CAPACITY matches the max_lba value (plus one) of the report zones - * command reply for devices with RC_BASIS == 0. + * command reply. * * Returns 0 upon success or an error code upon failure. */ @@ -709,6 +709,7 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf, u64 zone_blocks; sector_t max_lba; unsigned char *rec; + u8 same; int ret; /* Do a report zone to get max_lba and the size of the first zone */ @@ -716,9 +717,26 @@ static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf, if (ret) return ret; - if (sdkp->rc_basis == 0) { - /* The max_lba field is the capacity of this device */ - max_lba = get_unaligned_be64(&buf[8]); + /* + * From ZBC-1: "If the ZONE LIST LENGTH field is zero then the SAME + * field is invalid and should be ignored by the application client." + */ + if (get_unaligned_be32(&buf[0]) == 0) { + sd_printk(KERN_INFO, sdkp, "No zones have been reported\n"); + return -EIO; + } + + same = buf[4] & 0xf; + max_lba = get_unaligned_be64(&buf[8]); + /* + * The max_lba field is the largest addressable LBA of the disk if: + * - Either RC BASIS == 1. + * - Or RC BASIS == 0, there is at least one zone in the response + * (max_lba != 0) and all zones have the same type (same == 1 || + * same == 2). + */ + if ((sdkp->rc_basis == 0 && max_lba && (same == 1 || same == 2)) || + sdkp->rc_basis == 1) { if (sdkp->capacity != max_lba + 1) { if (sdkp->first_scan) sd_printk(KERN_WARNING, sdkp,