From patchwork Tue Jan 19 09:38:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12029999 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 7DC2AC433DB for ; Tue, 19 Jan 2021 14:48:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52E5E2168B for ; Tue, 19 Jan 2021 14:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389541AbhASOjQ (ORCPT ); Tue, 19 Jan 2021 09:39:16 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:36726 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbhASJlW (ORCPT ); Tue, 19 Jan 2021 04:41:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611049769; x=1642585769; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y6dOEwqLpl0B2L45bIDXFCcME1XrSfA+Q8mO9kbSPHc=; b=gDkfrG7ahHw8KmVsyTeIPsgP2R6h1hVRE5AFBdx2J2LSaQK3sXHj2gpZ DfrrLG56fZZgrwj4qUc8R6nRE5D8LotAqgM/QWiHPo7XnEi0z/65ezt+w erTYYxQOL06Ppw4VL7g3Iu/iTeEw9kw8BJM04YmqiqFFJrP7Ygv7P/I10 dETLGljsItWxvsZcraUc3O5+c1CtWIluXglHHENyjPjFfyIyy7Rzfr2v5 I23MhUHyybHwg+B5/GCZrM8rjfl5CJo7vgMQxp9aR6LRznnj3uCd2+Zsb RP6zeF16rfhNo1dqwoW6Czo0JHYr9wFNr6BLcH5J0b/8CX1PfcKe2vFFR Q==; IronPort-SDR: zTByC7BIThlntQYJm3Qzdl7DbKqFTlIZOCZ4tzCbKWKbjsKT/51ga1SR8a3CqEFA707G2tNre/ ISfoU6kotVn62F3AntEZLVtfdvYEMdSuN1L2Jr9MGOwYdXyhlCWWz/+T1hiKWnLgcwB53ZfeBV Zd5Xj/tAkCxkZCFMo1ikuLb/M2QT8IQlycrQt4Tx6JRKgoy7vLq9nWnGdjy/xBYA0SI++efFAk 40RS53CpqkwkDss9e+rseADAO0JRDxRVVu1gPOALRHeA7IgdbYplrYXrWFl6JYjAJDU8RSKTTe QeE= X-IronPort-AV: E=Sophos;i="5.79,358,1602518400"; d="scan'208";a="261745163" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Jan 2021 17:45:50 +0800 IronPort-SDR: HnpRZwGCisi7JSHvFJMkkUK7P8t8pgPkmXJTk2rEw12dd0o4vH8mB0N/TNrGCvomTiNszmRst4 Kh4JrdD/H4hhZRkhjBuMNBywbxPDfG1AyMSDvkNdfb68BkTwlsGyJD6f9tB3yaJ0+MSOqdI4ie FkaR+Z42EyfIhS9h96v5ncNGB1AoVFX32ZUKJFYp6YfI1jELSaPbqLr7Ve7F6x3Lxv9/7a0jWb 3gjyjroTEN5+Bd7HBV3bAt6y/m1KqYvn8ulZdAejTcn+m4nFb0H6Qpl6jUVr+0zNTVYVx8coTQ GSQuwok4ykcsTovf9zdGGgae Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2021 01:23:34 -0800 IronPort-SDR: 79N2C0ZoAd+Zxs0uDr+yZ4vdd5KapVnQ8vdbXp+UcwS2zZpatDr9F6m2kTio+J18lHmhPxQy+6 uA3mMfEcD/pOd50k58A08UU5338TTFOqgsqKAg9Y88ZWFcPng7iAZ9OoULV7KULuyEeQzkdnSO Ysdunngd5ryYGaJvskLw7WzMe5XQR8mCgmgZk4+meFtU46kxFlyt9mgLy5dU8ibVsiia8T0Otd Z18OO4dq8IbPXVckOMN1/gjHaFCjRTNu31Obl5uP1pMjOhCMajxIU/3TzBNsupGY/TRnQnugWw Wpk= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Jan 2021 01:38:56 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: Chaitanya Kulkarni Subject: [PATCH v2 1/2] block: introduce zone_write_granularity limit Date: Tue, 19 Jan 2021 18:38:54 +0900 Message-Id: <20210119093855.1633232-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210119093855.1633232-1-damien.lemoal@wdc.com> References: <20210119093855.1633232-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Per ZBC and ZAC specifications, host-managed SMR hard-disks mandate that all writes into sequential write required zones be aligned to the device physical block size. However, NVMe ZNS does not have this constraint and allows write operations into sequential zones to be logical block size aligned. This inconsistency does not help with portability of software across device types. To solve this, introduce the zone_write_granularity queue limit to indicate the alignment constraint, in bytes, of write operations into zones of a zoned block device. This new limit is exported as a read-only sysfs queue attribute and the helper blk_queue_zone_write_granularity() introduced for drivers to set this limit. The scsi disk driver is modified to use this helper to set host-managed SMR disk zone write granularity to the disk physical block size. The nvme driver zns support use this helper to set the new limit to the logical block size of the zoned namespace. Signed-off-by: Damien Le Moal --- Documentation/block/queue-sysfs.rst | 7 +++++++ block/blk-settings.c | 28 ++++++++++++++++++++++++++++ block/blk-sysfs.c | 7 +++++++ drivers/nvme/host/zns.c | 1 + drivers/scsi/sd_zbc.c | 10 ++++++++++ include/linux/blkdev.h | 3 +++ 6 files changed, 56 insertions(+) diff --git a/Documentation/block/queue-sysfs.rst b/Documentation/block/queue-sysfs.rst index 2638d3446b79..c8bf8bc3c03a 100644 --- a/Documentation/block/queue-sysfs.rst +++ b/Documentation/block/queue-sysfs.rst @@ -273,4 +273,11 @@ devices are described in the ZBC (Zoned Block Commands) and ZAC do not support zone commands, they will be treated as regular block devices and zoned will report "none". +zone_write_granularity (RO) +--------------------------- +This indicates the alignment constraint, in bytes, for write operations in +sequential zones of zoned block devices (devices with a zoned attributed +that reports "host-managed" or "host-aware"). This value is always 0 for +regular block devices. + Jens Axboe , February 2009 diff --git a/block/blk-settings.c b/block/blk-settings.c index 43990b1d148b..6be6ed9485e3 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -60,6 +60,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->io_opt = 0; lim->misaligned = 0; lim->zoned = BLK_ZONED_NONE; + lim->zone_write_granularity = 0; } EXPORT_SYMBOL(blk_set_default_limits); @@ -366,6 +367,31 @@ void blk_queue_physical_block_size(struct request_queue *q, unsigned int size) } EXPORT_SYMBOL(blk_queue_physical_block_size); +/** + * blk_queue_zone_write_granularity - set zone write granularity for the queue + * @q: the request queue for the zoned device + * @size: the zone write granularity size, in bytes + * + * Description: + * This should be set to the lowest possible size allowing to write in + * sequential zones of a zoned block device. + */ +void blk_queue_zone_write_granularity(struct request_queue *q, + unsigned int size) +{ + if (WARN_ON(!blk_queue_is_zoned(q))) + return; + + q->limits.zone_write_granularity = size; + + if (q->limits.zone_write_granularity < q->limits.logical_block_size) + q->limits.zone_write_granularity = q->limits.logical_block_size; + + if (q->limits.zone_write_granularity < q->limits.io_min) + q->limits.zone_write_granularity = q->limits.io_min; +} +EXPORT_SYMBOL_GPL(blk_queue_zone_write_granularity); + /** * blk_queue_alignment_offset - set physical block alignment offset * @q: the request queue for the device @@ -631,6 +657,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->discard_granularity; } + t->zone_write_granularity = max(t->zone_write_granularity, + b->zone_write_granularity); t->zoned = max(t->zoned, b->zoned); return ret; } diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index b513f1683af0..7ea3dd4d876b 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -219,6 +219,11 @@ static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) (unsigned long long)q->limits.max_write_zeroes_sectors << 9); } +static ssize_t queue_zone_write_granularity_show(struct request_queue *q, char *page) +{ + return queue_var_show(q->limits.zone_write_granularity, page); +} + static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) { unsigned long long max_sectors = q->limits.max_zone_append_sectors; @@ -585,6 +590,7 @@ QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); +QUEUE_RO_ENTRY(queue_zone_write_granularity, "zone_write_granularity"); QUEUE_RO_ENTRY(queue_zoned, "zoned"); QUEUE_RO_ENTRY(queue_nr_zones, "nr_zones"); @@ -639,6 +645,7 @@ static struct attribute *queue_attrs[] = { &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, + &queue_zone_write_granularity_entry.attr, &queue_nonrot_entry.attr, &queue_zoned_entry.attr, &queue_nr_zones_entry.attr, diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 1dfe9a3500e3..f25311ccd996 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -113,6 +113,7 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf) blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); blk_queue_max_open_zones(q, le32_to_cpu(id->mor) + 1); blk_queue_max_active_zones(q, le32_to_cpu(id->mar) + 1); + blk_queue_zone_write_granularity(q, q->limits.logical_block_size); free_data: kfree(id); return status; diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index cf07b7f93579..41d602f7e62e 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -789,6 +789,16 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) blk_queue_max_active_zones(q, 0); nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks); + /* + * Per ZBC and ZAC specifications, writes in sequential write required + * zones of host-managed devices must be aligned to the device physical + * block size. + */ + if (blk_queue_zoned_model(q) == BLK_ZONED_HM) + blk_queue_zone_write_granularity(q, sdkp->physical_block_size); + else + blk_queue_zone_write_granularity(q, sdkp->device->sector_size); + /* READ16/WRITE16 is mandatory for ZBC disks */ sdkp->device->use_16_for_rw = 1; sdkp->device->use_10_for_rw = 0; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f94ee3089e01..011b3d2cd273 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -337,6 +337,7 @@ struct queue_limits { unsigned int max_zone_append_sectors; unsigned int discard_granularity; unsigned int discard_alignment; + unsigned int zone_write_granularity; unsigned short max_segments; unsigned short max_integrity_segments; @@ -1161,6 +1162,8 @@ extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); extern void blk_queue_max_zone_append_sectors(struct request_queue *q, unsigned int max_zone_append_sectors); extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); +void blk_queue_zone_write_granularity(struct request_queue *q, + unsigned int size); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); void blk_queue_update_readahead(struct request_queue *q); From patchwork Tue Jan 19 09:38:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12029933 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 65F22C433E0 for ; Tue, 19 Jan 2021 14:40:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E07A20DD4 for ; Tue, 19 Jan 2021 14:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391208AbhASOju (ORCPT ); Tue, 19 Jan 2021 09:39:50 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:36901 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730106AbhASJls (ORCPT ); Tue, 19 Jan 2021 04:41:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611049807; x=1642585807; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gf41tJSgK06B/Ga4VjMMXYqoISVLe/c4wgOY899USOM=; b=Xpuq4YwKBhK5mr0FVX5LURtse2AOw3sn8fUWeqbn5pPxmLcAxZMfAATg xKN//XibR7FdYmfJoL/IPI9S+j1cgGi2OwuH1sCpgTVU6uE+JzQSjnuPe 4fDsTs3Jej7EG/iNiMUDnv3eZMlIah4rWabT9Eh78dt6IJfa2ypSt4Yed kY3LHLvngZPIQFVl1t0yzYwjX8PYbZpYIwJjUvp0qXy3qZ4eJDOD74vCw pHQthRzrL7Wd06rkSGlDL+DzufA8t/z8itDg7NP1WN2+ZE3fqXE6vdVPC xefrvzJD5aMjYw0MOVP1XLNYRqscZMMooZzrPN+k21XKBg2K5d/QleNCR A==; IronPort-SDR: hezkYgGg1unwe+41YcWGJ0rTblGMJ5Jch6EJPah6sK75B2RCvbBJMhiLkqQvG4T7DpKAu5RvgP kyaa16wiOeZus09sIzoE8u8Tw2Hto6CSLMXZwS6tx4H56E0YACBteOJYM4rqoMDrBIdikUBDC2 plpTy6qND9zGP8V9EGIGyrwMM9sgR01AjzafaYfqOMBHB45XWvW4S+K//Z5XC40yA0vHnPo8T9 Ta+KEWxz2136YSxxoxEuxnE1LPmwdwnhktphYE4suOqC86qzAXkqaLoo0XpwlvDL1N3Bjw5fP2 eD8= X-IronPort-AV: E=Sophos;i="5.79,358,1602518400"; d="scan'208";a="261745164" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 19 Jan 2021 17:45:51 +0800 IronPort-SDR: kMv+UtXFqylEi1HE1pNur+CS2ezi3pWNrJIPs0rtD39PH/DfK8zEqfnWVHqGZv0cR1YhFoYwOU thzqqGO7SWjC0I51j4jg8Y7yvDNLkBq5hsmkxWxPLIvsVvOPWTlDxkRAGgImE67QXMilTS98+n O9tk3gp0UEc8ZJdoCymcEX0IFYwmPtfKc15pyl/9WkoE/iz69T6jomR50j2zzv0MAeWHnqVX/0 gPo0hYZz+wihms38OpvjSYEbgobp9v6K0RzgrTCYdiHZ8qDd3J+igJ97fcYbo3PPnyWmIeG5UL LTXxaZmAhm7OiSB9yFqhKxM4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2021 01:23:35 -0800 IronPort-SDR: xIDxcBheQlgXo7ZUms0qQyLNEdYsboFRp17WDB1JXkkAD5fs5ESUVcU4h96k9BkShlr32PIxbs l226qLi3nmQe3bW2biWVEIPPGXS2ZYuoVI1F5c/wKVkDi0zU3N8fC27qygcSi65qFOZ4AMeq+h O+K/2xEn4j3JtFLfpmqcvrWBbaEwogH76ACSBKaKqkN7GP/N0BfxpqjaHXIcLOUbNxMlJRM5oG CNRDB6n26SxqQgcHgEa/kUaF+2b993sMM5CFQKdZBdrVSZr2ZVn8Ix8o+F8vQVvDMfNsJHnVY1 vm0= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 Jan 2021 01:38:57 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: Chaitanya Kulkarni Subject: [PATCH v2 2/2] block: document zone_append_max_bytes attribute Date: Tue, 19 Jan 2021 18:38:55 +0900 Message-Id: <20210119093855.1633232-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210119093855.1633232-1-damien.lemoal@wdc.com> References: <20210119093855.1633232-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The description of the zone_append_max_bytes sysfs queue attribute is missing from Documentation/block/queue-sysfs.rst. Add it. Signed-off-by: Damien Le Moal --- Documentation/block/queue-sysfs.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/block/queue-sysfs.rst b/Documentation/block/queue-sysfs.rst index c8bf8bc3c03a..4dc7f0d499a8 100644 --- a/Documentation/block/queue-sysfs.rst +++ b/Documentation/block/queue-sysfs.rst @@ -261,6 +261,12 @@ For block drivers that support REQ_OP_WRITE_ZEROES, the maximum number of bytes that can be zeroed at once. The value 0 means that REQ_OP_WRITE_ZEROES is not supported. +zone_append_max_bytes (RO) +-------------------------- +This is the maximum number of bytes that can be written to a sequential +zone of a zoned block device using a zone append write operation +(REQ_OP_ZONE_APPEND). This value is always 0 for regular block devices. + zoned (RO) ---------- This indicates if the device is a zoned block device and the zone model of the