All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
	linux-nvme@lists.infradead.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org
Cc: linux-block@vger.kernel.org, Wen Xiong <wenxiong@linux.ibm.com>,
	Keith Busch <kbusch@kernel.org>, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH V2 1/9] blk-mq: add blk_mq_max_nr_hw_queues()
Date: Wed, 26 Jul 2023 17:40:19 +0800	[thread overview]
Message-ID: <20230726094027.535126-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20230726094027.535126-1-ming.lei@redhat.com>

blk_mq_alloc_tag_set() may override set->nr_hw_queues as 1 in case of kdump
kernel. This way causes trouble for driver, because blk-mq and driver see
different queue mapping. Especially the only online CPU may not be 1 for
kdump kernel, in which 'maxcpus=1' is passed from kernel command line,
then driver may map hctx0 into one inactive real hw queue which cpu
affinity is 0(offline).

The issue exists on all drivers which use managed irq and support
multiple hw queue.

Prepare for fixing this kind of issue by applying the added helper, so
driver can take blk-mq max nr_hw_queues knowledge into account when
calculating io queues.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq.c         | 16 ++++++++++++++++
 include/linux/blk-mq.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index b04ff6f56926..617d6f849a7b 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -140,6 +140,22 @@ void blk_mq_freeze_queue_wait(struct request_queue *q)
 }
 EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_wait);
 
+/*
+ * Return the max supported nr_hw_queues for each hw queue type
+ *
+ * blk_mq_alloc_tag_set() may change nr_hw_queues for kdump kernel, so
+ * driver has to take blk-mq max supported nr_hw_queues into account
+ * when figuring out nr_hw_queues from hardware info, for avoiding
+ * inconsistency between driver and blk-mq.
+ */
+unsigned int blk_mq_max_nr_hw_queues(void)
+{
+	if (is_kdump_kernel())
+		return 1;
+	return nr_cpu_ids;
+}
+EXPORT_SYMBOL_GPL(blk_mq_max_nr_hw_queues);
+
 int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
 				     unsigned long timeout)
 {
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 495ca198775f..4c0cfd1f9e52 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -711,6 +711,7 @@ int blk_mq_alloc_sq_tag_set(struct blk_mq_tag_set *set,
 		const struct blk_mq_ops *ops, unsigned int queue_depth,
 		unsigned int set_flags);
 void blk_mq_free_tag_set(struct blk_mq_tag_set *set);
+unsigned int blk_mq_max_nr_hw_queues(void);
 
 void blk_mq_free_request(struct request *rq);
 int blk_rq_poll(struct request *rq, struct io_comp_batch *iob,
-- 
2.40.1


  reply	other threads:[~2023-07-26  9:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26  9:40 [PATCH V2 0/9] blk-mq: fix wrong queue mapping for kdump kernel Ming Lei
2023-07-26  9:40 ` Ming Lei [this message]
2023-07-26 16:36   ` [PATCH V2 1/9] blk-mq: add blk_mq_max_nr_hw_queues() John Garry
2023-07-27  1:06     ` Ming Lei
2023-07-26  9:40 ` [PATCH V2 2/9] nvme-pci: use blk_mq_max_nr_hw_queues() to calculate io queues Ming Lei
2023-07-26  9:40 ` [PATCH V2 3/9] scsi: core: add helper of scsi_max_nr_hw_queues() Ming Lei
2023-07-26  9:40 ` [PATCH V2 4/9] scsi: lpfc: use blk_mq_max_nr_hw_queues() to calculate io vectors Ming Lei
2023-07-26 22:12   ` Justin Tee
2023-07-27  1:19     ` Ming Lei
2023-07-27 16:56       ` Justin Tee
2023-07-26  9:40 ` [PATCH V2 5/9] scsi: hisi: take blk_mq_max_nr_hw_queues() into account for calculating " Ming Lei
2023-07-26 15:42   ` John Garry
2023-07-27  1:15     ` Ming Lei
2023-07-27  7:35       ` John Garry
2023-07-27  9:42         ` Ming Lei
2023-07-27 10:28           ` John Garry
2023-07-27 10:56             ` Ming Lei
2023-07-27 11:30               ` John Garry
2023-07-27 12:01                 ` Ming Lei
2023-07-27 12:36                   ` John Garry
2023-07-26  9:40 ` [PATCH V2 6/9] scsi: mpi3mr: " Ming Lei
2023-07-26  9:40 ` [PATCH V2 7/9] scsi: megaraid: " Ming Lei
2023-07-26  9:40 ` [PATCH V2 8/9] scsi: mpt3sas: " Ming Lei
2023-07-26  9:40 ` [PATCH V2 9/9] scsi: pm8001: " Ming Lei
2023-07-31  7:14 ` [PATCH V2 0/9] blk-mq: fix wrong queue mapping for kdump kernel Christoph Hellwig

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=20230726094027.535126-2-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=wenxiong@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.