From patchwork Thu Jul 2 06:54:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Javier_Gonz=C3=A1lez?= X-Patchwork-Id: 11637893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9B50739 for ; Thu, 2 Jul 2020 06:55:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B14A6208B8 for ; Thu, 2 Jul 2020 06:55:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=javigon-com.20150623.gappssmtp.com header.i=@javigon-com.20150623.gappssmtp.com header.b="ASNQQXlO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbgGBGzG (ORCPT ); Thu, 2 Jul 2020 02:55:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbgGBGzG (ORCPT ); Thu, 2 Jul 2020 02:55:06 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D76BC08C5C1 for ; Wed, 1 Jul 2020 23:55:05 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id dp18so27944991ejc.8 for ; Wed, 01 Jul 2020 23:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jNqe3xdMxYATpvkBSQ9DPSFzqAXCkxXTgUf0+2M14v8=; b=ASNQQXlO2BS6HubW/chFoh77ZBHR2d6dw101imcfuWkntcyR6qnBw/a48xBQzmstf5 7DLyUy+9rDpTkYmCjsQwhx48rHwV5sT4dnPHCaHEQew3/UEj0Tfbfip1wiIxE6p5vl65 DE0KRZhDCoR+v4BnF9R0xaYOERxUe0+1qd8gV3RUKVJYQrQyEqGIbEJZNJUAivUqEjHh 7JzNU3P9jYtOL/D8D4645XG2Y80izIk+D86VrSHJF/lQUKjAyKdnpPzR6DefMNGG8BdR ikF1YNpH/eKDeOPkeaivUdgVDXeJhF8+62WkqPnkjBdVWD8saaOAW/EpFKj5gJTNgUzY SSOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jNqe3xdMxYATpvkBSQ9DPSFzqAXCkxXTgUf0+2M14v8=; b=BQicgA2Tr+272halb1AcpBu/tk60QmVkjuHZ1RWANKY76przEg05v/xllWsTmaC551 wBLCoQxuCoR/1WxL8HP5XtUFrtXh3Wpc2ws3649ThbEGTtZr4bzYA6CeWBU6Mzhiry6y jftHBvAMgVUPJm9a5tAwO7Gg26FpEH17JBe+pHEuQUj7PXTI5STCi3jxVIz/W/vsyhTL oWQRgSouyyw63sRDaW2DTYsUxPxKQpf0ecx04hI3kbDaIV1WD0j/xANkQqf1hhrayJly nFvafjpVkrZOWmLF11SfrBei14nzrfX1vd4bd7yZ2ouPmp5A/WlfyFp+T4Qfi2yxM6T+ 7DFg== X-Gm-Message-State: AOAM531bGlv3Q5ARJdYuj4f2/OCbjneCw7aISle1Ns5ezYAFZo5popnj 9wQdgk3YEWAr3wQsbgJ/HzWJku7Wc2P6G2Lb X-Google-Smtp-Source: ABdhPJxDuednJiBTcKqTYBXgxGdlZ70OidSmz7DMv99/hfqdMejYL8GqON/h3xnBNhSzE3cnX69bTQ== X-Received: by 2002:a17:906:33ca:: with SMTP id w10mr18822882eja.171.1593672904159; Wed, 01 Jul 2020 23:55:04 -0700 (PDT) Received: from localhost.localdomain ([194.62.217.57]) by smtp.gmail.com with ESMTPSA id cz2sm7912769edb.82.2020.07.01.23.55.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2020 23:55:03 -0700 (PDT) From: =?utf-8?q?Javier_Gonz=C3=A1lez?= To: linux-nvme@lists.infradead.org Cc: linux-block@vger.kernel.org, hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@kernel.dk, Damien.LeMoal@wdc.com, mb@lightnvm.io, =?utf-8?q?Javier_Gonz=C3=A1lez?= , SelvaKumar S , Kanchan Joshi , Nitesh Shetty Subject: [PATCH 1/4] block: Add zone flags to queue zone prop. Date: Thu, 2 Jul 2020 08:54:35 +0200 Message-Id: <20200702065438.46350-2-javier@javigon.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200702065438.46350-1-javier@javigon.com> References: <20200702065438.46350-1-javier@javigon.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Javier González As the zoned block device will have to deal with features that are optional for the backend device, add a flag field to inform the block layer about supported features. This builds on top of blk_zone_report_flags and extendes to the zone report code. Signed-off-by: Javier González Signed-off-by: SelvaKumar S Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty --- block/blk-zoned.c | 3 ++- drivers/block/null_blk_zoned.c | 2 ++ drivers/nvme/host/zns.c | 1 + drivers/scsi/sd.c | 2 ++ include/linux/blkdev.h | 3 +++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 81152a260354..0f156e96e48f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -312,7 +312,8 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, return ret; rep.nr_zones = ret; - rep.flags = BLK_ZONE_REP_CAPACITY; + rep.flags = q->zone_flags; + if (copy_to_user(argp, &rep, sizeof(struct blk_zone_report))) return -EFAULT; return 0; diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index b05832eb21b2..957c2103f240 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -78,6 +78,8 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) } q->limits.zoned = BLK_ZONED_HM; + q->zone_flags = BLK_ZONE_REP_CAPACITY; + blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE); diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 0642d3c54e8f..888264261ba3 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -81,6 +81,7 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, } q->limits.zoned = BLK_ZONED_HM; + q->zone_flags = BLK_ZONE_REP_CAPACITY; blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); free_data: kfree(id); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index d90fefffe31b..b9c920bace28 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2967,6 +2967,7 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) if (sdkp->device->type == TYPE_ZBC) { /* Host-managed */ q->limits.zoned = BLK_ZONED_HM; + q->zone_flags = BLK_ZONE_REP_CAPACITY; } else { sdkp->zoned = (buffer[8] >> 4) & 3; if (sdkp->zoned == 1 && !disk_has_partitions(sdkp->disk)) { @@ -2983,6 +2984,7 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) "Drive-managed SMR disk\n"); } } + if (blk_queue_is_zoned(q) && sdkp->first_scan) sd_printk(KERN_NOTICE, sdkp, "Host-%s zoned block device\n", q->limits.zoned == BLK_ZONED_HM ? "managed" : "aware"); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 8fd900998b4e..3f2e3425fa53 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -512,12 +512,15 @@ struct request_queue { * Stacking drivers (device mappers) may or may not initialize * these fields. * + * Flags represent features as described by blk_zone_report_flags in blkzoned.h + * * Reads of this information must be protected with blk_queue_enter() / * blk_queue_exit(). Modifying this information is only allowed while * no requests are being processed. See also blk_mq_freeze_queue() and * blk_mq_unfreeze_queue(). */ unsigned int nr_zones; + unsigned int zone_flags; unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; #endif /* CONFIG_BLK_DEV_ZONED */ From patchwork Thu Jul 2 06:54:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Javier_Gonz=C3=A1lez?= X-Patchwork-Id: 11637895 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0AA413BD for ; Thu, 2 Jul 2020 06:55:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 840FF208B8 for ; Thu, 2 Jul 2020 06:55:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=javigon-com.20150623.gappssmtp.com header.i=@javigon-com.20150623.gappssmtp.com header.b="W9vhYFnz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727954AbgGBGzH (ORCPT ); Thu, 2 Jul 2020 02:55:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727948AbgGBGzH (ORCPT ); Thu, 2 Jul 2020 02:55:07 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3D0EC08C5DC for ; Wed, 1 Jul 2020 23:55:06 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id w6so27950152ejq.6 for ; Wed, 01 Jul 2020 23:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZbGfoLD1hyDSJuDUf+5wLzWjwZYjdlwlztihqUAYr0o=; b=W9vhYFnzU/7cJIIbbRFkTAHBr8D9MoArsDYN/pgfeBU/TeHkGOyhMnLRyJR3ffz44r 21oGwfofsrh16+IMrlTsBeZ+NwrNcTwPrDNW7puNBzjDgr7azt3gBcjwtGy7BsbST9qb aaxeRCBlrhKJQAHrXTrikNRO3x0HR1sJHpS1VUtMWvGOfWmG0HRvp8SPTd4s0YWOrAd+ c4OTko+2eoCHJmWtUN7DBX0A+o+LTLU9M0sXehPuDlkO86WKd/iWBmYhNfNBnGi2vV10 Xgc+QM4XHLXBXuhtHU1xXy1EOW7I2CI+cc4TI9nugEhMl+jQ85iIvlenmao2RmyQffsA HdBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZbGfoLD1hyDSJuDUf+5wLzWjwZYjdlwlztihqUAYr0o=; b=PvnXybaYvd2Ha+srKXhigG3USPdBtYqBLFtWJJH/L0S7JWDwmIX5h1zgA0UqnsXiTy a7g0sZiKoaRmgh1MLeNMZP/hXY5PBS8PXM21e6/V89E3Ue1oFkC8yZFCrGfc1jgXdW8m rv9THZ4dchaCgrXRklRvhQr/Hg6MyithCo+5yTHE8/Pgw+bEEgInDSQMoQdIxx2Kpfgu uCRNhgYQ9LAT9630LMeBuvlQTd22JNLp9a/K38VNtpFrso9uYk2SLBbZWSPNQmHm1393 qll61P/tSxfs9eatVSDAoFkZFmxKG0qllHxGq1SWlBInrXiXDwbRoGJKElP9DPwnB50a S/LA== X-Gm-Message-State: AOAM532hBwywW6KfKloXEoeg9lVOZRSNWmZUAeIyRYshU8aPFYQekMs/ 1wFb+4iS7Aj0qbT2V/YToD1CJQ== X-Google-Smtp-Source: ABdhPJx32JrMy5eydsY52ILcBd63eiMqYEYl8hr9LGadI8mRzZdjLGJTtpC4LAsrp6Gt65msb5MZQQ== X-Received: by 2002:a17:906:1682:: with SMTP id s2mr27993699ejd.532.1593672905359; Wed, 01 Jul 2020 23:55:05 -0700 (PDT) Received: from localhost.localdomain ([194.62.217.57]) by smtp.gmail.com with ESMTPSA id cz2sm7912769edb.82.2020.07.01.23.55.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2020 23:55:04 -0700 (PDT) From: =?utf-8?q?Javier_Gonz=C3=A1lez?= To: linux-nvme@lists.infradead.org Cc: linux-block@vger.kernel.org, hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@kernel.dk, Damien.LeMoal@wdc.com, mb@lightnvm.io, =?utf-8?q?Javier_Gonz=C3=A1lez?= , SelvaKumar S , Kanchan Joshi , Nitesh Shetty Subject: [PATCH 2/4] block: add support for zone offline transition Date: Thu, 2 Jul 2020 08:54:36 +0200 Message-Id: <20200702065438.46350-3-javier@javigon.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200702065438.46350-1-javier@javigon.com> References: <20200702065438.46350-1-javier@javigon.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Javier González Add support for offline transition on the zoned block device. Use the existing feature flags for the underlying driver to report support for the feature, as currently this transition is only supported in ZNS and not in ZAC/ZBC Signed-off-by: Javier González Signed-off-by: SelvaKumar S Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty --- block/blk-core.c | 2 ++ block/blk-zoned.c | 8 +++++++- drivers/nvme/host/core.c | 3 +++ drivers/nvme/host/zns.c | 2 +- include/linux/blk_types.h | 3 +++ include/linux/blkdev.h | 1 - include/uapi/linux/blkzoned.h | 3 +++ 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 03252af8c82c..589cbdacc5ec 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -140,6 +140,7 @@ static const char *const blk_op_name[] = { REQ_OP_NAME(ZONE_CLOSE), REQ_OP_NAME(ZONE_FINISH), REQ_OP_NAME(ZONE_APPEND), + REQ_OP_NAME(ZONE_OFFLINE), REQ_OP_NAME(WRITE_SAME), REQ_OP_NAME(WRITE_ZEROES), REQ_OP_NAME(SCSI_IN), @@ -1030,6 +1031,7 @@ generic_make_request_checks(struct bio *bio) case REQ_OP_ZONE_OPEN: case REQ_OP_ZONE_CLOSE: case REQ_OP_ZONE_FINISH: + case REQ_OP_ZONE_OFFLINE: if (!blk_queue_is_zoned(q)) goto not_supported; break; diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 0f156e96e48f..b97f67f462b4 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -320,7 +320,8 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, } /* - * BLKRESETZONE, BLKOPENZONE, BLKCLOSEZONE and BLKFINISHZONE ioctl processing. + * BLKRESETZONE, BLKOPENZONE, BLKCLOSEZONE, BLKFINISHZONE and BLKOFFLINEZONE + * ioctl processing. * Called from blkdev_ioctl. */ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, @@ -363,6 +364,11 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, case BLKFINISHZONE: op = REQ_OP_ZONE_FINISH; break; + case BLKOFFLINEZONE: + if (!(q->zone_flags & BLK_ZONE_REP_OFFLINE)) + return -EINVAL; + op = REQ_OP_ZONE_OFFLINE; + break; default: return -ENOTTY; } diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index e5f754889234..1f5c7fc3d2c9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -776,6 +776,9 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req, case REQ_OP_ZONE_FINISH: ret = nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_FINISH); break; + case REQ_OP_ZONE_OFFLINE: + ret = nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_OFFLINE); + break; case REQ_OP_WRITE_ZEROES: ret = nvme_setup_write_zeroes(ns, req, cmd); break; diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 888264261ba3..b34d2ed13825 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -81,7 +81,7 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, } q->limits.zoned = BLK_ZONED_HM; - q->zone_flags = BLK_ZONE_REP_CAPACITY; + q->zone_flags = BLK_ZONE_REP_CAPACITY | BLK_ZONE_REP_OFFLINE; blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); free_data: kfree(id); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index ccb895f911b1..c0123c643e2f 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -316,6 +316,8 @@ enum req_opf { REQ_OP_ZONE_FINISH = 12, /* write data at the current zone write pointer */ REQ_OP_ZONE_APPEND = 13, + /* Transition a zone to offline */ + REQ_OP_ZONE_OFFLINE = 14, /* SCSI passthrough using struct scsi_request */ REQ_OP_SCSI_IN = 32, @@ -455,6 +457,7 @@ static inline bool op_is_zone_mgmt(enum req_opf op) case REQ_OP_ZONE_OPEN: case REQ_OP_ZONE_CLOSE: case REQ_OP_ZONE_FINISH: + case REQ_OP_ZONE_OFFLINE: return true; default: return false; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 3f2e3425fa53..e489b646486d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -370,7 +370,6 @@ extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg); extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg); - #else /* CONFIG_BLK_DEV_ZONED */ static inline unsigned int blkdev_nr_zones(struct gendisk *disk) diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h index 42c3366cc25f..e5adf4a9f4b0 100644 --- a/include/uapi/linux/blkzoned.h +++ b/include/uapi/linux/blkzoned.h @@ -77,9 +77,11 @@ enum blk_zone_cond { * enum blk_zone_report_flags - Feature flags of reported zone descriptors. * * @BLK_ZONE_REP_CAPACITY: Zone descriptor has capacity field. + * @BLK_ZONE_REP_OFFLINE : Zone device supports offline transition. */ enum blk_zone_report_flags { BLK_ZONE_REP_CAPACITY = (1 << 0), + BLK_ZONE_REP_OFFLINE = (1 << 1), }; /** @@ -166,5 +168,6 @@ struct blk_zone_range { #define BLKOPENZONE _IOW(0x12, 134, struct blk_zone_range) #define BLKCLOSEZONE _IOW(0x12, 135, struct blk_zone_range) #define BLKFINISHZONE _IOW(0x12, 136, struct blk_zone_range) +#define BLKOFFLINEZONE _IOW(0x12, 137, struct blk_zone_range) #endif /* _UAPI_BLKZONED_H */ From patchwork Thu Jul 2 06:54:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Javier_Gonz=C3=A1lez?= X-Patchwork-Id: 11637897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87F9613BD for ; Thu, 2 Jul 2020 06:55:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DF6A208B8 for ; Thu, 2 Jul 2020 06:55:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=javigon-com.20150623.gappssmtp.com header.i=@javigon-com.20150623.gappssmtp.com header.b="jHPI8BGb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727961AbgGBGzI (ORCPT ); Thu, 2 Jul 2020 02:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbgGBGzI (ORCPT ); Thu, 2 Jul 2020 02:55:08 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 064E8C08C5C1 for ; Wed, 1 Jul 2020 23:55:08 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id d16so15802210edz.12 for ; Wed, 01 Jul 2020 23:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mBAEu2FkWCoUHddbe3NyP7a2YbJ4zD2w9Baf5z5Fx3Y=; b=jHPI8BGbaFFQIyi+Ut/ZHPViE0BmHnwBxTqZmPLkMoHWRgHbdfRnnbAVKe7BbGy28l dKxmms0rCd+k3CM2k5gzfrEdfM/pzj4sMWf/CnqiTjRzVjC5rGwrqyGMgj9eYgXnmjGI McMkAFROTNUEdX8iVjve2Pnh53/9mEN2tgT6aaQWMSyOukiLup7oz/ao/P42hPR1/JIy Mo4XFxAFXEuhpk2ABdelkGx8KtMmdyCHzShc7PSmHjNBVCyWAGvjYH7FEr3P2n87aqCT +dkU6iygsMqcE1YG5NKX73kZE3P6jm7cqYoc1oz9YaLc6LAjPKkbs/t4O++3DCQ6woo4 Vw0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mBAEu2FkWCoUHddbe3NyP7a2YbJ4zD2w9Baf5z5Fx3Y=; b=tlO1mPrWDADyf0BzxDkUO0srBU2zqU/eQBtgPoyocJW9q6jvQ9joppufgRl3hi3Tax m+rkg0oPwy+P+EEiSv7n35h9hSG52XhgvAL3rZmavZyf+sDGK6iD0sxlXO01rLdUT5GC fkT4OgmRtL4s2WpEI/kT+YgfAjo4U90X1B8OK1aDcOeWzDKU5VX5Uty0yjnGYGqYCds3 8M+2ptN76xVMSpcAyb/z/bF7fmwCOpqPK6czCjeJu0YunF9q/1zHG8CIGI1IQ8bElnd0 cD3I5T8eO40rdxI+4YEQIYqSgL/niFcbsZynqlrIeNKe6acxSBVBecVy+VIYkRLyc3U/ ilDg== X-Gm-Message-State: AOAM531hijGQqAs68286wcG+uG95oTYCQ+qZ2XicXHKFAXK05nx2DKP0 Dh0UH2QtuzqHH0DhPy1FTQ4liQ== X-Google-Smtp-Source: ABdhPJyL/BVcaBeMvR6W5Ilnhz2uE3e8A+oPUeNUiZyJBer3LEpqy+GpLnE79vkjfvRjc2E9oipsMQ== X-Received: by 2002:a05:6402:3064:: with SMTP id bs4mr33813102edb.350.1593672906690; Wed, 01 Jul 2020 23:55:06 -0700 (PDT) Received: from localhost.localdomain ([194.62.217.57]) by smtp.gmail.com with ESMTPSA id cz2sm7912769edb.82.2020.07.01.23.55.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2020 23:55:06 -0700 (PDT) From: =?utf-8?q?Javier_Gonz=C3=A1lez?= To: linux-nvme@lists.infradead.org Cc: linux-block@vger.kernel.org, hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@kernel.dk, Damien.LeMoal@wdc.com, mb@lightnvm.io, =?utf-8?q?Javier_Gonz=C3=A1lez?= , SelvaKumar S , Kanchan Joshi , Nitesh Shetty Subject: [PATCH 3/4] nvme: Add consistency check for zone count Date: Thu, 2 Jul 2020 08:54:37 +0200 Message-Id: <20200702065438.46350-4-javier@javigon.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200702065438.46350-1-javier@javigon.com> References: <20200702065438.46350-1-javier@javigon.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Javier González Since the number of zones is calculated through the reported device capacity and the ZNS specification allows to report the total number of zones in the device, add an extra check to guarantee consistency between the device and the kernel. Also, fix a checkpatch warning: unsigned -> unsigned int in the process Signed-off-by: Javier González Signed-off-by: SelvaKumar S Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty --- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/nvme.h | 6 ++++-- drivers/nvme/host/zns.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1f5c7fc3d2c9..8b9c69172931 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1994,7 +1994,7 @@ static int __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) case NVME_CSI_NVM: break; case NVME_CSI_ZNS: - ret = nvme_update_zone_info(disk, ns, lbaf); + ret = nvme_update_zone_info(disk, ns, lbaf, le64_to_cpu(id->nsze)); if (ret) return ret; break; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 662f95fbd909..ef80e0b4df56 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -407,6 +407,7 @@ struct nvme_ns { u32 sws; u8 pi_type; #ifdef CONFIG_BLK_DEV_ZONED + u64 nr_zones; u64 zsze; #endif unsigned long features; @@ -700,7 +701,7 @@ static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys) #ifdef CONFIG_BLK_DEV_ZONED int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, - unsigned lbaf); + unsigned int lbaf, sector_t nsze); int nvme_report_zones(struct gendisk *disk, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); @@ -720,7 +721,8 @@ static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, static inline int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, - unsigned lbaf) + unsigned lbaf + sector_t nsze) { dev_warn(ns->ctrl->device, "Please enable CONFIG_BLK_DEV_ZONED to support ZNS devices\n"); diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index b34d2ed13825..d785d179a343 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -32,13 +32,36 @@ static int nvme_set_max_append(struct nvme_ctrl *ctrl) return 0; } +static u64 nvme_zns_nr_zones(struct nvme_ns *ns) +{ + struct nvme_command c = { }; + struct nvme_zone_report report; + int buflen = sizeof(struct nvme_zone_report); + int ret; + + c.zmr.opcode = nvme_cmd_zone_mgmt_recv; + c.zmr.nsid = cpu_to_le32(ns->head->ns_id); + c.zmr.slba = cpu_to_le64(0); + c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen)); + c.zmr.zra = NVME_ZRA_ZONE_REPORT; + c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL; + c.zmr.pr = 0; + + ret = nvme_submit_sync_cmd(ns->queue, &c, &report, buflen); + if (ret) + return ret; + + return le64_to_cpu(report.nr_zones); +} + int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, - unsigned lbaf) + unsigned int lbaf, sector_t nsze) { // struct nvme_effects_log *log = ns->head->effects; struct request_queue *q = disk->queue; struct nvme_command c = { }; struct nvme_id_ns_zns *id; + sector_t cap_nr_zones; int status; /* Driver requires zone append support */ @@ -80,6 +103,20 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, goto free_data; } + ns->nr_zones = nvme_zns_nr_zones(ns); + if (!ns->nr_zones) { + status = -EINVAL; + goto free_data; + } + + cap_nr_zones = nvme_lba_to_sect(ns, le64_to_cpu(nsze)) >> ilog2(ns->zsze); + if (ns->nr_zones != cap_nr_zones) { + dev_err(ns->ctrl->device, "inconsistent zone count: %llu/%llu\n", + ns->nr_zones, cap_nr_zones); + status = -EINVAL; + goto free_data; + } + q->limits.zoned = BLK_ZONED_HM; q->zone_flags = BLK_ZONE_REP_CAPACITY | BLK_ZONE_REP_OFFLINE; blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); From patchwork Thu Jul 2 06:54:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Javier_Gonz=C3=A1lez?= X-Patchwork-Id: 11637899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDEF5739 for ; Thu, 2 Jul 2020 06:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D422E2085B for ; Thu, 2 Jul 2020 06:55:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=javigon-com.20150623.gappssmtp.com header.i=@javigon-com.20150623.gappssmtp.com header.b="iSI69gI8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727955AbgGBGzK (ORCPT ); Thu, 2 Jul 2020 02:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727948AbgGBGzJ (ORCPT ); Thu, 2 Jul 2020 02:55:09 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B6A5C08C5C1 for ; Wed, 1 Jul 2020 23:55:09 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id lx13so9276339ejb.4 for ; Wed, 01 Jul 2020 23:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KE1I2nGLyS8CRjZ/jic6a8RSadPgihMjPPFDgHjzHMg=; b=iSI69gI878xIDoelv9gFlLnZhYRwvAVY9q1JBjG2Qjd8i71nqsGwzLotgrgunzDkox AnhhPvj1drlVlMWWh7QHjdSH/9DRhJvTJo7/nsVISDJX/mTllv+2gF13q9z/zjxcsxQr 6iLwiKFBIsNkMcsTOA1Bz9DZQr/CLy7bSqd5/L7MSl7MprYvmVDOKDUFLJjqQf7fj8bB 7Jl+a6Ms8XOf8rBjVkQotXVRRmjG7tQaXN51yNyemj8lXcYrvJbVzTcJLRUhGQ+wXI5d l30oBMN/s2kQsa8ZvShhwoRQ6RsYRUHJKJ8o9F42zv88xiol012lmWmBE68vYqImRbjm /D8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KE1I2nGLyS8CRjZ/jic6a8RSadPgihMjPPFDgHjzHMg=; b=M1Acov41SkMqoBSLv1vbHhW2EUL8i1yR+IsJ5A7ENKykhpb57Q+a6X7zHqDOBopr9P tzMm5ib2ZLyCBrZbZRh2BAulD1/Ny2uvBLkiSC/4vuQeRIpmqC+ELrArM4ADZd6Mtl2p 4bj7CE47ua7HgwrgH2gsVR3BcMMiIuSCushHgr46q+MaD0X0p/JhGoG4uL1TIp0oXKnS yiIZWEJgkhqOrzdJpHbbULSViNzwsWR5+XGe+Mmidid6g2cLiSEYKwY7BGcsYNnvWPSy 2erGNxg8M598cqp7FteUjj6Q4YwGe23AgvTAOwkJEliVUS8F/9gB6STLjXsoN4QxFbJn jVeQ== X-Gm-Message-State: AOAM533evyTD1+Ab2l9Gg9yBbYHK//98L1YkgJ5PPEt+xYE/T7pg1sHy 7Ti8cvE4Kv2k9FnEAoqYMm/CZQ== X-Google-Smtp-Source: ABdhPJwJG3y7TU8m5PYTa437Kd8cPSYym48DCfQUbSzji2cGVF6r8In6Ka+RH/eoCSwz0o1tdjAZmA== X-Received: by 2002:a17:906:3e13:: with SMTP id k19mr25715216eji.476.1593672907887; Wed, 01 Jul 2020 23:55:07 -0700 (PDT) Received: from localhost.localdomain ([194.62.217.57]) by smtp.gmail.com with ESMTPSA id cz2sm7912769edb.82.2020.07.01.23.55.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jul 2020 23:55:07 -0700 (PDT) From: =?utf-8?q?Javier_Gonz=C3=A1lez?= To: linux-nvme@lists.infradead.org Cc: linux-block@vger.kernel.org, hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, axboe@kernel.dk, Damien.LeMoal@wdc.com, mb@lightnvm.io, =?utf-8?q?Javier_Gonz=C3=A1lez?= , SelvaKumar S , Kanchan Joshi , Nitesh Shetty Subject: [PATCH 4/4] block: add attributes to zone report Date: Thu, 2 Jul 2020 08:54:38 +0200 Message-Id: <20200702065438.46350-5-javier@javigon.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200702065438.46350-1-javier@javigon.com> References: <20200702065438.46350-1-javier@javigon.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Javier González Add zone attributes field to the blk_zone structure. Use ZNS attributes as base for zoned block devices and add the current atributes in ZAC/ZBC. Signed-off-by: Javier González Signed-off-by: SelvaKumar S Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty --- drivers/nvme/host/zns.c | 3 ++- drivers/scsi/sd.c | 2 +- drivers/scsi/sd_zbc.c | 8 ++++++-- include/uapi/linux/blkzoned.h | 26 +++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index d785d179a343..749382a14968 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -118,7 +118,7 @@ int nvme_update_zone_info(struct gendisk *disk, struct nvme_ns *ns, } q->limits.zoned = BLK_ZONED_HM; - q->zone_flags = BLK_ZONE_REP_CAPACITY | BLK_ZONE_REP_OFFLINE; + q->zone_flags = BLK_ZONE_REP_CAPACITY | BLK_ZONE_REP_CAPACITY | BLK_ZONE_REP_OFFLINE; blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); free_data: kfree(id); @@ -197,6 +197,7 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns, zone.capacity = nvme_lba_to_sect(ns, le64_to_cpu(entry->zcap)); zone.start = nvme_lba_to_sect(ns, le64_to_cpu(entry->zslba)); zone.wp = nvme_lba_to_sect(ns, le64_to_cpu(entry->wp)); + zone.attr = entry->za; return cb(&zone, idx, data); } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b9c920bace28..63270598aa76 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2967,7 +2967,7 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp) if (sdkp->device->type == TYPE_ZBC) { /* Host-managed */ q->limits.zoned = BLK_ZONED_HM; - q->zone_flags = BLK_ZONE_REP_CAPACITY; + q->zone_flags = BLK_ZONE_REP_CAPACITY | BLK_ZONE_REP_ATTR; } else { sdkp->zoned = (buffer[8] >> 4) & 3; if (sdkp->zoned == 1 && !disk_has_partitions(sdkp->disk)) { diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 183a20720da9..51c7f82b59c5 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -53,10 +53,14 @@ static int sd_zbc_parse_report(struct scsi_disk *sdkp, u8 *buf, zone.type = buf[0] & 0x0f; zone.cond = (buf[1] >> 4) & 0xf; - if (buf[1] & 0x01) + if (buf[1] & 0x01) { + zone.attr |= BLK_ZONE_ATTR_NRW; zone.reset = 1; - if (buf[1] & 0x02) + } + if (buf[1] & 0x02) { + zone.attr |= BLK_ZONE_ATTR_NSQ; zone.non_seq = 1; + } zone.len = logical_to_sectors(sdp, get_unaligned_be64(&buf[8])); zone.capacity = zone.len; diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h index e5adf4a9f4b0..315617827acd 100644 --- a/include/uapi/linux/blkzoned.h +++ b/include/uapi/linux/blkzoned.h @@ -78,10 +78,33 @@ enum blk_zone_cond { * * @BLK_ZONE_REP_CAPACITY: Zone descriptor has capacity field. * @BLK_ZONE_REP_OFFLINE : Zone device supports offline transition. + * @BLK_ZONE_REP_ATTR: Zone attributes reported. */ enum blk_zone_report_flags { BLK_ZONE_REP_CAPACITY = (1 << 0), BLK_ZONE_REP_OFFLINE = (1 << 1), + BLK_ZONE_REP_ATTR = (1 << 2), +}; + +/** + * enum blk_zone_attr - Zone Attributes + * + * Attributes of the zone. Reported in struct blk_zone -> attr + * + * @BLK_ZONE_ATTR_ZFC: Zone Finished by Controller due to a zone active excursion + * @BLK_ZONE_ATTR_FZR: Finish Zone Recommended required by controller + * @BLK_ZONE_ATTR_RZR: Reset Zone Recommended required by controller + * @BLK_ZONE_ATTR_NSQ: Non Sequential zone + * @BLK_ZONE_ATTR_NRW: Need Reset Write Pointer required by controller + * @BLK_ZONE_ATTR_ZDEV: Zone Descriptor Extension Valid in zone report + */ +enum blk_zone_attr { + BLK_ZONE_ATTR_ZFC = 1 << 0, + BLK_ZONE_ATTR_FZR = 1 << 1, + BLK_ZONE_ATTR_RZR = 1 << 2, + BLK_ZONE_ATTR_NSQ = 1 << 3, + BLK_ZONE_ATTR_NRW = 1 << 4, + BLK_ZONE_ATTR_ZDEV = 1 << 7, }; /** @@ -110,7 +133,8 @@ struct blk_zone { __u8 cond; /* Zone condition */ __u8 non_seq; /* Non-sequential write resources active */ __u8 reset; /* Reset write pointer recommended */ - __u8 resv[4]; + __u8 attr; /* Zone attributes */ + __u8 resv[3]; __u64 capacity; /* Zone capacity in number of sectors */ __u8 reserved[24]; };