public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: ensure we hold a queue reference when using queue limits
@ 2024-01-12 16:15 Jens Axboe
  2024-01-12 16:46 ` Christoph Hellwig
  2024-01-13  2:05 ` Ming Lei
  0 siblings, 2 replies; 4+ messages in thread
From: Jens Axboe @ 2024-01-12 16:15 UTC (permalink / raw)
  To: linux-block@vger.kernel.org; +Cc: Christoph Hellwig

q_usage_counter is the only thing preventing us from the limits changing
under us in __bio_split_to_limits, but blk_mq_submit_bio doesn't hold
it while calling into it.

Move the splitting inside the region where we know we've got a queue
reference. Ideally this could still remain a shared section of code, but
let's keep the fix simple and defer any refactoring here to later.

Reported-by: Christoph Hellwig <hch@lst.de>
Fixes: 9d497e2941c3 ("block: don't protect submit_bio_checks by q_usage_counter")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f57b86d6de6a..e02c4b1af8c5 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2964,12 +2964,6 @@ void blk_mq_submit_bio(struct bio *bio)
 	blk_status_t ret;
 
 	bio = blk_queue_bounce(bio, q);
-	if (bio_may_exceed_limits(bio, &q->limits)) {
-		bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
-		if (!bio)
-			return;
-	}
-
 	bio_set_ioprio(bio);
 
 	if (plug) {
@@ -2978,6 +2972,11 @@ void blk_mq_submit_bio(struct bio *bio)
 			rq = NULL;
 	}
 	if (rq) {
+		if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
+			bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
+			if (!bio)
+				return;
+		}
 		if (!bio_integrity_prep(bio))
 			return;
 		if (blk_mq_attempt_bio_merge(q, bio, nr_segs))
@@ -2988,6 +2987,11 @@ void blk_mq_submit_bio(struct bio *bio)
 	} else {
 		if (unlikely(bio_queue_enter(bio)))
 			return;
+		if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
+			bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
+			if (!bio)
+				goto fail;
+		}
 		if (!bio_integrity_prep(bio))
 			goto fail;
 	}

-- 
Jens Axboe


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

* Re: [PATCH] block: ensure we hold a queue reference when using queue limits
  2024-01-12 16:15 [PATCH] block: ensure we hold a queue reference when using queue limits Jens Axboe
@ 2024-01-12 16:46 ` Christoph Hellwig
  2024-01-13  2:05 ` Ming Lei
  1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2024-01-12 16:46 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block@vger.kernel.org, Christoph Hellwig

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH] block: ensure we hold a queue reference when using queue limits
  2024-01-12 16:15 [PATCH] block: ensure we hold a queue reference when using queue limits Jens Axboe
  2024-01-12 16:46 ` Christoph Hellwig
@ 2024-01-13  2:05 ` Ming Lei
  2024-01-13 15:38   ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Ming Lei @ 2024-01-13  2:05 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block@vger.kernel.org, Christoph Hellwig

On Sat, Jan 13, 2024 at 12:15 AM Jens Axboe <axboe@kernel.dk> wrote:
>
> q_usage_counter is the only thing preventing us from the limits changing
> under us in __bio_split_to_limits, but blk_mq_submit_bio doesn't hold
> it while calling into it.
>
> Move the splitting inside the region where we know we've got a queue
> reference. Ideally this could still remain a shared section of code, but
> let's keep the fix simple and defer any refactoring here to later.
>
> Reported-by: Christoph Hellwig <hch@lst.de>
> Fixes: 9d497e2941c3 ("block: don't protect submit_bio_checks by q_usage_counter")

The fixes tag is wrong, and it should be:

Fixes: 900e08075202 ("block: move queue enter logic into blk_mq_submit_bio()")

> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>
> ---
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index f57b86d6de6a..e02c4b1af8c5 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2964,12 +2964,6 @@ void blk_mq_submit_bio(struct bio *bio)
>         blk_status_t ret;
>
>         bio = blk_queue_bounce(bio, q);
> -       if (bio_may_exceed_limits(bio, &q->limits)) {
> -               bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
> -               if (!bio)
> -                       return;
> -       }
> -
>         bio_set_ioprio(bio);
>
>         if (plug) {
> @@ -2978,6 +2972,11 @@ void blk_mq_submit_bio(struct bio *bio)
>                         rq = NULL;
>         }
>         if (rq) {
> +               if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
> +                       bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
> +                       if (!bio)
> +                               return;
> +               }
>                 if (!bio_integrity_prep(bio))
>                         return;
>                 if (blk_mq_attempt_bio_merge(q, bio, nr_segs))
> @@ -2988,6 +2987,11 @@ void blk_mq_submit_bio(struct bio *bio)
>         } else {
>                 if (unlikely(bio_queue_enter(bio)))
>                         return;
> +               if (unlikely(bio_may_exceed_limits(bio, &q->limits))) {
> +                       bio = __bio_split_to_limits(bio, &q->limits, &nr_segs);
> +                       if (!bio)
> +                               goto fail;
> +               }

With "Fixes" tag fixed, the patch looks fine:

Reviewed-by: Ming Lei <ming.lei@redhat.com>


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

* Re: [PATCH] block: ensure we hold a queue reference when using queue limits
  2024-01-13  2:05 ` Ming Lei
@ 2024-01-13 15:38   ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2024-01-13 15:38 UTC (permalink / raw)
  To: Ming Lei; +Cc: linux-block@vger.kernel.org, Christoph Hellwig

On 1/12/24 7:05 PM, Ming Lei wrote:
> On Sat, Jan 13, 2024 at 12:15?AM Jens Axboe <axboe@kernel.dk> wrote:
>>
>> q_usage_counter is the only thing preventing us from the limits changing
>> under us in __bio_split_to_limits, but blk_mq_submit_bio doesn't hold
>> it while calling into it.
>>
>> Move the splitting inside the region where we know we've got a queue
>> reference. Ideally this could still remain a shared section of code, but
>> let's keep the fix simple and defer any refactoring here to later.
>>
>> Reported-by: Christoph Hellwig <hch@lst.de>
>> Fixes: 9d497e2941c3 ("block: don't protect submit_bio_checks by q_usage_counter")
> 
> The fixes tag is wrong, and it should be:
> 
> Fixes: 900e08075202 ("block: move queue enter logic into blk_mq_submit_bio()")

You're right, I fixed it up.

-- 
Jens Axboe


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

end of thread, other threads:[~2024-01-13 15:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12 16:15 [PATCH] block: ensure we hold a queue reference when using queue limits Jens Axboe
2024-01-12 16:46 ` Christoph Hellwig
2024-01-13  2:05 ` Ming Lei
2024-01-13 15:38   ` Jens Axboe

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