mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Jens Axboe <axboe@kernel.dk>, Peiyang He <peiyang_he@smail.nju.edu.cn>
Cc: ming.lei@redhat.com, fengnanchang@gmail.com,
	linux-block@vger.kernel.org, stable@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] blk-mq: fix null-ptr-deref in blk_mq_run_hw_queues
Date: Wed, 2 Dec 2026 16:10:21 -0800	[thread overview]
Message-ID: <dd98adc0-9019-4134-998e-2af8a83e02d7@acm.org> (raw)
In-Reply-To: <fcd94d7a-4514-4b46-b070-2d7011f8a52a@kernel.dk>

On 12/2/26 2:48 PM, Jens Axboe wrote:
> On 12/2/26 8:13 AM, Peiyang He wrote:
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index 54ccfc43c27c..bf129a6a77b5 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -2412,6 +2412,14 @@ void blk_mq_run_hw_queues(struct request_queue *q, bool async)
>>   	struct blk_mq_hw_ctx *hctx, *sq_hctx;
>>   	unsigned long i;
>>   
>> +	/*
>> +	 * __blk_mq_update_nr_hw_queues() updates nr_hw_queues and queue_hw_ctx
>> +	 * while the queue is frozen. So we can use q_usage_counter to avoid
>> +	 * racing with it.
>> +	 */
>> +	if (!percpu_ref_tryget(&q->q_usage_counter))
>> +		return;
>> +
>>   	sq_hctx = NULL;
>>   	if (blk_queue_sq_sched(q))
>>   		sq_hctx = blk_mq_get_sq_hctx(q);
>> @@ -2427,6 +2435,7 @@ void blk_mq_run_hw_queues(struct request_queue *q, bool async)
>>   		    !list_empty_careful(&hctx->dispatch))
>>   			blk_mq_run_hw_queue(hctx, async);
>>   	}
>> +	blk_queue_exit(q);
>>   }
>>   EXPORT_SYMBOL(blk_mq_run_hw_queues);
> 
> That's a hard pass, adding overhead to a fast path for a corner case in one
> driver. Yes we use this in tag iteration, but that's not at all a fast path.
> Please rethink this approach.

Hi Jens,

Would wrapping the blk_mq_run_hw_queues() body with
__blk_mq_run_dispatch_ops() be acceptable? The implementation of that
macro is as follows:

/* run the code block in @dispatch_ops with rcu/srcu read lock held */
#define __blk_mq_run_dispatch_ops(q, check_sleep, dispatch_ops)	\
do {								\
	if ((q)->tag_set->flags & BLK_MQ_F_BLOCKING) {		\
		struct blk_mq_tag_set *__tag_set = (q)->tag_set; \
		int srcu_idx;					\
								\
		might_sleep_if(check_sleep);			\
		srcu_idx = srcu_read_lock(__tag_set->srcu);	\
		(dispatch_ops);					\
		srcu_read_unlock(__tag_set->srcu, srcu_idx);	\
	} else {						\
		rcu_read_lock();				\
		(dispatch_ops);					\
		rcu_read_unlock();				\
	}							\
} while (0)

Please note that this change by itself is not sufficient - code that
modifies the number of hardware queues will have to be modified too.

Thanks,

Bart.

      reply	other threads:[~2026-12-03  0:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:13 Peiyang He
2026-12-02 17:41 ` Bart Van Assche
2026-12-02 22:48 ` Jens Axboe
2026-12-03  0:10   ` Bart Van Assche [this message]

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=dd98adc0-9019-4134-998e-2af8a83e02d7@acm.org \
    --to=bvanassche@acm.org \
    --cc=axboe@kernel.dk \
    --cc=fengnanchang@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=peiyang_he@smail.nju.edu.cn \
    --cc=stable@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

all inboxes | Powered by JetHome®