From patchwork Thu May 20 04:22:18 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: 12269003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21F83C433ED for ; Thu, 20 May 2021 04:22:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06BE4611C2 for ; Thu, 20 May 2021 04:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229449AbhETEXv (ORCPT ); Thu, 20 May 2021 00:23:51 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhETEXv (ORCPT ); Thu, 20 May 2021 00:23:51 -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=1621484550; x=1653020550; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=En+z6SQhhMqS5YqgbYEJrpwAEtj9dj060SIoCjGstIQ=; b=CWglqxVy2NvtTBx223MS28V38j3Di3ezIbTGSSxJFcttbYR1Efeacz+/ HT9o2i5ttcfXkYEHpxXTYIoUJ18eX4GfvAtKEowBycWJtgxEqIwIwRi57 cGlHenuvHLHw+eiMwUw+oVvtojZXlJNcwxbEyWMq6vmq6a3SdpEtC7roB Hf9qr2Loz2KslSry2R5li1UTRaiGnP5G0gTc2JjzItmLRIkSQKTJdmDgH YY9VYUVarbrtLvcw77xESAbeDKVPLLKLlmLu/Cu4JjL310cu49NSerryD 7kTW7Y7w1v6nu1hhCnETokOruaLiinWw2vqjWhP2o+mUEz3n3xLKU+6gr g==; IronPort-SDR: ImI9k1e0y+oHMH9AC8lWS13C2vLNdAIJxlWjPAyKiZ5K5R0xIJUDtuzyfbL/eT6mdVNhuoa/BA b9nTq9GbvQ8t+cOx5Tr939zK1UCVZqlO6tLzVAxmkhnBGFHkE7nfD8o8vMGnJuVFOj5br3HKD3 EfiuC/iA/8ZfwZcffmMRPhTnqa0Hf7hb6nvXkCtUN7alGk2Q1jbw2wi8Yl81545WOZNuWzKmv/ 9CFl/6Ny9Xf8gDBfX4OPMEs3T4MRzEHwrFe/qMEWIptXcL64GmiHg+nmdjz9kPIcB7LbamJpG2 +/k= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105831" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:30 +0800 IronPort-SDR: Bau0DUBV/oBQDP21Ef8TJlBm14upRm1nbYU5JM9D/mS9O7skthtD5pvW0Vf687uElAHwbLEApr B9/m4dj3VoZg54XGlOr8yimNyRJ9iPPO7PBvYS0MsfcgONhIHcAbQqxoOrVJuAAjY/BVu/XGsZ rHnBAyDFKtbLgzQbt5pX+kXGbMywdvKh5/in7W4dKjvjWT1BNa/VL2DSEwTsHvCbj00XBzD+WL 79TGpOG3JRd3eYuGDbEE7qF3u99JjrzUikmdAi8E6UhD/2CnC9YE2YsOgQR0ld0RfRZSuuAAN0 Y4STprFfb9XIh4oGqfKFvWnO Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:07 -0700 IronPort-SDR: gt6MzuvMay/jelRNeh6XVooUj61ms8LYauZTwb79ZgHR3WRXwuZKhb1HuHrOBzH5pQGZbR6iho oHAZdnaizDkMaS3rJCjgxW8RjnIFLDBhJznfuQ9kaoGjJD5h8SspKAuxrufwf83g3F47Tmjxyq RMxesU2q+qUhIh6T9G6gpcwfz2nspjZUF1/Mlet+SWcDCA2Q36uvTfuT/q0V9QlrCAeecf94PI bid4PXCYWV4snetOBMWD1UrPUqfOypNLS0hVgOBz2wNha5+3AqLicsuPFhg6+c/KMBYaQ+yW37 voI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:29 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 01/11] block: improve handling of all zones reset operation Date: Thu, 20 May 2021 13:22:18 +0900 Message-Id: <20210520042228.974083-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- block/blk-zoned.c | 117 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 27 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 250cb76ee615..0ded16b0f713 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -161,18 +161,87 @@ 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; + 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 +269,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 +291,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 +466,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 Thu May 20 04:22:19 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: 12269005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3F0BC43460 for ; Thu, 20 May 2021 04:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92EF86108C for ; Thu, 20 May 2021 04:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbhETEXx (ORCPT ); Thu, 20 May 2021 00:23:53 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhETEXw (ORCPT ); Thu, 20 May 2021 00:23:52 -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=1621484552; x=1653020552; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=fBlyNPaqEFSSoSs+6AtZVHwfafhe/Inr4ytd1alMRuo=; b=IOTdSYgj9xv3gy43gOgHPKIGmvB70YlxUnYbrr8Zu8xslOfYMUqk77qr kVPK6NdZkqVvXkKPbKNqlPUhsimM+9jtcBRHkdHiu1PFX45zm2J2w7alf ihtfskn7vf3y/sEPYsuVTuO0zO2/n0HbT7T2GkbAPBCQ9fgdEiNWc6vB/ zU9ACyhD/fOyeVH4X6N/qKw+tULiAZwxpn0FHJlu501CL84CjxEZcLwa1 dAmeDaL4StMaJBCUItqzk7LCnnzIHEW/CPO1J2wCh9ACr8zRuuS3yxIls doTT35zGTKi2aTpcykQdrmZ9vJ+8/SLE1kvoU2TNwQ0GbeeKmUC1F6tYG w==; IronPort-SDR: xNHmcVC/GgncsUxlu6sDS3vI70+xmV+YCzuJzHdySrU/pbD6Fa6QRj+XVfVyjDBZ/nmM2H7iy4 +Sb7j8hP6x+NJwZiY5JNFSJ7kZSMChNhHq7Hae5KbmfHNktREVAEgzKk7GQApMM1MpioeZaZgQ R8/F+JdvgzH4qDaFTVIiIWgo0dBuA67CWt8KDXI+0na92i0V6IO7+5YFFCQZAuBqPDxqONcbec +5ihSkrOPWEz+nByCeMluIIqrpPuU73FAxLacn/Qy+2TIoSOecJCLhjrG0a4RC38l5wGN5JKxm gCA= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105835" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:32 +0800 IronPort-SDR: CwgA/NFFAaWGZCsdIsv4G6BeyBNmE8pRmbMIPjYAdRcdbRzGA9uoS9V9OAdj1znRoIgJrKKw30 eTDukeu0zJOwYuqA3aeudCW77cOVhKbzODz/rNahtd/sQAI4x6SNtTsde+SBD0TqZPhMcRBT8A yAAWX5UWVrYMnzp/tVV7XN6EgJoVEWikKxpZ13q4SGeExkWVxgv3K6QtUPbWttSNdoAd3GuvwH 0mnUBf/GFTsuYrdMtMorvmg7guZI4mI0IEarp4JoD7Qpu5hVmjyEjdJ0u9s9XH86At3xCgKizp /A25amfEwezr2UQDE0DqdRAz Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:09 -0700 IronPort-SDR: J/48wiKhHEXS5SbzrB86Ab9A0rGE/5PNyqwr9Kj+Ra6ZBE7KWJmVhqAati3UyEL4cZQYdumb5c xO1BgASlgG89rXBU01EAiuIZc4cm4I6vAZ63H5dzpZjU8cpQVIsaNJTQkT0PY7RcEtiJfySMo9 6UwCfUdDiOMGpgVtJy74bqieMbYN05GgcGptHNQXvpa2pJ8VpJHZMBVlZyJGZNIBMp/E8ui49u f0LhLIOqRKRQohOdwylH78Jp1etczoUz+BVjXfQ7/d+viOLe+ETTf2l/mX0IbYWTAjLxeckIq2 Fxk= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:31 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 02/11] block: introduce bio zone helpers Date: Thu, 20 May 2021 13:22:19 +0900 Message-Id: <20210520042228.974083-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 Thu May 20 04:22:20 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: 12269007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE5C4C433ED for ; Thu, 20 May 2021 04:22:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C14CA611AE for ; Thu, 20 May 2021 04:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbhETEXy (ORCPT ); Thu, 20 May 2021 00:23:54 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhETEXy (ORCPT ); Thu, 20 May 2021 00:23:54 -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=1621484553; x=1653020553; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=IuQdErNrCgq4pGDKQDnDOnNbcTOBLuJiLkqhDgmcHEI=; b=k6soq7labINe13FwXJzxDxCPDv2e7uJcZ3JWnJ/SU7eqwIGGhfjTQLUv EfWPgW2bi3tUFbEU3VFdJvqFK6bDLXaxCfQ5oPMNTJG7La94IAF7TgQq0 SnMdA6wNUU+6rsCrxYg75/mRO0KU8C3Oksj1reGFbqym7GsBUlIxpw0pW IAG0wm2hyd2caLux/A4EagSRIQ0GldU82hcy8xa0fyD7vOriBwIVjO6HF JCIEG4RYbNSfJs41uAQCZnlbRMo+N2fAlzQhY3uRFztRfrlpRM9TeBrAf tHOd5rAOWnzIoJy6wQ4WlWPlrlItMEKSuW1bKxG7n5AhbC3d1ESoF8Ljh g==; IronPort-SDR: xgo///tvFaiDJLKx+K1svpB189S04rDEMsW8HWDmAxfjTcakD3W0SvCwH739lJ3oh190KMzg4R LvAjJRsoHpTmT0vQMWEuuQeb5CQhrLdXCi6EYKWk+oAgzTivEvhtei2yTizSZ270GL5GKcTLI3 IDevjETnqnSB8/M63WJLtPG5zuqX7uTHLgiE0uVNZ+G6LV9Jg6WOSL4EwM8cD4edURs1Bf2AWs EOds1RmeklzzbxQyuW/ZkMC9HfGsP0roOGdVlAz9WPhFrMf8Q/8EWrekBoKV8Fd2RRW/TkMKir RGc= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105838" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:33 +0800 IronPort-SDR: mLKILvbbAiwu7XvXlKMiFw69f7l93nlj/4Vj1lUMWDh6EwdyvuKpjueKws3P+Ac02yZkBifUl+ jrAG2lXIGsjY5jimUoOkfAZftCEhxdm4miAOhRnZ6V64HLmONfSCK7o9x2Ym8hf1MwHPz8cKwK ndDqAm/5LDtN9jGScr1UFZZ86RK0UCiHVngjsRsx6gijjVKCYbB45fGVgn+nn1YjFTEhR0E6Wq TEGknwJWy8R0BtRsKn7BnkWmfLRJgRLEAzjxOH1qnM3GdmgQSrfJm/quE7vPB/J9s5G1Jd1EYv fKn9pkApXKvmXwVnLFlknSQX Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:10 -0700 IronPort-SDR: CAw9+Fo4qDxasNQN/GopsJamFgI79cMYrsl9EI8NqsZOkQIFLVSxw1Q0Lp3x2zQmy0lNX4pAQf CMHbnNDHBmRvTOhtXDapU30f3hBZ7ZTtBtY2JcDwc7TnRQcaakwVAIqMhXiJ0lSfRhkdBNUjYG M1j6HdMWWHZImOKE+m6Rr9GX8LM58CM8WveF466Sr6z4hdal4gyGZI/v34ldLN8HiECxj3XS62 C6pUWSCHUo2Xj3cA01K/OVEHvq8HqY1VVZ1kfaMofsowqbTfZmR3GXYE+TNvBgz0QhbG70nAKV q4g= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:32 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 03/11] block: introduce BIO_ZONE_WRITE_LOCKED bio flag Date: Thu, 20 May 2021 13:22:20 +0900 Message-Id: <20210520042228.974083-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 Thu May 20 04:22:21 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: 12269009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6DB1C433B4 for ; Thu, 20 May 2021 04:22:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6BC26108C for ; Thu, 20 May 2021 04:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbhETEXz (ORCPT ); Thu, 20 May 2021 00:23:55 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhETEXz (ORCPT ); Thu, 20 May 2021 00:23:55 -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=1621484554; x=1653020554; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=0wvrBF+PmXIKL6WT7q2S9+AJ0dOhYMZY187Y9appg7A=; b=GkiUlet1rGKHKC2lfkZdgP2ttIwFp6U8xqxTgz6m0l1p7NMw/kqLH0kJ l8SREamrJ4IRqeosVk7gxDQR3q5cspN0qqOPSOpDfIo7S4WmeGHAcdi00 SEPC7V18s508t+1Ew1wx7QD+9Os/+n0PKcgb5hKrq183h3YIReKtTHBh8 1wOTnYQvYRSt++eowI2zFpe+6M6P2rs4PGCB5WYucOj1d9spm+g24L8mt +U8OHsQ5C3/RCSgQnlX32Hkq++McMQddHxAehJMEagD+CBmSflOywG3wF lKkUVwRnOOAy6UTrJiVmdstM4Yx0VeD1WUUCQUJGTvKN8QTWGQKezpLwr A==; IronPort-SDR: kOwB16Ky8SIwlIpHVNbkXlDaREX3G/sLFiHDesiRQRfWF/ZgqZngb1A8ky8tsPXTmz1mD9HnZw mrZN5a+mp8J3A5qnK1W3itQBfuvW+tAHwL12An5F1jhOa5CN/rBQ729JTniwtVxmRHefyGN/6u LMZFQJuQmZnqZ+M5CD2JyMaVn1/MkXJs6EZhg38pRPS+SoI4ywaW0yYREjRJ2l5n7x2YoAq8VF w9efrtSF4ndTazdp6OGcorVcQiPF30asD43qtfYyX5vVll4mcIZ2VyKiGOm7npeVglT9KJ5RXb gH4= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105840" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:34 +0800 IronPort-SDR: yYROGyYqIWvwZAgTrcXkVblYqhkM4O8b4tBulyNZrn7lyP4lX1y9YHn1iaCZfR83oIFCXsDSG1 FZP/WnYIsU17P7SEWTgyHjHzVAIL9pr0cCSN2PEcrbWOjcozY3/c1OFHQo00Z7Pvs3INqN2uqm LMCONb2Xc2nfNUi1imSOX6PekAmp1XBUoPlU4IoUAO8u5U80bWHqN8MxriXobb05HULMI41TFu uisqwQtfkYgU9u3BCG/+JKEtCUJ8XlCuw1fLd9SQ/pdZBTL1+JkV2GBZyl/sRFe6CntY4o6raZ RB5Haumka03Yr1+3XdV77Nv3 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:11 -0700 IronPort-SDR: iMmTcvoJTNMSGxLdflsNlb0SPMpOaH43yQqsXpbohPjfRNCpHlofi/mjOrwqlECx8ajOvgT7K9 cEbfH3r3qOk2NkgY3djchM2QSKyxEVQpnpFlFXFmsOr2/6w9gCvjGwxs2LpGyGDtbqre2riAhM HoNF0seytkMRnXc4Yr7EDkash/6hYoN9qv550pNm0I0SgA2Jxsrm52xpGDl0LAC2jX3qjT6dJv +R8Eg4GP/AJEvKh3GNTpdF5iSK1ucH5Ihr1UNZRzQ4kecA64JmH3Gq4Di2xw2S8IgGBlfhHO98 7wg= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:33 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 04/11] dm: Fix dm_accept_partial_bio() Date: Thu, 20 May 2021 13:22:21 +0900 Message-Id: <20210520042228.974083-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke --- drivers/md/dm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ca2aedd8ee7d..a9211575bfed 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1237,8 +1237,9 @@ 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, zone management operations + * (REQ_OP_ZONE_RESET, REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE and + * REQ_OP_ZONE_FINISH) and 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 +1269,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 Thu May 20 04:22:22 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: 12269011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C627C43460 for ; Thu, 20 May 2021 04:22:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B3B6611BD for ; Thu, 20 May 2021 04:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbhETEX4 (ORCPT ); Thu, 20 May 2021 00:23:56 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhETEX4 (ORCPT ); Thu, 20 May 2021 00:23:56 -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=1621484555; x=1653020555; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=mJtdvFpXsZHL3tsBZuMYjJqXEQBTOjo23wrT4soN/3I=; b=AZ384J7lpTcsivhfEk1103jLyEoK/1rR1qY/z9lHZlJpoPllpwhdl/By xVrRa3zDNrg9RzuwSYzPUW7sM5lRHEf4AiuRyLqmAWgmXSQOqUUF5JVyk li6cMlFUiNo7tMGg/uhBQnDCdCm9JWo+ykFBov9ZPuLOIcUmBhCfPudy2 jePLz/zZjB6BlkDUSBpC6pLAxgLmpqz0vavaMcfK+5Lm0yFSAp/+mfwDb lEtJpB2w/mpW6ONsv2DPJ8uYYcfAAmDvGwg132Q1lyTtCSSc1o1aM/x6e 7Nzq7SC2toIQsiGkFSrC1nIhNOI8J0AurP34q0OW39Xk6h4QewHx74J1M Q==; IronPort-SDR: bL2JtEr65HmuibeJrAlsD1FgEsmUaqDg6n7tfC1nXIsl4xG2aXtAgh5LUIjYHqcYfJK25JU/3H Dw7EhFy/NOqayR7gjauqFzR+la4AjGphbhO4So+kJQ1AkQagUCRhkTB6Tp9RsjbMqxCoMveIoj pzyF4rk0PcQrNErD1STnsR5eHvBQGlsaSVuZ573x3LN0XYxA/uItNqS3wLnhTMNi/sC0DpIgcF yOKyVhnPJUkV84fYChfYq73fPacKR/Oj1V88mslnwigq3evCQVCMKgjnvL+OlIks8+L/NWMEfe RoY= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105842" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:35 +0800 IronPort-SDR: fa7LPvfmF7sRa3d2wD6EOSJjZrDSnQMPc5TqufVDBpXdVUE1i3PMLjWYuS8Ul+X7kE3lWMT6rs QJYfV1N80aNlDDeJtNjjZuqei55s/6tFvAbn3j4wFLIprdJJSY7/+5U8Oeuml6MiWMgtdhssn+ 1Fjz1XZQyhiCcszOhfyTmAIG0s05QBQY8zMzmOg2sThv3Kv1Nw23ta21E51ooKyDPhUhWEZB3/ joXDXm1D508TlhCGLmXIQ/KgqhltF559F2z/0occuDSy3/tWRpiZhyVChcUpdicS5BXFA7faQm XHkf/gfhd7cGiwhGFMIy2oWi Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:12 -0700 IronPort-SDR: 6kNOHqXrru0/CddEeEBMWKY14E7If5+84cgNhp8D/5XGKZ1yOqXB0WBBrgGWbvYPZOK+iFtJ+c ooqEd9ivvptwZC9IGLDSl8/FAlzAn4Yjl+FJo45XtC3jxbQwsgZxlI6/AqwrbttYhJQMA57B4W ufs6e8zTLtxqhchXNUNfyexTCivuTA86KhbCytPVZXZQgtYLHu9QC8IyENgm48Iao7GY1utEpQ U7wfIAH1A4EYDVQxH8V0nsBcfkuQ+/YIbs3xzM0Phbu/aFxFZ/FwsWGhsCdu2XIM/YdOEY/RJ1 TUI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:34 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 05/11] dm: cleanup device_area_is_invalid() Date: Thu, 20 May 2021 13:22:22 +0900 Message-Id: <20210520042228.974083-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 Thu May 20 04:22:23 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: 12269013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 008F1C433B4 for ; Thu, 20 May 2021 04:22:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBADB611BD for ; Thu, 20 May 2021 04:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbhETEX5 (ORCPT ); Thu, 20 May 2021 00:23:57 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbhETEX5 (ORCPT ); Thu, 20 May 2021 00:23:57 -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=1621484556; x=1653020556; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=MgrOAN1o4/1fpwx6e37zXOJtnBRopBpCpAEqiVV+/r0=; b=E1/wTk83nIYlHvPTT+b1CCSAGkTWznXllVnbAXJ9RkscmNP1mb7PGXyv i9lSwn0YBC+KbhZ010EzS9c1tRu5/ZWM1TGankNs27hr8TDSlzNyGRNn8 9jrRl6FWcdZlnt2crqcrPc54ruTBWliDGM7xVKaPAg8mCppvBhFIYOEG+ 3a11OAYVIyprOEBjOIbjnxgkW+z7ZFNpb9S78fJ9Z14AczEH5gEmzTqfQ N9R2MIMd6I81mwRXo05w+kaW4qAUakJTAoCcIwLW3XyH0GMtGMQv8yPTt XXL/n3MVvrsCfCY0lbuaokm5B+Zhd8e/MrKo0lZCLOCX+MoYXF2A9G1AT A==; IronPort-SDR: Kv1gbtDuDFhMZLQc6AxYatFXTphmwG589nKQYKGsiGxcS/6HAP5ChJ5QWNZRopO5rj0qcIOSHe 8j9msxaOdmLt0QKO1ZCtj3XuAhsj19ha6aBc72aHB9gtfckQaYF/YXsTF+8hYyzYCLyNxOwySr cOdvyxGN0ekEwoeYRaP0gwRMu6Kf4eAedVwHu2VEYwtcx4PdgoNCmeiE8+e6JcvlhnEm6Q8CV1 Ii9dLmsXlyBDYxNkkkO3zntGWDVSqYCDrSdVi8Y2Xh898D1KO0L7tN9PtQ+JpvAZ6Wlr2NS+4l RQs= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105844" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:36 +0800 IronPort-SDR: ijJ2Ftl00Cx7ZXp0F6UN1L24C/jRWFhhrnn3i3i2tNDYcsQLJZJwPN21O63h9QvYFtbWYb2c9I xE7L7d9hXKGD5N+bKmffOXBA8nZRApTYN7G11gpR/jeisKBEzxgC9GgKuNie6ifq9iIELDKxKw AuQWACGsF8O124A2WOlPflT5Dh8XuQPLMWjmNeLHhmgAH/In8kBY65eymN9CVMja2S5POh08BU H16beMzcRvOK6VXLK+ux0IF09s+jq2HbT7MtZg6IDRPu+mvbxwD3HOnu/3VhknOlkPwSit7EGp a5mZp4escayxRCrveZnM2wIA Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:13 -0700 IronPort-SDR: 6CLLGNogmHoAL7lQIK0JrqY1VTi154qviNec+jXeqn8czq0qwNEqI8S5jdZGO0wzbN0TGYHD4I LRlu+YIdC7I5Stuj1GJxbjv0kovjuCWiqg0xG5XOcmOVldED+udXyTz9ChoAk0dTclh/ALHxgq VNzScIj3MX2pUds8AECkiC6Wj94HBxb13vcRrXA3OH8qrcWs+gb3fqbncOD0yluqFquchayq+P SliZXFP5zUn0NN7UdEll2hjS3ox9MD4mJ/vVBoOSL7ofPszT9tr0NZ3SVElyzLimLUpqmKG13/ jwU= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:35 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 06/11] dm: move zone related code to dm-zone.c Date: Thu, 20 May 2021 13:22:23 +0900 Message-Id: <20210520042228.974083-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 a9211575bfed..45d2dc2ee844 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 Thu May 20 04:22:24 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: 12269015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43CC8C43460 for ; Thu, 20 May 2021 04:22:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25192611AE for ; Thu, 20 May 2021 04:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbhETEX7 (ORCPT ); Thu, 20 May 2021 00:23:59 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbhETEX6 (ORCPT ); Thu, 20 May 2021 00:23:58 -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=1621484557; x=1653020557; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=ig1LCLNVNN/TAqyjRgCT7Z4n/o7x3VRmirTRPRre1Dw=; b=YDGWb+2GDOSBqX6DJ7aXXZoQnHIvOLi1KGDnqbrt44lbBVdPxEX8ZabA R9iuFIXU+vYWTejyBM31+XIWTdSQWR0Cpw8fECtYXcstt2+H4AunpmQE9 3A3ZKHVEv0fxLXKuQAdvI1bHvrg2plEWQeEhspiaigDyjz92XxvQNFnWQ waWjaY8dJp70D7hJB1u7ptCYsI+mBk4vt+bOkubK9XVWvMbc3PjWsa18p LhEqfBuoIJuSen0Pf6nHWdpWTm9skr5B+vh474zjDlh5SUwQkCdxHDrEu 4Y+f+Qub+KYM++Z9LS17V7lHeD8oxUCKdMq+9s1kYXgpnlqsATMl3WF1a g==; IronPort-SDR: H74MrWBf5jssPjDu0t3v+HLQTQcUG5WDA3LMH2tfnLIcZdgucc4eKegDpA7VocItdvqqweIhmk 3howi17I9DY557ZZx4DbPF45lpoIKF9yzJI05gQ3ak6wUM2Z14cRkpCGK0s0sNPg1eNKINlWxA +e81rCeEjEBaYWehI8KkJ3FQzBmp0cEF8BP7dGdcTQ/FJxtNOUCBXz20/bE1I6KUdu2G9C2LxP ntqWkoPPsZGF1Q/m6vQE3cL5oUphIrH9vncJsFmE23B3Bh95bDPW6HGDNA5e9v4Vks/jfbr/bP uYQ= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105845" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:37 +0800 IronPort-SDR: Q2euIYXnS2h9QpXspzlz9zaLgHhj6RWe6d5weExG3pDBrggqKP9ENRX25evZvUZ4ZHPeKRxjxF uulkCQwH09aNuPDZifG9qUfHZAqwaeRGVZ/1dr200gr/dCpH+icmMDuave2H+suHJrv2+fo0W0 Qka774JTjcFItDJsaYOnjgkwXUUAzRXc1IKJs6XO+DKRITOSoAcXGrx5MEBxsbL3z9V4fSvPgr IjtEkb/eDxLCmmSGB9/ZXLUPdcRYNl2ojmEsrqdEikv85zTwqaFQMT5+/3mu9uqHj4EZ4fDPtt vowhyaaWJH/FAeoxD1usdObo Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:14 -0700 IronPort-SDR: cG7vf1BhVMia8mihm4DOpw3HfRP7lqYzKMtAthqTj2Y3m04ur5pUNCGoLDYh08R4sAaL0RgXF+ 8NH9za11LIb/k5FgFpwqRXNZQylKfvu0UZtZYT4Hr7fZPuTRdWNIyPBZyTk0K+WWB7Oe6Ppi7U cO0bpkWBTUHuyoUPrFZsN5Dr3Vl1m82lOlZFqim2/NPPCbDhab+793byUy3KggVFhL81tOXoUR 8wupFwd9HjtHPjuwTUDOF1ZZgrV6xxrvk/AqZt0hqOWyQ5EX8uNOKMcMPpzVoUlLRn7qCuITJI irk= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:37 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 07/11] dm: Introduce dm_report_zones() Date: Thu, 20 May 2021 13:22:24 +0900 Message-Id: <20210520042228.974083-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 Thu May 20 04:22:25 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: 12269017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F377C433B4 for ; Thu, 20 May 2021 04:22:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 749FC611BD for ; Thu, 20 May 2021 04:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbhETEYA (ORCPT ); Thu, 20 May 2021 00:24:00 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbhETEYA (ORCPT ); Thu, 20 May 2021 00:24:00 -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=1621484559; x=1653020559; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=aVa7W8T6lKCbKI/ygLHjB1phf2zK6Oo7yLjeZw7C+Rk=; b=Nw4nbl5o60COMijYae++rd9Hm8kD2WVua8ivf6HkYBfTHr4JYE34F1m/ f1SCZSphM6pButW1ohQF3GpKT1FeyZ+HdbKvAoKj6ngiST1oZqibxNEhx dLqCL6RL9sSN6ayjGfWsho804BAH0RnLqCYFmPYJ7lRLTbLZSAOoSFZrH hYV6os1cO4UtzTAE7HEky/2MIjKYwAATS5zUXiiiCKt757X0NVJtgVk1E KseDHyFZTxSEDFqG+lo4qqCrkQB+1oA/AP0lwg++GFRrisUjxhxmuuK1h +YVfY/orcf9KDe8E+Csl0YI+IpNmWQmC2EtdEsw/oAsoLHpIoYToGGch+ g==; IronPort-SDR: bUMu9tfoRhJXkcILhI2knKGNawdXsHr8Wp4K/4pjS98aOtkPcoCgYblokspieBGmn0AGFETNtX KayLK7bLfX0qD2PNmJlIQYMw+bWxHHo6VemSguYa6xHdZbIRoC0XAAu4FbsZfaQxLtOn+PPUJs I5DcwYRcV8PI1dEohBegLqlpJMcTKbgSmTn63v236fwG6m+Y4D2GBpRoAOJHVUQ61zjbmv4LKO v2R8aBdcFHmg8M8l/ivxCTj2cWbDwPdbfmZyyq4WRmZYqSVsnZ9Te7VYMTu8u/2NrtUkGjph6P 0Pk= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105847" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:39 +0800 IronPort-SDR: NjQ6DjpQ3TnELLmMtFw9ejdS5K7A79bElUDnos2hV+MLAcCxmwUoH87e/DgGr9vnv6A0k+d1KP Mm5l49ieJv110po2W8ZTpuV1cH8dChHL6q8XC3Rd/WGgb5mk7kdVno3w5CUKbBzgt7I+1sapm8 v4Wrn7srIrDjNfVQJbs3za/rXyHxGOTESQ9YF6Ihzve8gJG0mEvJGmORIjTSOBWMf93iGVLHSi U8nXRJytGi61hYAFJpcTZOegYjhtEmtURJGrDM0gx1MqZxnyggv2+MDi/H1Of7HaVmxHPjsCX5 /PgBm7Y1EIpQvadqIoA1ClzQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:16 -0700 IronPort-SDR: EcgtPPVTygsH3V0v7Emrr9J3ApOBd7B84hDHEv92sZCdLVTsv+90suF9sH+EOn0ruhHH8kTlEN 3DdwhRX+SkDcCahzp8aDfF4vbw5nelKPKqCDMzIINkI/ZKlfivVKKiO9C2Fvo8rGegzJQsncxY nVKVD/e48L+SDn7ekC87wmd5UoUVuPMxWjJ3GINP8VP0XAH92k8ACmzRhcXK3rk5APNHc0X5qz PGXpAdN/t8I25lljyPakU5sBTB//QBzPR5yrFltPk58ElfnasAHYS2kZH6ktHNjK+99gCHsJvE +gg= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:38 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 08/11] dm: Forbid requeue of writes to zones Date: Thu, 20 May 2021 13:22:25 +0900 Message-Id: <20210520042228.974083-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 45d2dc2ee844..4426019a89cc 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 Thu May 20 04:22:26 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: 12269019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD7CCC43460 for ; Thu, 20 May 2021 04:22:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B56BA611BD for ; Thu, 20 May 2021 04:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbhETEYB (ORCPT ); Thu, 20 May 2021 00:24:01 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbhETEYB (ORCPT ); Thu, 20 May 2021 00:24:01 -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=1621484560; x=1653020560; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=GrYIYra7P0QhMjflEcQS+evpfDJJISFMIs/aUgAFK6g=; b=EfQLHk6dZ554z8ZnGuA/tahSW5NlqFuxayOCS6hrXjE6q7QSh+ifSkuK bO2GcNH95nExRgStfNzKSSQMxlFjMxuBzjLlIpa9HHGNDq7iy9YrwEDYw PekykVa7jtJze1RaSOLnvUAgTR8am3xGklXsPYj2zLgOaWyoe3rwMAEs/ JbsNUvR1PFJrvRHsfi2pHukeKXT+YoqYBD+oRm8Lg3WPJzRK3wcp/IxeQ r0npvP47JbN6PiKC5U1qiRVjmxC7l0C5MGaufo9/3UNipDGakj4aNY7BY J21optfUGrdtrOzFhTA+DUcxV5WQGqjCuugs9l7wk31X70lFdDl8Klzjy g==; IronPort-SDR: cN82n55wIXcx92gqfMkIodSmuNB3rNbCUbwMYQil5S+XsrNVlWvrXySgAVyhXS3e46L6w7UKUm IsIlevQ+60UCQ6gmX1pUVedeO06MEsvhHIxHHtmilf9rGUG0Nso8DqGHV1lG9S1GksX+Q8/3xm DLVRUa09dcIrjdkWrGvz5YppwSIWxsH2J7Tfiw5utAmClUBitmxgsmIkP1X8ivzs182USEfpuT tYcESiR0aA7PWDeJtCUYCAqcxMos/9vi0vnhq6YMRPcqTb6Q53/5f9U73YGokoNj1L8i/tkV/6 y00= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105850" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:40 +0800 IronPort-SDR: mHrr8xaFdMCtO+pYEkhSPT2ambrvUvVkjGmSKmeNuRrL0YjiaAQoDhFt//def8C97iQh49Zxsa WJ+5iG6bTPp+noDGBfniFlNZu4Tkb3U8XtX3AA873Om4Rv3j8LbJRW5T0pSrJfLvJp4hQKhoYK mFlxGM2yfpALZEZAyOq2j6MNDPsl2alsk8vcVXfp6drRaUoT0zk2LfLSTaSu8jRPpLXQCywoqL rQ+EFOuv/G+ZLBIK2vzK0k4tg7OtzgLgLmDVuiz8nm2ZXlFeYZCqKY6J3Nvh8AH2abhjA+7fGo umscq0GTB4nQ2aJPrPMaz8eS Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:17 -0700 IronPort-SDR: 01laeq7wLl69mRIp9Ql4E+WXkE0luF55BS29xYCRDwOPtYpk2I0zTlnEM3q1KecQu3hRFOza0P F1UUM5bzdFbz3k1JMkO/e8wyoJeY+ypsE5lKDVK0kENmft4ewQwxJ02Wt2hV2Xxc54FuI53KLE zvSoKkpkkAA1y/yn/xEikd5aa0z8KmycfagIIIrj47YIL3YnHoUYBTw7J7yYGLdrO5P7EsS4qq OHnfXGoX1PKxPsVgzQZ797f+oS+PSCH7yh8PQuCGugj1Q6bkAJPEV+UIFe9Qj4+tEGBNZGofbU DZc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:39 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 09/11] dm: rearrange core declarations Date: Thu, 20 May 2021 13:22:26 +0900 Message-Id: <20210520042228.974083-10-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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 4426019a89cc..563504163b74 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); } /* @@ -1247,7 +1202,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))) { @@ -1273,7 +1228,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))) { @@ -1281,7 +1236,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); @@ -1570,7 +1525,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; @@ -1611,7 +1566,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 Thu May 20 04:22:27 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: 12269023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E54FCC433ED for ; Thu, 20 May 2021 04:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDF54611AE for ; Thu, 20 May 2021 04:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbhETEYC (ORCPT ); Thu, 20 May 2021 00:24:02 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbhETEYC (ORCPT ); Thu, 20 May 2021 00:24:02 -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=1621484561; x=1653020561; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=N2JJBDhvIPEgpYcsw82DN3r126qN2TP30GgYYtJnxB4=; b=VKXjnHpnOjsqJIR8NF6+NR5NGHg6s1JZr6syC86Og3xUKvgjDv85rZj8 QqmvhHRgXJhbVVIT0LwA1C2evOkHgB6qNUavKTeTjIz2wdkWlB/0hsIkO ilngxrSNX4RXLzob83p/xFVmIwh/LsMLSRVxe9uW3xDrz8qXyDGaxOm5O gNyLh8TjIwAwFicFdC/EWQobZoC8C49Qy4Ilh/ChgSJDp6gzH2na/fG9q Jqs+VYAgu7gTa/vulPyqyvep0JCb+x0Dkev+6vwQLblMgUjokSU8+6KHP XTQyswApaUVqDck0yZeYauQTqt/hMiaV6NAhFYJKzcHk8w7Xrd7VURYNK w==; IronPort-SDR: yn9KIJxxprXzdQqb47IuynFuXgOi5yfSOKiVnEWa5dcgzi2yAphZ8zOsH7N242vNqkmnifHTG3 1BC53agWeQsnSPLKRNJfpfbrSAiirbwD7I01Go6zoguXeIbs6sWVzhuaaIU5NFN/DPgsF16Otw ZrfRkp5G2Z5brIggcleKOPox3S6GHu247+uPwlsWviZ4zxtVa9MhtDXGOC05Zh2D99iqrhzQJT vJ55bRMI+nv2JTly6FsCoxJK5Ff8JhzpayJSpZyGkVXeawDy8LnOHxh5iovaPFHgG+nVk9gfS3 vR8= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105852" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:41 +0800 IronPort-SDR: qfyqN74uno5zQCagLK0VqJsIil9VRwvQm6b8cTF5hqcFhTSNj8+pGhcVPe9XjbVHp6QqqzO9xI KQfPHvizE6d2Yts6s5CqGPLXoh+2KGbwHlb5wAUzguRDnl/jfC6j+QHgFr4g2RYcEK//sX/JAL z6tfWFZKjLvMjO6U/VfUQ3GhpHQxJbcea9FxEXRWI1WfBSDmRyXgANrtEl5qaCw9KUh4go5wT2 V0L9gE+HeZBCzUrFLu1Jsp4sSK0JP7P8gC803ZZ1eAY5W39wbV+UDvJNBnIIIgY29te4laquez IrbzX18Qz59jcSyb+AxuFpfx Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:18 -0700 IronPort-SDR: P79YIIAwdI67681uEHc93vmQZas1vpA6PTGthRUzcqF+6VRwf8+qi4xveHPDDorM9kGLIGnFIi 7l8zj50jZ7WveZmKWBiQt87c9H3v86w3F9EnWLnrF7PGZh7i09R7iZf0LvXPeXDEv+N7g4yxQj D/2E8tQumlE9GaH//LXVpOncMcpWBcRP1leJIlzU/4jdl2HrRZPqLp54D4nM//yRsIHjToMHA2 6pdp7+UMRgOb976DJTYIJJKoupufrOxCI8Q0cwsyxaeyfcXkpqwDBExAx5LV0/X+R6yTgxNbl6 ZcE= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:40 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 10/11] dm: introduce zone append emulation Date: Thu, 20 May 2021 13:22:27 +0900 Message-Id: <20210520042228.974083-11-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- drivers/md/dm-core.h | 14 + drivers/md/dm-table.c | 19 +- drivers/md/dm-zone.c | 615 ++++++++++++++++++++++++++++++++-- drivers/md/dm.c | 39 ++- drivers/md/dm.h | 18 +- include/linux/device-mapper.h | 6 + 6 files changed, 657 insertions(+), 54 deletions(-) diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h index cfabc1c91f9f..2dbb0c7ff720 100644 --- a/drivers/md/dm-core.h +++ b/drivers/md/dm-core.h @@ -114,6 +114,12 @@ struct mapped_device { bool init_tio_pdu:1; struct srcu_struct io_barrier; + +#ifdef CONFIG_BLK_DEV_ZONED + unsigned int nr_zones; + spinlock_t zwp_offset_lock; + unsigned int *zwp_offset; +#endif }; /* @@ -128,6 +134,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 +150,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..c298bab28390 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -4,55 +4,73 @@ */ #include +#include +#include +#include #include "dm-core.h" +#define DM_MSG_PREFIX "zone" + +#define DM_ZONE_INVALID_WP_OFST UINT_MAX +#define DM_ZONE_UPDATING_WP_OFST (DM_ZONE_INVALID_WP_OFST - 1) + /* - * 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 +139,551 @@ 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_init_zoned_dev(struct mapped_device *md) { - if (!blk_queue_is_zoned(q)) - return; + spin_lock_init(&md->zwp_offset_lock); +} + +void dm_cleanup_zoned_dev(struct mapped_device *md) +{ + 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 zone_sectors = blk_queue_zone_sectors(md->queue); + unsigned int zno = bio_zone_no(orig_bio); + unsigned long flags; + bool good_io = false; + + spin_lock_irqsave(&md->zwp_offset_lock, flags); + + /* + * 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 (md->zwp_offset[zno] == DM_ZONE_INVALID_WP_OFST) { + unsigned int wp_offset; + int ret; + + md->zwp_offset[zno] = DM_ZONE_UPDATING_WP_OFST; + + spin_unlock_irqrestore(&md->zwp_offset_lock, flags); + ret = dm_update_zone_wp_offset(md, zno, &wp_offset); + spin_lock_irqsave(&md->zwp_offset_lock, flags); + + if (ret) { + md->zwp_offset[zno] = DM_ZONE_INVALID_WP_OFST; + goto out; + } + md->zwp_offset[zno] = wp_offset; + } else if (md->zwp_offset[zno] == DM_ZONE_UPDATING_WP_OFST) { + DMWARN_LIMIT("Invalid DM_ZONE_UPDATING_WP_OFST state"); + goto out; + } + + switch (bio_op(orig_bio)) { + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + break; + case REQ_OP_ZONE_RESET: + case REQ_OP_ZONE_FINISH: + goto good; + 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 + md->zwp_offset[zno]; + break; + default: + DMWARN_LIMIT("Invalid BIO operation"); + goto out; + } + + /* Cannot write to a full zone */ + if (md->zwp_offset[zno] >= zone_sectors) + goto out; + + /* Writes must be aligned to the zone write pointer */ + if ((clone->bi_iter.bi_sector & (zone_sectors - 1)) != md->zwp_offset[zno]) + goto out; + +good: + good_io = true; + +out: + spin_unlock_irqrestore(&md->zwp_offset_lock, flags); + + return good_io; +} + +/* + * 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); + blk_status_t sts = BLK_STS_OK; + unsigned long flags; + + spin_lock_irqsave(&md->zwp_offset_lock, flags); + + /* Update the zone wp offset */ + switch (bio_op(orig_bio)) { + case REQ_OP_ZONE_RESET: + md->zwp_offset[zno] = 0; + break; + case REQ_OP_ZONE_FINISH: + md->zwp_offset[zno] = blk_queue_zone_sectors(md->queue); + break; + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + md->zwp_offset[zno] += nr_sectors; + break; + 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"); + sts = BLK_STS_IOERR; + break; + } + md->zwp_offset[zno] += nr_sectors; + break; + default: + DMWARN_LIMIT("Invalid BIO operation"); + sts = BLK_STS_IOERR; + break; + } + + spin_unlock_irqrestore(&md->zwp_offset_lock, flags); + + return sts; +} + +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 long flags; + 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); + + spin_lock_irqsave(&md->zwp_offset_lock, flags); + 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. + */ + if (md->zwp_offset[zno] != DM_ZONE_UPDATING_WP_OFST) + 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. + */ + if (WARN_ON_ONCE(md->zwp_offset[zno] < bio_sectors(orig_bio))) + md->zwp_offset[zno] = DM_ZONE_INVALID_WP_OFST; + else + orig_bio->bi_iter.bi_sector += + md->zwp_offset[zno] - bio_sectors(orig_bio); + } + spin_unlock_irqrestore(&md->zwp_offset_lock, flags); + + dm_zone_unlock(q, zno, clone); } diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 563504163b74..5038bf522b0d 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); @@ -1213,7 +1203,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; @@ -1757,6 +1756,7 @@ static struct mapped_device *alloc_dev(int minor) INIT_LIST_HEAD(&md->uevent_list); INIT_LIST_HEAD(&md->table_devices); spin_lock_init(&md->uevent_lock); + dm_init_zoned_dev(md); /* * default to bio-based until DM table is loaded and md->type @@ -1956,11 +1956,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); @@ -2079,7 +2084,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; @@ -2188,6 +2196,7 @@ static void __dm_destroy(struct mapped_device *md, bool wait) dm_device_name(md), atomic_read(&md->holders)); dm_sysfs_exit(md); + dm_cleanup_zoned_dev(md); dm_table_destroy(__unbind(md)); free_dev(md); } diff --git a/drivers/md/dm.h b/drivers/md/dm.h index 39c243258e24..65f20d8cc415 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,27 @@ 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_init_zoned_dev(struct mapped_device *md); +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_init_zoned_dev(struct mapped_device *md) {} +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 Thu May 20 04:22:28 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: 12269021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE48EC433B4 for ; Thu, 20 May 2021 04:22:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FAD4611BD for ; Thu, 20 May 2021 04:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbhETEYD (ORCPT ); Thu, 20 May 2021 00:24:03 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:63405 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbhETEYD (ORCPT ); Thu, 20 May 2021 00:24:03 -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=1621484562; x=1653020562; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=BAURSxmhtP/eUdL/GC1yQw7Mcrh5EWOqnnX0mGjtPdQ=; b=d2Tt1COOzOJE4LeyPk/Ce8Ax2NnAde2uayahVHF05e2v5ULEceP2Xmrw zaL6ft+hfezlK0U1V9ES+WlBdEk0UbUEUb+lftchK1K2vVP9DTAh+g+el bF2UtAV2mJeZnqIBawH2sT+H1q2vtD/sw1XrNXGLofF8QU5o+yKJKzWlD eKqQXOEpwtJJ9OkhIiaMSpUk78+6++shb0Jrazo6qdj/uTPZCtF2Ktm61 qmkt48WUNbXRHpFKtLSx7pc1r3UYY28sAXnRVBY2rLnv8nrcvUQBPQpo8 RaI/o17nSmUFlG28mksnMC8yAedNlsQfpA4Vc2bSg70vSV9p0iaP2mCZi Q==; IronPort-SDR: slJhnKjnbND22Rd7rtMUZzkqRMH711+hF6y837ZphoaaODYnCTfdC4ydgYVDEwKbnR9M0FqhTV 5W7XcYS83DNh8Jos68xVXJF4SvYZf9Bqy+q7liPpgQ3yA0OJMTBvGZ3V6LWsJUbmSmr4jfCbLk UrLbrlpmK1PzKW+DPvf77GzSw11rlbHkKmovvZZL7m2Q5NU2zrvrZoI8blqCbfP5xthjBqHpSY /4dEa/pS3CN/qRSVTAjWlxFqpdIqVDLLBnpxMHSWBaA+6KN4U1yx72xW28gLSCJOMFrOFkTUww lAI= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="168105853" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 May 2021 12:22:42 +0800 IronPort-SDR: Jaw5uw8ORAYd3tY9zXOzguLmc8G1J0kyi3h58ajGvzirG6gZejT8AtrUyaqXvbwYfZhacI4E2m l2SBZBsqRRczlpDNhyMtq0rlsH8WZ/P54aDxe46J+0D+PRZ1IZFf6abiFw8h1N3BUIdmY/gXt/ bUHObUP6W0sRwWNHtHGrSQPV+wnahn7tUYn2mOifbHPFJGr5A4D198V/KLjpWwasZv47muVYIT NV0t0KwdQAcjxqSrcj1HFG4uYP8fh660Evp3RkHMP8kU/l6/jWorSt8qGSK4HqyEbjcjudfr+n BNMTpflvv7Ua5mNklsQR0hEI Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 21:02:19 -0700 IronPort-SDR: uIEnt6j+SWWkCs8OnuX2F4ckxYIIbMDwF+h1O/e2ATFkGGhNDagi5H+9hnLbov9gRoM/vexk4M 1VLze6v9TC2z5KsIFLIRgeJEgJZ4nthJn/T+LkLFh3Gp63losI3oC6aR4X0+uLK8bneewub9Mk O1c/VFTLphVK1QZbQRk+oUVFkJ7AHjoI5ORxCgkr7rN9mMU4rKxL70XJJKysuahRRby9XP1tM0 Zj195sPrd9sYOwQ9p0Tn+fE6mpKDv7ygvIeptLnzXej/Hyyuk6qarV/r+xh1BLlDZweWrNZ+0o fkY= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 19 May 2021 21:22:41 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH v2 11/11] dm crypt: Fix zoned block device support Date: Thu, 20 May 2021 13:22:28 +0900 Message-Id: <20210520042228.974083-12-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520042228.974083-1-damien.lemoal@wdc.com> References: <20210520042228.974083-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 --- 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) {