From patchwork Sun Sep 13 06:03:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 296770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14FBEC433E2 for ; Sun, 13 Sep 2020 06:03:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C392721655 for ; Sun, 13 Sep 2020 06:03:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="jqElMUUC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725920AbgIMGDQ (ORCPT ); Sun, 13 Sep 2020 02:03:16 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:60244 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbgIMGDK (ORCPT ); Sun, 13 Sep 2020 02:03:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1599976990; x=1631512990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZUbVqWuuZoA0ZQHXbwKVfA8exH/uMbHKkSc99fRXoEA=; b=jqElMUUC4q6dKTSym0/vnl30G4VaYlxZ4AxOM6ym2vx4MHA5PjQ1G5/b XS+AoiFd4iigFoQkB4RzHP6Ug5WpxpibTIkpsHRS9wUbxV3yvmeYmUMvQ EhoyI4cuZTHuZrXfh6VGQ6xiwkTuYEs4Cme3nd2/oEA2+OzwZDkRfSijO tJHKSnCktXRxTVhDlM+QOiB9A17L0AZFEDG7BYwtijD/EyUoLXM28tKPf lN3ZpP8Rxwm63UZZRNoWWo2DPm/i1AEo60GpKawuwleA+YSnShxE9F/eL KQJ0zD0xHSMIO+EmmqUM3yczNXOJSvq+OPb7hdoe3Bmj3vB+dJkrBL0NG Q==; IronPort-SDR: KY6xSL4u3/ommgeA+S6SYfMPVWa569W8+4OH7AyNqEcnaBrkcE3Ti9LFCFgGIGy5Q4N3v3/1uw 5HBJLeC3U120lgyQxQVlHgO/k+RLxNpyNeiZOTJYGdikQMAu+QTXNygf3m99li8fuSNmkevDTV /Lh0eyToNmuO/wpLuAFEHz48+M/U559eUM6ljKo84bMwPYM+J0YMW5NrmdLv41kKG8irW8ll7i Y051Qej8E/dI6K0+fBHGG6KAps51d6w0vho009wYM0mhcM/SZ10luH1PJw9JC0mBNURlhtkSBA A8Y= X-IronPort-AV: E=Sophos;i="5.76,421,1592841600"; d="scan'208";a="148458732" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Sep 2020 14:03:10 +0800 IronPort-SDR: dPQMEvcbtEUyo3PB4O8Im7EFyfMOO8U4U+FHRQrCR8iUOA3JD6UbBOczM5yzbpr5pgd0R5AdPr jDy597nQuHbQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2020 22:49:28 -0700 IronPort-SDR: 2ZAfHddjima2jQnl1LuWCagNDioY5z44T8WYMlb9Dg/YER2tebNEqCEK7GbMNstI8DnJceAEp2 s5wTewPKLjSA== WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Sep 2020 23:03:09 -0700 From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" , Borislav Petkov Cc: linux-block@vger.kernel.org, Jens Axboe , Johannes Thumshirn Subject: [PATCH 1/2] scsi: Fix handling of host-aware ZBC disks Date: Sun, 13 Sep 2020 15:03:03 +0900 Message-Id: <20200913060304.294898-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200913060304.294898-1-damien.lemoal@wdc.com> References: <20200913060304.294898-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When CONFIG_BLK_DEV_ZONED is disabled, allow using host-aware ZBC disks as regular disks. In this case, ensure that command completion is correctly executed by changing sd_zbc_complete() to return good_bytes instead of 0, causing a hang during device probe (endless retries). When CONFIG_BLK_DEV_ZONED is enabled and a host-aware disk is detected to have partitions, it will be used as a regular disk. In this case, make sure to not do anything in sd_zbc_revalidate_zones() as that triggers warnings. Reported-by: Borislav Petkov Fixes: b72053072c0b ("block: allow partitions on host aware zone devices") Cc: Signed-off-by: Damien Le Moal --- drivers/scsi/sd.c | 22 ++++++++++++++++++---- drivers/scsi/sd.h | 2 +- drivers/scsi/sd_zbc.c | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 95018e650f2d..7f0371185a45 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2968,22 +2968,36 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) } else { sdkp->zoned = (buffer[8] >> 4) & 3; if (sdkp->zoned == 1 && !disk_has_partitions(sdkp->disk)) { +#ifdef CONFIG_BLK_DEV_ZONED /* Host-aware */ q->limits.zoned = BLK_ZONED_HA; +#else + /* Host-aware drive is treated as a regular disk */ + q->limits.zoned = BLK_ZONED_NONE; +#endif } else { /* * Treat drive-managed devices and host-aware devices * with partitions as regular block devices. */ q->limits.zoned = BLK_ZONED_NONE; - if (sdkp->zoned == 2 && sdkp->first_scan) - sd_printk(KERN_NOTICE, sdkp, - "Drive-managed SMR disk\n"); } } - if (blk_queue_is_zoned(q) && sdkp->first_scan) + + if (!sdkp->first_scan) + goto out; + + if (blk_queue_is_zoned(q)) { sd_printk(KERN_NOTICE, sdkp, "Host-%s zoned block device\n", q->limits.zoned == BLK_ZONED_HM ? "managed" : "aware"); + } else { + if (sdkp->zoned == 1) + sd_printk(KERN_NOTICE, sdkp, + "Host-aware SMR disk used as regular disk\n"); + else if (sdkp->zoned == 2) + sd_printk(KERN_NOTICE, sdkp, + "Drive-managed SMR disk\n"); + } out: kfree(buffer); diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 4933e7daf17d..7251434100e6 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -259,7 +259,7 @@ static inline blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd, static inline unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, struct scsi_sense_hdr *sshdr) { - return 0; + return good_bytes; } static inline blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 0e94ff056bff..a739456dea02 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -667,7 +667,11 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp) u32 max_append; int ret = 0; - if (!sd_is_zoned(sdkp)) + /* + * There is nothing to do for regular disks, including host-aware disks + * that have partitions. + */ + if (!blk_queue_is_zoned(q)) return 0; /* From patchwork Sun Sep 13 06:03:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 296769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EE42C43461 for ; Sun, 13 Sep 2020 06:03:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC89C21655 for ; Sun, 13 Sep 2020 06:03:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="BMrL7GgI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725922AbgIMGDY (ORCPT ); Sun, 13 Sep 2020 02:03:24 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:60247 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbgIMGDM (ORCPT ); Sun, 13 Sep 2020 02:03:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1599976991; x=1631512991; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jxd9y2JXL2aUJ7WYNs3dtOces+LIigDvq1lvki3gPVk=; b=BMrL7GgIcedUlE/mgI18JitShiPyKlFS9IYwvM998U5S4zjPGVE/WFh8 fNE+BcyTPw2TfDy+qHtKGUZNoTSPcPpl0ElgFZiaLne9jZ9xJr6GzuXhN ZskcpprfOKTReMcAgMDyrw84Q4yWNBkCBabXZOmVrkBgAp6uWL1FJ9hXs GZzjOKy7ETyirRF5DL5S4XhEtFCEVJ034fmqTyIdkiZ2dPUPG4rp2bs7B sv5its/sEzxbCIUiYtdAXLusb3gprx9I0GIADVxnUqUsk4y9TC5KrGcPx W0WmlrlmM8RCNgTqsJM97P3WrpZvSP7EwZa6e4Rw6LKj58nQmWv51ugVq g==; IronPort-SDR: Qfbojx1AjKVSvhP35JPtdgsvAmIR3SLBZ4R71P0btHxakHpG7DQWDZpSZBxEKQ899egDBWawYB W7CEjBYxr91sB5xtIIgMUJPrOPEvl4f1QYtDttBGZcWzdovzxTusZPFYyGwaTsA8lo2QCMNEuF wAIP91JzjoQ2vQBjSvG51XU9jw4R02sTSQJv4snFSq3OEdVDe3fYCMBhqrOBftW4R6V0I4OEZ1 iS/eWsKHth/13AxHYreNspr8PvQq2hFzPbZwJ4t9FQdBl5Si+QKO+MyIRnlyZ0qoLaqIUEAXo/ Ht8= X-IronPort-AV: E=Sophos;i="5.76,421,1592841600"; d="scan'208";a="148458736" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Sep 2020 14:03:11 +0800 IronPort-SDR: ZbusAnwiNjm6KS07uwyzwB4ys857MwGOc1WL9FS5wDZIYs7ILGwHz7CWIG29+IXf3sBBLYvi/5 f+7pzP4x+UCg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2020 22:49:29 -0700 IronPort-SDR: NtwP2buxnEKly/SpYwBfPl0DoYL9CswEBrsbgvIb4Us04KZ6H0knJi77SNHEtXJEnPve8iypHT 1YG+X+AwAo/w== WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Sep 2020 23:03:10 -0700 From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" , Borislav Petkov Cc: linux-block@vger.kernel.org, Jens Axboe , Johannes Thumshirn Subject: [PATCH 2/2] scsi: Fix ZBC disk initialization Date: Sun, 13 Sep 2020 15:03:04 +0900 Message-Id: <20200913060304.294898-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200913060304.294898-1-damien.lemoal@wdc.com> References: <20200913060304.294898-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make sure to call sd_zbc_init_disk() when the sdkp->zoned field is known, that is, once sd_read_block_characteristics() is executed in sd_revalidate_disk(), so that host-aware disks also get initialized. To do so, move sd_zbc_init_disk() call in sd_zbc_revalidate_zones() and make sure to execute it for all zoned disks, including for host-aware disks used as regular disks as these disk zoned model may be changed back to BLK_ZONED_HA when partitions are deleted. Reported-by: Borislav Petkov Fixes: 5795eb443060 ("scsi: sd_zbc: emulate ZONE_APPEND commands") Cc: # v5.8+ Signed-off-by: Damien Le Moal --- drivers/scsi/sd.c | 4 --- drivers/scsi/sd.h | 6 ----- drivers/scsi/sd_zbc.c | 60 +++++++++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 7f0371185a45..3d2cffb8e9aa 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3418,10 +3418,6 @@ static int sd_probe(struct device *dev) sdkp->first_scan = 1; sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; - error = sd_zbc_init_disk(sdkp); - if (error) - goto out_free_index; - sd_revalidate_disk(gd); gd->flags = GENHD_FL_EXT_DEVT; diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 7251434100e6..a3aad608bc38 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -215,7 +215,6 @@ static inline int sd_is_zoned(struct scsi_disk *sdkp) #ifdef CONFIG_BLK_DEV_ZONED -int sd_zbc_init_disk(struct scsi_disk *sdkp); void sd_zbc_release_disk(struct scsi_disk *sdkp); int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buffer); int sd_zbc_revalidate_zones(struct scsi_disk *sdkp); @@ -231,11 +230,6 @@ blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, sector_t *lba, #else /* CONFIG_BLK_DEV_ZONED */ -static inline int sd_zbc_init_disk(struct scsi_disk *sdkp) -{ - return 0; -} - static inline void sd_zbc_release_disk(struct scsi_disk *sdkp) {} static inline int sd_zbc_read_zones(struct scsi_disk *sdkp, diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index a739456dea02..cf07b7f93579 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -651,6 +651,28 @@ static void sd_zbc_print_zones(struct scsi_disk *sdkp) sdkp->zone_blocks); } +static int sd_zbc_init_disk(struct scsi_disk *sdkp) +{ + sdkp->zones_wp_offset = NULL; + spin_lock_init(&sdkp->zones_wp_offset_lock); + sdkp->rev_wp_offset = NULL; + mutex_init(&sdkp->rev_mutex); + INIT_WORK(&sdkp->zone_wp_offset_work, sd_zbc_update_wp_offset_workfn); + sdkp->zone_wp_update_buf = kzalloc(SD_BUF_SIZE, GFP_KERNEL); + if (!sdkp->zone_wp_update_buf) + return -ENOMEM; + + return 0; +} + +void sd_zbc_release_disk(struct scsi_disk *sdkp) +{ + kvfree(sdkp->zones_wp_offset); + sdkp->zones_wp_offset = NULL; + kfree(sdkp->zone_wp_update_buf); + sdkp->zone_wp_update_buf = NULL; +} + static void sd_zbc_revalidate_zones_cb(struct gendisk *disk) { struct scsi_disk *sdkp = scsi_disk(disk); @@ -667,6 +689,19 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp) u32 max_append; int ret = 0; + /* + * For all zoned disks, initialize zone append emulation data if not + * already done. This is necessary also for host-aware disks used as + * regular disks due to the presence of partitions as these partitions + * may be deleted and the disk zoned model changed back from + * BLK_ZONED_NONE to BLK_ZONED_HA. + */ + if (sd_is_zoned(sdkp) && !sdkp->zone_wp_update_buf) { + ret = sd_zbc_init_disk(sdkp); + if (ret) + return ret; + } + /* * There is nothing to do for regular disks, including host-aware disks * that have partitions. @@ -768,28 +803,3 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) return ret; } - -int sd_zbc_init_disk(struct scsi_disk *sdkp) -{ - if (!sd_is_zoned(sdkp)) - return 0; - - sdkp->zones_wp_offset = NULL; - spin_lock_init(&sdkp->zones_wp_offset_lock); - sdkp->rev_wp_offset = NULL; - mutex_init(&sdkp->rev_mutex); - INIT_WORK(&sdkp->zone_wp_offset_work, sd_zbc_update_wp_offset_workfn); - sdkp->zone_wp_update_buf = kzalloc(SD_BUF_SIZE, GFP_KERNEL); - if (!sdkp->zone_wp_update_buf) - return -ENOMEM; - - return 0; -} - -void sd_zbc_release_disk(struct scsi_disk *sdkp) -{ - kvfree(sdkp->zones_wp_offset); - sdkp->zones_wp_offset = NULL; - kfree(sdkp->zone_wp_update_buf); - sdkp->zone_wp_update_buf = NULL; -}