From patchwork Tue May 25 21:24:51 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: 12280209 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,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 22B5EC47087 for ; Tue, 25 May 2021 21:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEF696138C for ; Tue, 25 May 2021 21:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbhEYV0g (ORCPT ); Tue, 25 May 2021 17:26:36 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36430 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhEYV0f (ORCPT ); Tue, 25 May 2021 17:26:35 -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=1621977905; x=1653513905; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=HZ9nR2Wt42duKB9VuSB+rN7vKo5fCE+w/TkjdyuaIWU=; b=nznf1nz675X/RygMqHQmYJ+3w935Wf+i/eVXjWd9H8shPbcCTdqMA6+C 7mdvYFGfYbc+/z+Gc7gFpK9TlHlupTlFcyM/RAm5lTJlsIsCCdU4u4MxH MjqXgeFjvg31JXV6eDzkQzKfkRQr28Hb+Iefg5LRwIiuEljPGqAd0jsBH UBdhgB2ZjWpEBhoGEBkfsMAHvA/GfAh5IOQAZHp3q5iWWTs62W9ibg7r5 et2q+3Ey72mivdDsXivzVzX4vv5Mf8ZoDtTrHnDUDNVqer+pS04QWmaXW XBCJYNxWrguXVtbVdgW3DdfYgJ4ztvs66ZiSujWc64kND3ybKu2yT4moQ Q==; IronPort-SDR: yjJ5SRO19Fkg17LQ6JZJNXdy2LhfjX1uLlHi3TbESUrBgv9Y6uaectNRn9YBG6CzkKew0FnAAe J286kbU0cL1KzwenW+dGkYDOTZIebV/JPtYV98daWy5o//2owOQTPHxvsla/yh6Julnck4ywt9 AgmSnoPxmxOd+AMKpJ66uEaGHnaVA9E3btBscv3KDpFmg8ijoLDOt0nZKXgz+DszslM/WsBRHg IywCg7PZYnddDyYHCsI0v5IlpjAKCRz5zfpuiiz77+5oG4iwwucqqOwkIXHFxqi+RCqYGWA9IO 9/I= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717511" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:05 +0800 IronPort-SDR: SNXme9tGNxRjyOuwPa8+XJyiodwcNwnQbHdPSVdA1/bI/rubuq5lwVfHxqWS1QGr/rPGw+R5Dy PNJanEA+WFrSrA7ZLBXC36Lz4+L2XUhc1w7X9/UbvBKAEoOuOnkdhDW/3A9qDff/1nCNVEHZGx +CTqLJmABfoc8SBtz5EkWwVfWOhhhXSYt8NMEfPuDDncur1JgWRgT/fPAfE9WP+P/EUbwsagxz sIx5h+c9k8xBXX4Y9qLcchF9MRXGPzkOWhOdylHzbP3Xv7G1Fxq+koJtT5V1HJBpbpT8gc0lhI 3C/1Vi8m3K6MeQWoS8NnEDeB Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:32 -0700 IronPort-SDR: JXYChdx1ksGzEd1nsxFuICFcsVeq3qezQ9YjTp4HHfAm48yAJ4QYFmSuJzzl+J7CCn7wDZV6Nf qEtxIRVtV86UZxLbGnvbenK6EqJ8cBxtzhep30GM5ZokG4PGzvOG4ao2vM7cTS+4F9d1UrqHEs dWr5l6wGPWvs5OmWCN0ZKZkNeqNjb/syemoUm1v+HW/c8NGzmwIUe4mA4LAtZPWsAr4gIq7xYO lUJbnAdfpS0VEhUYMLNGqZ1GnRPkh+9YJvdvzrk6MUbvNr4f4XeIGxAqbJ9CcAGr8Ma9PxBXSB /2U= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:05 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 01/11] block: improve handling of all zones reset operation Date: Wed, 26 May 2021 06:24:51 +0900 Message-Id: <20210525212501.226888-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org SCSI, ZNS and null_blk zoned devices support resetting all zones using a single command (REQ_OP_ZONE_RESET_ALL), as indicated using the device request queue flag QUEUE_FLAG_ZONE_RESETALL. This flag is not set for device mapper targets creating zoned devices. In this case, a user request for resetting all zones of a device is processed in blkdev_zone_mgmt() by issuing a REQ_OP_ZONE_RESET operation for each zone of the device. This leads to different behaviors of the BLKRESETZONE ioctl() depending on the target device support for the reset all operation. E.g. blkzone reset /dev/sdX will reset all zones of a SCSI device using a single command that will ignore conventional, read-only or offline zones. But a dm-linear device including conventional, read-only or offline zones cannot be reset in the same manner as some of the single zone reset operations issued by blkdev_zone_mgmt() will fail. E.g.: blkzone reset /dev/dm-Y blkzone: /dev/dm-0: BLKRESETZONE ioctl failed: Remote I/O error To simplify applications and tools development, unify the behavior of the all-zone reset operation by modifying blkdev_zone_mgmt() to not issue a zone reset operation for conventional, read-only and offline zones, thus mimicking what an actual reset-all device command does on a device supporting REQ_OP_ZONE_RESET_ALL. This emulation is done using the new function blkdev_zone_reset_all_emulated(). The zones needing a reset are identified using a bitmap that is initialized using a zone report. Since empty zones do not need a reset, also ignore these zones. The function blkdev_zone_reset_all() is introduced for block devices natively supporting reset all operations. blkdev_zone_mgmt() is modified to call either function to execute an all zone reset request. Signed-off-by: Damien Le Moal [hch: split into multiple functions] Signed-off-by: Christoph Hellwig Reviewed-by: Chaitanya Kulkarni Reviewed-by: Hannes Reinecke --- block/blk-zoned.c | 119 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 27 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 250cb76ee615..86fce751bb17 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -161,18 +161,89 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL_GPL(blkdev_report_zones); -static inline bool blkdev_allow_reset_all_zones(struct block_device *bdev, - sector_t sector, - sector_t nr_sectors) +static inline unsigned long *blk_alloc_zone_bitmap(int node, + unsigned int nr_zones) { - if (!blk_queue_zone_resetall(bdev_get_queue(bdev))) - return false; + return kcalloc_node(BITS_TO_LONGS(nr_zones), sizeof(unsigned long), + GFP_NOIO, node); +} +static int blk_zone_need_reset_cb(struct blk_zone *zone, unsigned int idx, + void *data) +{ /* - * REQ_OP_ZONE_RESET_ALL can be executed only if the number of sectors - * of the applicable zone range is the entire disk. + * For an all-zones reset, ignore conventional, empty, read-only + * and offline zones. */ - return !sector && nr_sectors == get_capacity(bdev->bd_disk); + switch (zone->cond) { + case BLK_ZONE_COND_NOT_WP: + case BLK_ZONE_COND_EMPTY: + case BLK_ZONE_COND_READONLY: + case BLK_ZONE_COND_OFFLINE: + return 0; + default: + set_bit(idx, (unsigned long *)data); + return 0; + } +} + +static int blkdev_zone_reset_all_emulated(struct block_device *bdev, + gfp_t gfp_mask) +{ + struct request_queue *q = bdev_get_queue(bdev); + sector_t capacity = get_capacity(bdev->bd_disk); + sector_t zone_sectors = blk_queue_zone_sectors(q); + unsigned long *need_reset; + struct bio *bio = NULL; + sector_t sector = 0; + int ret; + + need_reset = blk_alloc_zone_bitmap(q->node, q->nr_zones); + if (!need_reset) + return -ENOMEM; + + ret = bdev->bd_disk->fops->report_zones(bdev->bd_disk, 0, + q->nr_zones, blk_zone_need_reset_cb, + need_reset); + if (ret < 0) + goto out_free_need_reset; + + ret = 0; + while (sector < capacity) { + if (!test_bit(blk_queue_zone_no(q, sector), need_reset)) { + sector += zone_sectors; + continue; + } + + bio = blk_next_bio(bio, 0, gfp_mask); + bio_set_dev(bio, bdev); + bio->bi_opf = REQ_OP_ZONE_RESET | REQ_SYNC; + bio->bi_iter.bi_sector = sector; + sector += zone_sectors; + + /* This may take a while, so be nice to others */ + cond_resched(); + } + + if (bio) { + ret = submit_bio_wait(bio); + bio_put(bio); + } + +out_free_need_reset: + kfree(need_reset); + return ret; +} + +static int blkdev_zone_reset_all(struct block_device *bdev, gfp_t gfp_mask) +{ + struct bio bio; + + bio_init(&bio, NULL, 0); + bio_set_dev(&bio, bdev); + bio.bi_opf = REQ_OP_ZONE_RESET_ALL | REQ_SYNC; + + return submit_bio_wait(&bio); } /** @@ -200,7 +271,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, sector_t capacity = get_capacity(bdev->bd_disk); sector_t end_sector = sector + nr_sectors; struct bio *bio = NULL; - int ret; + int ret = 0; if (!blk_queue_is_zoned(q)) return -EOPNOTSUPP; @@ -222,20 +293,21 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity) return -EINVAL; + /* + * In the case of a zone reset operation over all zones, + * REQ_OP_ZONE_RESET_ALL can be used with devices supporting this + * command. For other devices, we emulate this command behavior by + * identifying the zones needing a reset. + */ + if (op == REQ_OP_ZONE_RESET && sector == 0 && nr_sectors == capacity) { + if (!blk_queue_zone_resetall(q)) + return blkdev_zone_reset_all_emulated(bdev, gfp_mask); + return blkdev_zone_reset_all(bdev, gfp_mask); + } + while (sector < end_sector) { bio = blk_next_bio(bio, 0, gfp_mask); bio_set_dev(bio, bdev); - - /* - * Special case for the zone reset operation that reset all - * zones, this is useful for applications like mkfs. - */ - if (op == REQ_OP_ZONE_RESET && - blkdev_allow_reset_all_zones(bdev, sector, nr_sectors)) { - bio->bi_opf = REQ_OP_ZONE_RESET_ALL | REQ_SYNC; - break; - } - bio->bi_opf = op | REQ_SYNC; bio->bi_iter.bi_sector = sector; sector += zone_sectors; @@ -396,13 +468,6 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, return ret; } -static inline unsigned long *blk_alloc_zone_bitmap(int node, - unsigned int nr_zones) -{ - return kcalloc_node(BITS_TO_LONGS(nr_zones), sizeof(unsigned long), - GFP_NOIO, node); -} - void blk_queue_free_zone_bitmaps(struct request_queue *q) { kfree(q->conv_zones_bitmap); From patchwork Tue May 25 21:24:52 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: 12280211 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,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 3825CC47086 for ; Tue, 25 May 2021 21:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E99361417 for ; Tue, 25 May 2021 21:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbhEYV0h (ORCPT ); Tue, 25 May 2021 17:26:37 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36430 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhEYV0g (ORCPT ); Tue, 25 May 2021 17:26:36 -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=1621977906; x=1653513906; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=cnqRYx2R05sP7V9ec2jM+bey4sRJDAw/pWEMU80Ln+I=; b=G+dbrM+Fg2vGmhVAAB9GeDwzXwFqcERUqntOnbqeB81ubRlxzdM93mpc Nzi6Bs/IeBdBxH4ynnJ5lzFoY3tJLWQldpFVDYroKH5v9haabgX/uu5Av GEtK6l/sbeKg/iSPmL/bawXhsEZN2CAuCZ8xn99a4nG0WPOXDZPLMOOWH +avfVWXv5dsioDaKOrZvpF3KWcBDZJ5yn608wnXZca+0KbfRRP8CjPkfc HyBNVagoy3Qld2K8moevGdevlED6ODaNUxENQ/EMoleelT3N26Fv6nOia ELxrr3D3QZWjFhFYJFjbtcd3rYBPX4qqGjgJ3Si+taYrExPq1pISTeB/D w==; IronPort-SDR: DiQEplpgH98rnY+MufPYr8le1uBP1276f+8s94+kOrCBGYsqeJVZx4a1lI3rADf1ld9wjcmD14 DwwSlfQyXTtrdOmkXU7ukGs0pp8YCxVoIdlLdDEJyZtHlbN/XSN0AyGmPsI61yIOLYobanpH5K o5o3c7/nClafJycWBAjo5W6E9uvsR7qjaLHkEuYd+b4vYiyEKrhDMYv+IJfPsCNvELkfSRokUP a5c7OUn74amp9zx8f6RpKOxgD/aRqlqYRA2GcCCLKUCyQgTyLqCOzwl1tBoGD1FdOUPN6v8KOk wmg= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717514" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:06 +0800 IronPort-SDR: 5nyBrgiom04S+WKdZ8HNv/EMYxN8Qkdp2kjrIvNtjxHgm+vWhMg7IgOJQ0tjgijEzHcWAxhqx8 u5fGBkgiQ5avUq73/3N9vpHD7tKX0Yr0Pma4AGcEJEVMz+G9/08IjstV4jdM4U2MpImfDOLnsj lYZfKvM752VHS8xMKIoxZ+kVwON3RjqYR6ef+L25GkIy0ikB3ZHOoj2PMcUnEDzCtK0aHhPEph pgMkghAmxqetyIAlF2Xc98rMjFb95TnfV73KRvLsT3vYx4oHwJzcuz0vXJXpVlXqmFaKtQwz0r HuIY3cdNQULJ4rm6UE6JXpZa Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:34 -0700 IronPort-SDR: METJ6JkdC2rJw/wpyWsuv8N7jzQudGNSY6gML668bluLFD0tIn3SFp/V7/AIqHqY5r/YKPpWT1 ffZP6HcvFV9i86+tGzvlNZgDn8pYS/GPJlWGyJrsT8WG9WguRKrNn4/BVLuRzbWQyCYvV35AIf U3ViBdYghgNAik5M0yR/oT3KumOT3izeUi/wtl2SsJUVq8U1+8wI1wXG6DGg8sgWiV10y+7J2i N3WZbNOukAt11JGUP0Qqd5LK4qwunBjY+JZ7pNkb77xSZJW/o8oC8c1Ke3CH9ArYD+qZFiQjjY ciw= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:06 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 02/11] block: introduce bio zone helpers Date: Wed, 26 May 2021 06:24:52 +0900 Message-Id: <20210525212501.226888-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce the helper functions bio_zone_no() and bio_zone_is_seq(). Both are the BIO counterparts of the request helpers blk_rq_zone_no() and blk_rq_zone_is_seq(), respectively returning the number of the target zone of a bio and true if the BIO target zone is sequential. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Reviewed-by: Himanshu Madhani --- include/linux/blkdev.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f69c75bd6d27..2db0f376f5d9 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1008,6 +1008,18 @@ static inline unsigned int blk_rq_stats_sectors(const struct request *rq) /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ const char *blk_zone_cond_str(enum blk_zone_cond zone_cond); +static inline unsigned int bio_zone_no(struct bio *bio) +{ + return blk_queue_zone_no(bdev_get_queue(bio->bi_bdev), + bio->bi_iter.bi_sector); +} + +static inline unsigned int bio_zone_is_seq(struct bio *bio) +{ + return blk_queue_zone_is_seq(bdev_get_queue(bio->bi_bdev), + bio->bi_iter.bi_sector); +} + static inline unsigned int blk_rq_zone_no(struct request *rq) { return blk_queue_zone_no(rq->q, blk_rq_pos(rq)); From patchwork Tue May 25 21:24:53 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: 12280213 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,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 45157C4707F for ; Tue, 25 May 2021 21:25:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FBEB61417 for ; Tue, 25 May 2021 21:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbhEYV0i (ORCPT ); Tue, 25 May 2021 17:26:38 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36430 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhEYV0i (ORCPT ); Tue, 25 May 2021 17:26:38 -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=1621977908; x=1653513908; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=6kRIuS/fUul5WvYm1RwOlXRDAyrR8fnPc2uP9r0LZSo=; b=OtMngLOAhXuzazCr/J0DDOA8RX2s4kNKmAHMSNisn++i95U1ebItJF3z lGyAvqLhIH4SqKXTCtV7AjbguXiMgI1yt4Ele8qNWVhqXS1iJQMppc1Ct hueZBAF+4H0DfQ003nQEkQT4aRJhxpcCUAGdbwsXpmxZYX+1jG1YFJOTr cxsaAc2t31yZuIl21jnIWjgBgCEReotGK9qOZxOG5Qo08nSLQ0/JvwZ/o jj3MmLamuN4RsqqJsbL6rk+zw8215jxWv1myB9K6VhA93hifcEwSTyIeJ RGMF+G95Bi9eOd4X4cqEQTQIrjHI6L6vA4cCt5bwlctXFWvQ6NtI/MAHu w==; IronPort-SDR: oVknKXiiR96A0FRWVp7vF6d/vRhk7VUjOZtJ08CWUwwW0RHdyatrLaH2xKViqwApI6naEJdCnz 8JbUsTz23T70dFiX1AC2EDpzdj1spuq/7X5cqWN3lsXYV4y1cEfTu3vvt2lX+yqm1iYSIcaKF/ jEBqL0JprInrF5SfC+k20i1tXfGQc+EA2QqEAlItdzJdNnoTAyQkKLCgJkJPvX3sCuSTm1tqz3 x6qPEcBbOazgMNc0gYu3kT1chNNNkasUaM/ZLqc09BosGB4O96E6I77f+4yzSX64volLlKyE74 dDA= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717517" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:07 +0800 IronPort-SDR: mqnDTol9pcB/H5Kxjt659KtIUT9r3hdXiWD77/wfHBOKYwpOhOIhFuuht5YQpgthYLHfc0jEQi yfmzi5lN/YLeWsVbFfM9DesbunfrA3HS3Zxx7CkLwmigDJ9fi/0ylHvgzrJY/t5dNM+LXE/mW/ 9RTp6ZqR0qshM1AXUQuYwbJuXSxiaBnbGVWGScgBRFW6QtOrAWukCcLMc/WNzqsaUCxZgruwML +IjkZPlmYzr6URM8Wmz1XXgKQ9qdZ5GKyczBBmUPG+siQR3iqPcRjKgH+6CXzFfEpT6VTjS0g8 xm1wgo1WLP6H7UFS9UMQztAK Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:35 -0700 IronPort-SDR: cs03JQLS7hcWIucz1TPDpUrFjTrNuBxSxEa0ivmhTBQZlYUdzzUf0LsQmP1wn5ZwLyox9oAJul 7A/Ft9j4Kbu5eFHderB/Nkfvjd2fU4N7j/SQXDU8THQ9+g4NBCJexgQ7U1WEVwM0Oz6w1qV5L0 d/I0x1HE9tizeAKl7iRnrWJVPwi4HhsvP5qSLwoRZmrXJtmhohds7u930lzts9qBPl36SD0ycV RzLbC4oSSOxtpzuJRcKK7Q9sweMu8KAwG6MEkk1Y/VtPPq8oasAyDEUuH/erj6S+a/a8RWs9Ev JgQ= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:07 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 03/11] block: introduce BIO_ZONE_WRITE_LOCKED bio flag Date: Wed, 26 May 2021 06:24:53 +0900 Message-Id: <20210525212501.226888-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce the BIO flag BIO_ZONE_WRITE_LOCKED to indicate that a BIO owns the write lock of the zone it is targeting. This is the counterpart of the struct request flag RQF_ZONE_WRITE_LOCKED. This new BIO flag is reserved for now for zone write locking control for device mapper targets exposing a zoned block device. Since in this case, the lock flag must not be propagated to the struct request that will be used to process the BIO, a BIO private flag is used rather than changing the RQF_ZONE_WRITE_LOCKED request flag into a common REQ_XXX flag that could be used for both BIO and request. This avoids conflicts down the stack with the block IO scheduler zone write locking (in mq-deadline). Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Reviewed-by: Chaitanya Kulkarni Reviewed-by: Himanshu Madhani --- include/linux/blk_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index db026b6ec15a..e5cf12f102a2 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -304,6 +304,7 @@ enum { BIO_CGROUP_ACCT, /* has been accounted to a cgroup */ BIO_TRACKED, /* set if bio goes through the rq_qos path */ BIO_REMAPPED, + BIO_ZONE_WRITE_LOCKED, /* Owns a zoned device zone write lock */ BIO_FLAG_LAST }; From patchwork Tue May 25 21:24: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: 12280215 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,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 402B0C47086 for ; Tue, 25 May 2021 21:25:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 234E661417 for ; Tue, 25 May 2021 21:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231685AbhEYV0j (ORCPT ); Tue, 25 May 2021 17:26:39 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36430 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbhEYV0j (ORCPT ); Tue, 25 May 2021 17:26:39 -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=1621977909; x=1653513909; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=/0Fs2t/8Lct+NB2zQOgVL64FvfANBQSa/F9el7DrQpI=; b=hfpq35XNvQ74CNj2BrGviw7kmQc6y4jggSCEkTKnjkqZUyYfB55vT9aD vwfqkdqMRpcukHzib28vbPpxAIOh11xp3/HlNJg09yMCMhVgmy+zdAg1z 29sI3ahUXNDvZvlrHYNupdI8tbSLYKMcuEq6ZK/1mjOI+YWlbub2oIdGB rW5VDrwlMjJntirSAewvMEyPIoCBc7cP9aEQ5YlGAmiM6rJqsolfPhOOQ BLoOD4gyHRgZuk0sjXIg3d93Yc/KkM20ZAtRa/Bmlc9gCG+Ifvmo84k0V +tjCNPNQMuRLJ5ajoFlnJ/jc4xeBUBz1+vf3Hikl7DuKYc9NbOp84Q5/q A==; IronPort-SDR: +K1J4ZWh1T94S7Ab8U6qBpa0IKvnlC2vF9+fkKcEia6yzkI603NMiAqoJtWEjDvuf13Oadjclm skwQq+rCd3qG+XXHh2knUyPyNrHBBt8oI19OybaBsfcFfEtAJLHhouNwbUnZZAJ7I/GJkueJWo LSarhnrOlkdDuU7I0SoK/pkeinFuoMvGSwVWx/qQblbtZNgO1cJaAPgXERuF3FqJI4BmQdJvXR N0t5gEDV7xEtK6XSNn4nomE9N/kCp+RlH7ZrN1EhbFvy9qW1TExgvhIYcls8K/AJSaEZ5pwgh1 ahY= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717521" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:09 +0800 IronPort-SDR: OxATa0SMAN5fewINGwCGYfT5JgEkva7M/i8CEZaOS8SfWwYb9DhmeW+bldd4rj6wH1rxA8P0Q+ dAsI6lffzNDtPpPyR5KU2puoGux/CwfEESyTfCc/a4ZJDxC38Z9UtDxrjUgnnLcrWqVjr3kFVx 5hje+MxwvXqoc7mOyI28LTlvJqOeM12ErB0nWBrVKBqhPWqu2DFh8AXPAYrRq6FiMoL2XWufxp Br+FqWZk+7LZsLuH9wqSG9Zk7bl3ZGTUgXgW1ikra15YThN7kuC6Zoqm2PrXx2DXftjZpwgKNG rxYGLM+GAhUXEFAAi1wIMtLH Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:36 -0700 IronPort-SDR: 3WNVVCsgoR+ULzKivcrpIeAvbOp+kxOVyC48DtAIJxBDV5vcEXViErn5CAUrjJQMKqfidv6Nmn lW4Bg5t3O66RzOS5xKoyVViesIm8tMGdOlCpsqFHGufkP5rGYHsGX7RlmFhbYMsT2IfulamBmL mB7wkTHfZUs7VDnI13816sg/w+4Zx8k7tQhufvjmRMMR8poDM1pV7kBtqNnBEUJba7UsoT9Rz3 1LtKYOjwWvvRvRLBKX62ZoFKG0/THsY8cfbQ9toC+X1FKFXWKX+1V5m47kED3THFGonbQhIKBI scs= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:08 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 04/11] dm: Fix dm_accept_partial_bio() Date: Wed, 26 May 2021 06:24:54 +0900 Message-Id: <20210525212501.226888-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Fix dm_accept_partial_bio() to actually check that zone management commands are not passed as explained in the function documentation comment. Also, since a zone append operation cannot be split, add REQ_OP_ZONE_APPEND as a forbidden command. White lines are added around the group of BUG_ON() calls to make the code more legible. Signed-off-by: Damien Le Moal --- drivers/md/dm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ca2aedd8ee7d..11af20080639 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1237,8 +1237,8 @@ static int dm_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, /* * A target may call dm_accept_partial_bio only from the map routine. It is - * allowed for all bio types except REQ_PREFLUSH, REQ_OP_ZONE_RESET, - * REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE and REQ_OP_ZONE_FINISH. + * allowed for all bio types except REQ_PREFLUSH, REQ_OP_ZONE_* zone management + * operations and REQ_OP_ZONE_APPEND (zone append writes). * * dm_accept_partial_bio informs the dm that the target only wants to process * additional n_sectors sectors of the bio and the rest of the data should be @@ -1268,9 +1268,13 @@ void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors) { struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone); unsigned bi_size = bio->bi_iter.bi_size >> SECTOR_SHIFT; + BUG_ON(bio->bi_opf & REQ_PREFLUSH); + BUG_ON(op_is_zone_mgmt(bio_op(bio))); + BUG_ON(bio_op(bio) == REQ_OP_ZONE_APPEND); BUG_ON(bi_size > *tio->len_ptr); BUG_ON(n_sectors > bi_size); + *tio->len_ptr -= bi_size - n_sectors; bio->bi_iter.bi_size = n_sectors << SECTOR_SHIFT; } From patchwork Tue May 25 21:24: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: 12280217 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,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 8C3D9C4707F for ; Tue, 25 May 2021 21:25:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69C93611BE for ; Tue, 25 May 2021 21:25:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232832AbhEYV0n (ORCPT ); Tue, 25 May 2021 17:26:43 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36430 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231838AbhEYV0k (ORCPT ); Tue, 25 May 2021 17:26:40 -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=1621977910; x=1653513910; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=NfTdCDjWprAigWJYaD23uduh85Vk9Qoh0V7PA2PEAio=; b=WKTCEti2pnkhVzEV4uRfHHtZfudAWDK3PTkaGUK3AAZM38oKDSLG3E1l U/oPdIxleGVb2CpV6Fl8ONZszQ+NlErkAuL81PNao9voUWX3xflBDGkUx GviZWr9y1i4fQ6M/4i2CRs0ZvWx6dtv1tKXmiCUBzfgiGUd5LODg+fmpA s/txWRwWCdqXPUV95MT3k7h3sIum4fYwCBXvKKju5TVUw6gHx1AdGVZfK HRzOyWapgz2GEPgWkeIN0sAeE8IlsoFT8jp+AqwVSdzNVBBPi30w3Rb9o GJoKJWDc2mv1N1X28uYr51KIpqNKJqXAk5ISfXxb0W1rbLt/s25AALvKc Q==; IronPort-SDR: 3DBhMCjvL9RCWCtu9SF1W/lT5WOAVCnCRn1B+HXQJl9k4D6rmWd3i6TIIEErTr7I5aLJFbOlkR 4PGJUh1+6qWRiv+GdGbpap12cJhSslW54t5jCi/eUy5vPrRlJrPRxM6knMVfsrEH8sAfTXogLn uzLTlwC38/2MZ0cNmTPN+mbyrnIk0YXZpcXVcV883WjGHJ3i4DKNiKJzBbRSvHNaMTPfB/jKsc RlRAxDrunIm2YItxdE2j5+4KAmK+6OoAPV+PIRDycu9qZYeXjdQv87hKC0q86H2hkYB7tOGMhr bXU= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717525" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:10 +0800 IronPort-SDR: nS9Tf5/29Hv+dRkfS8czRYCSXuxu3vCP96S+1WrHVE8S3tFoDROAk7GEH2SLDRcq+n583Px2mf 0zwNDQXEZRXuWwI3drqQDMuhfZtbCLUKtJWQwzvtbFCrpRvDRabv+rB4VkMk2V2n9ceu/KTAUC ylTlAUAVCwY1x5d/zpuFE3wYCPPl5nDbyTmxnO2THDewD4NNyy8KqoBOcu9tuXsPsKY5C75L/V 44CL8gHEZjQ9kJPpvzE5BjQ0YJdWjClV5kLAjSOWe1p5ZwfOBGLYhE9nAZVWBLODTFFk/mH3+j XoEzVJgoAPEGUt5T6Vfe7DPo Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:37 -0700 IronPort-SDR: 9MGmzkS4eqpzox3GSh+m6FwTZ2A8jKGfs3LK10mBr04kxWvv+f5pPf+dITjf+/Rgr/JwS4Y91l /qfqaRsYRFK/hntKveHxn9+PNamC60e0DQFaBnC4AJvxCnCVJHvk0rc8K0JrNNogBqlGlaDdse vjnA+wsKHtk2X2cyt7se75j0b6h2J4rz05kaMfbrCaBoDnKg6KD59UIK963ti52Y3PY0qjkPRn uSvw1Sx6Yg/+cwXjPx1w8baliE444Y83EBleDFznQqcptUe+kG38/AEBTdCAjatLi0Q6g7Jc1o f3Y= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:10 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 05/11] dm: cleanup device_area_is_invalid() Date: Wed, 26 May 2021 06:24:55 +0900 Message-Id: <20210525212501.226888-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org In device_area_is_invalid(), use bdev_is_zoned() instead of open coding the test on the zoned model returned by bdev_zoned_model(). Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Reviewed-by: Himanshu Madhani --- drivers/md/dm-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index ee47a332b462..21fd9cd4da32 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -249,7 +249,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, * If the target is mapped to zoned block device(s), check * that the zones are not partially mapped. */ - if (bdev_zoned_model(bdev) != BLK_ZONED_NONE) { + if (bdev_is_zoned(bdev)) { unsigned int zone_sectors = bdev_zone_sectors(bdev); if (start & (zone_sectors - 1)) { From patchwork Tue May 25 21:24:56 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: 12280219 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,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 2FBE9C47089 for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15AD561417 for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232200AbhEYV0o (ORCPT ); Tue, 25 May 2021 17:26:44 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36430 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhEYV0n (ORCPT ); Tue, 25 May 2021 17:26:43 -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=1621977913; x=1653513913; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=NFDVj12G1cIiBpkkJ+xVxGjioQchYAhGgThHQ32LasU=; b=ip+IfTMy7gfgysVCNl4FPvLMtO6+37Hzj9YcJ9SXsS1/jwpE2zCsdq57 cB5pY5bZBM687Vu9qTHbQqVmmhgmutHcbWTL+/1sbk77FoN2rHgErWArS Hhz5C6gHZd94DEiSvsehfrlFASnLDYgGpA59cobRV1cUrZiDt9dUxhOkQ EmcVOQlEOBAgOk/GIFCidcri+rZv/99UrCfrQmWZQvQhHrsjcmmh+NWOw 9L6w7UIrAPWzObLcKxTrytgXY5HFHM60RKKMzkd60Cdwy8ypWRwTf/fNY z7g6KTbpar9NZwFDI8zzHK3dhMLRnj8480AnCFWDshB2Co6Ee0QYxm6aH A==; IronPort-SDR: mhK98u00I1XIpIyylb6ujbEdHfc4Wu5pVTWb7YE/5DMzBWXLR+GYRe+upx5P/WfuchYwvHvQZH mTDBgrTrzGv/fVlBpHuntYYJQxDVrYExTqRzTlYAy5dl66qVRbytlC4LHw6ukmKtRkH7Hx4zth 4LWM1kkAYMxw8sABEFwPI9Oc0bTHLAO7RBObpn8cbbpvMFoKbTQwQU/MSe9CGp3+ubnzSUhGdb OkifQ1fPprza455fK0H0ZYAB1V1ObCYW+R7188IPAOUrJvuzJoCJBKDS7v9RO6Yh9K3n1KwCUb iIU= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717528" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:11 +0800 IronPort-SDR: /UuhItDH9nKnQ+cYek/imHdA2KKavZzXIIY0ynHuHK8cdZMqJ4ErwSXimnKMHzYfw6mcdiCwgd SOgZNDQVd0YXVj0ZxwauSJq8Lj3bWZynMS0k1FNAnmsbbjaEIaqlucT1w47iuAVjNdaLFkORgb SL62NMTljz7zcrGKP78YbFWG3hPJm6Tw+DO/UC1Xx/i6oJyDoMons+epdOScqjwBQFu+NbHyIp uDI/C5lvsdoTpf3EfEDtZrR7RVVmQNT1qni+ZywM5U8wY5mN9bPlr7qytwFUDICBNQQpbOw/MD t5vS5Iqc0j7Itw7+AZWI3lne Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:38 -0700 IronPort-SDR: nVgte37Yi4En00VqZY7CHg2Ck5Zja5zDiLxN7bmoDn3lgi8jozlu5qA8xlNQAX5otyotwy1POE wnrIvT7XFaXuTBNZxG7fsW8uCP0TMiKZcQDtliy1743VHxaoDvP2Gx6m0meCu9O76DPSMK8l+0 MzWMj+2KOi2rXRqf5QzQBuqNZgTYV+s0Hx0OrNzwmHb5lU9HeRKR4MDvrpV016vKyKG/nSxeJB e1nrWZZ7AlTUe3JjnTdkPl2PkCyJGiRGObKSLN4V2G3CzCjdmgR8SY4yVdCUEMfbYWqL1Fw1MW bnw= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:11 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 06/11] dm: move zone related code to dm-zone.c Date: Wed, 26 May 2021 06:24:56 +0900 Message-Id: <20210525212501.226888-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move core and table code used for zoned targets and conditionally defined with #ifdef CONFIG_BLK_DEV_ZONED to the new file dm-zone.c. This file is conditionally compiled depending on CONFIG_BLK_DEV_ZONED. The small helper dm_set_zones_restrictions() is introduced to initialize a mapped device request queue zone attributes in dm_table_set_restrictions(). Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/Makefile | 4 ++ drivers/md/dm-table.c | 14 ++---- drivers/md/dm-zone.c | 102 ++++++++++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 78 -------------------------------- drivers/md/dm.h | 11 +++++ 5 files changed, 120 insertions(+), 89 deletions(-) create mode 100644 drivers/md/dm-zone.c diff --git a/drivers/md/Makefile b/drivers/md/Makefile index ef7ddc27685c..a74aaf8b1445 100644 --- a/drivers/md/Makefile +++ b/drivers/md/Makefile @@ -92,6 +92,10 @@ ifeq ($(CONFIG_DM_UEVENT),y) dm-mod-objs += dm-uevent.o endif +ifeq ($(CONFIG_BLK_DEV_ZONED),y) +dm-mod-objs += dm-zone.o +endif + ifeq ($(CONFIG_DM_VERITY_FEC),y) dm-verity-objs += dm-verity-fec.o endif diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 21fd9cd4da32..dd9f648ab598 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -2064,17 +2064,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, dm_table_any_dev_attr(t, device_is_not_random, NULL)) blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q); - /* - * For a zoned target, the number of zones should be updated for the - * correct value to be exposed in sysfs queue/nr_zones. For a BIO based - * target, this is all that is needed. - */ -#ifdef CONFIG_BLK_DEV_ZONED - if (blk_queue_is_zoned(q)) { - WARN_ON_ONCE(queue_is_mq(q)); - q->nr_zones = blkdev_nr_zones(t->md->disk); - } -#endif + /* For a zoned target, setup the zones related queue attributes */ + if (blk_queue_is_zoned(q)) + dm_set_zones_restrictions(t, q); dm_update_keyslot_manager(q, t); blk_queue_update_readahead(q); diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c new file mode 100644 index 000000000000..3243c42b7951 --- /dev/null +++ b/drivers/md/dm-zone.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 Western Digital Corporation or its affiliates. + */ + +#include + +#include "dm-core.h" + +/* + * User facing dm device block device report zone operation. This calls the + * report_zones operation for each target of a device table. This operation is + * generally implemented by targets using dm_report_zones(). + */ +int dm_blk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, void *data) +{ + struct mapped_device *md = disk->private_data; + struct dm_table *map; + int srcu_idx, ret; + struct dm_report_zones_args args = { + .next_sector = sector, + .orig_data = data, + .orig_cb = cb, + }; + + if (dm_suspended_md(md)) + return -EAGAIN; + + map = dm_get_live_table(md, &srcu_idx); + if (!map) { + ret = -EIO; + goto out; + } + + do { + struct dm_target *tgt; + + tgt = dm_table_find_target(map, args.next_sector); + if (WARN_ON_ONCE(!tgt->type->report_zones)) { + ret = -EIO; + goto out; + } + + args.tgt = tgt; + ret = tgt->type->report_zones(tgt, &args, + nr_zones - args.zone_idx); + if (ret < 0) + goto out; + } while (args.zone_idx < nr_zones && + args.next_sector < get_capacity(disk)); + + ret = args.zone_idx; +out: + dm_put_live_table(md, srcu_idx); + return ret; +} + +int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) +{ + struct dm_report_zones_args *args = data; + sector_t sector_diff = args->tgt->begin - args->start; + + /* + * Ignore zones beyond the target range. + */ + if (zone->start >= args->start + args->tgt->len) + return 0; + + /* + * Remap the start sector and write pointer position of the zone + * to match its position in the target range. + */ + zone->start += sector_diff; + if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) { + if (zone->cond == BLK_ZONE_COND_FULL) + zone->wp = zone->start + zone->len; + else if (zone->cond == BLK_ZONE_COND_EMPTY) + zone->wp = zone->start; + else + zone->wp += sector_diff; + } + + args->next_sector = zone->start + zone->len; + return args->orig_cb(zone, args->zone_idx++, args->orig_data); +} +EXPORT_SYMBOL_GPL(dm_report_zones_cb); + +void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) +{ + if (!blk_queue_is_zoned(q)) + return; + + /* + * For a zoned target, the number of zones should be updated for the + * correct value to be exposed in sysfs queue/nr_zones. For a BIO based + * target, this is all that is needed. + */ + WARN_ON_ONCE(queue_is_mq(q)); + q->nr_zones = blkdev_nr_zones(t->md->disk); +} + diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 11af20080639..c49976cc4e44 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -444,84 +444,6 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo) return dm_get_geometry(md, geo); } -#ifdef CONFIG_BLK_DEV_ZONED -int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) -{ - struct dm_report_zones_args *args = data; - sector_t sector_diff = args->tgt->begin - args->start; - - /* - * Ignore zones beyond the target range. - */ - if (zone->start >= args->start + args->tgt->len) - return 0; - - /* - * Remap the start sector and write pointer position of the zone - * to match its position in the target range. - */ - zone->start += sector_diff; - if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) { - if (zone->cond == BLK_ZONE_COND_FULL) - zone->wp = zone->start + zone->len; - else if (zone->cond == BLK_ZONE_COND_EMPTY) - zone->wp = zone->start; - else - zone->wp += sector_diff; - } - - args->next_sector = zone->start + zone->len; - return args->orig_cb(zone, args->zone_idx++, args->orig_data); -} -EXPORT_SYMBOL_GPL(dm_report_zones_cb); - -static int dm_blk_report_zones(struct gendisk *disk, sector_t sector, - unsigned int nr_zones, report_zones_cb cb, void *data) -{ - struct mapped_device *md = disk->private_data; - struct dm_table *map; - int srcu_idx, ret; - struct dm_report_zones_args args = { - .next_sector = sector, - .orig_data = data, - .orig_cb = cb, - }; - - if (dm_suspended_md(md)) - return -EAGAIN; - - map = dm_get_live_table(md, &srcu_idx); - if (!map) { - ret = -EIO; - goto out; - } - - do { - struct dm_target *tgt; - - tgt = dm_table_find_target(map, args.next_sector); - if (WARN_ON_ONCE(!tgt->type->report_zones)) { - ret = -EIO; - goto out; - } - - args.tgt = tgt; - ret = tgt->type->report_zones(tgt, &args, - nr_zones - args.zone_idx); - if (ret < 0) - goto out; - } while (args.zone_idx < nr_zones && - args.next_sector < get_capacity(disk)); - - ret = args.zone_idx; -out: - dm_put_live_table(md, srcu_idx); - return ret; -} -#else -#define dm_blk_report_zones NULL -#endif /* CONFIG_BLK_DEV_ZONED */ - static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx, struct block_device **bdev) { diff --git a/drivers/md/dm.h b/drivers/md/dm.h index b441ad772c18..fdf1536a4b62 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -100,6 +100,17 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t); */ #define dm_target_hybrid(t) (dm_target_bio_based(t) && dm_target_request_based(t)) +/* + * Zoned targets related functions. + */ +void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q); +#ifdef CONFIG_BLK_DEV_ZONED +int dm_blk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, void *data); +#else +#define dm_blk_report_zones NULL +#endif + /*----------------------------------------------------------------- * A registry of target types. *---------------------------------------------------------------*/ From patchwork Tue May 25 21:24:57 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: 12280223 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,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 867D5C4707F for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7081B6138C for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229976AbhEYV0p (ORCPT ); Tue, 25 May 2021 17:26:45 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36441 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232769AbhEYV0n (ORCPT ); Tue, 25 May 2021 17:26:43 -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=1621977913; x=1653513913; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=nT50xLpTVaUfz/iFvC58nOvFcskAeykP4XiHqrg6BYc=; b=AVciql1xolgsuhbZefhuINRA9UsZm8S/W7Dw3rRnRRuXyaEnRLE5ME42 YyU+L4ANk1TSjTx7t2OFwqc3lSTGQ+GoffhlyaNORfLweuqspHJddsqFh Sqm/upGWpiGiUHE768u/YfdmFsRf3LACcR61FzNaNrzW/scApUFCdZ00q W9fX8WacCgPgd2bDSbC0PsLS6zM5N5ZiTtW3LpUF0zj1HKlRoYb/pUizw xx0S7tv7y6HzkhFkpRILAzcR0oZ6M3YaKsJsXgBRwihu6b2UwTIQWuaWT jaP7PHwrqQKubAEwW98aThsioIW8mlc1MM36PZ4bU6D7r4wB6PvIqCtlH g==; IronPort-SDR: BdvODX2bm1vmNdq63o5lWOP9rKWvSp7X69+3PwiBmG3cKPgz/KjBZi3Q9OyuhSxPOEG3Vff9UA 6649B+HSNFN5Vc95uW5Pyuw6lY99OzyyfURcpHV0w/39NFpf5iHG1hF4K/seigBCp4oVG4+Kw8 XubBUfBYcqE7oAglN8Fwfp6gBE1K0rvZGp5JqDl6DEd/sUALvZ9xkzoY6ahZ5M4scp8wgHN7Er WM31Ap+nd2YC9g+ITQNPcZC35AchUd5nDAsg5UTxoYah94phVZdHd1eIkHyhYvTUIcumtbvfom 3rk= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717533" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:12 +0800 IronPort-SDR: q3OB0VnTgV4jiCRqR+hG+bOiSTPzsltpssU6FtUqo8vLuNGpYaAPYV8Ix+w5wHQJGSlkfRKzzH OVgO+icH09CFBIPu3SxWZ7d8VaFXcXWj/HjJ4gO7iUuKM6ZNY/uWcZZyXOQmA27vZx7ugQGAr3 pFOcf2dAtqQJk6HTIMVbVVL2SNa97Q/sLHD5lVf8WGnl3i/IJss2k/dUmBdpH+swev/rmf3pUE jAQhZ1vTxYXzjRSBVNBHbWohr2Ppz1MUM3rPmMPGPshK/iZgob+hoZgc2wO7DMuAkWS96fb2Zv jYCMp/rtd6iujrQqDLyGajFG Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:40 -0700 IronPort-SDR: 8cS/GDNZrClTdleFDrLru3OBcppNA7XH7h94rIzbghBh8hgaS9NSlzHJgUaL3pm3ATTWbe1+zn pmvnWYsQkP7IZZRFh/C/o5nyuWZjXYqOUcsITS+vUCzX9aJeMlMeexFIn98C0dSE/K/Rn6dKMX sVtGzAJopMZ7A1qBwEGoVP3MWE+W3Nf8h+iL90djMtsIK2yBBeqqoz/v9Ens5YRUCSnfvsHLlI S149d8GcGZeACDv+pfWQF/XPnnxbiNJ/HOQIN3wLvEz9dLPyvvOTYrgOC/N4Sa5/qaHuO/N4nS lZQ= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:12 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 07/11] dm: Introduce dm_report_zones() Date: Wed, 26 May 2021 06:24:57 +0900 Message-Id: <20210525212501.226888-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org To simplify the implementation of the report_zones operation of a zoned target, introduce the function dm_report_zones() to set a target mapping start sector in struct dm_report_zones_args and call blkdev_report_zones(). This new function is exported and the report zones callback function dm_report_zones_cb() is not. dm-linear, dm-flakey and dm-crypt are modified to use dm_report_zones(). Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/dm-crypt.c | 7 +++---- drivers/md/dm-flakey.c | 7 +++---- drivers/md/dm-linear.c | 7 +++---- drivers/md/dm-zone.c | 23 ++++++++++++++++++++--- include/linux/device-mapper.h | 3 ++- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index b0ab080f2567..f410ceee51d7 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3138,11 +3138,10 @@ static int crypt_report_zones(struct dm_target *ti, struct dm_report_zones_args *args, unsigned int nr_zones) { struct crypt_config *cc = ti->private; - sector_t sector = cc->start + dm_target_offset(ti, args->next_sector); - args->start = cc->start; - return blkdev_report_zones(cc->dev->bdev, sector, nr_zones, - dm_report_zones_cb, args); + return dm_report_zones(cc->dev->bdev, cc->start, + cc->start + dm_target_offset(ti, args->next_sector), + args, nr_zones); } #else #define crypt_report_zones NULL diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c index b7fee9936f05..5877220c01ed 100644 --- a/drivers/md/dm-flakey.c +++ b/drivers/md/dm-flakey.c @@ -463,11 +463,10 @@ static int flakey_report_zones(struct dm_target *ti, struct dm_report_zones_args *args, unsigned int nr_zones) { struct flakey_c *fc = ti->private; - sector_t sector = flakey_map_sector(ti, args->next_sector); - args->start = fc->start; - return blkdev_report_zones(fc->dev->bdev, sector, nr_zones, - dm_report_zones_cb, args); + return dm_report_zones(fc->dev->bdev, fc->start, + flakey_map_sector(ti, args->next_sector), + args, nr_zones); } #else #define flakey_report_zones NULL diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 92db0f5e7f28..c91f1e2e2f65 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -140,11 +140,10 @@ static int linear_report_zones(struct dm_target *ti, struct dm_report_zones_args *args, unsigned int nr_zones) { struct linear_c *lc = ti->private; - sector_t sector = linear_map_sector(ti, args->next_sector); - args->start = lc->start; - return blkdev_report_zones(lc->dev->bdev, sector, nr_zones, - dm_report_zones_cb, args); + return dm_report_zones(lc->dev->bdev, lc->start, + linear_map_sector(ti, args->next_sector), + args, nr_zones); } #else #define linear_report_zones NULL diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index 3243c42b7951..b42474043249 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -56,7 +56,8 @@ int dm_blk_report_zones(struct gendisk *disk, sector_t sector, return ret; } -int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) +static int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, + void *data) { struct dm_report_zones_args *args = data; sector_t sector_diff = args->tgt->begin - args->start; @@ -84,7 +85,24 @@ int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) args->next_sector = zone->start + zone->len; return args->orig_cb(zone, args->zone_idx++, args->orig_data); } -EXPORT_SYMBOL_GPL(dm_report_zones_cb); + +/* + * Helper for drivers of zoned targets to implement struct target_type + * report_zones operation. + */ +int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, + struct dm_report_zones_args *args, unsigned int nr_zones) +{ + /* + * Set the target mapping start sector first so that + * dm_report_zones_cb() can correctly remap zone information. + */ + args->start = start; + + return blkdev_report_zones(bdev, sector, nr_zones, + dm_report_zones_cb, args); +} +EXPORT_SYMBOL_GPL(dm_report_zones); void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) { @@ -99,4 +117,3 @@ void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) WARN_ON_ONCE(queue_is_mq(q)); q->nr_zones = blkdev_nr_zones(t->md->disk); } - diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index ff700fb6ce1d..caea0a079d2d 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -478,7 +478,8 @@ struct dm_report_zones_args { /* must be filled by ->report_zones before calling dm_report_zones_cb */ sector_t start; }; -int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data); +int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, + struct dm_report_zones_args *args, unsigned int nr_zones); #endif /* CONFIG_BLK_DEV_ZONED */ /* From patchwork Tue May 25 21:24:58 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: 12280221 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,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 9E9A5C4708A for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D9CB611BE for ; Tue, 25 May 2021 21:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231838AbhEYV0p (ORCPT ); Tue, 25 May 2021 17:26:45 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36441 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232006AbhEYV0o (ORCPT ); Tue, 25 May 2021 17:26:44 -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=1621977914; x=1653513914; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=PPqL/jfrmA+hhRRrzr2vGOU3ZQvBfOeDHMkCng2K9OI=; b=N1sOZAKBfaEhE7xVAdYbN/3exz/Visps7jefV7fFdbJFGaL7D/mpkRCN i4qx248ESTps2dJJ1Fv1MNB5xVuR6vNO7BxccuhEqFQAPqaNkc/2hn1P7 lIRtQkCCqPjp2r+RxynUTR3jxDPNm4rL9XrFr53YNFmXKa92uHT8B9H8m 7rvlR5ch/tSDGSth+JxSDxSCd/QM3Y5xo9zZj5JfOmAnoQM4wqIdXs51a 5Uw7EXAkHa8fXis1CGo6TO/6K48dq/II45WwFlKksBaQ2f5sukfjf3qak vMXWx/5WdEkBDDNVbaMi0xPNOOjEPBeiVHEbjw1LozQ54BQ6TFaGZWrbe g==; IronPort-SDR: ExoThD2spBX1CdWo8RIKHmDvuEkYkvedXfuMiVNYgAAcbDCVCyv+tzwqJv/Pclrq3cfBbTx3jy WdGs+TuCjGGGebA1j2jKYneOCOQ8O4PBHfPs3czJIVZsaAjJSjO0BIdMckdi+OXNW08BoaSf0t kLvykNhf0jbzNRFeu9oc51aau5pyUZ51Hn8cxJdwcLnr/MNaTITD2tnGHzfRXWvl9bIRP54hQ3 D7BfJr03SYJ0dNX+sMSwWT6S6vmRYSgwmVUe72HnrXKcBh1IHfblBjAU4Mwe9wo2jjyxG/z/ZH jGk= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717537" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:14 +0800 IronPort-SDR: A8aIf2tOMFLex+0SpH3A29vIqlxouWPSpNGRNcsSjbeUWIKymMr04bIMV7s+SIi7maghkmb5Qn MpWZhr1PpDVmHpyTXlbJssOxXh2xbYqNQDz2bAe5wz3TWXVMSZBiPJlP1eodVo9UEjD/fyAxwH VCRj80SznwCIk+C/MhuzgRxLRcV4VbMF/WD1d+pxCo4Hzeexa9ucvUzUho6GgrhuxHd6o9J6Pt Udvls+P47mxcxjuXLWXWTu+9IvQeWH+HRuGwAtm8gBjU0mx5QWYu96QXw5w79qBZlkPzkcnUH3 5uq1seB6sDEeW07J4ILcEieo Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:41 -0700 IronPort-SDR: FFF1c2FJ+cgQhwiu2tSFsJhXIDXOtA/SS6F6R1Iy5+bwYpMV7vaYEY7WPhSqBcsD8tMZkR9flM 99Ne8g2pnfyxWCGLrZkpx1PRwBUmLTH9oCqNOZUCCOw1WtLMkfbiij+gpskbG8opzpmObsaPXQ A00LILqLiLlzH9QEHCjEOElt6aqVLCrglHOFMM9LI5kd9t180Ntk5oYtuQ0J/CyNO0QmkBk/MG MS5+OopH4yZp3elwi2jYQnBYTwXU9a5vYn22BCOizO2XEH7REaNpp9UEbqwotRcYVQzqx8ZM1f WjU= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:13 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 08/11] dm: Forbid requeue of writes to zones Date: Wed, 26 May 2021 06:24:58 +0900 Message-Id: <20210525212501.226888-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org A target map method requesting the requeue of a bio with DM_MAPIO_REQUEUE or completing it with DM_ENDIO_REQUEUE can cause unaligned write errors if the bio is a write operation targeting a sequential zone. If a zoned target request such a requeue, warn about it and kill the IO. The function dm_is_zone_write() is introduced to detect write operations to zoned targets. This change does not affect the target drivers supporting zoned devices and exposing a zoned device, namely dm-crypt, dm-linear and dm-flakey as none of these targets ever request a requeue. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/dm-zone.c | 17 +++++++++++++++++ drivers/md/dm.c | 18 +++++++++++++++--- drivers/md/dm.h | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index b42474043249..edc3bbb45637 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -104,6 +104,23 @@ int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, } EXPORT_SYMBOL_GPL(dm_report_zones); +bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) +{ + struct request_queue *q = md->queue; + + if (!blk_queue_is_zoned(q)) + return false; + + switch (bio_op(bio)) { + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + return !op_is_flush(bio->bi_opf) && bio_sectors(bio); + default: + return false; + } +} + void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) { if (!blk_queue_is_zoned(q)) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index c49976cc4e44..ed8c5a8df2e5 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -846,11 +846,15 @@ static void dec_pending(struct dm_io *io, blk_status_t error) * Target requested pushing back the I/O. */ spin_lock_irqsave(&md->deferred_lock, flags); - if (__noflush_suspending(md)) + if (__noflush_suspending(md) && + !WARN_ON_ONCE(dm_is_zone_write(md, bio))) /* NOTE early return due to BLK_STS_DM_REQUEUE below */ bio_list_add_head(&md->deferred, io->orig_bio); else - /* noflush suspend was interrupted. */ + /* + * noflush suspend was interrupted or this is + * a write to a zoned target. + */ io->status = BLK_STS_IOERR; spin_unlock_irqrestore(&md->deferred_lock, flags); } @@ -947,7 +951,15 @@ static void clone_endio(struct bio *bio) int r = endio(tio->ti, bio, &error); switch (r) { case DM_ENDIO_REQUEUE: - error = BLK_STS_DM_REQUEUE; + /* + * Requeuing writes to a sequential zone of a zoned + * target will break the sequential write pattern: + * fail such IO. + */ + if (WARN_ON_ONCE(dm_is_zone_write(md, bio))) + error = BLK_STS_IOERR; + else + error = BLK_STS_DM_REQUEUE; fallthrough; case DM_ENDIO_DONE: break; diff --git a/drivers/md/dm.h b/drivers/md/dm.h index fdf1536a4b62..39c243258e24 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -107,8 +107,13 @@ void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q); #ifdef CONFIG_BLK_DEV_ZONED int dm_blk_report_zones(struct gendisk *disk, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); +bool dm_is_zone_write(struct mapped_device *md, struct bio *bio); #else #define dm_blk_report_zones NULL +static inline bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) +{ + return false; +} #endif /*----------------------------------------------------------------- From patchwork Tue May 25 21:24:59 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: 12280225 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,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 7D976C47087 for ; Tue, 25 May 2021 21:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59A6E6138C for ; Tue, 25 May 2021 21:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231614AbhEYV0s (ORCPT ); Tue, 25 May 2021 17:26:48 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36441 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232778AbhEYV0p (ORCPT ); Tue, 25 May 2021 17:26:45 -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=1621977915; x=1653513915; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=qHj3M9XFL/tykUsf56Cg90qnsKbQHFHiajzEaN4c+7Y=; b=lb4WMvI45zpFU3Yis245VL5Bk2RTgx8BlVpwRorW+6oubXpFLxe20CQF iIik1kzEuUvvGUVGHH26EQzkLdmLN+PBoErh1KAW/0TwK+565YXTIa+lU DANixe3lgqPTwnvWddC3tXFTl6hAHZKmQJ850MyBDLoTeblFHjS+I+3fr bfIv9fZowbX66Mk3pubDV7lO8flU0FayUZd93AI9wLYG1JvKRtaFwYxmD 6/KTVH2BmR7Ab4ISO8ywi1WapUZBLcWCp5VATc+zQXb1dYswL6Zsss+G4 LRS07pLsDgKWjcxqmY6KBMGlkoO2UPN3UpveAb6mosQtxfswwo6QkQayy Q==; IronPort-SDR: 4aqBaFOPxIWwtAQ2cMd1FST12Kkp1hTzLsycO/JQbKZGGPmJRugj2GUgRc+LMlbV1Ns9hw5pQw wCMMd5TyNjY/LIQI28hK3P741xeruFFKDsql6uDmEqBXbT2BMZr/QMkT5W9wvWAQ9LmY0hy/xc RStPvaLYPY4p0tRSYjtWYVsXrWnH8dk5KjvAVZ+PGWySnOQrPtYcswMAoORKKrAOqUUvesWhe+ 63wEXW4LbcTdXwSoRaMx7g8aGU5SgP7f9rQNqKK5cZ+kiov2SiAXUSAF/SkCia1+hRPiF8PB+r HDE= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717544" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:15 +0800 IronPort-SDR: rc+Pe9SwTQTrsvgorcjsPqao+Mx4cSXQ8fQD4WQN9yxBCsWw/MGDBGc0IoOkZ44UpoR8NS7ofV ZE6218DUkc0r8eI4GDVxjDW3hHO2dBo3cz3S5Ip8G+fsY2gbyBPzQzcPYCeFpAoKao4W9yqDlc QDfe39Co9/DwtMezXBd0yxxgatbe+eHsiHcgL0e9eHRy8pB6cbvvynGZ0KIf0Zs5057qzziuX2 vb299YVpN+LaMByhb+rkz7iEUK1MM4fefYb3WD2nDHHNA1Mgqgj0whGKhftpHumBCBX+TrAmgf h4bv68Bvk4gCwYm64M35fiR8 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:42 -0700 IronPort-SDR: xEuFmaKQgjMwJH+B41lM58oV43m0MVuK4NhI2z06SszfC0Lf2a6om3NjXE2LgFLumNV7I5x9Pc BZNUkf5C5s3Znc46xCyUH140EwnXtkLIv+zNItNDstCLg94ITt7pV7PgbIcMfbqc+K16mzxpgR hBuZ05VbsVJ3LNVdOuXY4uBqPDN3JDADN58NL9VaOKu0KQHjwGPajQ8xRKlnsn14MZnucoJk3A mVBqLniix6kaKbR1JstC0wEStQrpEbJzc4aHs+Yp/I7JWCkmJVGevbWuhavr8UxcT5zetSCOIe WRc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:14 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 09/11] dm: rearrange core declarations Date: Wed, 26 May 2021 06:24:59 +0900 Message-Id: <20210525212501.226888-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move the definitions of struct dm_target_io, struct dm_io and of the bits of the flags field of struct mapped_device from dm.c to dm-core.h to make them usable from dm-zone.c. For the same reason, declare dec_pending() in dm-core.h after renaming it to dm_io_dec_pending(). And for symmetry of the function names, introduce the inline helper dm_io_inc_pending() instead of directly using atomic_inc() calls. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/dm-core.h | 52 ++++++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 59 ++++++-------------------------------------- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h index 5953ff2bd260..cfabc1c91f9f 100644 --- a/drivers/md/dm-core.h +++ b/drivers/md/dm-core.h @@ -116,6 +116,19 @@ struct mapped_device { struct srcu_struct io_barrier; }; +/* + * Bits for the flags field of struct mapped_device. + */ +#define DMF_BLOCK_IO_FOR_SUSPEND 0 +#define DMF_SUSPENDED 1 +#define DMF_FROZEN 2 +#define DMF_FREEING 3 +#define DMF_DELETING 4 +#define DMF_NOFLUSH_SUSPENDING 5 +#define DMF_DEFERRED_REMOVE 6 +#define DMF_SUSPENDED_INTERNALLY 7 +#define DMF_POST_SUSPENDING 8 + void disable_discard(struct mapped_device *md); void disable_write_same(struct mapped_device *md); void disable_write_zeroes(struct mapped_device *md); @@ -173,6 +186,45 @@ struct dm_table { #endif }; +/* + * One of these is allocated per clone bio. + */ +#define DM_TIO_MAGIC 7282014 +struct dm_target_io { + unsigned int magic; + struct dm_io *io; + struct dm_target *ti; + unsigned int target_bio_nr; + unsigned int *len_ptr; + bool inside_dm_io; + struct bio clone; +}; + +/* + * One of these is allocated per original bio. + * It contains the first clone used for that original. + */ +#define DM_IO_MAGIC 5191977 +struct dm_io { + unsigned int magic; + struct mapped_device *md; + blk_status_t status; + atomic_t io_count; + struct bio *orig_bio; + unsigned long start_time; + spinlock_t endio_lock; + struct dm_stats_aux stats_aux; + /* last member of dm_target_io is 'struct bio' */ + struct dm_target_io tio; +}; + +static inline void dm_io_inc_pending(struct dm_io *io) +{ + atomic_inc(&io->io_count); +} + +void dm_io_dec_pending(struct dm_io *io, blk_status_t error); + static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj) { return &container_of(kobj, struct dm_kobject_holder, kobj)->completion; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ed8c5a8df2e5..c200658d8bcb 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -74,38 +74,6 @@ struct clone_info { unsigned sector_count; }; -/* - * One of these is allocated per clone bio. - */ -#define DM_TIO_MAGIC 7282014 -struct dm_target_io { - unsigned magic; - struct dm_io *io; - struct dm_target *ti; - unsigned target_bio_nr; - unsigned *len_ptr; - bool inside_dm_io; - struct bio clone; -}; - -/* - * One of these is allocated per original bio. - * It contains the first clone used for that original. - */ -#define DM_IO_MAGIC 5191977 -struct dm_io { - unsigned magic; - struct mapped_device *md; - blk_status_t status; - atomic_t io_count; - struct bio *orig_bio; - unsigned long start_time; - spinlock_t endio_lock; - struct dm_stats_aux stats_aux; - /* last member of dm_target_io is 'struct bio' */ - struct dm_target_io tio; -}; - #define DM_TARGET_IO_BIO_OFFSET (offsetof(struct dm_target_io, clone)) #define DM_IO_BIO_OFFSET \ (offsetof(struct dm_target_io, clone) + offsetof(struct dm_io, tio)) @@ -137,19 +105,6 @@ EXPORT_SYMBOL_GPL(dm_bio_get_target_bio_nr); #define MINOR_ALLOCED ((void *)-1) -/* - * Bits for the md->flags field. - */ -#define DMF_BLOCK_IO_FOR_SUSPEND 0 -#define DMF_SUSPENDED 1 -#define DMF_FROZEN 2 -#define DMF_FREEING 3 -#define DMF_DELETING 4 -#define DMF_NOFLUSH_SUSPENDING 5 -#define DMF_DEFERRED_REMOVE 6 -#define DMF_SUSPENDED_INTERNALLY 7 -#define DMF_POST_SUSPENDING 8 - #define DM_NUMA_NODE NUMA_NO_NODE static int dm_numa_node = DM_NUMA_NODE; @@ -825,7 +780,7 @@ static int __noflush_suspending(struct mapped_device *md) * Decrements the number of outstanding ios that a bio has been * cloned into, completing the original io if necc. */ -static void dec_pending(struct dm_io *io, blk_status_t error) +void dm_io_dec_pending(struct dm_io *io, blk_status_t error) { unsigned long flags; blk_status_t io_error; @@ -978,7 +933,7 @@ static void clone_endio(struct bio *bio) } free_tio(tio); - dec_pending(io, error); + dm_io_dec_pending(io, error); } /* @@ -1246,7 +1201,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio) * anything, the target has assumed ownership of * this io. */ - atomic_inc(&io->io_count); + dm_io_inc_pending(io); sector = clone->bi_iter.bi_sector; if (unlikely(swap_bios_limit(ti, clone))) { @@ -1272,7 +1227,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio) up(&md->swap_bios_semaphore); } free_tio(tio); - dec_pending(io, BLK_STS_IOERR); + dm_io_dec_pending(io, BLK_STS_IOERR); break; case DM_MAPIO_REQUEUE: if (unlikely(swap_bios_limit(ti, clone))) { @@ -1280,7 +1235,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio) up(&md->swap_bios_semaphore); } free_tio(tio); - dec_pending(io, BLK_STS_DM_REQUEUE); + dm_io_dec_pending(io, BLK_STS_DM_REQUEUE); break; default: DMWARN("unimplemented target map return value: %d", r); @@ -1569,7 +1524,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md, if (bio->bi_opf & REQ_PREFLUSH) { error = __send_empty_flush(&ci); - /* dec_pending submits any data associated with flush */ + /* dm_io_dec_pending submits any data associated with flush */ } else if (op_is_zone_mgmt(bio_op(bio))) { ci.bio = bio; ci.sector_count = 0; @@ -1610,7 +1565,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md, } /* drop the extra reference count */ - dec_pending(ci.io, errno_to_blk_status(error)); + dm_io_dec_pending(ci.io, errno_to_blk_status(error)); return ret; } From patchwork Tue May 25 21:25:00 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: 12280229 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,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 4628EC47086 for ; Tue, 25 May 2021 21:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 230D361417 for ; Tue, 25 May 2021 21:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbhEYV0t (ORCPT ); Tue, 25 May 2021 17:26:49 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36446 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbhEYV0q (ORCPT ); Tue, 25 May 2021 17:26:46 -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=1621977916; x=1653513916; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=mne2dHj7J1YkqBYt6OVqysXv6Mse0zTSn9jNKWo5xoc=; b=iBrTs0DwvTNg/pWIz7KjAJ3J8spQ0Et2gH/JYPNUcwvrpNbRT2EH8BG9 nMuuwPLE6D5eAQVcSl0/gZvhdRyzMF28g/JdQ9N2XbEb6gs0UjofKAw3N UlQxSnMn0oiSxZljY8Z0YEakfMjWDunje9cg9/DKVs2i7qro5KAiC/6M3 JWr6yE+xglvpJgV8DP+TcB0V5ZD1fGV1y7LR621Mxy+cy4BQQ7vvl73e4 ErIEDbp+57SJz2k4dzXusAtylZ+F1KrzMeABAqLlyZH82ThN6kNHaW15t xp3AGX4BGLFT1E5faHiWDkeQNr+bD7x5K8bsgr3Wgz1k99r7tD+EGdZzo g==; IronPort-SDR: qiSfIIC+zGVL1fLCMDZdpSOgX/Gz8h1a3fRwvTYpTjpOBxm6wbAG/P4YHDrjLw/bevbC4AiE0t xSLQGNQ7K+5IHw98DVZOW04rvdVCUkUp5zRDYxH9VaKZFfRRBCAeSMYtlqoLLPWxdHUWpsGkaW GdVYQ0G4CjMhSjkELr4jhJ7nzAzvykKofi+CbYhQklV8RcxeLJYatmCqzB6d0HZcETo3sr+kuE 5/XzeUbvkDPCueIRqx+KWaWsPF+EPfziqUrGx+fHFhJoUsTRXPq8nXrRq0hbGvo0a7tPlpKdHe Alw= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717547" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:16 +0800 IronPort-SDR: i4oNJByae6APaJywYuoepqIwVWhng/xKbwl1yLMB9R5SKk2wuyOvlCXGAgT3TrKf0KEJOUoY59 5/vdFFDFuSMMFeKC4YsaZ6rWAOI0KEBTQw4/aSMjKOKchC3Ji+g59gN1PfjawURjqAv1qX809A PdHAlRgf6i81tfWZfpvfIncflrxJG30kCWXEB36avv5R74u4bAqOBkoyVnpNe1HNbqQSKvSD1t RKnGMHPLNJ0q7WwXvNZicKUel/iDylgHi5loTaZnkxIyKjYJyn6M5Q62EV+u63P7ebLeDsHxg3 LPdp7HN3nuKmzVJr6cuSCOhA Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:43 -0700 IronPort-SDR: uZv710VIlkrY5n3XqncdT3yb4cWfdvwrK+xh0mVR5E+D9UH/ipnTv58USU40LhdgOc0CSo+DzK 5an0UnXC9n8rl50nmdSoho5GXWFrTwyMBztSM6nAl4oYgnozEI3bN8KVbwQrXWJh0nUHWLFalD TJR3hNbqqOzQ2bWHWQLqRenYhmEAaBpQHu30n3YhOOV7CCiojrcDDPVud2bgPgyEkADo8LennG ORFGdlrPyprIwfbh9ko0PRtomapDmwW6/7AjvP/vD/tdq56StYHirxe5rk4SmsGDlqx/ic0FmL 6J4= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:15 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 10/11] dm: introduce zone append emulation Date: Wed, 26 May 2021 06:25:00 +0900 Message-Id: <20210525212501.226888-11-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org For zoned targets that cannot support zone append operations, implement an emulation using regular write operations. If the original BIO submitted by the user is a zone append operation, change its clone into a regular write operation directed at the target zone write pointer position. To do so, an array of write pointer offsets (write pointer position relative to the start of a zone) is added to struct mapped_device. All operations that modify a sequential zone write pointer (writes, zone reset, zone finish and zone append) are intersepted in __map_bio() and processed using the new functions dm_zone_map_bio(). Detection of the target ability to natively support zone append operations is done from dm_table_set_restrictions() by calling the function dm_set_zones_restrictions(). A target that does not support zone append operation, either by explicitly declaring it using the new struct dm_target field zone_append_not_supported, or because the device table contains a non-zoned device, has its mapped device marked with the new flag DMF_ZONE_APPEND_EMULATED. The helper function dm_emulate_zone_append() is introduced to test a mapped device for this new flag. Atomicity of the zones write pointer tracking and updates is done using a zone write locking mechanism based on a bitmap. This is similar to the block layer method but based on BIOs rather than struct request. A zone write lock is taken in dm_zone_map_bio() for any clone BIO with an operation type that changes the BIO target zone write pointer position. The zone write lock is released if the clone BIO is failed before submission or when dm_zone_endio() is called when the clone BIO completes. The zone write lock bitmap of the mapped device, together with a bitmap indicating zone types (conv_zones_bitmap) and the write pointer offset array (zwp_offset) are allocated and initialized with a full device zone report in dm_set_zones_restrictions() using the function dm_revalidate_zones(). For failed operations that may have modified a zone write pointer, the zone write pointer offset is marked as invalid in dm_zone_endio(). Zones with an invalid write pointer offset are checked and the write pointer updated using an internal report zone operation when the faulty zone is accessed again by the user. All functions added for this emulation have a minimal overhead for zoned targets natively supporting zone append operations. Regular device targets are also not affected. The added code also does not impact builds with CONFIG_BLK_DEV_ZONED disabled by stubbing out all dm zone related functions. Signed-off-by: Damien Le Moal Reviewed-by: Himanshu Madhani Reviewed-by: Hannes Reinecke --- drivers/md/dm-core.h | 13 + drivers/md/dm-table.c | 19 +- drivers/md/dm-zone.c | 580 ++++++++++++++++++++++++++++++++-- drivers/md/dm.c | 38 ++- drivers/md/dm.h | 16 +- include/linux/device-mapper.h | 6 + 6 files changed, 618 insertions(+), 54 deletions(-) diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h index cfabc1c91f9f..edc1553c4eea 100644 --- a/drivers/md/dm-core.h +++ b/drivers/md/dm-core.h @@ -114,6 +114,11 @@ struct mapped_device { bool init_tio_pdu:1; struct srcu_struct io_barrier; + +#ifdef CONFIG_BLK_DEV_ZONED + unsigned int nr_zones; + unsigned int *zwp_offset; +#endif }; /* @@ -128,6 +133,7 @@ struct mapped_device { #define DMF_DEFERRED_REMOVE 6 #define DMF_SUSPENDED_INTERNALLY 7 #define DMF_POST_SUSPENDING 8 +#define DMF_EMULATE_ZONE_APPEND 9 void disable_discard(struct mapped_device *md); void disable_write_same(struct mapped_device *md); @@ -143,6 +149,13 @@ static inline struct dm_stats *dm_get_stats(struct mapped_device *md) return &md->stats; } +static inline bool dm_emulate_zone_append(struct mapped_device *md) +{ + if (blk_queue_is_zoned(md->queue)) + return test_bit(DMF_EMULATE_ZONE_APPEND, &md->flags); + return false; +} + #define DM_TABLE_MAX_DEPTH 16 struct dm_table { diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index dd9f648ab598..21fdccfb16cf 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1981,11 +1981,12 @@ static int device_requires_stable_pages(struct dm_target *ti, return blk_queue_stable_writes(q); } -void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, - struct queue_limits *limits) +int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, + struct queue_limits *limits) { bool wc = false, fua = false; int page_size = PAGE_SIZE; + int r; /* * Copy table's limits to the DM device's request_queue @@ -2064,12 +2065,20 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, dm_table_any_dev_attr(t, device_is_not_random, NULL)) blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q); - /* For a zoned target, setup the zones related queue attributes */ - if (blk_queue_is_zoned(q)) - dm_set_zones_restrictions(t, q); + /* + * For a zoned target, setup the zones related queue attributes + * and resources necessary for zone append emulation if necessary. + */ + if (blk_queue_is_zoned(q)) { + r = dm_set_zones_restrictions(t, q); + if (r) + return r; + } dm_update_keyslot_manager(q, t); blk_queue_update_readahead(q); + + return 0; } unsigned int dm_table_get_num_targets(struct dm_table *t) diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index edc3bbb45637..c2f26949f5ee 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -4,55 +4,72 @@ */ #include +#include +#include +#include #include "dm-core.h" +#define DM_MSG_PREFIX "zone" + +#define DM_ZONE_INVALID_WP_OFST UINT_MAX + /* - * User facing dm device block device report zone operation. This calls the - * report_zones operation for each target of a device table. This operation is - * generally implemented by targets using dm_report_zones(). + * For internal zone reports bypassing the top BIO submission path. */ -int dm_blk_report_zones(struct gendisk *disk, sector_t sector, - unsigned int nr_zones, report_zones_cb cb, void *data) +static int dm_blk_do_report_zones(struct mapped_device *md, struct dm_table *t, + sector_t sector, unsigned int nr_zones, + report_zones_cb cb, void *data) { - struct mapped_device *md = disk->private_data; - struct dm_table *map; - int srcu_idx, ret; + struct gendisk *disk = md->disk; + int ret; struct dm_report_zones_args args = { .next_sector = sector, .orig_data = data, .orig_cb = cb, }; - if (dm_suspended_md(md)) - return -EAGAIN; - - map = dm_get_live_table(md, &srcu_idx); - if (!map) { - ret = -EIO; - goto out; - } - do { struct dm_target *tgt; - tgt = dm_table_find_target(map, args.next_sector); - if (WARN_ON_ONCE(!tgt->type->report_zones)) { - ret = -EIO; - goto out; - } + tgt = dm_table_find_target(t, args.next_sector); + if (WARN_ON_ONCE(!tgt->type->report_zones)) + return -EIO; args.tgt = tgt; ret = tgt->type->report_zones(tgt, &args, nr_zones - args.zone_idx); if (ret < 0) - goto out; + return ret; } while (args.zone_idx < nr_zones && args.next_sector < get_capacity(disk)); - ret = args.zone_idx; -out: + return args.zone_idx; +} + +/* + * User facing dm device block device report zone operation. This calls the + * report_zones operation for each target of a device table. This operation is + * generally implemented by targets using dm_report_zones(). + */ +int dm_blk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, void *data) +{ + struct mapped_device *md = disk->private_data; + struct dm_table *map; + int srcu_idx, ret; + + if (dm_suspended_md(md)) + return -EAGAIN; + + map = dm_get_live_table(md, &srcu_idx); + if (!map) + return -EIO; + + ret = dm_blk_do_report_zones(md, map, sector, nr_zones, cb, data); + dm_put_live_table(md, srcu_idx); + return ret; } @@ -121,16 +138,517 @@ bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) } } -void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) +void dm_cleanup_zoned_dev(struct mapped_device *md) { - if (!blk_queue_is_zoned(q)) - return; + struct request_queue *q = md->queue; + + if (q) { + kfree(q->conv_zones_bitmap); + q->conv_zones_bitmap = NULL; + kfree(q->seq_zones_wlock); + q->seq_zones_wlock = NULL; + } + + kvfree(md->zwp_offset); + md->zwp_offset = NULL; + md->nr_zones = 0; +} + +static unsigned int dm_get_zone_wp_offset(struct blk_zone *zone) +{ + switch (zone->cond) { + case BLK_ZONE_COND_IMP_OPEN: + case BLK_ZONE_COND_EXP_OPEN: + case BLK_ZONE_COND_CLOSED: + return zone->wp - zone->start; + case BLK_ZONE_COND_FULL: + return zone->len; + case BLK_ZONE_COND_EMPTY: + case BLK_ZONE_COND_NOT_WP: + case BLK_ZONE_COND_OFFLINE: + case BLK_ZONE_COND_READONLY: + default: + /* + * Conventional, offline and read-only zones do not have a valid + * write pointer. Use 0 as for an empty zone. + */ + return 0; + } +} + +static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx, + void *data) +{ + struct mapped_device *md = data; + struct request_queue *q = md->queue; + + switch (zone->type) { + case BLK_ZONE_TYPE_CONVENTIONAL: + if (!q->conv_zones_bitmap) { + q->conv_zones_bitmap = + kcalloc(BITS_TO_LONGS(q->nr_zones), + sizeof(unsigned long), GFP_NOIO); + if (!q->conv_zones_bitmap) + return -ENOMEM; + } + set_bit(idx, q->conv_zones_bitmap); + break; + case BLK_ZONE_TYPE_SEQWRITE_REQ: + case BLK_ZONE_TYPE_SEQWRITE_PREF: + if (!q->seq_zones_wlock) { + q->seq_zones_wlock = + kcalloc(BITS_TO_LONGS(q->nr_zones), + sizeof(unsigned long), GFP_NOIO); + if (!q->seq_zones_wlock) + return -ENOMEM; + } + if (!md->zwp_offset) { + md->zwp_offset = + kvcalloc(q->nr_zones, sizeof(unsigned int), + GFP_NOIO); + if (!md->zwp_offset) + return -ENOMEM; + } + md->zwp_offset[idx] = dm_get_zone_wp_offset(zone); + + break; + default: + DMERR("Invalid zone type 0x%x at sectors %llu", + (int)zone->type, zone->start); + return -ENODEV; + } + + return 0; +} + +/* + * Revalidate the zones of a mapped device to initialize resource necessary + * for zone append emulation. Note that we cannot simply use the block layer + * blk_revalidate_disk_zones() function here as the mapped device is suspended + * (this is called from __bind() context). + */ +static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t) +{ + struct request_queue *q = md->queue; + int ret; + + /* + * Check if something changed. If yes, cleanup the current resources + * and reallocate everything. + */ + if (!q->nr_zones || q->nr_zones != md->nr_zones) + dm_cleanup_zoned_dev(md); + if (md->nr_zones) + return 0; + + /* Scan all zones to initialize everything */ + ret = dm_blk_do_report_zones(md, t, 0, q->nr_zones, + dm_zone_revalidate_cb, md); + if (ret < 0) + goto err; + if (ret != q->nr_zones) { + ret = -EIO; + goto err; + } + + md->nr_zones = q->nr_zones; + + return 0; + +err: + DMERR("Revalidate zones failed %d", ret); + dm_cleanup_zoned_dev(md); + return ret; +} + +static int device_not_zone_append_capable(struct dm_target *ti, + struct dm_dev *dev, sector_t start, + sector_t len, void *data) +{ + return !blk_queue_is_zoned(bdev_get_queue(dev->bdev)); +} + +static bool dm_table_supports_zone_append(struct dm_table *t) +{ + struct dm_target *ti; + unsigned int i; + + for (i = 0; i < dm_table_get_num_targets(t); i++) { + ti = dm_table_get_target(t, i); + + if (ti->emulate_zone_append) + return false; + + if (!ti->type->iterate_devices || + ti->type->iterate_devices(ti, device_not_zone_append_capable, NULL)) + return false; + } + + return true; +} + +int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) +{ + struct mapped_device *md = t->md; /* * For a zoned target, the number of zones should be updated for the - * correct value to be exposed in sysfs queue/nr_zones. For a BIO based - * target, this is all that is needed. + * correct value to be exposed in sysfs queue/nr_zones. */ WARN_ON_ONCE(queue_is_mq(q)); - q->nr_zones = blkdev_nr_zones(t->md->disk); + q->nr_zones = blkdev_nr_zones(md->disk); + + /* Check if zone append is natively supported */ + if (dm_table_supports_zone_append(t)) { + clear_bit(DMF_EMULATE_ZONE_APPEND, &md->flags); + dm_cleanup_zoned_dev(md); + return 0; + } + + /* + * Mark the mapped device as needing zone append emulation and + * initialize the emulation resources once the capacity is set. + */ + set_bit(DMF_EMULATE_ZONE_APPEND, &md->flags); + if (!get_capacity(md->disk)) + return 0; + + return dm_revalidate_zones(md, t); +} + +static int dm_update_zone_wp_offset_cb(struct blk_zone *zone, unsigned int idx, + void *data) +{ + unsigned int *wp_offset = data; + + *wp_offset = dm_get_zone_wp_offset(zone); + + return 0; +} + +static int dm_update_zone_wp_offset(struct mapped_device *md, unsigned int zno, + unsigned int *wp_ofst) +{ + sector_t sector = zno * blk_queue_zone_sectors(md->queue); + unsigned int noio_flag; + struct dm_table *t; + int srcu_idx, ret; + + t = dm_get_live_table(md, &srcu_idx); + if (!t) + return -EIO; + + /* + * Ensure that all memory allocations in this context are done as if + * GFP_NOIO was specified. + */ + noio_flag = memalloc_noio_save(); + ret = dm_blk_do_report_zones(md, t, sector, 1, + dm_update_zone_wp_offset_cb, wp_ofst); + memalloc_noio_restore(noio_flag); + + dm_put_live_table(md, srcu_idx); + + if (ret != 1) + return -EIO; + + return 0; +} + +/* + * First phase of BIO mapping for targets with zone append emulation: + * check all BIO that change a zone writer pointer and change zone + * append operations into regular write operations. + */ +static bool dm_zone_map_bio_begin(struct mapped_device *md, + struct bio *orig_bio, struct bio *clone) +{ + sector_t zsectors = blk_queue_zone_sectors(md->queue); + unsigned int zno = bio_zone_no(orig_bio); + unsigned int zwp_offset = READ_ONCE(md->zwp_offset[zno]); + + /* + * If the target zone is in an error state, recover by inspecting the + * zone to get its current write pointer position. Note that since the + * target zone is already locked, a BIO issuing context should never + * see the zone write in the DM_ZONE_UPDATING_WP_OFST state. + */ + if (zwp_offset == DM_ZONE_INVALID_WP_OFST) { + if (dm_update_zone_wp_offset(md, zno, &zwp_offset)) + return false; + WRITE_ONCE(md->zwp_offset[zno], zwp_offset); + } + + switch (bio_op(orig_bio)) { + case REQ_OP_ZONE_RESET: + case REQ_OP_ZONE_FINISH: + return true; + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + /* Writes must be aligned to the zone write pointer */ + if ((clone->bi_iter.bi_sector & (zsectors - 1)) != zwp_offset) + return false; + break; + case REQ_OP_ZONE_APPEND: + /* + * Change zone append operations into a non-mergeable regular + * writes directed at the current write pointer position of the + * target zone. + */ + clone->bi_opf = REQ_OP_WRITE | REQ_NOMERGE | + (orig_bio->bi_opf & (~REQ_OP_MASK)); + clone->bi_iter.bi_sector = + orig_bio->bi_iter.bi_sector + zwp_offset; + break; + default: + DMWARN_LIMIT("Invalid BIO operation"); + return false; + } + + /* Cannot write to a full zone */ + if (zwp_offset >= zsectors) + return false; + + return true; +} + +/* + * Second phase of BIO mapping for targets with zone append emulation: + * update the zone write pointer offset array to account for the additional + * data written to a zone. Note that at this point, the remapped clone BIO + * may already have completed, so we do not touch it. + */ +static blk_status_t dm_zone_map_bio_end(struct mapped_device *md, + struct bio *orig_bio, + unsigned int nr_sectors) +{ + unsigned int zno = bio_zone_no(orig_bio); + unsigned int zwp_offset = READ_ONCE(md->zwp_offset[zno]); + + /* The clone BIO may already have been completed and failed */ + if (zwp_offset == DM_ZONE_INVALID_WP_OFST) + return BLK_STS_IOERR; + + /* Update the zone wp offset */ + switch (bio_op(orig_bio)) { + case REQ_OP_ZONE_RESET: + WRITE_ONCE(md->zwp_offset[zno], 0); + return BLK_STS_OK; + case REQ_OP_ZONE_FINISH: + WRITE_ONCE(md->zwp_offset[zno], + blk_queue_zone_sectors(md->queue)); + return BLK_STS_OK; + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + WRITE_ONCE(md->zwp_offset[zno], zwp_offset + nr_sectors); + return BLK_STS_OK; + case REQ_OP_ZONE_APPEND: + /* + * Check that the target did not truncate the write operation + * emulating a zone append. + */ + if (nr_sectors != bio_sectors(orig_bio)) { + DMWARN_LIMIT("Truncated write for zone append"); + return BLK_STS_IOERR; + } + WRITE_ONCE(md->zwp_offset[zno], zwp_offset + nr_sectors); + return BLK_STS_OK; + default: + DMWARN_LIMIT("Invalid BIO operation"); + return BLK_STS_IOERR; + } +} + +static inline void dm_zone_lock(struct request_queue *q, + unsigned int zno, struct bio *clone) +{ + if (WARN_ON_ONCE(bio_flagged(clone, BIO_ZONE_WRITE_LOCKED))) + return; + + wait_on_bit_lock_io(q->seq_zones_wlock, zno, TASK_UNINTERRUPTIBLE); + bio_set_flag(clone, BIO_ZONE_WRITE_LOCKED); +} + +static inline void dm_zone_unlock(struct request_queue *q, + unsigned int zno, struct bio *clone) +{ + if (!bio_flagged(clone, BIO_ZONE_WRITE_LOCKED)) + return; + + WARN_ON_ONCE(!test_bit(zno, q->seq_zones_wlock)); + clear_bit_unlock(zno, q->seq_zones_wlock); + smp_mb__after_atomic(); + wake_up_bit(q->seq_zones_wlock, zno); + + bio_clear_flag(clone, BIO_ZONE_WRITE_LOCKED); +} + +static bool dm_need_zone_wp_tracking(struct bio *orig_bio) +{ + /* + * Special processing is not needed for operations that do not need the + * zone write lock, that is, all operations that target conventional + * zones and all operations that do not modify directly a sequential + * zone write pointer. + */ + if (op_is_flush(orig_bio->bi_opf) && !bio_sectors(orig_bio)) + return false; + switch (bio_op(orig_bio)) { + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + case REQ_OP_ZONE_RESET: + case REQ_OP_ZONE_FINISH: + case REQ_OP_ZONE_APPEND: + return bio_zone_is_seq(orig_bio); + default: + return false; + } +} + +/* + * Special IO mapping for targets needing zone append emulation. + */ +int dm_zone_map_bio(struct dm_target_io *tio) +{ + struct dm_io *io = tio->io; + struct dm_target *ti = tio->ti; + struct mapped_device *md = io->md; + struct request_queue *q = md->queue; + struct bio *orig_bio = io->orig_bio; + struct bio *clone = &tio->clone; + unsigned int zno; + blk_status_t sts; + int r; + + /* + * IOs that do not change a zone write pointer do not need + * any additional special processing. + */ + if (!dm_need_zone_wp_tracking(orig_bio)) + return ti->type->map(ti, clone); + + /* Lock the target zone */ + zno = bio_zone_no(orig_bio); + dm_zone_lock(q, zno, clone); + + /* + * Check that the bio and the target zone write pointer offset are + * both valid, and if the bio is a zone append, remap it to a write. + */ + if (!dm_zone_map_bio_begin(md, orig_bio, clone)) { + dm_zone_unlock(q, zno, clone); + return DM_MAPIO_KILL; + } + + /* + * The target map function may issue and complete the IO quickly. + * Take an extra reference on the IO to make sure it does disappear + * until we run dm_zone_map_bio_end(). + */ + dm_io_inc_pending(io); + + /* Let the target do its work */ + r = ti->type->map(ti, clone); + switch (r) { + case DM_MAPIO_SUBMITTED: + /* + * The target submitted the clone BIO. The target zone will + * be unlocked on completion of the clone. + */ + sts = dm_zone_map_bio_end(md, orig_bio, *tio->len_ptr); + break; + case DM_MAPIO_REMAPPED: + /* + * The target only remapped the clone BIO. In case of error, + * unlock the target zone here as the clone will not be + * submitted. + */ + sts = dm_zone_map_bio_end(md, orig_bio, *tio->len_ptr); + if (sts != BLK_STS_OK) + dm_zone_unlock(q, zno, clone); + break; + case DM_MAPIO_REQUEUE: + case DM_MAPIO_KILL: + default: + dm_zone_unlock(q, zno, clone); + sts = BLK_STS_IOERR; + break; + } + + /* Drop the extra reference on the IO */ + dm_io_dec_pending(io, sts); + + if (sts != BLK_STS_OK) + return DM_MAPIO_KILL; + + return r; +} + +/* + * IO completion callback called from clone_endio(). + */ +void dm_zone_endio(struct dm_io *io, struct bio *clone) +{ + struct mapped_device *md = io->md; + struct request_queue *q = md->queue; + struct bio *orig_bio = io->orig_bio; + unsigned int zwp_offset; + unsigned int zno; + + /* + * For targets that do not emulate zone append, we only need to + * handle native zone-append bios. + */ + if (!dm_emulate_zone_append(md)) { + /* + * Get the offset within the zone of the written sector + * and add that to the original bio sector position. + */ + if (clone->bi_status == BLK_STS_OK && + bio_op(clone) == REQ_OP_ZONE_APPEND) { + sector_t mask = (sector_t)blk_queue_zone_sectors(q) - 1; + + orig_bio->bi_iter.bi_sector += + clone->bi_iter.bi_sector & mask; + } + + return; + } + + /* + * For targets that do emulate zone append, if the clone BIO does not + * own the target zone write lock, we have nothing to do. + */ + if (!bio_flagged(clone, BIO_ZONE_WRITE_LOCKED)) + return; + + zno = bio_zone_no(orig_bio); + + if (clone->bi_status != BLK_STS_OK) { + /* + * BIOs that modify a zone write pointer may leave the zone + * in an unknown state in case of failure (e.g. the write + * pointer was only partially advanced). In this case, set + * the target zone write pointer as invalid unless it is + * already being updated. + */ + WRITE_ONCE(md->zwp_offset[zno], DM_ZONE_INVALID_WP_OFST); + } else if (bio_op(orig_bio) == REQ_OP_ZONE_APPEND) { + /* + * Get the written sector for zone append operation that were + * emulated using regular write operations. + */ + zwp_offset = READ_ONCE(md->zwp_offset[zno]); + if (WARN_ON_ONCE(zwp_offset < bio_sectors(orig_bio))) + WRITE_ONCE(md->zwp_offset[zno], + DM_ZONE_INVALID_WP_OFST); + else + orig_bio->bi_iter.bi_sector += + zwp_offset - bio_sectors(orig_bio); + } + + dm_zone_unlock(q, zno, clone); } diff --git a/drivers/md/dm.c b/drivers/md/dm.c index c200658d8bcb..7bc2ddc80814 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -875,7 +875,6 @@ static void clone_endio(struct bio *bio) struct dm_io *io = tio->io; struct mapped_device *md = tio->io->md; dm_endio_fn endio = tio->ti->type->end_io; - struct bio *orig_bio = io->orig_bio; struct request_queue *q = bio->bi_bdev->bd_disk->queue; if (unlikely(error == BLK_STS_TARGET)) { @@ -890,17 +889,8 @@ static void clone_endio(struct bio *bio) disable_write_zeroes(md); } - /* - * For zone-append bios get offset in zone of the written - * sector and add that to the original bio sector pos. - */ - if (bio_op(orig_bio) == REQ_OP_ZONE_APPEND) { - sector_t written_sector = bio->bi_iter.bi_sector; - struct request_queue *q = orig_bio->bi_bdev->bd_disk->queue; - u64 mask = (u64)blk_queue_zone_sectors(q) - 1; - - orig_bio->bi_iter.bi_sector += written_sector & mask; - } + if (blk_queue_is_zoned(q)) + dm_zone_endio(io, bio); if (endio) { int r = endio(tio->ti, bio, &error); @@ -1212,7 +1202,16 @@ static blk_qc_t __map_bio(struct dm_target_io *tio) down(&md->swap_bios_semaphore); } - r = ti->type->map(ti, clone); + /* + * Check if the IO needs a special mapping due to zone append emulation + * on zoned target. In this case, dm_zone_map_begin() calls the target + * map operation. + */ + if (dm_emulate_zone_append(io->md)) + r = dm_zone_map_bio(tio); + else + r = ti->type->map(ti, clone); + switch (r) { case DM_MAPIO_SUBMITTED: break; @@ -1710,6 +1709,7 @@ static void cleanup_mapped_device(struct mapped_device *md) mutex_destroy(&md->swap_bios_lock); dm_mq_cleanup_mapped_device(md); + dm_cleanup_zoned_dev(md); } /* @@ -1955,11 +1955,16 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, goto out; } + ret = dm_table_set_restrictions(t, q, limits); + if (ret) { + old_map = ERR_PTR(ret); + goto out; + } + old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); rcu_assign_pointer(md->map, (void *)t); md->immutable_target_type = dm_table_get_immutable_target_type(t); - dm_table_set_restrictions(t, q, limits); if (old_map) dm_sync_table(md); @@ -2078,7 +2083,10 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) DMERR("Cannot calculate initial queue limits"); return r; } - dm_table_set_restrictions(t, md->queue, &limits); + r = dm_table_set_restrictions(t, md->queue, &limits); + if (r) + return r; + blk_register_queue(md->disk); return 0; diff --git a/drivers/md/dm.h b/drivers/md/dm.h index 39c243258e24..742d9c80efe1 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -45,6 +45,8 @@ struct dm_dev_internal { struct dm_table; struct dm_md_mempools; +struct dm_target_io; +struct dm_io; /*----------------------------------------------------------------- * Internal table functions. @@ -56,8 +58,8 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector); bool dm_table_has_no_data_devices(struct dm_table *table); int dm_calculate_queue_limits(struct dm_table *table, struct queue_limits *limits); -void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, - struct queue_limits *limits); +int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, + struct queue_limits *limits); struct list_head *dm_table_get_devices(struct dm_table *t); void dm_table_presuspend_targets(struct dm_table *t); void dm_table_presuspend_undo_targets(struct dm_table *t); @@ -103,17 +105,25 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t); /* * Zoned targets related functions. */ -void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q); +int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q); +void dm_zone_endio(struct dm_io *io, struct bio *clone); #ifdef CONFIG_BLK_DEV_ZONED +void dm_cleanup_zoned_dev(struct mapped_device *md); int dm_blk_report_zones(struct gendisk *disk, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); bool dm_is_zone_write(struct mapped_device *md, struct bio *bio); +int dm_zone_map_bio(struct dm_target_io *io); #else +static inline void dm_cleanup_zoned_dev(struct mapped_device *md) {} #define dm_blk_report_zones NULL static inline bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) { return false; } +static inline int dm_zone_map_bio(struct dm_target_io *tio) +{ + return DM_MAPIO_KILL; +} #endif /*----------------------------------------------------------------- diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index caea0a079d2d..7457d49acf9a 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -361,6 +361,12 @@ struct dm_target { * Set if we need to limit the number of in-flight bios when swapping. */ bool limit_swap_bios:1; + + /* + * Set if this target implements a a zoned device and needs emulation of + * zone append operations using regular writes. + */ + bool emulate_zone_append:1; }; void *dm_per_bio_data(struct bio *bio, size_t data_size); From patchwork Tue May 25 21:25:01 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: 12280227 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,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 5B4D0C4707F for ; Tue, 25 May 2021 21:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4117C6142E for ; Tue, 25 May 2021 21:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbhEYV0t (ORCPT ); Tue, 25 May 2021 17:26:49 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:36450 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232508AbhEYV0r (ORCPT ); Tue, 25 May 2021 17:26:47 -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=1621977917; x=1653513917; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=bFcRaggZ9tBN12RVTPVwAzImTsSc/VkMzkTVeX3Uo8g=; b=HyayAsfXi2EJ+XHR5ykqc/SdLHwKSW3xM645Ah5RW+Z9kJCRGgvFjykW gseSApcjol8/HQhDd/nxmLRS0FjYVs9N+taVSV9OKMDALeXNUzFoQ3gK5 platCEo2MOtoIE7GtLoJ3n8rookhql2yE7D0J9VrPUg8l5U+s+uhpTw8D i0VOBqDL4UwWdTdX5QfKndaM2g/fT5uTgMzqZBCeLPQIrqKUurtSUSc2v lGBnK0Gs0hZp5slSoK4Nv5YVuSkZMWNp6ARaxNns6EnIJEDBpRnZMDi7h 74lbF+QhCnwtFsZ0VRgeMtqbwUf1aXuPCemGggXCZRXWk00G5bYmx0tG8 w==; IronPort-SDR: 0j8o+QnfmfuARJ3/B1gTKcwDjmkfdLlAqz5IBV/yiq2NrYJdZOL6KN3P6UU6mwcYnW7JyDnJJ7 aKbaBVOIBKeY7rQXl/96Pc18Qz4BueDAhl9wjk2h9OC3+KnyETCCZy/zzSygnFehsG8+qEwXX8 fZzbx3xDqTVp8LsR0d1ofhY7RZBkQK05PLxvxqDzKmYdMPE/FkRZgP+tmJSszHD6Tk1goD6ffR cjAi6Z1EiZScstKrhOz41XHNnGCIKYefvceGFy8/4LME1AjpMoH8C8wGdMOWMVug/COaenhwBp IsM= X-IronPort-AV: E=Sophos;i="5.82,329,1613404800"; d="scan'208";a="168717550" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 May 2021 05:25:17 +0800 IronPort-SDR: 1QfQARWClb/cmw6YSKcfDEQ5e4eOMQ25ohk6kmiLsdw/WCiIv5dAcXrz/l0CRabD2qrv9mEvWK e9v+RBTSaO8e0qq6dumBMH726z6+dqCy9wr3O9XhIKd32X9y6EB40MwaWxG4jTmNUCfdVGUuoQ aY/SFKE8qR3UJ8D2S5jWfVhIPMuGynGbQsWUOcjIYGH92uwPn2VL1+3YZy62XUgPrr7L6Nijp+ PTXk007YQORBbZRzgDZH1HUFNPUO54ifDShZ/nYzARohE+r3SJxP0IYMsOCaZvZrNxsYszvbUV BP3ICFCO3Hy0g2triUJMrH1p Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 14:04:44 -0700 IronPort-SDR: FNmk77p8RaJkKJ4Lf3DM2Ud9DNupkU6U5O1zROkYxyKxSGhxq4OJunGO10+o4L6MuRYtE2H1Fm po1vbCpBIFroKqFEYU3NDhTff2xyL58bH+mLvyJ5deJuKcgsD6BBAh8lLqygUWRQlH8k/Cu6yl FafTPsK47Kcw2TinMkQH+7J/7/yP8tQe69m71KK4x49inIVgLiBsngobFb6vHGIIibRq+0dC78 ey/iqrz7U2rHkRpxzRP+MaA9lgOO/OAGdLY3rFFte99MK8UsGuQtYi5VZJKkQdR0wOtAoPsExe IUU= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 25 May 2021 14:25:17 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v5 11/11] dm crypt: Fix zoned block device support Date: Wed, 26 May 2021 06:25:01 +0900 Message-Id: <20210525212501.226888-12-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525212501.226888-1-damien.lemoal@wdc.com> References: <20210525212501.226888-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Zone append BIOs (REQ_OP_ZONE_APPEND) always specify the start sector of the zone to be written instead of the actual sector location to write. The write location is determined by the device and returned to the host upon completion of the operation. This interface, while simple and efficient for writing into sequential zones of a zoned block device, is incompatible with the use of sector values to calculate a cypher block IV. All data written in a zone end up using the same IV values corresponding to the first sectors of the zone, but read operation will specify any sector within the zone resulting in an IV mismatch between encryption and decryption. To solve this problem, report to DM core that zone append operations are not supported. This result in the zone append operations being emulated using regular write operations. Reported-by: Shin'ichiro Kawasaki Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/dm-crypt.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index f410ceee51d7..50f4cbd600d5 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3280,14 +3280,28 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) } cc->start = tmpll; - /* - * For zoned block devices, we need to preserve the issuer write - * ordering. To do so, disable write workqueues and force inline - * encryption completion. - */ if (bdev_is_zoned(cc->dev->bdev)) { + /* + * For zoned block devices, we need to preserve the issuer write + * ordering. To do so, disable write workqueues and force inline + * encryption completion. + */ set_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags); set_bit(DM_CRYPT_WRITE_INLINE, &cc->flags); + + /* + * All zone append writes to a zone of a zoned block device will + * have the same BIO sector, the start of the zone. When the + * cypher IV mode uses sector values, all data targeting a + * zone will be encrypted using the first sector numbers of the + * zone. This will not result in write errors but will + * cause most reads to fail as reads will use the sector values + * for the actual data locations, resulting in IV mismatch. + * To avoid this problem, ask DM core to emulate zone append + * operations with regular writes. + */ + DMDEBUG("Zone append operations will be emulated"); + ti->emulate_zone_append = true; } if (crypt_integrity_aead(cc) || cc->integrity_iv_size) {