linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] blk-throttle: Set BIO_THROTTLED when bio has been throttled
@ 2021-11-18 13:15 Laibin Qiu
  2021-11-29 18:16 ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Laibin Qiu @ 2021-11-18 13:15 UTC (permalink / raw)
  To: tj, axboe; +Cc: cgroups, linux-block, linux-kernel

1.In current process, all bio will set the BIO_THROTTLED flag
after __blk_throtl_bio().

2.If bio needs to be throttled, it will start the timer and
stop submit bio directly. Bio will submit in blk_throtl_dispatch_work_fn()
when the timer expires. But in the current process, if bio is throttled.
The BIO_THROTTLED will be set to bio after timer start. If the bio
has been completed, it may cause use-after-free.

Fix this by move BIO_THROTTLED set before timer set.

Signed-off-by: Laibin Qiu <qiulaibin@huawei.com>
---
 block/blk-throttle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 39bb6e68a9a2..ddfbff4465d5 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -2149,6 +2149,7 @@ bool __blk_throtl_bio(struct bio *bio)
 	td->nr_queued[rw]++;
 	throtl_add_bio_tg(bio, qn, tg);
 	throttled = true;
+	bio_set_flag(bio, BIO_THROTTLED);
 
 	/*
 	 * Update @tg's dispatch time and force schedule dispatch if @tg
@@ -2163,7 +2164,6 @@ bool __blk_throtl_bio(struct bio *bio)
 
 out_unlock:
 	spin_unlock_irq(&q->queue_lock);
-	bio_set_flag(bio, BIO_THROTTLED);
 
 #ifdef CONFIG_BLK_DEV_THROTTLING_LOW
 	if (throttled || !td->track_bio_latency)
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-06 19:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 13:15 [PATCH -next] blk-throttle: Set BIO_THROTTLED when bio has been throttled Laibin Qiu
2021-11-29 18:16 ` Tejun Heo
2021-12-13  9:24   ` QiuLaibin
2021-12-13 20:12     ` Tejun Heo
2021-12-14  9:12       ` QiuLaibin
2022-01-06 19:52         ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).