public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Valentin Schneider <vschneid@redhat.com>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>, Jens Axboe <axboe@kernel.dk>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [RFC PATCH bitmap-for-next 4/4] blk_mq: Fix cpumask_check() warning in blk_mq_hctx_next_cpu()
Date: Thu,  6 Oct 2022 13:21:12 +0100	[thread overview]
Message-ID: <20221006122112.663119-5-vschneid@redhat.com> (raw)
In-Reply-To: <20221006122112.663119-1-vschneid@redhat.com>

blk_mq_hctx_next_cpu() implements a form of cpumask_next_and_wrap() using
cpumask_next_and_cpu() and blk_mq_first_mapped_cpu():

[    5.398453] WARNING: CPU: 3 PID: 162 at include/linux/cpumask.h:110 __blk_mq_delay_run_hw_queue+0x16b/0x180
[    5.399317] Modules linked in:
[    5.399646] CPU: 3 PID: 162 Comm: ssh-keygen Tainted: G                 N 6.0.0-rc4-00004-g93003cb24006 #55
[    5.400135] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
[    5.405430] Call Trace:
[    5.406152]  <TASK>
[    5.406452]  blk_mq_sched_insert_requests+0x67/0x150
[    5.406759]  blk_mq_flush_plug_list+0xd0/0x280
[    5.406987]  ? bit_wait+0x60/0x60
[    5.407317]  __blk_flush_plug+0xdb/0x120
[    5.407561]  ? bit_wait+0x60/0x60
[    5.407765]  io_schedule_prepare+0x38/0x40
[...]

This triggers a warning when next_cpu == nr_cpu_ids - 1, so rewrite it
using cpumask_next_and_wrap() directly. The backwards-going goto can be
removed, as the cpumask_next*() operation already ANDs hctx->cpumask and
cpu_online_mask, which implies checking for an online CPU.

No change in behaviour intended.

Suggested-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
 block/blk-mq.c | 39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index c96c8c4f751b..1520794dd9ea 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2038,42 +2038,29 @@ static inline int blk_mq_first_mapped_cpu(struct blk_mq_hw_ctx *hctx)
  */
 static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
 {
-	bool tried = false;
 	int next_cpu = hctx->next_cpu;
 
 	if (hctx->queue->nr_hw_queues == 1)
 		return WORK_CPU_UNBOUND;
 
-	if (--hctx->next_cpu_batch <= 0) {
-select_cpu:
-		next_cpu = cpumask_next_and(next_cpu, hctx->cpumask,
-				cpu_online_mask);
-		if (next_cpu >= nr_cpu_ids)
-			next_cpu = blk_mq_first_mapped_cpu(hctx);
+	if (--hctx->next_cpu_batch > 0 && cpu_online(next_cpu))
+		return next_cpu;
+
+	next_cpu = cpumask_next_and_wrap(next_cpu, hctx->cpumask, cpu_online_mask, next_cpu, false);
+	if (next_cpu < nr_cpu_ids) {
 		hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
+		hctx->next_cpu = next_cpu;
+		return next_cpu;
 	}
 
 	/*
-	 * Do unbound schedule if we can't find a online CPU for this hctx,
-	 * and it should only happen in the path of handling CPU DEAD.
+	 * No other online CPU in hctx->cpumask.
+	 *
+	 * Make sure to re-select CPU next time once after CPUs
+	 * in hctx->cpumask become online again.
 	 */
-	if (!cpu_online(next_cpu)) {
-		if (!tried) {
-			tried = true;
-			goto select_cpu;
-		}
-
-		/*
-		 * Make sure to re-select CPU next time once after CPUs
-		 * in hctx->cpumask become online again.
-		 */
-		hctx->next_cpu = next_cpu;
-		hctx->next_cpu_batch = 1;
-		return WORK_CPU_UNBOUND;
-	}
-
-	hctx->next_cpu = next_cpu;
-	return next_cpu;
+	hctx->next_cpu_batch = 1;
+	return WORK_CPU_UNBOUND;
 }
 
 /**
-- 
2.31.1


  parent reply	other threads:[~2022-10-06 12:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-06 12:21 [RFC PATCH bitmap-for-next 0/4] lib/cpumask, blk_mq: Fix blk_mq_hctx_next_cpu() vs cpumask_check() Valentin Schneider
2022-10-06 12:21 ` [RFC PATCH bitmap-for-next 1/4] lib/cpumask: Generate cpumask_next_wrap() body with a macro Valentin Schneider
2022-10-06 12:21 ` [RFC PATCH bitmap-for-next 2/4] lib/cpumask: Fix cpumask_check() warning in cpumask_next_wrap*() Valentin Schneider
2022-10-06 12:21 ` [RFC PATCH bitmap-for-next 3/4] lib/cpumask: Introduce cpumask_next_and_wrap() Valentin Schneider
2022-10-06 12:21 ` Valentin Schneider [this message]
2022-10-06 13:50   ` [RFC PATCH bitmap-for-next 4/4] blk_mq: Fix cpumask_check() warning in blk_mq_hctx_next_cpu() Yury Norov
2022-10-06 15:17     ` Valentin Schneider
2022-10-07  5:15       ` Yury Norov

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=20221006122112.663119-5-vschneid@redhat.com \
    --to=vschneid@redhat.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=yury.norov@gmail.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