From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796256626; b=xIeBG+l5Q4j+dDKGRKujN61HNLEEkL8F1S87kPnYSjjBhyF79xfzao9NhFcLYsa5pUCn KA6QmztRcBNwlZHKOSWjuqcOM1mb8j1tLXK0TbSyNU0CnTkHtWDZzP/vjQXnhpWr8jcd+ 9XWxyLNfyGKsqbSf6GJ9yTcx+B/zmOrSGXnprstUwu+I/jjlpn9dKeuyjGltelvpU8uSb 8gQSiJxS6o9A98fJO8l7AAQryGrCpVpf8SdUqTMqd9osYHDbzney7cvQ4HTiNE5rJ06dx XFvPKHu9N+Xh4oeI85copeXMS0icI2ryB1TNr+yjqAMkV7WpNgkeup7lRJROz1Youbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796256626; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=AlHe+xRGiYDeRBcP+7uOEoMYvQh+XwFNN9JliiaUveg=; b=N5EMH/+P5uUzNivww4Fi4wYH4huK28Dejc36Is4BmElJVvvLB1WjxP8g1hH0gHz7BNmx zTs82qMeEKQjf7yX6z3i6ciZakmxNdZEjaPxefoL1tHp2MZImKnJZxP3Or1NDZRMuZWRj 1DItxL4uq2y9ZlYeXRNXsbVIc8V/V4sE2Eka5r0JH2K7sAOKL/YXKwA4sOiYfwPFLMEtX r+HqR+Rq4Dp/tpyd3FncKih+F5Q8Sg2136Df0Uz4WRgTZ2LyVtsbjqlUDFSE+64D+eeGa ZsBZAZuI2QVN23M6hStoJ8LuUCXLWZk3EZ298+gc909I+SMfuWfZ+JT5dHbk8Enrf+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=TpHKBeyR; arc=none smtp.remote-ip=199.89.1.14 Received: from 011.lax.mailroute.net (011.lax.mailroute.net [199.89.1.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A50E0606A322; Thu, 3 Dec 2026 00:10:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A50E0606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=TpHKBeyR Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jfw4d0xRGz1XLwXS; Thu, 3 Dec 2026 00:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject :user-agent:mime-version:date:date:message-id:received:received; s=mr01; t=1796256622; x=1798848623; bh=AlHe+xRGiYDeRBcP+7uOEoMY vQh+XwFNN9JliiaUveg=; b=TpHKBeyRzWENI/qWvgfEhkdR2qGgQswBlUSQn2HP iAUEw097bgKkTZrK4MATnsZHw9BTob+Mf81WlnnyxPURZ6ZnQkO1XUsKZEVCsxJs wwwKR9nB7+1KDLUVotPQg26PQPd/k9mqMDuQ4kOmrP7Ee/Yzntgb2nflryRVGRUA bPWJOai0hYh7U4netw1E+IBXxJ3I3NqMIt2RoBpJ7ZEheidmzs17147wnZ8K9sJD /FXfZBzA0pcYw5YN+85fTB9KyZ69SHx+Hrfx8aaRK5kvrfm0hxXF6NR6FjyOHaA9 AoXO6Fs+wwxvhFSran6RHcP1fAHBUFqzmbZlkR+7cwBLPw== X-Virus-Scanned: by MailRoute Received: from 011.lax.mailroute.net ([127.0.0.1]) by localhost (011.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id mrNbnRdBJKLJ; Thu, 3 Dec 2026 00:10:22 +0000 (UTC) Received: from [IPV6:2a00:79e0:2ed2:d:8501:d30d:dfc2:7f37] (unknown [104.135.182.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 011.lax.mailroute.net (Postfix) with ESMTPSA id 4jfw4Z0938z1XLyP5; Thu, 3 Dec 2026 00:10:21 +0000 (UTC) Message-ID: Date: Wed, 2 Dec 2026 16:10:21 -0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] blk-mq: fix null-ptr-deref in blk_mq_run_hw_queues To: Jens Axboe , Peiyang He Cc: ming.lei@redhat.com, fengnanchang@gmail.com, linux-block@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org References: Content-Language: en-US From: Bart Van Assche In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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.