Linux block layer
 help / color / mirror / Atom feed
* [PATCH] block: validate QoS before calling __rq_qos_done_bio()
@ 2025-08-26 16:30 Nilay Shroff
  2025-08-26 16:34 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Nilay Shroff @ 2025-08-26 16:30 UTC (permalink / raw)
  To: linux-block; +Cc: ming.lei, yukuai1, axboe, hch, venkat88, gjoyce

If a bio has BIO_QOS_xxx set, it doesn't guarantee that q->rq_qos is
also present at-least for stacked block devices. For instance, in case
of NVMe when multipath is enabled, the bottom device may have QoS
enabled but top device doesn't. So always validate QoS is enabled and
q->rq_qos is present before calling __rq_qos_done_bio().

Fixes: 370ac285f23a ("block: avoid cpu_hotplug_lock depedency on freeze_lock")
Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Closes: https://lore.kernel.org/all/3a07b752-06a4-4eee-b302-f4669feb859d@linux.ibm.com/
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
 block/blk-rq-qos.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index 1fe22000a379..b538f2c0febc 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -149,12 +149,15 @@ static inline void rq_qos_done_bio(struct bio *bio)
 	q = bdev_get_queue(bio->bi_bdev);
 
 	/*
-	 * If a bio has BIO_QOS_xxx set, it implicitly implies that
-	 * q->rq_qos is present. So, we skip re-checking q->rq_qos
-	 * here as an extra optimization and directly call
-	 * __rq_qos_done_bio().
+	 * A BIO may carry BIO_QOS_* flags even if the associated request_queue
+	 * does not have rq_qos enabled. This can happen with stacked block
+	 * devices — for example, NVMe multipath, where it's possible that the
+	 * bottom device has QoS enabled but the top device does not. Therefore,
+	 * always verify that q->rq_qos is present and QoS is enabled before
+	 * calling __rq_qos_done_bio().
 	 */
-	__rq_qos_done_bio(q->rq_qos, bio);
+	if (test_bit(QUEUE_FLAG_QOS_ENABLED, &q->queue_flags) && q->rq_qos)
+		__rq_qos_done_bio(q->rq_qos, bio);
 }
 
 static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio)
-- 
2.50.1


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

* Re: [PATCH] block: validate QoS before calling __rq_qos_done_bio()
  2025-08-26 16:30 [PATCH] block: validate QoS before calling __rq_qos_done_bio() Nilay Shroff
@ 2025-08-26 16:34 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-08-26 16:34 UTC (permalink / raw)
  To: linux-block, Nilay Shroff; +Cc: ming.lei, yukuai1, hch, venkat88, gjoyce


On Tue, 26 Aug 2025 22:00:32 +0530, Nilay Shroff wrote:
> If a bio has BIO_QOS_xxx set, it doesn't guarantee that q->rq_qos is
> also present at-least for stacked block devices. For instance, in case
> of NVMe when multipath is enabled, the bottom device may have QoS
> enabled but top device doesn't. So always validate QoS is enabled and
> q->rq_qos is present before calling __rq_qos_done_bio().
> 
> 
> [...]

Applied, thanks!

[1/1] block: validate QoS before calling __rq_qos_done_bio()
      commit: e3ef9445cd9d90e43de0bd3cd55d437773dfd139

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-08-26 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 16:30 [PATCH] block: validate QoS before calling __rq_qos_done_bio() Nilay Shroff
2025-08-26 16:34 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox