From patchwork Wed May 1 00:09:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650111 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5DF323A9; Wed, 1 May 2024 00:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522178; cv=none; b=Osbc4mNkFYmAANu1YPyKlfh4yatBmuPMqATn638iRjRwlmYJSiwBqcL45NSEsEFDHvkagQC0JAFLe00Ts+ZbRZpxmdkuLDCDq+X6lRQUnMj9kIy/0pd2gwlwx6XovNbWdrcFibXRVlVAG/lKjEBc0HGzjkmInQ8lJo83qAaGUvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522178; c=relaxed/simple; bh=ChfFb/6we4dypVrsro7WzU7smRAFTQaHLrdAlWc0GnU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tcDBDdHoU6etVJq96YmqMkMcz0xAemVc+LnMvc0CBmRRF51mLTs+Z9gSyFIHWX4cr0O87lzn1pfzMU2npVPLJFoyOV21CEYsblvrlLWsDYj7F2Lh+8yHH3Buc1fKSnKOOdCM5tAP7hDk8YKHUO0Y7zKCwdFDF4L4dTGgCqbdu+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kr3Wv5AG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kr3Wv5AG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97E47C4AF19; Wed, 1 May 2024 00:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522178; bh=ChfFb/6we4dypVrsro7WzU7smRAFTQaHLrdAlWc0GnU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Kr3Wv5AGRHWWmpOXdsAkqZJ/sNchKnSu4UxPUGmD+UtrE026OYNIqp2NMymlNHqs9 ZOYXNeNQOc/q6egNnNqnFp5MzgOCmVSfE9KMPgAPEuneny0FbRVewZBIRZDJ3Vhp9l PRPJHSIhc0Ete0zrhztw9612RIqFrCVbk0LPlZ2FlxhZsYvoO+4qzRK0JE9CGNIj65 mcEItNqwl23clFCXbfB4J6nRkJll5SwERuknsPfOrSRUSZ+7q/CH4c5Iu5V/fdp0O7 gm5yJIFMt6698lnqtaNZ1OB+p9pFrmELT9NHw9g7fF5pgr2qlGiYDLSng4JiKJggjE inxGXPjNJ3AsQ== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 01/14] dm: Check that a zoned table leads to a valid mapped device Date: Wed, 1 May 2024 09:09:22 +0900 Message-ID: <20240501000935.100534-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using targets such as dm-linear, a mapped device can be created to contain only conventional zones. Such device should not be treated as zoned as it does not contain any mandatory sequential write required zone. Since such device can be randomly written, we can modify dm_set_zones_restrictions() to set the mapped device zoned queue limit to false to expose it as a regular block device. The function dm_check_zoned() does this after counting the number of conventional zones of the mapped device and comparing it to the total number of zones reported. The special dm_check_zoned_cb() report zones callback function is used to count conventional zones. Signed-off-by: Damien Le Moal Reviewed-by: Benjamin Marzinski --- drivers/md/dm-table.c | 3 ++- drivers/md/dm-zone.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 41f1d731ae5a..2c6fbd87363f 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -2042,7 +2042,8 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, r = dm_set_zones_restrictions(t, q); if (r) return r; - if (!static_key_enabled(&zoned_enabled.key)) + if (blk_queue_is_zoned(q) && + !static_key_enabled(&zoned_enabled.key)) static_branch_enable(&zoned_enabled); } diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index d17ae4486a6a..3071f67d72aa 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -145,6 +145,48 @@ bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) } } +/* + * Count conventional zones of a mapped zoned device. If the device + * only has conventional zones, do not expose it as zoned. + */ +static int dm_check_zoned_cb(struct blk_zone *zone, unsigned int idx, + void *data) +{ + unsigned int *nr_conv_zones = data; + + if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) + (*nr_conv_zones)++; + + return 0; +} + +static int dm_check_zoned(struct mapped_device *md, struct dm_table *t) +{ + struct gendisk *disk = md->disk; + unsigned int nr_conv_zones = 0; + int ret; + + /* Revalidate only if something changed. */ + md->zone_revalidate_map = t; + ret = dm_blk_report_zones(disk, 0, UINT_MAX, + dm_check_zoned_cb, &nr_conv_zones); + md->zone_revalidate_map = NULL; + if (ret < 0) { + DMERR("Check zoned failed %d", ret); + return ret; + } + + if (nr_conv_zones >= ret) { + disk->queue->limits.max_open_zones = 0; + disk->queue->limits.max_active_zones = 0; + disk->queue->limits.zoned = false; + clear_bit(DMF_EMULATE_ZONE_APPEND, &md->flags); + disk->nr_zones = 0; + } + + 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 @@ -208,6 +250,7 @@ static bool dm_table_supports_zone_append(struct dm_table *t) int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) { struct mapped_device *md = t->md; + int ret; /* * Check if zone append is natively supported, and if not, set the @@ -224,6 +267,16 @@ int dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) if (!get_capacity(md->disk)) return 0; + /* + * Check that the mapped device will indeed be zoned, that is, that it + * has sequential write required zones. + */ + ret = dm_check_zoned(md, t); + if (ret) + return ret; + if (!blk_queue_is_zoned(q)) + return 0; + if (!md->disk->nr_zones) { DMINFO("%s using %s zone append", md->disk->disk_name, From patchwork Wed May 1 00:09:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650112 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3C8633F9; Wed, 1 May 2024 00:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522180; cv=none; b=X/xiFv3lQh+ShCliQvd822FKVfGnfNCzeyVSth6Csvd8HTTr5YAT23ZUG4yohXLg3rqquLI0KAgSNMJt7H8knAt3mEumByKwUWoluvPQxCx/rCtbBiNGUt5ybfZPf6GlcUDnxXk7x1M+57s+ZV4+PbJ0YYNaZLP33M0tnC7eB2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522180; c=relaxed/simple; bh=fFeesJRkVknw7/RMtxm8FMNxBrpXsSCO1ccVPKN7cd0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cDZZ7MuRMEpJ54NFSwXCauXU3Tk/MkP/q7Gj5UZm3IOtjphalAKnw5re2s3PpLk2yMyhrmrNpCoAhY8K3gL1VGdTAvR905w6buv2f//DxYaSTHr8D6R0K9m2Pmd5vY9IN8ZJznL43B05bwLjJNzwBUSnZUU9W8tm51SXobIsu74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M9Jy2BKS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M9Jy2BKS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACFDFC2BBFC; Wed, 1 May 2024 00:09:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522179; bh=fFeesJRkVknw7/RMtxm8FMNxBrpXsSCO1ccVPKN7cd0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=M9Jy2BKS1ydoEQYDyTT4+GfMFXaHLAzAZ5n/t1FOQFFoZ79xi03fg2bKXh2Au9/b7 r/s6H0kTWFkXB/CjHAWLODWpEZLIq8RORbKAGEjnHlrSEgKnxMHvBHEfZYNRuL/vq6 srX59bZwXe9H7rpx4zy3vel1BzcutPYXASrvL3TiErJYhjEexyDSAT4BueN+YqdCiY Aifvryy99rWYyYiN7M06IRDjP/HM23yRDGOtj0qiUEiNLgIvbPJZFlA4mZeOgZodq+ HSTOrLXuYZGwHx1xWw3QW7AHjh5VWITeHOwae7c+WMHraEx/p2rSec7ar8jD8o9rPE yT1PosPvkYPQA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 02/14] block: Exclude conventional zones when faking max open limit Date: Wed, 1 May 2024 09:09:23 +0900 Message-ID: <20240501000935.100534-3-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For a device that has no limits for the maximum number of open and active zones, we default to using the number of zones, limited to BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE (128), for the maximum number of open zones indicated to the user. However, for a device that has conventional zones and less zones than BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, we should not account conventional zones and set the limit to the number of sequential write required zones. Furthermore, for cases where the limit is equal to the number of sequential write required zones, we can advertize a limit of 0 to indicate "no limits". Fix this by moving the zone write plug mempool resizing from disk_revalidate_zone_resources() to disk_update_zone_resources() where we can safely compute the number of conventional zones and update the limits. Fixes: 843283e96e5a ("block: Fake max open zones limit when there is no limit") Reported-by: Shin'ichiro Kawasaki Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index bad68277c0b2..6cf3e319513c 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1513,10 +1513,6 @@ static int disk_revalidate_zone_resources(struct gendisk *disk, if (!disk->zone_wplugs_hash) return disk_alloc_zone_resources(disk, pool_size); - /* Resize the zone write plug memory pool if needed. */ - if (disk->zone_wplugs_pool->min_nr != pool_size) - return mempool_resize(disk->zone_wplugs_pool, pool_size); - return 0; } @@ -1536,27 +1532,51 @@ static int disk_update_zone_resources(struct gendisk *disk, struct blk_revalidate_zone_args *args) { struct request_queue *q = disk->queue; + unsigned int nr_seq_zones, nr_conv_zones = 0; + unsigned int pool_size; struct queue_limits lim; disk->nr_zones = args->nr_zones; disk->zone_capacity = args->zone_capacity; swap(disk->conv_zones_bitmap, args->conv_zones_bitmap); + if (disk->conv_zones_bitmap) + nr_conv_zones = bitmap_weight(disk->conv_zones_bitmap, + disk->nr_zones); + if (nr_conv_zones >= disk->nr_zones) { + pr_warn("%s: Invalid number of conventional zones %u / %u\n", + disk->disk_name, nr_conv_zones, disk->nr_zones); + return -ENODEV; + } + + if (!disk->zone_wplugs_pool) + return 0; /* - * If the device has no limit on the maximum number of open and active + * If the device has no limits on the maximum number of open and active * zones, set its max open zone limit to the mempool size to indicate * to the user that there is a potential performance impact due to * dynamic zone write plug allocation when simultaneously writing to * more zones than the size of the mempool. */ - if (disk->zone_wplugs_pool) { - lim = queue_limits_start_update(q); - if (!lim.max_open_zones && !lim.max_active_zones) - lim.max_open_zones = disk->zone_wplugs_pool->min_nr; - return queue_limits_commit_update(q, &lim); + lim = queue_limits_start_update(q); + + nr_seq_zones = disk->nr_zones - nr_conv_zones; + pool_size = max(lim.max_open_zones, lim.max_active_zones); + if (!pool_size) + pool_size = min(BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, nr_seq_zones); + + /* Resize the zone write plug memory pool if needed. */ + if (disk->zone_wplugs_pool->min_nr != pool_size) + mempool_resize(disk->zone_wplugs_pool, pool_size); + + if (!lim.max_open_zones && !lim.max_active_zones) { + if (pool_size < nr_seq_zones) + lim.max_open_zones = pool_size; + else + lim.max_open_zones = 0; } - return 0; + return queue_limits_commit_update(q, &lim); } /* From patchwork Wed May 1 00:09:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650113 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F014546BA; Wed, 1 May 2024 00:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522181; cv=none; b=dvODVkD5U9ADGNrsAVXUiKSXbSAbjyJ8472NE28Q2a+BFb+8txnlH8CDzTqonSj/OpE9AQ6QpITzcKnz3S/TPQRTp+StpmhlNUnDH+1Jqc56p20q4mqYBCbeDcqiOnybTyba1irnaopy+4qxVaeX8O1H9stqR9JyGdKo1XGPkZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522181; c=relaxed/simple; bh=hKhf3tu/OWCDWFwaZGcp2SnI5XVx3uBpkPAcElWwqTg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KbL+DPE1Rf0e4NmxsJtWY48+l2xhSw53XYR/Mg0NT2SiLrphfQHIw8HIkbFI3a2F3wl4P7xHAHpV5kmgm3RRdEKNG5p/uq1nOm+lDLqXWKNiUMlGQUf7lXnyG0e6Zlq5yPjmciFv5Z/WkbJGGYQgLWwkJLTS7Fcr2XvlqgJFwjk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZE+GuJTo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZE+GuJTo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1EB0C4AF1C; Wed, 1 May 2024 00:09:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522180; bh=hKhf3tu/OWCDWFwaZGcp2SnI5XVx3uBpkPAcElWwqTg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZE+GuJToJwF5V2wonCwgYj7EbitfKeizcG14BYyTTM9Vnf5uYcWVcNAxaMJSQM9Ep ts3ubtpXsnJqyrM/pltEnB/4Kn9ABqXS6iOeqd/qx2WbnJ2BzRbV5JLpBuWlPtV6ZV yApFzTPZ5/U4weQRlGkERvOQhe4jc6aGcuzJ2dP5Ju7Mha5mehtObVPnI0knwLJDGW eQkJsbort48rjbJulLRQFAfVXMB83glwSPj/3FbZeP86sBh3GoUZUHOkAQBM+xssFz 7Ib7dGERDMP4GxgImbhmhAhWqyF75cs3QqP4ZLfc9SyhQheMfj7MDlAIgdVIOYkIol a+2LIv39xhD2w== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 03/14] block: Fix zone write plug initialization from blk_revalidate_zone_cb() Date: Wed, 1 May 2024 09:09:24 +0900 Message-ID: <20240501000935.100534-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When revalidating the zones of a zoned block device, blk_revalidate_zone_cb() must allocate a zone write plug for any sequential write required zone that is not empty nor full. However, the current code tests the latter case by comparing the zone write pointer offset to the zone size instead of the zone capacity. Furthermore, disk_get_and_lock_zone_wplug() is called with a sector argument equal to the zone start instead of the current zone write pointer position. This commit fixes both issues by calling disk_get_and_lock_zone_wplug() for a zone that is not empty and with a write pointer offset lower than the zone capacity and use the zone capacity sector as the sector argument for disk_get_and_lock_zone_wplug(). Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 6cf3e319513c..e92ae0729cf8 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1666,10 +1666,11 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, * empty nor full. So make sure we have a zone write plug for * such zone if the device has a zone write plug hash table. */ + if (!disk->zone_wplugs_hash) + break; wp_offset = blk_zone_wp_offset(zone); - if (disk->zone_wplugs_hash && - wp_offset && wp_offset < zone_sectors) { - zwplug = disk_get_and_lock_zone_wplug(disk, zone->start, + if (wp_offset && wp_offset < zone->capacity) { + zwplug = disk_get_and_lock_zone_wplug(disk, zone->wp, GFP_NOIO, &flags); if (!zwplug) return -ENOMEM; From patchwork Wed May 1 00:09:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650114 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2881B4C97; Wed, 1 May 2024 00:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522182; cv=none; b=KZGMFhS/Qujx0AN3aklAHLxb3Rg/VCNnKfiieXK3MhgZyzOC1PefcGjp05yFVyLzMVilvMeNkV54xfiK2mp21VFDec+G2Bf4lwri3wPJDnqZg70klc0vbQJaMh8ia3WGLOIUFhN4H30ID7MMifRifMWoSWLFytYsgSu5WYeL+PQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522182; c=relaxed/simple; bh=UYbDBB4mkhgIbm/O5DApC2B+iCtz2RxHZIN2xmykWVA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RtrGKN9B6hYBkEJWj7ELhUbrpNXOX/1LzPQhXZDQXkN44Bdk2dFcbKLHr5ID+Ac1m5RXoVGZ8Xg7QP3HBJD8NQ96SQskhD/Q81e3TGnvAkAgZTGhjL/XV98j/GHIZNmWfWwyJ2GwDZ0/HiGNQRUWG5200hSAu9ClSdGP44ZixVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hcNBcUEC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hcNBcUEC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6775C2BBFC; Wed, 1 May 2024 00:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522181; bh=UYbDBB4mkhgIbm/O5DApC2B+iCtz2RxHZIN2xmykWVA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hcNBcUECZNdajHr9utKxGMpz2Hj8ytwc0WsD2+GamcTTyYGRefBktAOVzfxHzfOI/ 8ABYfcSRMdmNI0V4eudVxnG8GR0x6/TA6WB6vvmrz2sNx3LR2L1illhb5CWnvHwuYo hpThRxQc3NWuldbNSf5L8ZGQUqizGG0mdjYeuBpWddXXTf7G1/s7tUvibNRpKm8S3J 9TtUr/DeGZtmEYC26Hg/1kCA2b/yQtQ0xpTnPISRlgTy9TtrmMPCqI80cV4kCgXPCs uzk+mPZ6+049x65Rn9NCTpWLBQ4IWP4/F8ViXhMRJuDoIXoiFHLU7hvJJaQ5g4ONr8 KQZXdtP1WF9Ew== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 04/14] block: Fix reference counting for zone write plugs in error state Date: Wed, 1 May 2024 09:09:25 +0900 Message-ID: <20240501000935.100534-5-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When zone is reset or finished, disk_zone_wplug_set_wp_offset() is called to update the zone write plug write pointer offset and to clear the zone error state (BLK_ZONE_WPLUG_ERROR flag) if it is set. However, this processing is missing dropping the reference to the zone write plug that was taken in disk_zone_wplug_set_error() when the error flag was first set. Furthermore, the error state handling must release the zone write plug lock to first execute a report zones command. When the report zone races with a reset or finish operation that clears the error, we can end up decrementing the zone write plug reference count twice: once in disk_zone_wplug_set_wp_offset() for the reset/finish operation and one more time in disk_zone_wplugs_work() once disk_zone_wplug_handle_error() completes. Fix this by introducing disk_zone_wplug_clear_error() as the symmetric function of disk_zone_wplug_set_error(). disk_zone_wplug_clear_error() decrements the zone write plug reference count obtained in disk_zone_wplug_set_error() only if the error handling has not started yet, that is, only if disk_zone_wplugs_work() has not yet taken the zone write plug off the error list. This ensure that either disk_zone_wplug_clear_error() or disk_zone_wplugs_work() drop the zone write plug reference count. Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 75 +++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index e92ae0729cf8..0f2ab448ab48 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -658,6 +658,54 @@ static void disk_zone_wplug_abort_unaligned(struct gendisk *disk, bio_list_merge(&zwplug->bio_list, &bl); } +static inline void disk_zone_wplug_set_error(struct gendisk *disk, + struct blk_zone_wplug *zwplug) +{ + unsigned long flags; + + if (zwplug->flags & BLK_ZONE_WPLUG_ERROR) + return; + + /* + * At this point, we already have a reference on the zone write plug. + * However, since we are going to add the plug to the disk zone write + * plugs work list, increase its reference count. This reference will + * be dropped in disk_zone_wplugs_work() once the error state is + * handled, or in disk_zone_wplug_clear_error() if the zone is reset or + * finished. + */ + zwplug->flags |= BLK_ZONE_WPLUG_ERROR; + atomic_inc(&zwplug->ref); + + spin_lock_irqsave(&disk->zone_wplugs_lock, flags); + list_add_tail(&zwplug->link, &disk->zone_wplugs_err_list); + spin_unlock_irqrestore(&disk->zone_wplugs_lock, flags); +} + +static inline void disk_zone_wplug_clear_error(struct gendisk *disk, + struct blk_zone_wplug *zwplug) +{ + unsigned long flags; + + if (!(zwplug->flags & BLK_ZONE_WPLUG_ERROR)) + return; + + /* + * We are racing with the error handling work which drops the reference + * on the zone write plug after handling the error state. So remove the + * plug from the error list and drop its reference count only if the + * error handling has not yet started, that is, if the zone write plug + * is still listed. + */ + spin_lock_irqsave(&disk->zone_wplugs_lock, flags); + if (!list_empty(&zwplug->link)) { + list_del_init(&zwplug->link); + zwplug->flags &= ~BLK_ZONE_WPLUG_ERROR; + disk_put_zone_wplug(zwplug); + } + spin_unlock_irqrestore(&disk->zone_wplugs_lock, flags); +} + /* * Set a zone write plug write pointer offset to either 0 (zone reset case) * or to the zone size (zone finish case). This aborts all plugged BIOs, which @@ -691,12 +739,7 @@ static void disk_zone_wplug_set_wp_offset(struct gendisk *disk, * in a good state. So clear the error flag and decrement the * error count if we were in error state. */ - if (zwplug->flags & BLK_ZONE_WPLUG_ERROR) { - zwplug->flags &= ~BLK_ZONE_WPLUG_ERROR; - spin_lock(&disk->zone_wplugs_lock); - list_del_init(&zwplug->link); - spin_unlock(&disk->zone_wplugs_lock); - } + disk_zone_wplug_clear_error(disk, zwplug); /* * The zone write plug now has no BIO plugged: remove it from the @@ -885,26 +928,6 @@ void blk_zone_write_plug_attempt_merge(struct request *req) spin_unlock_irqrestore(&zwplug->lock, flags); } -static inline void disk_zone_wplug_set_error(struct gendisk *disk, - struct blk_zone_wplug *zwplug) -{ - if (!(zwplug->flags & BLK_ZONE_WPLUG_ERROR)) { - unsigned long flags; - - /* - * Increase the plug reference count. The reference will be - * dropped in disk_zone_wplugs_work() once the error state - * is handled. - */ - zwplug->flags |= BLK_ZONE_WPLUG_ERROR; - atomic_inc(&zwplug->ref); - - spin_lock_irqsave(&disk->zone_wplugs_lock, flags); - list_add_tail(&zwplug->link, &disk->zone_wplugs_err_list); - spin_unlock_irqrestore(&disk->zone_wplugs_lock, flags); - } -} - /* * Check and prepare a BIO for submission by incrementing the write pointer * offset of its zone write plug and changing zone append operations into From patchwork Wed May 1 00:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650115 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C806F6FC6; Wed, 1 May 2024 00:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522182; cv=none; b=DcBULIsy6K9xkWNsJIZx68zm9g7FWbMm6qNpg4cdYslY0RnoJtT4uw/OkZNbyEDNSSyERjrnt9MLcUxm6FFkzaTnln2sr+MqfNZ5e0PLe4XRRaHjafZVgS0wQsf3BBVN/t0c2XXPaOeCZt+tREMr2/qozipwUgF4E+umCzljgv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522182; c=relaxed/simple; bh=5cwhLXMz8QrTZmJ2aIUIscsxFcBNRSCdVudZVldb9z4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WzNhjTkYP4qmPbn2N6gtxfB4lnqDoAkvVyCMMje3j95u/89Ec0GC1B2ZhpgtHUDQ34R/ZkPw7Wc9h3Jt3CJPblRZ1k3DXsRUWW/z+8SvmrnLUL+gbJTKAcOf6bmDOe8alSu9kFUOzrWTHx8lFtFYijLcb85z4DY3ysLKM3Y8u24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DuaXJIk7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DuaXJIk7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB019C4AF19; Wed, 1 May 2024 00:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522182; bh=5cwhLXMz8QrTZmJ2aIUIscsxFcBNRSCdVudZVldb9z4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DuaXJIk7hwz2EIdcXIWgHPmDx4UEd/zPGPLdyQ/G5q8nfvS0Q5FOtcZ7tfHG/eW6E 3/tPcwG+vUEII+i2oqDmEDMXb+kiJ9tckQBQs6DoicC5MR7dsRVBUcoNFRnkycSRBE /zdnyk1OBMV28EDh7dEsWm6EYtnXSr2MYti67mjILIEqmPanJ3VuMgTW4+AgvK3V3M 6x4SZpSDr5S+CY+aitcVFQj6Uy63rDjMQ/rBX7q6RoY94DtELbgi+XszyvVM6/z4vw 5rzuX8zKVSxWb/iYQcbmwEfpdufErQsYKRvYdxCLTitym184Y1pHkqxu0wl+iwNYc4 z6vGFbOQaFzIg== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 05/14] block: Hold a reference on zone write plugs to schedule submission Date: Wed, 1 May 2024 09:09:26 +0900 Message-ID: <20240501000935.100534-6-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since a zone write plug BIO work is a field of struct blk_zone_wplug, we must ensure that a zone write plug is never freed when its BIO submission work is queued or running. Do this by holding a reference on the zone write plug when the submission work is scheduled for execution with queue_work() and releasing the reference at the end of the execution of the work function blk_zone_wplug_bio_work(). The helper function disk_zone_wplug_schedule_bio_work() is introduced to get a reference on a zone write plug and queue its work. This helper is used in disk_zone_wplug_unplug_bio() and disk_zone_wplug_handle_error(). Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 0f2ab448ab48..e28a3e6342f9 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1132,6 +1132,19 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs) } EXPORT_SYMBOL_GPL(blk_zone_plug_bio); +static void disk_zone_wplug_schedule_bio_work(struct gendisk *disk, + struct blk_zone_wplug *zwplug) +{ + /* + * Take a reference on the zone write plug and schedule the submission + * of the next plugged BIO. blk_zone_wplug_bio_work() will release the + * reference we take here. + */ + WARN_ON_ONCE(!(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED)); + atomic_inc(&zwplug->ref); + queue_work(disk->zone_wplugs_wq, &zwplug->bio_work); +} + static void disk_zone_wplug_unplug_bio(struct gendisk *disk, struct blk_zone_wplug *zwplug) { @@ -1151,8 +1164,8 @@ static void disk_zone_wplug_unplug_bio(struct gendisk *disk, /* Schedule submission of the next plugged BIO if we have one. */ if (!bio_list_empty(&zwplug->bio_list)) { + disk_zone_wplug_schedule_bio_work(disk, zwplug); spin_unlock_irqrestore(&zwplug->lock, flags); - queue_work(disk->zone_wplugs_wq, &zwplug->bio_work); return; } @@ -1252,14 +1265,14 @@ static void blk_zone_wplug_bio_work(struct work_struct *work) if (!bio) { zwplug->flags &= ~BLK_ZONE_WPLUG_PLUGGED; spin_unlock_irqrestore(&zwplug->lock, flags); - return; + goto put_zwplug; } if (!blk_zone_wplug_prepare_bio(zwplug, bio)) { /* Error recovery will decide what to do with the BIO. */ bio_list_add_head(&zwplug->bio_list, bio); spin_unlock_irqrestore(&zwplug->lock, flags); - return; + goto put_zwplug; } spin_unlock_irqrestore(&zwplug->lock, flags); @@ -1275,6 +1288,10 @@ static void blk_zone_wplug_bio_work(struct work_struct *work) */ if (bdev->bd_has_submit_bio) blk_queue_exit(bdev->bd_disk->queue); + +put_zwplug: + /* Drop the reference we took in disk_zone_wplug_schedule_bio_work(). */ + disk_put_zone_wplug(zwplug); } static unsigned int blk_zone_wp_offset(struct blk_zone *zone) @@ -1354,8 +1371,7 @@ static void disk_zone_wplug_handle_error(struct gendisk *disk, /* Restart BIO submission if we still have any BIO left. */ if (!bio_list_empty(&zwplug->bio_list)) { - WARN_ON_ONCE(!(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED)); - queue_work(disk->zone_wplugs_wq, &zwplug->bio_work); + disk_zone_wplug_schedule_bio_work(disk, zwplug); goto unlock; } From patchwork Wed May 1 00:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650116 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D4848BFF; Wed, 1 May 2024 00:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522184; cv=none; b=qaq7G19xft4fqU9j17yZRDdx1BG1xt0x1F6sPUrITkPa2x3Ph7s9bmIl/QgDlJXBI9VbBOEJrfxJisnEi7B58bK/aZY8sP13ZLIa59u2GkaaVl9RTygrjSctP+3h/arYkT09vt1EcdFqaKhwl1A9PvKTcTrvF2PQcP4+bVtdBjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522184; c=relaxed/simple; bh=1SA+Z7DPXTFODGai/jtytIByOfxLxTJLEng9yLpKoQY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nSk1rxNnN9nzznBgGUNf8Hj7+mUdSgpoLftpaqouJIfUsGcI2AhL5KhT2H9k3G9EL8u9K97sXLQCYCKLyhnRs7xCH9v2CIqKJ32mzokbGle45zA9LGPSFi90vSeUsyC9zv8r47bcNR8JaqhCWMj+a/BkaurqeXECNhAaiMEsyWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kpf8Q0wH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kpf8Q0wH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B04FC4AF1C; Wed, 1 May 2024 00:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522183; bh=1SA+Z7DPXTFODGai/jtytIByOfxLxTJLEng9yLpKoQY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Kpf8Q0wHgVgvTIwhcqPKfHkK3IzNStk4JUWBDS5z3tz8nqCIu7EX3QBzi8W30P94O cYSVcrmUD6H0GVoLVlnJCclM5tzxsc32YtT3ilrMiq3C/CG2veX6rgiyb814CcaMIi NVAqJrnHZ3O+pNOEsWHkIlABD8LhwXhI/KsTMBytVZU863wxlXDzHQhXilvHI6gqX4 9Y6XznoFAmsmj4wVVK7uSmBUJCS9zDblHFKNZxPlTl2qtgv/DhtUs/qKYvGzJCdUV/ /8bNRksUNjSfTd9avRR/Q+DRZbDifNB47B5zSo4G84EJb3NgbWPm0FXEhjcRAd5/0v hETDgFfi8bo/Q== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 06/14] block: Unhash a zone write plug only if needed Date: Wed, 1 May 2024 09:09:27 +0900 Message-ID: <20240501000935.100534-7-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix disk_remove_zone_wplug() to ensure that a zone write plug already removed from a disk hash table of zone write plugs is not removed again. Do this by checking the BLK_ZONE_WPLUG_UNHASHED flag of the plug and calling hlist_del_init_rcu() only if the flag is not set. Furthermore, since BIO completions can happen at any time, that is, decrementing of the zone write plug reference count can happen at any time, make sure to use disk_put_zone_wplug() instead of atomic_dec() to ensure that the zone write plug is freed when its last reference is dropped. In order to do this, disk_remove_zone_wplug() is moved after the definition of disk_put_zone_wplug(). disk_should_remove_zone_wplug() is moved as well to keep it together with disk_remove_zone_wplug(). To be consistent with this change, add a check in disk_put_zone_wplug() to ensure that a zone write plug being freed was already removed from the disk hash table. Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 55 +++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index e28a3e6342f9..68a4264aded5 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -476,29 +476,6 @@ static bool disk_insert_zone_wplug(struct gendisk *disk, return true; } -static void disk_remove_zone_wplug(struct gendisk *disk, - struct blk_zone_wplug *zwplug) -{ - unsigned long flags; - - spin_lock_irqsave(&disk->zone_wplugs_lock, flags); - zwplug->flags |= BLK_ZONE_WPLUG_UNHASHED; - atomic_dec(&zwplug->ref); - hlist_del_init_rcu(&zwplug->node); - spin_unlock_irqrestore(&disk->zone_wplugs_lock, flags); -} - -static inline bool disk_should_remove_zone_wplug(struct gendisk *disk, - struct blk_zone_wplug *zwplug) -{ - /* If the zone is still busy, the plug cannot be removed. */ - if (zwplug->flags & BLK_ZONE_WPLUG_BUSY) - return false; - - /* We can remove zone write plugs for zones that are empty or full. */ - return !zwplug->wp_offset || zwplug->wp_offset >= disk->zone_capacity; -} - static struct blk_zone_wplug *disk_get_zone_wplug(struct gendisk *disk, sector_t sector) { @@ -534,11 +511,43 @@ static inline void disk_put_zone_wplug(struct blk_zone_wplug *zwplug) if (atomic_dec_and_test(&zwplug->ref)) { WARN_ON_ONCE(!bio_list_empty(&zwplug->bio_list)); WARN_ON_ONCE(!list_empty(&zwplug->link)); + WARN_ON_ONCE(!(zwplug->flags & BLK_ZONE_WPLUG_UNHASHED)); call_rcu(&zwplug->rcu_head, disk_free_zone_wplug_rcu); } } +static inline bool disk_should_remove_zone_wplug(struct gendisk *disk, + struct blk_zone_wplug *zwplug) +{ + /* If the zone is still busy, the plug cannot be removed. */ + if (zwplug->flags & BLK_ZONE_WPLUG_BUSY) + return false; + + /* We can remove zone write plugs for zones that are empty or full. */ + return !zwplug->wp_offset || zwplug->wp_offset >= disk->zone_capacity; +} + +static void disk_remove_zone_wplug(struct gendisk *disk, + struct blk_zone_wplug *zwplug) +{ + unsigned long flags; + + /* If the zone write plug was already removed, we have nothing to do. */ + if (zwplug->flags & BLK_ZONE_WPLUG_UNHASHED) + return; + + /* + * Mark the zone write plug as unhashed and drop the extra reference we + * took when the plug was inserted in the hash table. + */ + zwplug->flags |= BLK_ZONE_WPLUG_UNHASHED; + spin_lock_irqsave(&disk->zone_wplugs_lock, flags); + hlist_del_init_rcu(&zwplug->node); + spin_unlock_irqrestore(&disk->zone_wplugs_lock, flags); + disk_put_zone_wplug(zwplug); +} + static void blk_zone_wplug_bio_work(struct work_struct *work); /* From patchwork Wed May 1 00:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650117 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F1F59475; Wed, 1 May 2024 00:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522185; cv=none; b=qtPVBHEFFVcllzZK2J0fdD9N84W5PRe4OMRFOi//UjAekDj4F1wAC6mG9iQXfGw1rveZ9maMnuH+nr2KePDuM1IN+3yBp0xIQHNfsxHKB6O5Cnz/fVz05NjxIzl0sk7gKGD2KF5GwAfLhQN4WQdG4ov3CuP3j+vyGsk0wktru18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522185; c=relaxed/simple; bh=F/o8UB8C+DtWIsZV8WTwVmGSriyqvfA1esK0NjmzflU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ggxvZopf6KF/XHI6wLacf+C/EwB6ktwcn0enOQsWHXfS1q9i6XDgaAAWuKpbRx1qCCyXytMFRICItldYfV3LQehcrg/BNzgsFBpWAPATSU/Q1lDFhfUAym9ZIV13XwpBiFELzk+wvzeVh/hPRFfuQSebymg7hVmUBFNNOc4ddJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QTLx7Mdm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QTLx7Mdm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FBA4C2BBFC; Wed, 1 May 2024 00:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522184; bh=F/o8UB8C+DtWIsZV8WTwVmGSriyqvfA1esK0NjmzflU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QTLx7Mdmp6J6MA/0Rwtdlx2yjtD0HlssuuYr7Cf1rGRe3mCjgBlipXE+X7B2joPeQ 6YjpSuwkAiRQknkmIjwLlsdmc3jGLlx3Oria2IUAnx64Pq24RD8DkmOBblxCSVxKc/ pXmLxTDp1+9x+DMfuMKQ6uUmM30XydHvMrhVxSyY5Gc5iQ3rwELTLAS26koHDFlYjC j7CcCCN81lltFLymcqd9waAjrZqf/TH6mQi0Scrvl7o7oY2IeFflWjxc4w6TnBVOvr KyOgbH441I2XPww6++LKU2vmAK3L79sw3iwCCS/sszA6+nmqB17Cd9mi/cdN7HrTCE eQmfDnXEHdjig== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 07/14] block: Do not remove zone write plugs still in use Date: Wed, 1 May 2024 09:09:28 +0900 Message-ID: <20240501000935.100534-8-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Large write BIOs that span a zone boundary are split in blk_mq_submit_bio() before being passed to blk_zone_plug_bio() for zone write plugging. Such split BIO will be chained with one fragment targeting one zone and the remainder of the BIO targeting the next zone. The two BIOs can be executed in parallel, without a predetermine order relative to eachother and their completion may be reversed: the remainder first completing and the first fragment then completing. In such case, bio_endio() will not immediately execute blk_zone_write_plug_bio_endio() for the parent BIO (the remainder of the split BIO) as the BIOs are chained. blk_zone_write_plug_bio_endio() for the parent BIO will be executed only once the first fragment completes. In the case of a device with small zones and very large BIOs, uch completion pattern can lead to disk_should_remove_zone_wplug() to return true for the zone of the parent BIO when the parent BIO request completes and blk_zone_write_plug_complete_request() is executed. This triggers the removal of the zone write plug from the hash table using disk_remove_zone_wplug(). With the zone write plug of the parent BIO missing, the call to disk_get_zone_wplug() in blk_zone_write_plug_bio_endio() returns NULL and triggers a warning. This patterns can be recreated fairly easily using a scsi_debug device with small zone and btrfs. E.g. modprobe scsi_debug delay=0 dev_size_mb=1024 sector_size=4096 \ zbc=host-managed zone_cap_mb=3 zone_nr_conv=0 zone_size_mb=4 mkfs.btrfs -f -O zoned /dev/sda mount -t btrfs /dev/sda /mnt fio --name=wrtest --rw=randwrite --direct=1 --ioengine=libaio \ --bs=4k --iodepth=16 --size=1M --directory=/mnt --time_based \ --runtime=10 umount /dev/sda Will result in the warning: [ 29.035538] WARNING: CPU: 3 PID: 37 at block/blk-zoned.c:1207 blk_zone_write_plug_bio_endio+0xee/0x1e0 ... [ 29.058682] Call Trace: [ 29.059095] [ 29.059473] ? __warn+0x80/0x120 [ 29.059983] ? blk_zone_write_plug_bio_endio+0xee/0x1e0 [ 29.060728] ? report_bug+0x160/0x190 [ 29.061283] ? handle_bug+0x36/0x70 [ 29.061830] ? exc_invalid_op+0x17/0x60 [ 29.062399] ? asm_exc_invalid_op+0x1a/0x20 [ 29.063025] ? blk_zone_write_plug_bio_endio+0xee/0x1e0 [ 29.063760] bio_endio+0xb7/0x150 [ 29.064280] btrfs_clone_write_end_io+0x2b/0x60 [btrfs] [ 29.065049] blk_update_request+0x17c/0x500 [ 29.065666] scsi_end_request+0x27/0x1a0 [scsi_mod] [ 29.066356] scsi_io_completion+0x5b/0x690 [scsi_mod] [ 29.067077] blk_complete_reqs+0x3a/0x50 [ 29.067692] __do_softirq+0xcf/0x2b3 [ 29.068248] ? sort_range+0x20/0x20 [ 29.068791] run_ksoftirqd+0x1c/0x30 [ 29.069339] smpboot_thread_fn+0xcc/0x1b0 [ 29.069936] kthread+0xcf/0x100 [ 29.070438] ? kthread_complete_and_exit+0x20/0x20 [ 29.071314] ret_from_fork+0x31/0x50 [ 29.071873] ? kthread_complete_and_exit+0x20/0x20 [ 29.072563] ret_from_fork_asm+0x11/0x20 [ 29.073146] either when fio executes or when unmount is executed. Fix this by modifying disk_should_remove_zone_wplug() to check that the reference count to a zone write plug is not larger than 2, that is, that the only references left on the zone are the caller held reference (blk_zone_write_plug_complete_request()) and the initial extra reference for the zone write plug taken when it was initialized (and that is dropped when the zone write plug is removed from the hash table). To be consistent with this change, make sure to drop the request or BIO held reference to the zone write plug before calling disk_zone_wplug_unplug_bio(). All references are also dropped using disk_put_zone_wplug() instead of atomic_dec() to ensure that the zone write plug is freed if it needs to be. Comments are also improved to clarify zone write plugs reference handling. Reported-by: Shin'ichiro Kawasaki Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal --- block/blk-zoned.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 68a4264aded5..96ea97ad80a9 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -520,10 +520,28 @@ static inline void disk_put_zone_wplug(struct blk_zone_wplug *zwplug) static inline bool disk_should_remove_zone_wplug(struct gendisk *disk, struct blk_zone_wplug *zwplug) { - /* If the zone is still busy, the plug cannot be removed. */ + /* If the zone write plug was already removed, we are done. */ + if (zwplug->flags & BLK_ZONE_WPLUG_UNHASHED) + return false; + + /* If the zone write plug is still busy, it cannot be removed. */ if (zwplug->flags & BLK_ZONE_WPLUG_BUSY) return false; + /* + * Completions of BIOs with blk_zone_write_plug_bio_endio() may + * happen after handling a request completion with + * blk_zone_write_plug_complete_request() (e.g. with split BIOs + * that are chained). In such case, disk_zone_wplug_unplug_bio() + * should not attempt to remove the zone write plug until all BIO + * completions are seen. Check by looking at the zone write plug + * reference count, which is 2 when the plug is unused (one reference + * taken when the plug was allocated and another reference taken by the + * caller context). + */ + if (atomic_read(&zwplug->ref) > 2) + return false; + /* We can remove zone write plugs for zones that are empty or full. */ return !zwplug->wp_offset || zwplug->wp_offset >= disk->zone_capacity; } @@ -893,8 +911,9 @@ void blk_zone_write_plug_attempt_merge(struct request *req) struct bio *bio; /* - * Completion of this request needs to be handled with - * blk_zone_write_plug_complete_request(). + * Indicate that completion of this request needs to be handled with + * blk_zone_write_plug_complete_request(), which will drop the reference + * on the zone write plug we took above on entry to this function. */ req->rq_flags |= RQF_ZONE_WRITE_PLUGGING; @@ -1223,6 +1242,9 @@ void blk_zone_write_plug_bio_endio(struct bio *bio) spin_unlock_irqrestore(&zwplug->lock, flags); } + /* Drop the reference we took when the BIO was issued. */ + disk_put_zone_wplug(zwplug); + /* * For BIO-based devices, blk_zone_write_plug_complete_request() * is not called. So we need to schedule execution of the next @@ -1231,8 +1253,7 @@ void blk_zone_write_plug_bio_endio(struct bio *bio) if (bio->bi_bdev->bd_has_submit_bio) disk_zone_wplug_unplug_bio(disk, zwplug); - /* Drop the reference we took when the BIO was issued. */ - atomic_dec(&zwplug->ref); + /* Drop the reference we took when entering this function. */ disk_put_zone_wplug(zwplug); } @@ -1246,13 +1267,15 @@ void blk_zone_write_plug_complete_request(struct request *req) req->rq_flags &= ~RQF_ZONE_WRITE_PLUGGING; - disk_zone_wplug_unplug_bio(disk, zwplug); - /* * Drop the reference we took when the request was initialized in * blk_zone_write_plug_attempt_merge(). */ - atomic_dec(&zwplug->ref); + disk_put_zone_wplug(zwplug); + + disk_zone_wplug_unplug_bio(disk, zwplug); + + /* Drop the reference we took when entering this function. */ disk_put_zone_wplug(zwplug); } From patchwork Wed May 1 00:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650118 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5C04C8CE; Wed, 1 May 2024 00:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522186; cv=none; b=T77ixYZM+aghIt+YgdbifqseTN/payiLEralf88gAKRdDcWkKdyMrsVl1fNVQaaWcYY1H0S5mI/vQH2jGZpnuaszNa3bqMu3Z+roGYj6vdfJq44k4T38sc2yq4gAgbd9JJZ++z86Ry6gwBIB5Y1c4GO2YxAyQPbR4Dwwmy4U6gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522186; c=relaxed/simple; bh=F9wHY06hqfCHb1rrEjbYbLMUrUQ6FGujt9xlHLsvE2Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dW1M33jLjOwguXuwdV9pH1NU7KpM7Lyb+6ava9Ie47kLGceU6rs8vXHEI0pB40iyUW4lR6WhuX0HE/3D+w/Tpc8Db/qCDCG/1tjjn0eURNDPRQtSZDt3QZI6RLFwYFkdsKv/LRsrWDzbHoYytV6xgBBk0tqjtb7FO1HQoEdU+Ik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HeAJvzZW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HeAJvzZW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 361A5C4AF1A; Wed, 1 May 2024 00:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522185; bh=F9wHY06hqfCHb1rrEjbYbLMUrUQ6FGujt9xlHLsvE2Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HeAJvzZWG8/wWBF7TkW6X1LPWL2zq0iWl+j4UE4vIm7J0zHHmnFtBiyYlrM2UEERp lFl0OffmMBthPOig16QaomVeXOa0PL5NEMSdHcK/0VClPvjoZdpCy5+XVyb85IcoP1 iOt/30yeYhnkLm7fESKBj4YO+hmqe8YIi9lRYMtIbf4lQc2aeAygngbBusLWl0skwW X9jhHBHACecNDJclJYoJaPOc7wduvuChws9anxv2zfbTAMF/KdsoJvm6jb4+sLVnk0 d/zjD/M3+philoDrL0w1jc8cHEt1eekogiIy6Sp+ENGs9g7DTfkLMal0+zz4r0zMh9 sHDiPqwyRRDEw== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 08/14] block: Fix flush request sector restore Date: Wed, 1 May 2024 09:09:29 +0900 Message-ID: <20240501000935.100534-9-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make sure that a request bio is not NULL before trying to restore the request start sector. Reported-by: Yi Zhang Fixes: 6f8fd758de63 ("block: Restore sector of flush requests") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-flush.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-flush.c b/block/blk-flush.c index 2f58ae018464..c17cf8ed8113 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -130,7 +130,8 @@ static void blk_flush_restore_request(struct request *rq) * original @rq->bio. Restore it. */ rq->bio = rq->biotail; - rq->__sector = rq->bio->bi_iter.bi_sector; + if (rq->bio) + rq->__sector = rq->bio->bi_iter.bi_sector; /* make @rq a normal request */ rq->rq_flags &= ~RQF_FLUSH_SEQ; From patchwork Wed May 1 00:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650119 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A83DD52E; Wed, 1 May 2024 00:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522187; cv=none; b=LtWEEL/wHzEbnOc5nlthkK2s5NrgQaINBBbh7LAZAlWSQsQLVJyxBhK18GOiXxSunHgR12gsuK7JF0wb9KAc9LjUy52CpiF0WTMoxtqDoeC24koGsrICrfpOyEYrzQ0aFmHTLRts/5Nf9fJaHmrHVk0jc++DK82Tw1JntGBPF78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522187; c=relaxed/simple; bh=PT2HeYywBuUJ388cI4SBmbA/o2T4+Y7N0I/yohoQX0g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rsS8m6n9273XPdG9EvGd+u8lJ32FamX5EysrZYbCNJF/gx/W9C7/cp0uzQEjMB6Bp8c2hxMlxs921Jjm1m0ES3oRgXfKQlvoCLZxRvJVg9HDwNjBfscD7SQFuFQJ8zujobGtIoWHLh5YbALjZT+aZC+Wp4XkfoGELT6yh0oHr0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sePT+eIo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sePT+eIo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AEBDC4AF19; Wed, 1 May 2024 00:09:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522187; bh=PT2HeYywBuUJ388cI4SBmbA/o2T4+Y7N0I/yohoQX0g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sePT+eIolKOZP5ffC2t9C+KGN34Z1q50dAHgjb71zva63ZD68AQD7LGzRBBVWKOA+ 4vhPYDvjIH72uT9x+WOp3GQ5eeEYWoASpnKH+AdpzDVRmv9v7t+zo7kfoRReS6ZpZq h4pFFJttc91MgIh+ouWKYC+LsEC17Z3YogmYcQyNyGC7qQXyJLUCZUFCSK1sOa7jSZ yrSh8MiH69X5mAa+fIqTK4qbqpKZDspj2zbzvljhaY7TrHUJpOs4MRSuxJNND1k/q9 5/MQzzcNgJr5NiATMIOcMigYyxGK7OzP/RC8ZwiWdqKMnSZ8+YE8L9eOlXHmOnY4gR Efx1aGZEsHaEg== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 09/14] block: Fix handling of non-empty flush write requests to zones Date: Wed, 1 May 2024 09:09:30 +0900 Message-ID: <20240501000935.100534-10-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Zone write plugging ignores empty (no data) flush operations but handles flush BIOs that have data to ensure that the flush machinery generated write is processed in order. However, the call to blk_zone_write_plug_attempt_merge() which sets a request RQF_ZONE_WRITE_PLUGGING flag is called after blk_insert_flush(), thus missing indicating that a non empty flush request completion needs handling by zone write plugging. Fix this by moving the call to blk_zone_write_plug_attempt_merge() before blk_insert_flush(). And while at it, rename that function as blk_zone_write_plug_init_request() to be clear that it is not just about merging plugged BIOs in the request. While at it, also add a WARN_ONCE() check that the zone write plug for the request is not NULL. Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-mq.c | 6 +++--- block/blk-zoned.c | 12 ++++++++---- block/blk.h | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 434d45219e23..0fae9bd0ecd4 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3001,12 +3001,12 @@ void blk_mq_submit_bio(struct bio *bio) return; } + if (bio_zone_write_plugging(bio)) + blk_zone_write_plug_init_request(rq); + if (op_is_flush(bio->bi_opf) && blk_insert_flush(rq)) return; - if (bio_zone_write_plugging(bio)) - blk_zone_write_plug_attempt_merge(rq); - if (plug) { blk_add_rq_to_plug(plug, rq); return; diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 96ea97ad80a9..5a5803ca031c 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -874,8 +874,9 @@ void blk_zone_write_plug_bio_merged(struct bio *bio) /* * If the BIO was already plugged, then we were called through - * blk_zone_write_plug_attempt_merge() -> blk_attempt_bio_merge(). - * For this case, blk_zone_write_plug_attempt_merge() will handle the + * blk_zone_write_plug_init_request() -> blk_attempt_bio_merge(). + * For this case, we already hold a reference on the zone write plug for + * the BIO and blk_zone_write_plug_init_request() will handle the * zone write pointer offset update. */ if (bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING)) @@ -899,7 +900,7 @@ void blk_zone_write_plug_bio_merged(struct bio *bio) * already went through zone write plugging (either a new BIO or one that was * unplugged). */ -void blk_zone_write_plug_attempt_merge(struct request *req) +void blk_zone_write_plug_init_request(struct request *req) { sector_t req_back_sector = blk_rq_pos(req) + blk_rq_sectors(req); struct request_queue *q = req->q; @@ -910,6 +911,9 @@ void blk_zone_write_plug_attempt_merge(struct request *req) unsigned long flags; struct bio *bio; + if (WARN_ON_ONCE(!zwplug)) + return; + /* * Indicate that completion of this request needs to be handled with * blk_zone_write_plug_complete_request(), which will drop the reference @@ -1269,7 +1273,7 @@ void blk_zone_write_plug_complete_request(struct request *req) /* * Drop the reference we took when the request was initialized in - * blk_zone_write_plug_attempt_merge(). + * blk_zone_write_plug_init_request(). */ disk_put_zone_wplug(zwplug); diff --git a/block/blk.h b/block/blk.h index 1140c4a0be03..8a62b861453c 100644 --- a/block/blk.h +++ b/block/blk.h @@ -427,7 +427,7 @@ static inline bool bio_is_zone_append(struct bio *bio) bio_flagged(bio, BIO_EMULATES_ZONE_APPEND); } void blk_zone_write_plug_bio_merged(struct bio *bio); -void blk_zone_write_plug_attempt_merge(struct request *rq); +void blk_zone_write_plug_init_request(struct request *rq); static inline void blk_zone_update_request_bio(struct request *rq, struct bio *bio) { @@ -481,7 +481,7 @@ static inline bool bio_is_zone_append(struct bio *bio) static inline void blk_zone_write_plug_bio_merged(struct bio *bio) { } -static inline void blk_zone_write_plug_attempt_merge(struct request *rq) +static inline void blk_zone_write_plug_init_request(struct request *rq) { } static inline void blk_zone_update_request_bio(struct request *rq, From patchwork Wed May 1 00:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650120 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A813EAC7; Wed, 1 May 2024 00:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522188; cv=none; b=eHEloniO3CclwhbGtxpghHDKbzjExaRnOxLtOJDdG4KlXm+PInkyNyR7L4c+GXpNYpWSQh73dY0TuJzjHM+o+HENdvH8myDqx0L2qNHa2vFp63DthZN4mHCFDVAUYGnnZcz8PGGWHohZTzLZfb+h08a4ddagrN5ujVZGe8nKb9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522188; c=relaxed/simple; bh=XC2bM+ZkGdHP0BQoAi8mq38gQ4IUzXpjaBjM+7WZZeI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lPihnCusop0kIds+AMu1mD8vcpAfLyLPH8UYm1tewFeWmfRT/EK8Ar/dgZUSF2WeVel/9FuhFnj47mQGFixusT8F9XrkR5lyLW/342c8Ya/YmL5Kmg0Nl/5BF9jGShgdrvbgnFxNSpdQ/yyPZzFItczZfTmJ5PRpcDx/X+/r5kQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YrYYx+hV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YrYYx+hV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FD28C32789; Wed, 1 May 2024 00:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522188; bh=XC2bM+ZkGdHP0BQoAi8mq38gQ4IUzXpjaBjM+7WZZeI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YrYYx+hVmZhvUsiSKyESHEx0sB1hq4Nwzjgm1B2qTMv+2HtvgWd2wUvIwL1jxtMNR JbjdV9QPxTSzWjsO3agSZt8D+cbtFBiTvwgL+lChOt8FJFQc6fIcR9n1r7WhN/MRGO 8xde69A0sNYdXOIQCUzEZtU1HkSEK84if6KXkUVggHDg27DN9kDJIFZeSxunCxGtpY 0mBd3ViZlXiYPpjPybUn3gu1zK9LDV4K7/Nps1FqD34sGpWAk8FB0ZZ0wmRcFsNl7n HtmlEQMndWlpTVUrBirWvH7ZWwA5Lm0u/ui1iQaBpfj5HHUnd1640/1+erHfGILVHS ys0dYgGOlrGtw== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 10/14] block: Improve blk_zone_write_plug_bio_merged() Date: Wed, 1 May 2024 09:09:31 +0900 Message-ID: <20240501000935.100534-11-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Improve blk_zone_write_plug_bio_merged() to check that we succefully get a reference on the zone write plug of the merged BIO, as expected since for a merge we already have at least one request and one BIO referencing the zone write plug. Comments in this function are also improved to better explain the references to the BIO zone write plug. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 5a5803ca031c..d26b5bb432d1 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -885,11 +885,16 @@ void blk_zone_write_plug_bio_merged(struct bio *bio) bio_set_flag(bio, BIO_ZONE_WRITE_PLUGGING); /* - * Increase the plug reference count and advance the zone write - * pointer offset. + * Get a reference on the zone write plug of the target zone and advance + * the zone write pointer offset. Given that this is a merge, we already + * have at least one request and one BIO referencing the zone write + * plug. So this should not fail. */ zwplug = disk_get_zone_wplug(bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector); + if (WARN_ON_ONCE(!zwplug)) + return; + spin_lock_irqsave(&zwplug->lock, flags); zwplug->wp_offset += bio_sectors(bio); spin_unlock_irqrestore(&zwplug->lock, flags); From patchwork Wed May 1 00:09:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650121 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A11E6FBEA; Wed, 1 May 2024 00:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522189; cv=none; b=YVnmddZmmI7mh/cDi504M/oqMAKKxWVZmxQkO9uw3uph1FSoQcYucBYvBbspmMt+DWeUdKMMhHBf8rTHcAxEADQPigVoelxxzDFWoQfO8Gq5DvNYG3akFUFJShmhJiunh83838/EzFfeqhMUQKHUcss4pN89KeQ63Sh6QCOXTUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522189; c=relaxed/simple; bh=C6gqcfRQzZvC8Od9BVTqmjuk18l7ZxInf5cjSyxyMeY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GUEa5dfKoVQ35TnenB2Jah1GYCx/6JMd6eKw/jyuoEc5bqgwR8mpVQSrUPpAWNNHFOBxAQVs6bMlhPhpo6Dfugw2DTfmJo7HDvP/5eZ5VwsUbqavrYyy2n/VlsDVjyn2OZNp4s65sj+2sZ1buzygwnl11HuBYy3MRxmmc1YsBnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N85rSw0t; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N85rSw0t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 744CDC2BBFC; Wed, 1 May 2024 00:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522189; bh=C6gqcfRQzZvC8Od9BVTqmjuk18l7ZxInf5cjSyxyMeY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N85rSw0tsqeIZ6WnAKIlvd25tkclCnNJgWXRPlPrwCNm9a/BPPg9ZJgo0ch9IxTzw 50Dhz5ErH8o9YvWrIwDBgzxkvdLM0rw68pb1NySzrbQDLps6FF3LoA6mWrF9ioaBXZ N7phjYK31HaVwSTf5s66DBg6dBe1zCzimcNqTe/MIibPlB0a30dopCJkum0ajYMpIa ha7tmQWLCl8rB9GogltykO6YX+2sIaTV+T9lv4jB7cs2ZIggyC1WJv7i0kD+PmArof pPta/Z3Ok0BWriz0U7eWNTBtbmSqKA6LQUvuMXSOBTukbRPyf+0SgMvKcKhEXGnb1z lyTLCtU/5rmLA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 11/14] block: Improve zone write request completion handling Date: Wed, 1 May 2024 09:09:32 +0900 Message-ID: <20240501000935.100534-12-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 blk_zone_complete_request() must be called to handle the completion of a zone write request handled with zone write plugging. This function is called from blk_complete_request(), blk_update_request() and also in blk_mq_submit_bio() error path. Improve this by moving this function call into blk_mq_finish_request() as all requests are processed with this function when they complete as well as when they are freed without being executed. This also improves blk_update_request() used by scsi devices as these may repeatedly call this function to handle partial completions. To be consistent with this change, blk_zone_complete_request() is renamed to blk_zone_finish_request() and blk_zone_write_plug_complete_request() is renamed to blk_zone_write_plug_finish_request(). Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-mq.c | 6 ++---- block/blk-zoned.c | 11 ++++++----- block/blk.h | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 0fae9bd0ecd4..9f677ea85a52 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -691,6 +691,8 @@ static void blk_mq_finish_request(struct request *rq) { struct request_queue *q = rq->q; + blk_zone_finish_request(rq); + if (rq->rq_flags & RQF_USE_SCHED) { q->elevator->type->ops.finish_request(rq); /* @@ -828,8 +830,6 @@ static void blk_complete_request(struct request *req) bio = next; } while (bio); - blk_zone_complete_request(req); - /* * Reset counters so that the request stacking driver * can find how many bytes remain in the request @@ -940,7 +940,6 @@ bool blk_update_request(struct request *req, blk_status_t error, * completely done */ if (!req->bio) { - blk_zone_complete_request(req); /* * Reset counters so that the request stacking driver * can find how many bytes remain in the request @@ -2996,7 +2995,6 @@ void blk_mq_submit_bio(struct bio *bio) if (ret != BLK_STS_OK) { bio->bi_status = ret; bio_endio(bio); - blk_zone_complete_request(rq); blk_mq_free_request(rq); return; } diff --git a/block/blk-zoned.c b/block/blk-zoned.c index d26b5bb432d1..e590403504a6 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -531,7 +531,7 @@ static inline bool disk_should_remove_zone_wplug(struct gendisk *disk, /* * Completions of BIOs with blk_zone_write_plug_bio_endio() may * happen after handling a request completion with - * blk_zone_write_plug_complete_request() (e.g. with split BIOs + * blk_zone_write_plug_finish_request() (e.g. with split BIOs * that are chained). In such case, disk_zone_wplug_unplug_bio() * should not attempt to remove the zone write plug until all BIO * completions are seen. Check by looking at the zone write plug @@ -921,7 +921,7 @@ void blk_zone_write_plug_init_request(struct request *req) /* * Indicate that completion of this request needs to be handled with - * blk_zone_write_plug_complete_request(), which will drop the reference + * blk_zone_write_plug_finish_request(), which will drop the reference * on the zone write plug we took above on entry to this function. */ req->rq_flags |= RQF_ZONE_WRITE_PLUGGING; @@ -1255,7 +1255,7 @@ void blk_zone_write_plug_bio_endio(struct bio *bio) disk_put_zone_wplug(zwplug); /* - * For BIO-based devices, blk_zone_write_plug_complete_request() + * For BIO-based devices, blk_zone_write_plug_finish_request() * is not called. So we need to schedule execution of the next * plugged BIO here. */ @@ -1266,11 +1266,12 @@ void blk_zone_write_plug_bio_endio(struct bio *bio) disk_put_zone_wplug(zwplug); } -void blk_zone_write_plug_complete_request(struct request *req) +void blk_zone_write_plug_finish_request(struct request *req) { struct gendisk *disk = req->q->disk; - struct blk_zone_wplug *zwplug = disk_get_zone_wplug(disk, req->__sector); + struct blk_zone_wplug *zwplug; + zwplug = disk_get_zone_wplug(disk, req->__sector); if (WARN_ON_ONCE(!zwplug)) return; diff --git a/block/blk.h b/block/blk.h index 8a62b861453c..ee4f782d1496 100644 --- a/block/blk.h +++ b/block/blk.h @@ -453,11 +453,11 @@ static inline void blk_zone_bio_endio(struct bio *bio) blk_zone_write_plug_bio_endio(bio); } -void blk_zone_write_plug_complete_request(struct request *rq); -static inline void blk_zone_complete_request(struct request *rq) +void blk_zone_write_plug_finish_request(struct request *rq); +static inline void blk_zone_finish_request(struct request *rq) { if (rq->rq_flags & RQF_ZONE_WRITE_PLUGGING) - blk_zone_write_plug_complete_request(rq); + blk_zone_write_plug_finish_request(rq); } int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd, unsigned long arg); @@ -491,7 +491,7 @@ static inline void blk_zone_update_request_bio(struct request *rq, static inline void blk_zone_bio_endio(struct bio *bio) { } -static inline void blk_zone_complete_request(struct request *rq) +static inline void blk_zone_finish_request(struct request *rq) { } static inline int blkdev_report_zones_ioctl(struct block_device *bdev, From patchwork Wed May 1 00:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650122 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F91F10A19; Wed, 1 May 2024 00:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522190; cv=none; b=XRcheh6DoJAwBOiVatIrxB9r8pPP3qGKCku70HR5kiSztp/Wtr99M2pfroIyGPasvOi9xIUA3nGW+7FlWvR7oynm/iZrwIV+CpvcI5kIWw0J7i/VQJ3lwzFejS810V8Xfl0LYSeZux9YFyZUC4h+uUtoy0l3dbptQSGZHAqhybw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522190; c=relaxed/simple; bh=3EJwT+FRWdpdyQ6Z8AavgxjHs8UUT7vn5tXPlKnBZ6w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Azc2y+AEoTRvZdBEIsvSA1hW8NKrME8iVfQ1nFVcwhybb7tz5B+RJWUv7X5ssP+Mpx99fkQPehvrG5aTFaDt2GliogEXem7XcIUhjpajT6aUs3CdkV42Z/hEYeDG68sp4B8v9s8qYVK2cEf/5RYQdUa26xUf4nIgSi6jMaNFzlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AZhgX0tF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AZhgX0tF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 882B5C4AF19; Wed, 1 May 2024 00:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522190; bh=3EJwT+FRWdpdyQ6Z8AavgxjHs8UUT7vn5tXPlKnBZ6w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AZhgX0tFaVyLGaqRLdcJne+pFqV+lu2mMvXMLWpe7o36Dho8T9DktcOYvWsA3M8Vx rz/3RB/UjKZn862lQiLqjsPtQvth70LW9h8+1MbvDKTe7NiDW35XxD0w+F4BcOPVU2 +H+EeWOGr/NZQyXKp2oPDCpO3v/73JcMO8kW2Pccf/osQyTEH9z6sulHOyTHijPFAF FFYuawRnuiw7VmbSJYt8ZqT2wOqyeycSGP71Qq/Wkz58HqEiyLbi8iYJb21CB43qYB HuFboqQ14vfN7xWA4cDDzPHCI0O3qzTC7E1R2W/oowVmAmavJc3jNlICicsdA/7abv ESwR8wGtEdiAQ== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 12/14] block: Simplify blk_zone_write_plug_bio_endio() Date: Wed, 1 May 2024 09:09:33 +0900 Message-ID: <20240501000935.100534-13-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We already have the disk variable obtained from the bio when calling disk_get_zone_wplug(). So use that variable instead of dereferencing the bio bdev again for the disk argument of disk_get_zone_wplug(). Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index e590403504a6..a578d6784445 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1222,8 +1222,7 @@ void blk_zone_write_plug_bio_endio(struct bio *bio) { struct gendisk *disk = bio->bi_bdev->bd_disk; struct blk_zone_wplug *zwplug = - disk_get_zone_wplug(bio->bi_bdev->bd_disk, - bio->bi_iter.bi_sector); + disk_get_zone_wplug(disk, bio->bi_iter.bi_sector); unsigned long flags; if (WARN_ON_ONCE(!zwplug)) From patchwork Wed May 1 00:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650123 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B421513ADA; Wed, 1 May 2024 00:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522191; cv=none; b=KI/CxN0cYGbp45RRTpU/8hCOoFR6vUWhPyyZbBUbZDin7ahY0FhMgUciIfOHrCqMcxPTHIfySB2m4APe1zmeqcqXukBLfZJLCMkHuHBTFSa3yvtlU2/C9r0li/dYu30ZUfu1bdA22czIPLWEA4VJwZfJh/SRx9JidyMFr/Y+BJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522191; c=relaxed/simple; bh=GPtKqZiD9+8HwuaGBRXWPns1vmljSTWBxFLY5KfOtkU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxM6IYcEtNLSa81UZItrGsNuJuutK9LfiS2LHMDn4LXszOzeutdw4HyK30w/TIgAnr+3F19CWs686rDPRsztqsbLt6xu4QsFFCF09bwOrPanDS0GMW35ZqqN5XIlWD2dJ+cqG57FA6b7/rbq/WEf4tRyC1G8vW+lRLMnVlX1cMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MJKn4zmH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MJKn4zmH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D1ACC32789; Wed, 1 May 2024 00:09:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522191; bh=GPtKqZiD9+8HwuaGBRXWPns1vmljSTWBxFLY5KfOtkU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MJKn4zmHT14t1rXzNQ6ydjmPmTRgbNQm3zKKJs/drtTI/FSQrVrEncGs1ae7+Q/vT IeBXfF8COaO+FfratDoYA1Kefq767pZoOdPEyu/eGrkUbDLckt2H1devR8R3ptzR5G itfZDMiwVQZ4CVdtFe2Zlzb8fkmWE4rhpjxLk6diYrT+1Pua3l7vFEplzP55wz3Awx xa4IxvQIHTizQJPoZ8gpJuia0+vgv4aaW8o9OnNh+z2zAut2WRlf0dCl4X4oHwHeL8 BqMsP1A7RSeuXLB4ynovAE9xZzkSzKs7naS6S/6l9X+JfG1II1wzPMVdu/CvAHbreM IY6j89qjA+VlA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 13/14] block: Simplify zone write plug BIO abort Date: Wed, 1 May 2024 09:09:34 +0900 Message-ID: <20240501000935.100534-14-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When BIOs plugged in a zone write plug are aborted, blk_zone_wplug_bio_io_error() clears the BIO BIO_ZONE_WRITE_PLUGGING flag so that bio_io_error(bio) does not end up calling blk_zone_write_plug_bio_endio() and we thus need to manually drop the reference on the zone write plug held by the aborted BIO. Move the call to disk_put_zone_wplug() that is alwasy following the call to blk_zone_wplug_bio_io_error() inside that function to simplify the code. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-zoned.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index a578d6784445..9026e83e0746 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -634,12 +634,14 @@ static struct blk_zone_wplug *disk_get_and_lock_zone_wplug(struct gendisk *disk, return zwplug; } -static inline void blk_zone_wplug_bio_io_error(struct bio *bio) +static inline void blk_zone_wplug_bio_io_error(struct blk_zone_wplug *zwplug, + struct bio *bio) { - struct request_queue *q = bio->bi_bdev->bd_disk->queue; + struct request_queue *q = zwplug->disk->queue; bio_clear_flag(bio, BIO_ZONE_WRITE_PLUGGING); bio_io_error(bio); + disk_put_zone_wplug(zwplug); blk_queue_exit(q); } @@ -650,10 +652,8 @@ static void disk_zone_wplug_abort(struct blk_zone_wplug *zwplug) { struct bio *bio; - while ((bio = bio_list_pop(&zwplug->bio_list))) { - blk_zone_wplug_bio_io_error(bio); - disk_put_zone_wplug(zwplug); - } + while ((bio = bio_list_pop(&zwplug->bio_list))) + blk_zone_wplug_bio_io_error(zwplug, bio); } /* @@ -673,8 +673,7 @@ static void disk_zone_wplug_abort_unaligned(struct gendisk *disk, if (wp_offset >= zone_capacity || (bio_op(bio) != REQ_OP_ZONE_APPEND && bio_offset_from_zone_start(bio) != wp_offset)) { - blk_zone_wplug_bio_io_error(bio); - disk_put_zone_wplug(zwplug); + blk_zone_wplug_bio_io_error(zwplug, bio); continue; } From patchwork Wed May 1 00:09:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 13650124 X-Patchwork-Delegate: snitzer@redhat.com Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CC0F14AB8; Wed, 1 May 2024 00:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522192; cv=none; b=tv7ZAUm0FjIr3zTddgcRYjYwxU0MahSTtPi7qsczVnmjpP3Zj4erMdZdP2I9YiPbY2Q1PGcExQMCCp1ePjItWFs57J9/b4Co60UXvpUcVzbvQht7ZL+2+DnZ9IWverX+CaMV6V5Pk6bY9HEHZ5I8oOPQpvjNDersWiCdgnsUGww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714522192; c=relaxed/simple; bh=GgkXYMOex8Wwx3Wzdyn0crJ3gWNnGAT0xhN76cGFAbg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PzylothoGZdKHDzSKMfj8KD673Lm+l2juhhiBM2DfQbzU3FpyVV1VJR459JMxWlO2YCHtbVBU0vYlFPX3TEfBUMg6RcKKumb/YmpcKEhOSzayqb896569rxtRQRct+yQeBpMYp2DN9wT2bl2ZZPHbYDijThhwIq1nTa0mziBZEo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZFw56VAU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZFw56VAU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B17CFC2BBFC; Wed, 1 May 2024 00:09:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714522192; bh=GgkXYMOex8Wwx3Wzdyn0crJ3gWNnGAT0xhN76cGFAbg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZFw56VAUR/2FKxOkQPr/EuKA8CBZtw8FFKiFFx//2frZFgtFN5li7b1LOsJ/meBNI EDp1AffsQQ/CxSjN5H64CgDyfhxRJMxA9zlc0fDA61jgYknLyQbW2ruMs7cCAcDkSG R2vffBZqEQeGjOFcmhQarHESGP8I3UkSAkQGczXqUkoPZhkaGDy0r3m8mEJTMLTpXH +KiyXuBPvTso6uIXEu7QD5gslTm3p0t/XawZSXX+qevZcYfu0tOVAv37j7Op+sjOuU lPcKzrUlG3dlyJfSGp9G7fPtYTc58Jy1tVc/f3luo2VH+JfgHUm7pcX6uEJgW8oSOD p337LtJYvM3bA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH v2 14/14] block: Cleanup blk_revalidate_zone_cb() Date: Wed, 1 May 2024 09:09:35 +0900 Message-ID: <20240501000935.100534-15-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501000935.100534-1-dlemoal@kernel.org> References: <20240501000935.100534-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Define the code for checking conventional and sequential write required zones suing the functions blk_revalidate_conv_zone() and blk_revalidate_seq_zone() respectively. This simplifies the zone type switch-case in blk_revalidate_zone_cb(). No functional changes. Signed-off-by: Damien Le Moal --- block/blk-zoned.c | 129 +++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 52 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 9026e83e0746..a2030089081c 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1658,6 +1658,74 @@ static int disk_update_zone_resources(struct gendisk *disk, return queue_limits_commit_update(q, &lim); } +static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx, + struct blk_revalidate_zone_args *args) +{ + struct gendisk *disk = args->disk; + struct request_queue *q = disk->queue; + + if (zone->capacity != zone->len) { + pr_warn("%s: Invalid conventional zone capacity\n", + disk->disk_name); + return -ENODEV; + } + + if (!disk_need_zone_resources(disk)) + return 0; + + if (!args->conv_zones_bitmap) { + args->conv_zones_bitmap = + blk_alloc_zone_bitmap(q->node, args->nr_zones); + if (!args->conv_zones_bitmap) + return -ENOMEM; + } + + set_bit(idx, args->conv_zones_bitmap); + + return 0; +} + +static int blk_revalidate_seq_zone(struct blk_zone *zone, unsigned int idx, + struct blk_revalidate_zone_args *args) +{ + struct gendisk *disk = args->disk; + struct blk_zone_wplug *zwplug; + unsigned int wp_offset; + unsigned long flags; + + /* + * Remember the capacity of the first sequential zone and check + * if it is constant for all zones. + */ + if (!args->zone_capacity) + args->zone_capacity = zone->capacity; + if (zone->capacity != args->zone_capacity) { + pr_warn("%s: Invalid variable zone capacity\n", + disk->disk_name); + return -ENODEV; + } + + /* + * We need to track the write pointer of all zones that are not + * empty nor full. So make sure we have a zone write plug for + * such zone if the device has a zone write plug hash table. + */ + if (!disk->zone_wplugs_hash) + return 0; + + wp_offset = blk_zone_wp_offset(zone); + if (!wp_offset || wp_offset >= zone->capacity) + return 0; + + zwplug = disk_get_and_lock_zone_wplug(disk, zone->wp, GFP_NOIO, &flags); + if (!zwplug) + return -ENOMEM; + spin_unlock_irqrestore(&zwplug->lock, flags); + disk_put_zone_wplug(zwplug); + + return 0; +} + /* * Helper function to check the validity of zones of a zoned block device. */ @@ -1666,12 +1734,9 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, { struct blk_revalidate_zone_args *args = data; struct gendisk *disk = args->disk; - struct request_queue *q = disk->queue; sector_t capacity = get_capacity(disk); - sector_t zone_sectors = q->limits.chunk_sectors; - struct blk_zone_wplug *zwplug; - unsigned long flags; - unsigned int wp_offset; + sector_t zone_sectors = disk->queue->limits.chunk_sectors; + int ret; /* Check for bad zones and holes in the zone report */ if (zone->start != args->sector) { @@ -1711,62 +1776,22 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, /* Check zone type */ switch (zone->type) { case BLK_ZONE_TYPE_CONVENTIONAL: - if (zone->capacity != zone->len) { - pr_warn("%s: Invalid conventional zone capacity\n", - disk->disk_name); - return -ENODEV; - } - - if (!disk_need_zone_resources(disk)) - break; - if (!args->conv_zones_bitmap) { - args->conv_zones_bitmap = - blk_alloc_zone_bitmap(q->node, args->nr_zones); - if (!args->conv_zones_bitmap) - return -ENOMEM; - } - set_bit(idx, args->conv_zones_bitmap); + ret = blk_revalidate_conv_zone(zone, idx, args); break; case BLK_ZONE_TYPE_SEQWRITE_REQ: - /* - * Remember the capacity of the first sequential zone and check - * if it is constant for all zones. - */ - if (!args->zone_capacity) - args->zone_capacity = zone->capacity; - if (zone->capacity != args->zone_capacity) { - pr_warn("%s: Invalid variable zone capacity\n", - disk->disk_name); - return -ENODEV; - } - - /* - * We need to track the write pointer of all zones that are not - * empty nor full. So make sure we have a zone write plug for - * such zone if the device has a zone write plug hash table. - */ - if (!disk->zone_wplugs_hash) - break; - wp_offset = blk_zone_wp_offset(zone); - if (wp_offset && wp_offset < zone->capacity) { - zwplug = disk_get_and_lock_zone_wplug(disk, zone->wp, - GFP_NOIO, &flags); - if (!zwplug) - return -ENOMEM; - spin_unlock_irqrestore(&zwplug->lock, flags); - disk_put_zone_wplug(zwplug); - } - + ret = blk_revalidate_seq_zone(zone, idx, args); break; case BLK_ZONE_TYPE_SEQWRITE_PREF: default: pr_warn("%s: Invalid zone type 0x%x at sectors %llu\n", disk->disk_name, (int)zone->type, zone->start); - return -ENODEV; + ret = -ENODEV; } - args->sector += zone->len; - return 0; + if (!ret) + args->sector += zone->len; + + return ret; } /**