From: Damien Le Moal <dlemoal@kernel.org>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Subject: [PATCH v4 2/8] block: fix zone write plugs refcount handling in disk_zone_wplug_schedule_bio_work()
Date: Fri, 27 Feb 2026 22:19:45 +0900 [thread overview]
Message-ID: <20260227131951.2464150-3-dlemoal@kernel.org> (raw)
In-Reply-To: <20260227131951.2464150-1-dlemoal@kernel.org>
The function disk_zone_wplug_schedule_bio_work() always takes a
reference on the zone write plug of the BIO work being scheduled. This
ensures that the zone write plug cannot be freed while the BIO work is
being scheduled but has not run yet. However, this unconditional
reference taking is fragile since the reference taken is released by the
BIO work blk_zone_wplug_bio_work() function, which implies that there
always must be a 1:1 relation between the work being scheduled and the
work running.
Make sure to drop the reference taken when scheduling the BIO work if
the work is already scheduled, that is, when queue_work() returns false.
Fixes: 9e78c38ab30b ("block: Hold a reference on zone write plugs to schedule submission")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
block/blk-zoned.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 6e3ef181e837..7aae3c236cad 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1154,13 +1154,17 @@ static void disk_zone_wplug_schedule_bio_work(struct gendisk *disk,
lockdep_assert_held(&zwplug->lock);
/*
- * 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.
+ * Schedule the submission of the next plugged BIO. Taking a reference
+ * to the zone write plug is required as the bio_work belongs to the
+ * plug, and thus we must ensure that the write plug does not go away
+ * while the work is being scheduled but has not run yet.
+ * blk_zone_wplug_bio_work() will release the reference we take here,
+ * and we also drop this reference if the work is already scheduled.
*/
WARN_ON_ONCE(!(zwplug->flags & BLK_ZONE_WPLUG_PLUGGED));
refcount_inc(&zwplug->ref);
- queue_work(disk->zone_wplugs_wq, &zwplug->bio_work);
+ if (!queue_work(disk->zone_wplugs_wq, &zwplug->bio_work))
+ disk_put_zone_wplug(zwplug);
}
static inline void disk_zone_wplug_add_bio(struct gendisk *disk,
--
2.53.0
next prev parent reply other threads:[~2026-02-27 13:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 13:19 [PATCH v4 0/8] Improve zoned (SMR) HDD write throughput Damien Le Moal
2026-02-27 13:19 ` [PATCH v4 1/8] block: fix zone write plug removal Damien Le Moal
2026-02-27 13:44 ` Johannes Thumshirn
2026-02-27 13:50 ` Christoph Hellwig
2026-02-27 16:44 ` Jens Axboe
2026-02-27 13:19 ` Damien Le Moal [this message]
2026-02-27 13:19 ` [PATCH v4 3/8] block: rename and simplify disk_get_and_lock_zone_wplug() Damien Le Moal
2026-02-27 13:50 ` Christoph Hellwig
2026-02-27 13:19 ` [PATCH v4 4/8] block: remove disk_zone_is_full() Damien Le Moal
2026-02-27 13:19 ` [PATCH v4 5/8] block: rename struct gendisk zone_wplugs_lock field Damien Le Moal
2026-02-27 13:19 ` [PATCH v4 6/8] block: allow submitting all zone writes from a single context Damien Le Moal
2026-02-27 13:45 ` Johannes Thumshirn
2026-02-27 13:19 ` [PATCH v4 7/8] block: default to QD=1 writes for blk-mq rotational zoned devices Damien Le Moal
2026-02-27 13:19 ` [PATCH v4 8/8] Documentation: ABI: stable: document the zoned_qd1_writes attribute Damien Le Moal
2026-02-27 16:45 ` [PATCH v4 0/8] Improve zoned (SMR) HDD write throughput Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260227131951.2464150-3-dlemoal@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox