public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>, Ming Lei <ming.lei@redhat.com>,
	linux-block@vger.kernel.org
Subject: Re: [PATCH 2/2] blk-mq: ensure a q_usage_counter reference is held when splitting bios
Date: Thu, 11 Jan 2024 18:10:02 +0100	[thread overview]
Message-ID: <20240111171002.GA20150@lst.de> (raw)
In-Reply-To: <d91cb6ee-50bd-4397-b82f-d34dfc135b4a@kernel.dk>

On Thu, Jan 11, 2024 at 09:17:41AM -0700, Jens Axboe wrote:
> On 1/11/24 9:14 AM, Christoph Hellwig wrote:
> > On Thu, Jan 11, 2024 at 09:12:23AM -0700, Jens Axboe wrote:
> >> On 1/11/24 6:57 AM, Christoph Hellwig 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.
> >>>
> >>> Change __submit_bio to always acquire the q_usage_counter counter before
> >>> branching out into bio vs request based helper, and let blk_mq_submit_bio
> >>> tell it if it consumed the reference by handing it off to the request.
> >>
> >> This causes hangs for me on shutdown/reset:
> > 
> >> which seems to indicate that a reference is being leaked. Haven't poked
> >> any further at it, I'll drop these two for now.
> > 
> > Can you send me your .config?
> 
> Don't think it's .config related, hit it on my test box and then in my
> vm as well. It's likely due to batched allocations, would be my guess.
> I can start/halt the vm fine with just a boot, but if I do:

Yupp, cached rqs it was.  The incremental patch below fixes it.
Can you add some cached request testing to blktests so that this gets
covered by default?

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 421db29535ba50..39eb4b99320c11 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2967,8 +2967,14 @@ bool blk_mq_submit_bio(struct bio *bio)
 		if (rq && rq->q == q) {
 			if (blk_mq_attempt_bio_merge(q, bio, nr_segs))
 				return false;
-			if (blk_mq_use_cached_rq(rq, plug, bio))
+			if (blk_mq_use_cached_rq(rq, plug, bio)) {
+				/*
+				 * We're using the reference already owned by
+				 * rq from here on.
+				 */
+				blk_queue_exit(q);
 				goto has_rq;
+			}
 		}
 	}
 

  parent reply	other threads:[~2024-01-11 17:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 13:57 ensure q_usage_counter is held over bio splits Christoph Hellwig
2024-01-11 13:57 ` [PATCH 1/2] blk-mq: rename blk_mq_can_use_cached_rq Christoph Hellwig
2024-01-11 13:57 ` [PATCH 2/2] blk-mq: ensure a q_usage_counter reference is held when splitting bios Christoph Hellwig
2024-01-11 16:12   ` Jens Axboe
2024-01-11 16:14     ` Christoph Hellwig
2024-01-11 16:17       ` Jens Axboe
2024-01-11 16:18         ` Christoph Hellwig
2024-01-11 17:10         ` Christoph Hellwig [this message]
2024-01-11 17:18           ` Jens Axboe
2024-01-11 17:24             ` Christoph Hellwig
2024-01-11 20:06               ` Jens Axboe
2024-01-12  5:44                 ` Christoph Hellwig
2024-01-12 14:22                   ` Jens Axboe
2024-01-12 14:25                     ` Christoph Hellwig
2024-01-12 16:10                       ` Jens Axboe
2024-01-15 11:20                     ` Ulf Hansson
2024-01-22  7:34                       ` mmc vs highmem, was: " Christoph Hellwig
2024-01-22  9:26                         ` Arnd Bergmann
2024-01-22 13:39                           ` Christoph Hellwig
2024-01-22 14:57                             ` Arnd Bergmann
2024-01-23  9:11                               ` Christoph Hellwig
2024-01-24 11:59                                 ` Arnd Bergmann
2024-01-24 12:33                                   ` Linus Walleij
2024-01-24 12:54                                     ` Arnd Bergmann
2024-01-24 13:16                                       ` Linus Walleij
2024-01-24 14:14                                         ` Arnd Bergmann
2024-01-24 12:45                               ` Arnd Bergmann
2024-01-24 13:49                           ` Linus Walleij
2024-01-24 16:35                             ` Arnd Bergmann
2024-01-11 22:22   ` Ming Lei
2024-01-12  5:46     ` Christoph Hellwig
2024-01-11 16:03 ` ensure q_usage_counter is held over bio splits Jens Axboe
2024-01-14 14:38 ` (subset) " 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=20240111171002.GA20150@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /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