From patchwork Tue Apr 30 12:51:19 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: 13648971 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 1E18F17164C; Tue, 30 Apr 2024 12:51:34 +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=1714481495; cv=none; b=PGkJhjau5dH0BSJ5CYHlmtgONNHME0Z9VGteW6r8oNziLJ86fFuMjRS0S0musxkMdhNc3KpXCjPyWnht9qdJtcVSXeRgJetF+iuNtx+cblwVMGJDfbCKyiewPMBKjh8RVSrzrXl7dM5dp7ePyeO9hUc1wRvMHYSiv29STZtMNPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481495; c=relaxed/simple; bh=ChfFb/6we4dypVrsro7WzU7smRAFTQaHLrdAlWc0GnU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsFXtBEpuJaFRn7WHvJzYxreLghi/yqoyQ4SdA7b79MVMkd2IiCA8QjieSAT+vYkAe5IZSQN7CTVISr8jekmNqdEw4ecfP3Z15HvWC2/YOKSga/QayMPoT9DJLYBOnzwlRqxjDoeKlAVo7DVNYKcfrWL8yOQ+7CB0AIwr/DJXGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VCnfH4tG; 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="VCnfH4tG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E20F1C4AF18; Tue, 30 Apr 2024 12:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481494; bh=ChfFb/6we4dypVrsro7WzU7smRAFTQaHLrdAlWc0GnU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VCnfH4tGmtLOZ7VVR7zk1CmBT+5HXFnkiOhdIXeJ5mPThg1EYY//SA9DM7bR9xRNP gNVbvpRK/PGF9IC3XQj7zpw/h8btDSON9QYxJeoK3FQaQyYoNQqTACm6IcbOgDKiYE K2Vr09QzXUJ5kYi6vCot06D3kJgox6S6ZmIpBBj9riUfBVMjcLEMUAdYiQZlQ6PkrF KrnUJitkDqU++rLid5RHmLFGLlugEqeQSIjd/+26Pb4fsrXKpmoSqypQ2qX2Q04kHr /W5KZ72dIbK3NlcBRa0+b93pnlQPcqYbT+sQy/5e6gvLSD7E+CRbdihiNSRJibJ+TT 6oRisWlLwA3Jg== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 01/13] dm: Check that a zoned table leads to a valid mapped device Date: Tue, 30 Apr 2024 21:51:19 +0900 Message-ID: <20240430125131.668482-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 Tue Apr 30 12:51:20 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: 13648972 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 E110A17164C; Tue, 30 Apr 2024 12:51:35 +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=1714481496; cv=none; b=uP/QOGmjdgFeKxLEzleB42y1N1fd3+3ECMGfHu8ck9PUPjBqKWQk9bN0S9gDMHHtfctJlSKEVRNXXUReFwncTCu8WP3Htsr27ofFUcvEC/LrU7trlVIeB1OMX3eVSItbAr8fWUYabuZ7mCzNrr2kqxrFDSEn+NbWeIrmVF7cSNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481496; c=relaxed/simple; bh=NkeWfqpZRcpRuri12wck+tEOdIlu09m2GlIdM9dPNyM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WqQGQMOGi2fl6O3nrmaKZ7UL2AorsJNs4LuaZhCihFRcE4GueXluLPn5pK/r1ZoVEaCzZD8jRaT6u0viemCpksZbJxusR3aYkMDILXwUiWtKzsAyOTeJgKquHKoqpMerVDFlhg4XhzzS7qUnAJ0JU4+wGVbQx3X9iG+bN+anJ0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hZ5qm3wP; 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="hZ5qm3wP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B1B5C4AF1A; Tue, 30 Apr 2024 12:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481495; bh=NkeWfqpZRcpRuri12wck+tEOdIlu09m2GlIdM9dPNyM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hZ5qm3wPtk/hoBrE4o/BqW1JfyHdlo+qyjtHrZ+yPCYkcQi2x2s2FL4JLiCGIligg 92zUtEwnndbJ6pcN/ut3Vvy9RpTGqgFwVc/1tUOfH0UUjUPwKeX5hOqE8G1YTChV/P wImMyAB2gSS09jlWgNiczdgI0NoleMMp87vxzKy4uhn3N5vFBSuTYpvZgwbYW3hOUN bMeqT+OujY942fpKgXtDAUoQmSxt/EI70yf0TxM3kwInFvI3nP6vyo+nzejYzCkVNB oNr9ZyYrqS7NHXRw/fkcfAU/451axi/azzbram6zIKfMkDCrk+KAoVTPkeS7eLCTlI fEWhlCIrweXzw== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 02/13] block: Exclude conventional zones when faking max open limit Date: Tue, 30 Apr 2024 21:51:20 +0900 Message-ID: <20240430125131.668482-3-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 Tue Apr 30 12:51:21 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: 13648973 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 606DB171096; Tue, 30 Apr 2024 12:51:37 +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=1714481497; cv=none; b=FMVHtKCdDpprLqbQlwd6eqkhgNKJQMALfJjd2VU4EmSxDgg3tSqKwtnd9tck76cjUBusSKNpjuL0GN0qz55X2x8xPEaswOhser3V8uBgprk9Quc4oa+QOqW1Vw4NYXCi2q6ZN7BpRjFMJVMnQcFVWNwfNFWNWrjqct2Jv/Iu0NU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481497; c=relaxed/simple; bh=3ybx/BNEekLRwwpxdz12dy3oj1tDPE+cNVEDl1YepSg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d0aRrtsPxsTIzzGIDr7gGyoanj2+ccduVp/X0cVKt8AXuZnfrDPH8Yr06DVlOnl2VzphqkCom0ScuiXMzHTVZMMCgc3oLKBor0+vx7e3KXvmNPCyn+mB6f7G5++xinITkPD//w9c/uugsYDNH1M1XoLu2qBMRwB5btbkS06EcSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BJLhoOgF; 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="BJLhoOgF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D005C4AF18; Tue, 30 Apr 2024 12:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481496; bh=3ybx/BNEekLRwwpxdz12dy3oj1tDPE+cNVEDl1YepSg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BJLhoOgFpLQEgLa0Lisd5HhjsI+qPVi2F097UtJT9u0F8ADj6BZaccVuf6sabGp9s 7ZIQ3FZzFTn2/dbIpDqLfjYVfgRCxw5bpxh1XRDAJZ9wo6Nlz4Dr7FJvGoO6UryT9K liiCSVUWorumoaBxKpwUwFthLfd2xOkU3kzCvjPnaU2nKqEYdcNfM2GpZLDnVVM62x tXjM7sA3ciuT8ft78IvZ+QZ3E6gZAiF7+h2+mX5ylU9he6tphyEcoeHEO8bV/4n7S+ llcW63ZSxKy9liPxT8BUvXl4EF4/YOw2L9yNLvM7rjh+mPbxyKfY0IXPzi9kL7Xjs6 C+QLUaJXB+wpA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 03/13] block: Fix zone write plug initialization from blk_revalidate_zone_cb() Date: Tue, 30 Apr 2024 21:51:21 +0900 Message-ID: <20240430125131.668482-4-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 Tue Apr 30 12:51: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: 13648974 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 777C1171096; Tue, 30 Apr 2024 12:51: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=1714481498; cv=none; b=bSwjigDKomAGodhsEFneHZkxka3raYeiY2a/54BGxEC9qknv3VVReC/g4SA32wLSzCdj6lPwVlQHiIDp6MQMQwHFFxKoBGAGbRMhbaiJgKBJLcGp6mIV4S73mGlIUnCpdxgtaYAfGxz3Knh+6Nd2MUpI3YSPQpSat8hpRazz6MI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481498; c=relaxed/simple; bh=cYF0XCVNaKjlif5lITJ69C3QuZHOBKVEAIwcOsZ0T2c=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DZrUjlCH6QDzsB6OIdVXFjQjvpCMnISsGIlPp+0FXdKTjBrTx4e/4HTN+dUqYPmnLRSsLwrEomRX7Y16ZSRRHfInYDE9mSuIOwxFUs8o1ATk1dupSH3Jmx9bTiue1x1xwLg5zdcRW8UMHb1TWXkzvnI/VqvOeU3dXZjxG3uWpqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iK8rjibE; 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="iK8rjibE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F44BC2BBFC; Tue, 30 Apr 2024 12:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481498; bh=cYF0XCVNaKjlif5lITJ69C3QuZHOBKVEAIwcOsZ0T2c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iK8rjibEgR+MpHYsDzLnIPZAbGundvGWASxah1oyyy22S9lQ2uK2zBk1AoeG9NnIr K1AIwpoJOlV+33Mx5D/mANSbwWAEwk2BHbnp6AHaDsI6dmo4WWKqFoWNKtFXI6sd24 TvjUT4AwXKOhK0pBm39/fGYTLz8Lp9orSNVm52Z4c51VMUy4IFKGKuGjSjU7sBicdd Xu5g17D4wUcICV3whFqOiQfa7BZVs1GtONKy1wE5hB5lCuTBZZCfhNP6xLp4VKsgHr p/Hq/x71AguKRaQJixFrG/DPSNRiCEepQHjt9nWPG0i1SpWBBBYZKf7utc2fYnnjcP e0Yw44MNz5k6A== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 04/13] block: Fix reference counting for zone write plugs in error state Date: Tue, 30 Apr 2024 21:51:22 +0900 Message-ID: <20240430125131.668482-5-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- block/blk-zoned.c | 74 ++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index e92ae0729cf8..9bded29592e0 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -658,6 +658,53 @@ 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) +{ + if (!(zwplug->flags & BLK_ZONE_WPLUG_ERROR)) { + unsigned long flags; + + /* + * 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) +{ + if (zwplug->flags & BLK_ZONE_WPLUG_ERROR) { + unsigned long flags; + + /* + * 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 +738,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 +927,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 Tue Apr 30 12:51: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: 13648975 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 547E5171E40; Tue, 30 Apr 2024 12:51: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=1714481499; cv=none; b=F+/jXV8SdCxTpYeaslWiGS1+Btfa7fw9QAYTS4DlsTTsCgy1nFc1uVwCEpeLAKlTrNKuJFymE70QdsO2kgVGRaEDQKPp2nZBz+zVkeBzTI2Rts9yvCz3vhYMFHBlrAhli+htyR/NW3EamCv7J7hhOdZjLgkBrnFkoSmFqGeKuT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481499; c=relaxed/simple; bh=Lcxo+nJbtOj+dBCmtGlyawY7aPkYfCV2KhusyQ8HWSA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PmcDslyhvnwiPX+EAmEnjMUwUButUSRKou1VPb22fyMW3pu6kjraNd3bxRPh3tzuhOS93x/pIokLUgqWvwUqEXlApkpQ2h5mAuXHZxo2/A6wMEWITg/F2XjZzuJZqgIrnP7BYJhPF3kKjZmUjDw+d6p3HBFHeufqMGcAGtwSdSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tMDxgtF6; 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="tMDxgtF6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7350BC4AF1A; Tue, 30 Apr 2024 12:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481499; bh=Lcxo+nJbtOj+dBCmtGlyawY7aPkYfCV2KhusyQ8HWSA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tMDxgtF6V0cjqUvLRt4LpFVQ6nyk8THAKQm65pr7qEJyQO0kPIRcS6137aIYnEvwY YLW5kWFzqMloSNSj5rYKjtl9dg4r7nKJCWJO07g5OduWjPpAgJFLcNRje9g4LQEBZB YWvekfTFshder6QIWclK0CnddZT9qfRkE/sGBG3gaej7IDbaAbNEItQgF4I0fcUAei DquoEjEYCk7ZOOM37AyhmiF0aUmYdt0mx5jUiPDDzgnJztdJedcCu4rgRgXdeYZ+ZG 1w9rMS3IfeSEjgiHVo8qsEBXghyU3gvLBCJOTBxJMM9IlAZG6iiA/1PifPa4h5VEvM DJlpKlAI6W6UA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 05/13] block: Hold a reference on zone write plugs to schedule submission Date: Tue, 30 Apr 2024 21:51:23 +0900 Message-ID: <20240430125131.668482-6-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 9bded29592e0..03555ea64774 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1131,6 +1131,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) { @@ -1150,8 +1163,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; } @@ -1251,14 +1264,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); @@ -1274,6 +1287,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) @@ -1353,8 +1370,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 Tue Apr 30 12:51: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: 13648976 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 70774171E40; Tue, 30 Apr 2024 12:51: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=1714481500; cv=none; b=hO22bAfZKuKrLiCpJs6KWHTrKQ6WsV8LD47UBzFsI30aSD2KLIxFIAz7Jw0Ytv5WMHJgf+T6LK0cDjrDvuB62kDpuMx/fvClvS0Ia//YbS4WfFXjwa/rzHyw1WMoHJvWf5Oeg5ZDfOxUptZt+qtWueowNfLaMh1gf4iCHW0T25E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481500; c=relaxed/simple; bh=57RelSjjutDoHKvK1Hjat/0nCTLphGOX+8KB7rI6lzg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Um/O6g1qw12Xm7fcLNAWjNjaOWnIXO/kHaTd2eXhD95jkTulCh1OdNFZoq7tabDXTG7YrvJPmz29Zy7B5qSP0h6cMDnrW0rftUl40ztNvxxx3Vh/GAxoSan7fQaff/QF/kITpjfTL7kprTKKafzHz/74V8Wzjf4+9ZzBqYQcWNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z8jF2N08; 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="Z8jF2N08" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96B58C4AF19; Tue, 30 Apr 2024 12:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481500; bh=57RelSjjutDoHKvK1Hjat/0nCTLphGOX+8KB7rI6lzg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Z8jF2N08xG+EWjkEIaAx9i2LsFRMBmkfDNHZ8tE17J/2uirYAeN55121Ap2WVhrJg mcBeDbmYKtOBe2r92x7yOfi7FRUFgd81ztWse2s27NORjg+vK1zoxPJ3bykvuQ3pp1 hcQgnr4qrcTtLvXq+Uq0xQMHXTtl8vNrlyIYZWEE38BNKLObHw0wpJHN048pFESg1m 5yw1uFZ2tfjYracRcZCV6XyNqu8PWJ9DAb/l12FwdD0LZluOFcTjzyaLctHaFUHM4T K29iNgghYDwViul4xJPDbZJUU/1Q7cNZMcUZEsyY0Jr/TlMIwto10ILAyaWx2hPHZA +uPsVGQkhG5cQ== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 06/13] block: Unhash a zone write plug only if needed Date: Tue, 30 Apr 2024 21:51:24 +0900 Message-ID: <20240430125131.668482-7-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- block/blk-zoned.c | 54 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 03555ea64774..82e540dad900 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,42 @@ 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) +{ + if (!(zwplug->flags & BLK_ZONE_WPLUG_UNHASHED)) { + unsigned long flags; + + /* + * 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 Tue Apr 30 12:51: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: 13648977 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 977E6171641; Tue, 30 Apr 2024 12:51: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=1714481501; cv=none; b=m3WCHFttwTa/u2ngDnKAQ5a5LJKUXzACve1g52sSMaxLzHgOncv4xtTwx+5RNi1pgkfuPyXlZyN71ZEPBU5+s/ELS74xkYDO+XQFryvsLZMGFfKah0IeXJeIC2N0plqZfkwwK61AqIfWCGpGwUqn4n3EIudZbj/n/G9uS3K8zLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481501; c=relaxed/simple; bh=bhWcMqFFHVFC0hty2uVdf+vbsbPqs2/3RINkXh6NZ88=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iSNvEg5vyIqu8UiM4u2u3uAajX50bptJw/humPapZQlxMja9EFW4Wy8VnLzSaAAAEn4FfYbzC+EhYqMGDqjZDLrw3oKScDuFHEWiYiiem09MkSxEcJaLfsSc8I2nVPSWSuupDqFQKIIOVxapitmxl3mE9+5Vp2v8o8EcS2ahWDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bxbkWWBU; 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="bxbkWWBU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2FF3C4AF19; Tue, 30 Apr 2024 12:51:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481501; bh=bhWcMqFFHVFC0hty2uVdf+vbsbPqs2/3RINkXh6NZ88=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bxbkWWBUOzv+cKOBxf3N/ITk+tYAVrXsC1P1Wbu7kr/6wJyg8Y1B1gg8VwfLPyHEY FuluROY4iaQGmaSiEFyoKcLUTPoXs1CIRJ3XRbxXSnBlL+EVvuSupKhhCbJxnAXxvD rsvLPW3BgR70FyNXm3jLH6J5oWf/VeMNro13dmIVIaJbiwcRG+N1FC7chI1+1mMWYY 6R+mLiGh5We5oSm4GhT7LOweypswTqgun3+XJgTTsne0lufQ7MWyF3yP5ll1r1Wf30 U0QmTLlv1dSVEwmf5UpeLH3040OKbicuaI6Vlm8ojCZ+bE1+JyXSqObeBhK82fLgoS UIBOoFHFOUQtg== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 07/13] block: Do not remove zone write plugs still in use Date: Tue, 30 Apr 2024 21:51:25 +0900 Message-ID: <20240430125131.668482-8-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 tergetting 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 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 82e540dad900..5792e3b160c9 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -520,8 +520,9 @@ 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 (zwplug->flags & BLK_ZONE_WPLUG_BUSY) + /* If the zone write plug is still busy, it cannot be removed. */ + if ((zwplug->flags & BLK_ZONE_WPLUG_BUSY) || + atomic_read(&zwplug->ref) > 2) return false; /* We can remove zone write plugs for zones that are empty or full. */ @@ -891,8 +892,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; @@ -1221,6 +1223,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 @@ -1229,8 +1234,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); } @@ -1244,13 +1248,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 Tue Apr 30 12:51: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: 13648978 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 15D1A17109F; Tue, 30 Apr 2024 12:51: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=1714481503; cv=none; b=q8Hr+/HJ7hmqj+Hu/QVvk+d8b9u7rHkhFFoJQup9xB5gplCKkiJmnK51fupS904kebUdIwcPW5Zi2O9WI0s1T0VrGrlnhvc/CaSvkTI/YZ9kbpIvwCJ1XQv0LxobkRJmqd1svJ5gH/NpB2IRBwsVYH6ixMvnW8981GfHChTrCII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481503; c=relaxed/simple; bh=ra5cLPnbdrCAEFvfPA09kUSW6ZiM7XRDEYo3QaLJJXM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nptF9DBclomqdFzxMzyToVFckxCx/mLUKPppo/g/bxqkTLdU+JjPKG361DdhVguApy9PBockbJVIUYPqJ5hT29qsfEJ36D9hRjGu6zPR13Q5bMXk8wjBzgDUKcOe6r1BBTFnFRa7TakTqBwSv3nRSSBADsWG/SS2y47dVqX/0zw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nhQTR5HM; 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="nhQTR5HM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D69B1C4AF19; Tue, 30 Apr 2024 12:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481502; bh=ra5cLPnbdrCAEFvfPA09kUSW6ZiM7XRDEYo3QaLJJXM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nhQTR5HMxUhKdzK+QywpN1kip96bGArGhV1P8nslAdmcGrB7xCdeS4K8P/MhJXURX qL9KaATlqn+iLirfUYmXI9jf3A/5VDrvZ4P/0KVjyPk5kFgBty1ou5UHe/L8Fkyuiq /cS4k+/6xjucGZm/p8Ky6WrhGvdVFUoSy1MTiAZpvv+EOCOELEvcaeZ1i1Lk0wKduf MMvW6A8vWEjcTPOoOdlMw4hqnbMOukApXHCR+evJ/Ew9LxcN4a3cV+CYt0cKp0Os9U BrWeWghK/i6J5G4KSG1G+GBk8qRYFGEtlBWQO9IAnvfZ1osf9v73xTtWVWBFGJjz2d /Bwx/ypVDq0sg== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 08/13] block: Fix flush request sector restore Date: Tue, 30 Apr 2024 21:51:26 +0900 Message-ID: <20240430125131.668482-9-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 Tue Apr 30 12:51: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: 13648979 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 DB01C17109F; Tue, 30 Apr 2024 12:51: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=1714481503; cv=none; b=BzZNqJ448q2M0ff1GjuUXCybi5UlW7TWdGeWQ0t+vr8QmPnPYOWAV7dbez2a7iqQlXAn111hgYQsIRYR0zc60SO0ezPPfH2MpAdklIqhpIW1CRlNudOyM9MLZkf8rvH6bC7BgUiktOpdpPFIs+cTzfZZaGLDQklXMkY04MVPgGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481503; c=relaxed/simple; bh=Av8XEoFDDpdwTJ5LkNvF3ib8RqhGqorNq5wAI1QemRc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CQeZNqOe1TGhzybbnIFqZVgP+6n93uZOuoPwvCi+zdtcw5MdafgXJc2NtM6jrKHynkiixdcsK8sPV5NKqPliGcomYXZoJ+UWINVfz3gzJp1JOukrq/Yf9bKQCxJq3GZ1LKQxe7SRDk9pvXe/GUm89t+BqwIpUVQ6ff/QGL9qdXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j5n0VuwO; 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="j5n0VuwO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05CB1C2BBFC; Tue, 30 Apr 2024 12:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481503; bh=Av8XEoFDDpdwTJ5LkNvF3ib8RqhGqorNq5wAI1QemRc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=j5n0VuwONMCELoG367qRQ8Uj4K1ugDDhNk1baGr1+/nytTBZeHnHuZhWNXIE622xL UNKXdOWonRfoF3euJ7fn4FJy4PbXwys05hXebmC2ZAHuEA8bSDoBs5Ofzppg12k5lu DTAU5tLgiGrpHDRnV6vM6hZ8FOi3sPTvGFs6RQ0835hsNbfCmMf03LKCJTuZBKWRyQ dShpIXNp+OBezygcNWvhMvzbmLSNBjlUDZJx2rlHgJ9keC1zKGmFF5SAbTcbxgt0I4 DKwREuTe6AZWAXHC2R75hli0fsYC/GqIp5ZysYDHuTfe54jEhQJHEtzp3xfJQoM6zX du2LercapZASw== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 09/13] block: Fix handling of non-empty flush write requests to zones Date: Tue, 30 Apr 2024 21:51:27 +0900 Message-ID: <20240430125131.668482-10-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 5792e3b160c9..b551fe4e684f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -855,8 +855,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)) @@ -880,7 +881,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; @@ -891,6 +892,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 @@ -1250,7 +1254,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 Tue Apr 30 12:51: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: 13648980 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 0BEE5171641; Tue, 30 Apr 2024 12:51:45 +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=1714481505; cv=none; b=GUA5eEtQR+s//7z6HKIlx2dx3J6+wfVMh1jskh/izzCad3keAZ9qqjuW2kCDU4RRia2VYZTBhxSei0dcLn9+vO5EYGw+J8dgvcFKMNukdrq8EIf8fXDWnJRjxTfgNCX1NFoh7hThSVPkOVGoein7EpK7D+MgJPjuc+2oQATuNHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481505; c=relaxed/simple; bh=rxcDOJchV0H2cRWow4MQwLCQK/4ZMh+ro+93jdcguss=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5ERftxUgF+2gd75qkc1kPZoA0GoQHJFOFZ2OTcbwI7EedRdKgB3925SmCW7gE2kuB/wy/FnfWLj+BB25Kfcc7+pxtJJMAh9/ZJfYr5MAqZd1O88ILIk6LDmHUyPHgeIivtzG+476LtZoC4aogusNSmKBfMs8UL9+HmdPld7q0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nU2OTN7q; 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="nU2OTN7q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27EADC4AF1A; Tue, 30 Apr 2024 12:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481504; bh=rxcDOJchV0H2cRWow4MQwLCQK/4ZMh+ro+93jdcguss=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nU2OTN7q3G0OABTW4bLbTGHaYL0Y4jkJL8IvwMMhUvmB4QjJXL5mIpsWgjPi75PRm TaanVCFJOmKXMEQMbZV9Mr8V58oRYb0OOgxjjEuY/y2QHM4LcBzMZW2vG106BhXD2g R7xdm6BM5gxIqxEHG0yIRqJZSVyIukxxcetYrPs1qQ6Ue+eFHPWDE6EUZf97fu/Iol jn/ke7G8HBqXPCD+c1SBAbMK/OJHZJsyc1nWwKxae8rt4CuUKO7CF7ZLRlzKjsO8SN beEKRn3o+LNyPTzJuV01Su0uhAQmg8bRbXsU8o8nskdD4LHlHLmVXt7qrZa1L8ZK1/ IEpA96Y1DYVxg== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 10/13] block: Improve blk_zone_write_plug_bio_merged() Date: Tue, 30 Apr 2024 21:51:28 +0900 Message-ID: <20240430125131.668482-11-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 plugi 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 --- 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 b551fe4e684f..d962ba7c9ae1 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -866,11 +866,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 Tue Apr 30 12:51: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: 13648981 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 8A1C013CFA0; Tue, 30 Apr 2024 12:51: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=1714481506; cv=none; b=M6LtQzA36mbKqoDd7/RRy2tThRJs53UdXdwXwT5CnMXlHGHxEZeR5ioXJK7ICZNf9BDJRukxFk1prRRucFL3VyQNUjZ4Fbw45YQKE8OQeZw0JqWYALui+PXUCyQVsc44VQPBzilltiemrfsZwXgr9b+AvbZPQJsl17Byqh9wUps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481506; c=relaxed/simple; bh=zWCBQX5xIG5+9dYZKYbqfTHDPqTpZPTih+lmg8lWlFA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cR6pFjSDaMfeiPOL5Pz7rqf1lN1Y0jgqG6l2J+1D9RK9jfSQdwQzS1x9NOYnQwVStt7DZFIJIn6hLUJug3g23SKdp/agmv9wdc2g4XcI/n5zlmrUlJQ26f0mSaT3QC5dsMcPjgfi2/EGTOM+qzPdAqs59lYaYkF2cPFs38mjQNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i01wZ2Pk; 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="i01wZ2Pk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C333C4AF1B; Tue, 30 Apr 2024 12:51:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481506; bh=zWCBQX5xIG5+9dYZKYbqfTHDPqTpZPTih+lmg8lWlFA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i01wZ2PkUaAKDz+d+HrnvzBg6G8mKjBovWnuZfPXQuaRWcr8HoaQPNk7T9O36ieSz sqCMEzy1VgryLboXaKVMuQyU5QSS4M3+XX488Xue/lsLrjFHgK28CisMXDvmoEbtHE Z+OyBIWSi76s6Jld/ASCjNlTD7sLdf1tEnGyt5udwcScDrlfee8u9XiGsgO6bl8jaW Xsp/pP2paZXC3z9Sqx9kAWqnBs4Zks7HFm/mrg4JOcnucb8Qa9bYofKsGDMrVzVD0x Pcmphu14evKKnkZUaDe0Iih8RnLrJGo9mMgoSoPkuQOzvA6fZX4mhEHKOGwgRzga8T 1OBw2mW64hgvQ== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 11/13] block: Improve zone write request completion handling Date: Tue, 30 Apr 2024 21:51:29 +0900 Message-ID: <20240430125131.668482-12-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- block/blk-mq.c | 6 ++---- block/blk-zoned.c | 9 +++++---- block/blk.h | 8 ++++---- 3 files changed, 11 insertions(+), 12 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 d962ba7c9ae1..0047fe66f22d 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -902,7 +902,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; @@ -1236,7 +1236,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. */ @@ -1247,11 +1247,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 Tue Apr 30 12:51: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: 13648982 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 952C0171E7D; Tue, 30 Apr 2024 12:51: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=1714481507; cv=none; b=O5MeUfhhhUy/FQEy+OW9B0JkPP5z/ZfuWF4O8LyY0pFrBtkprjfn6nI+qFYTO7Twn0dck2doVoXS8uYCp4gdhrMaJISISJiEXm6LnsTdTVTApF4aYjq73cYn4yU0wljUMkwmjgd7toPm8K2oH245HpIvnAkDvVPsYU7vcBarKO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481507; c=relaxed/simple; bh=qT5FV1wDyuIbJOJEkkk63B+2mhbo22ZqrX0h70L2NUY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tJh+R0euvrPo6VZNDmLu3PUqpNaZ5cs1p8TGMvDsKPDxsFtokmhkLeNa4/aM5nuBOSyA+KYc5UVE6+gNjQo+j7yrMBYyIN0XtZU/8UuGCkpt3L9tV5x2KPUSp7CXKDKD+mm+AwFRmAElU4PK61cDATXQDYgnTkvTQM0x/qWyeKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t21A7kFi; 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="t21A7kFi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F2CAC2BBFC; Tue, 30 Apr 2024 12:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481507; bh=qT5FV1wDyuIbJOJEkkk63B+2mhbo22ZqrX0h70L2NUY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t21A7kFiWgWUK+NSTr0SybzpNBO8rwbvKI+u/GvsHn5iZAT7E975OK3gv7zO09vx4 VWd9z+5nE7R3LFOd/AY+a88LYlRiVdbMnbp+Pyrhsvwdnn6ybqDc6ltMWGQKawsSC9 vElkfPNIE72TKWJasvhL37W/TW5AFy0OMhlAjbFN3m4LphNvW3DgNduHWKq78fbiSN 4qo5F1VWJyvAvhaXvFS7A8urpJejBe1Whdwv2kexRp8sIGYRJQdP4uScI+wlUCwLF2 HGObLQ6M+zfIQurWbxItFwx1GFUwgwj3uSAmutyjvqOYjO5bxFXw9A1wppiioiVMVt qf71+V9VflKsw== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 12/13] block: Simplify blk_zone_write_plug_bio_endio() Date: Tue, 30 Apr 2024 21:51:30 +0900 Message-ID: <20240430125131.668482-13-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 0047fe66f22d..c819e3cc7a20 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1203,8 +1203,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 Tue Apr 30 12:51: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: 13648983 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 7A55B172786; Tue, 30 Apr 2024 12:51: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=1714481508; cv=none; b=l4kfPZiLjcj5vNJ4Oz2QqDOlMQGEnsDPY93N2oNdjLONoxp2KuDGc0EdostDA/08U1kH4dlj5BU1kagfOU3EfaNRWRQVc+a9UnzPctj2bknbTWaFTDK/23cNMvR62/QGi7tgr15FTv8Wjki1WOwCpqnIgHRv1Bykar7PjOlX3o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481508; c=relaxed/simple; bh=MRdsW+P27msNbM9tQINbf8dXSKB5x61YZFCUVVelG0s=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cu2WIk0d64GBkeeieeNMv4r6SPkS3/Hs0J99XoNI66Ohbzx8zRmNW4klHiGXYxPh9OKEK/ijbKqZwzwZQ2pTmcWJkD/YJZGSN+h+x90yZJSqlibaIOoHTcoVNoQZWG6Hd+URuWN17uaqkaPQYMnlUTv9sZRawcne151yvHC1iKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c+c0XlHH; 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="c+c0XlHH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 913D6C4AF1A; Tue, 30 Apr 2024 12:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714481508; bh=MRdsW+P27msNbM9tQINbf8dXSKB5x61YZFCUVVelG0s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=c+c0XlHHCFAY3y7MdcnsytME+c7zoExZBJc36mzxXfobcxFBvf3bbsp+10sISLbyN wUtOm31n+fUVNN0iyxixEbahBWhqOKIRICR0lfE6HR1/TMD/wyQh8qiSMxLMi8YBy9 J8QMdhff6QwkFgrVD8YYVOJIxCnXLVS8teSZ3BPcfNPQozHJ5CmRm+SNBqAhEBWzg8 ItNCD6Gv3Uj5umlql5BtQwx80Y5mniiZtWnEqaVQD3wRZ2YJ7FlrWzqwsQAtNKIW6P US7ckcadrwnHVVO7VqxgqXV5i7dqPs8nNn+C0xKLTVUzaMaCwAWJlXKvrmpoHvQ2OJ ww+UuDTqvD5SQ== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , dm-devel@lists.linux.dev, Mike Snitzer Subject: [PATCH 13/13] block: Simplify zone write plug BIO abort Date: Tue, 30 Apr 2024 21:51:31 +0900 Message-ID: <20240430125131.668482-14-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430125131.668482-1-dlemoal@kernel.org> References: <20240430125131.668482-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org 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 --- 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 c819e3cc7a20..ed180fdf66f4 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -616,12 +616,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); } @@ -632,10 +634,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); } /* @@ -655,8 +655,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; }