Skip to contentSkip to conversation

blk: honor isolcpus configuration

PATCH Superseded Aaron Tomlin 6 participants 39 messages Apr 1 – Apr 16

Subsystems (15)

v10 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v10 cover blk: honor isolcpus configuration

Hi Jens, Keith, Christoph, Sagi, Michael,

I have decided to drive this series forward on behalf of Daniel Wagner, the original author. This iteration addresses the outstanding architectural and concurrency concerns raised during the previous review cycle, and the series has been rebased on v7.0-rc5-509-g545475aebc2a.

Building upon prior iterations, this series introduces critical architectural refinements to the mapping and affinity spreading algorithms to guarantee thread safety and resilience against concurrent CPU-hotplug operations. Previously, the block layer relied on a shared global static mask (i.e., blk_hk_online_mask), which proved vulnerable to race conditions during rapid hotplug events. This vulnerability was recently highlighted by the kernel test robot, which encountered a NULL pointer dereference during rcutorture (cpuhotplug) stress testing due to concurrent mask modification.

To resolve this, the architecture has been fundamentally hardened. The global static state has been eradicated. Instead, the IRQ affinity core now employs a newly introduced irq_spread_hk_filter(), which safely intersects the natively calculated affinity mask with the HK_TYPE_IO_QUEUE mask. Crucially, this is achieved using a local, hotplug-safe snapshot via data_race(cpu_online_mask). This approach circumvents the hotplug lock deadlocks previously identified by Thomas Gleixner, whilst explicitly avoiding CONFIG_CPUMASK_OFFSTACK stack bloat hazards on high-core-count systems. A robust fallback mechanism guarantees that should an interrupt vector be assigned exclusively to isolated cores, it is safely re-routed to the system's online housekeeping CPUs.

Furthermore, following rigorous testing of multiple queue maps (such as NVMe poll queues) alongside isolated CPUs, this tenth iteration resolves a critical page fault regression. The multi-queue mapping logic has been corrected to strictly maintain absolute hardware queue indices, ensuring faultless queue initialization and preventing out-of-bounds memory access.

Please let me know your thoughts.

Changes in v10:

- Fixed a page fault regression encountered when initialising secondary queue maps (e.g., NVMe poll queues). Restored the qmap->queue_offset to the mq_map assignment to ensure CPUs are strictly mapped to absolute hardware indices (Keith Busch)

- Corrected the active_hctx tracker to utilise relative queue indices, preventing out-of-bounds mask assignments

- Fixed the blk_mq_validate() sanity check to properly evaluate absolute queue indices against the offset-adjusted loop index

- Corrected typographical errors within block/blk-mq-cpumap.c (Keith Busch)

- Clarified the commit message regarding the removal of the !SMP fallback code, explicitly noting that the core scheduler now mandates SMP unconditionally (Sebastian Andrzej Siewior)

- Added missing "Signed-off-by:" tags to properly record the patch series chain of custody

- Linked to v9: https://lore.kernel.org/lkml/[email protected]/

Changes in v9:

- Added "Reviewed-by:" tags

- Introduced irq_spread_hk_filter() to safely restrict managed IRQ affinity to housekeeping CPUs (Thomas Gleixner)

- Removed the unsafe global static variable blk_hk_online_mask from blk-mq-cpumap.c and blk-mq.c. blk_mq_online_queue_affinity() now returns a stable pointer, delegating safe intersection to the callers to prevent concurrent modification races (Thomas Gleixner, Hannes Reinecke)

- Resolved BUG: kernel NULL pointer dereference in __blk_mq_all_tag_iter reported by the kernel test robot during cpuhotplug rcutorture stress testing

- Linked to v8: https://lore.kernel.org/lkml/[email protected]/

Changes in v8:

- Added commit 524f5eea4bbe ("lib/group_cpus: remove !SMP code")

- Merged the new mapping logic directly into the existing function to avoid special casing

- Refined the group_mask_cpus_evenly() implementation with the following updates:

- Corrected the function name typo (changed group_masks_cpus_evenly to group_mask_cpus_evenly)

- Updated the documentation comment to accurately reflect the function's behavior

- Renamed the cpu_mask argument to mask for consistency

- Added a new patch for aacraid to include the missing number of queues calculation

- Restricted updates to only affect SCSI drivers that support PCI_IRQ_AFFINITY and do not utilize nvme-fabrics

- Removed the __free cleanup attribute usage for cpumask_var_t allocations due to compatibility issues

- Updated the documentation to explicitly highlight the limitations surrounding CPU offlining

- Collected accumulated Reviewed-by and Acked-by tags

- Linked to v7: https://patch.msgid.link/[email protected]

Changes in v7:

- Sent out the first part of the series independently:
https://lore.kernel.org/all/[email protected]/

- Added comprehensive kernel command-line documentation

- Added validation logic to ensure the resulting CPU-to-queue mapping is fully operational

- Rewrote the isolcpus mapping code to properly account for active hardware contexts (hctx)

- Introduced blk_mq_map_hk_irq_queues, which utilizes the mask retrieved from irq_get_affinity()

- Refactored blk_mq_map_hk_queues to require the caller to explicitly test for HK_TYPE_MANAGED_IRQ

- Linked to v6: https://patch.msgid.link/[email protected]

Changes in v6:

- Reintroduced the io_queue type for the isolcpus kernel parameter

- Prevented the offlining of a housekeeping CPU if an isolated CPU is still present, upgrading this behavior from a simple warning to a hard restriction

- Linked to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:

- Rebased the series onto the latest for-6.14/block branch.

- Updated the documentation regarding the managed_irq parameters

- Reworded the commit message for "blk-mq: issue warning when offlining hctx with online isolcpus" for better clarity

- Split the input and output parameters in the patch "lib/group_cpus: let group_cpu_evenly return number of groups"

- Dropped the patch "sched/isolation: document HK_TYPE housekeeping option"

- Linked to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:

- Added the patch "blk-mq: issue warning when offlining hctx with online isolcpus"

- Fixed the check in group_cpus_evenly(); the condition now properly uses housekeeping_enabled() instead of cpumask_weight(), as the latter always returns a valid mask

- Dropped the Fixes: tag from "lib/group_cpus.c: honor housekeeping config when grouping CPUs"

- Fixed an overlong line warning in the patch "scsi: use block layer helpers to calculate num of queues"

- Dropped the patch "sched/isolation: Add io_queue housekeeping option" in favor of simply documenting the housekeeping hk_type enum

- Added the patch "lib/group_cpus: let group_cpu_evenly return number of groups"

- Collected accumulated Reviewed-by and Acked-by tags

- Split the patchset by moving foundational changes into a separate preparation series:
https://lore.kernel.org/linux-nvme/20241202-refactor-blk-affinity-helpers-v6-0-27211e9c2cd5@kernel.org/

- Linked to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:

- Integrated patches from Ming Lei
(https://lore.kernel.org/all/[email protected]/):
"virtio: add APIs for retrieving vq affinity" and "blk-mq: introduce blk_mq_dev_map_queues"

- Replaced all instances of blk_mq_pci_map_queues and blk_mq_virtio_map_queues with the new unified blk_mq_dev_map_queues

- Updated and expanded the helper functions used for calculating the number of queues

- Added the CPU-to-hctx mapping function specifically to support the isolcpus=io_queue parameter

- Documented the hk_type enum and the newly introduced isolcpus=io_queue parameter

- Added the patch "scsi: pm8001: do not overwrite PCI queue mapping"

- Linked to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:

- Updated the feature documentation for clarity and completeness

- Split the blk/nvme-pci patch into smaller, logical commits

- Dropped the HK_TYPE_IO_QUEUE macro in favor of reusing HK_TYPE_MANAGED_IRQ

- Linked to v1: https://lore.kernel.org/r/[email protected]

Aaron Tomlin (1):
genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs

Daniel Wagner (12):
scsi: aacraid: use block layer helpers to calculate num of queues lib/group_cpus: remove dead !SMP code
lib/group_cpus: Add group_mask_cpus_evenly() genirq/affinity: Add cpumask to struct irq_affinity
blk-mq: add blk_mq_{online|possible}_queue_affinity
nvme-pci: use block layer helpers to constrain queue affinity
scsi: Use block layer helpers to constrain queue affinity
virtio: blk/scsi: use block layer helpers to constrain queue affinity
isolation: Introduce io_queue isolcpus type
blk-mq: use hk cpus only when isolcpus=io_queue is enabled
blk-mq: prevent offlining hk CPUs with associated online isolated CPUs
docs: add io_queue flag to isolcpus

 .../admin-guide/kernel-parameters.txt         |  22 +-
 block/blk-mq-cpumap.c                         | 199 ++++++++++++++++--
 block/blk-mq.c                                |  42 ++++
 drivers/block/virtio_blk.c                    |   4 +-
 drivers/nvme/host/pci.c                       |   1 +
 drivers/scsi/aacraid/comminit.c               |   3 +-
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c        |   1 +
 drivers/scsi/megaraid/megaraid_sas_base.c     |   5 +-
 drivers/scsi/mpi3mr/mpi3mr_fw.c               |   6 +-
 drivers/scsi/mpt3sas/mpt3sas_base.c           |   5 +-
 drivers/scsi/pm8001/pm8001_init.c             |   1 +
 drivers/scsi/virtio_scsi.c                    |   5 +-
 include/linux/blk-mq.h                        |   2 +
 include/linux/group_cpus.h                    |   3 +
 include/linux/interrupt.h                     |  16 +-
 include/linux/sched/isolation.h               |   1 +
 kernel/irq/affinity.c                         |  38 +++-
 kernel/sched/isolation.c                      |   7 +
 lib/group_cpus.c                              |  65 ++++--
 19 files changed, 378 insertions(+), 48 deletions(-)

base-commit: 545475aebc2a2e8df14fadc911a7a2d03ddd6a1f

Signature · 1 line
2.51.0
#1 lore raw

PATCH v10 1/13 scsi: aacraid: use block layer helpers to calculate num of queues

From: Daniel Wagner <[email protected]>

The calculation of the upper limit for queues does not depend solely on the number of online CPUs; for example, the isolcpus kernel command-line option must also be considered.

To account for this, the block layer provides a helper function to retrieve the maximum number of queues. Use it to set an appropriate upper queue number limit.

Fixes 94970cfb5f10 ("scsi: use block layer helpers to calculate num of queues")
---
 drivers/scsi/aacraid/comminit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/aacraid/comminit.c +1 -2
index 9bd3f5b868bc..ec165b57182d 100644
@@ -469,8 +469,7 @@ void aac_define_int_mode(struct aac_dev *dev)
 	}
 
 	/* Don't bother allocating more MSI-X vectors than cpus */
-	msi_count = min(dev->max_msix,
-		(unsigned int)num_online_cpus());
+	msi_count = blk_mq_num_online_queues(dev->max_msix);
 
 	dev->max_msix = msi_count;
 
Signature · 1 line
2.51.0
Reviewed-by on v10 1/13
#2 lore raw

Re: [PATCH v10 01/13] scsi: aacraid: use block layer helpers to calculate num of queues

Aaron,

Quoted 7 lines

The calculation of the upper limit for queues does not depend solely on the number of online CPUs; for example, the isolcpus kernel command-line option must also be considered.

To account for this, the block layer provides a helper function to retrieve the maximum number of queues. Use it to set an appropriate upper queue number limit.

Signature · 1 line
Martin K. Petersen
#3 lore raw

PATCH v10 2/13 lib/group_cpus: remove dead !SMP code

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

The support for the !SMP configuration has been removed from the core by commit cac5cefbade9 ("sched/smp: Make SMP unconditional").

While one can technically still compile a uniprocessor kernel, the core scheduler now mandates SMP unconditionally, rendering this particular !SMP fallback handling redundant. Therefore, remove the #ifdef CONFIG_SMP guards and the fallback logic.

[atomlin: Updated commit message to clarify !SMP removal context]
---
 lib/group_cpus.c | 20 --------------------
 1 file changed, 20 deletions(-)
lib/group_cpus.c +0 -20
index e6e18d7a49bb..b8d54398f88a 100644
@@ -9,8 +9,6 @@
 #include <linux/sort.h>
 #include <linux/group_cpus.h>
 
-#ifdef CONFIG_SMP
-
 static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,
 				unsigned int cpus_per_grp)
 {
@@ -564,22 +562,4 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)
 	*nummasks = min(nr_present + nr_others, numgrps);
 	return masks;
 }
-#else /* CONFIG_SMP */
-struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)
-{
-	struct cpumask *masks;
-
-	if (numgrps == 0)
-		return NULL;
-
-	masks = kzalloc_objs(*masks, numgrps);
-	if (!masks)
-		return NULL;
-
-	/* assign all CPUs(cpu 0) to the 1st group only */
-	cpumask_copy(&masks[0], cpu_possible_mask);
-	*nummasks = 1;
-	return masks;
-}
-#endif /* CONFIG_SMP */
 EXPORT_SYMBOL_GPL(group_cpus_evenly);
Signature · 1 line
2.51.0
Reviewed-by on v10 2/13
#4 lore raw

Re: [PATCH v10 02/13] lib/group_cpus: remove dead !SMP code

Aaron,

Quoted 2 lines

The support for the !SMP configuration has been removed from the core by commit cac5cefbade9 ("sched/smp: Make SMP unconditional").

Signature · 1 line
Martin K. Petersen
#5 lore raw

PATCH v10 3/13 lib/group_cpus: Add group_mask_cpus_evenly()

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

group_mask_cpu_evenly() allows the caller to pass in a CPU mask that should be evenly distributed. This new function is a more generic version of the existing group_cpus_evenly(), which always distributes all present CPUs into groups.

---
 include/linux/group_cpus.h |  3 ++
 lib/group_cpus.c           | 59 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
include/linux/group_cpus.h +3 -0
index 9d4e5ab6c314..defab4123a82 100644
@@ -10,5 +10,8 @@
 #include <linux/cpu.h>
 
 struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks);
+struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,
+				       const struct cpumask *mask,
+				       unsigned int *nummasks);
 
 #endif
lib/group_cpus.c +59 -0

68 lines not on this page · raw message

Signature · 1 line
2.51.0
#6 lore raw

PATCH v10 4/13 genirq/affinity: Add cpumask to struct irq_affinity

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Pass a cpumask to irq_create_affinity_masks as an additional constraint to consider when creating the affinity masks. This allows the caller to exclude specific CPUs, e.g., isolated CPUs (see the 'isolcpus' kernel command-line parameter).

---
 include/linux/interrupt.h | 16 ++++++++++------
 kernel/irq/affinity.c     | 12 ++++++++++--
 2 files changed, 20 insertions(+), 8 deletions(-)
include/linux/interrupt.h +10 -6
index 6cd26ffb0505..afd5a2c75b43 100644
@@ -287,18 +287,22 @@ struct irq_affinity_notify {
  * @nr_sets:		The number of interrupt sets for which affinity
  *			spreading is required
  * @set_size:		Array holding the size of each interrupt set
+ * @mask:		cpumask that constrains which CPUs to consider when
+ *			calculating the number and size of the interrupt sets
  * @calc_sets:		Callback for calculating the number and size
  *			of interrupt sets
  * @priv:		Private data for usage by @calc_sets, usually a
  *			pointer to driver/device specific data.
  */
 struct irq_affinity {
-	unsigned int	pre_vectors;
-	unsigned int	post_vectors;
-	unsigned int	nr_sets;
-	unsigned int	set_size[IRQ_AFFINITY_MAX_SETS];
-	void		(*calc_sets)(struct irq_affinity *, unsigned int nvecs);
-	void		*priv;
+	unsigned int		pre_vectors;
+	unsigned int		post_vectors;
+	unsigned int		nr_sets;
+	unsigned int		set_size[IRQ_AFFINITY_MAX_SETS];
+	const struct cpumask	*mask;
+	void			(*calc_sets)(struct irq_affinity *,
+					     unsigned int nvecs);
+	void			*priv;
 };
 
 /**
kernel/irq/affinity.c +10 -2
index 85c45cfe7223..076a5ef1e306 100644
@@ -70,7 +70,13 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 	 */
 	for (i = 0, usedvecs = 0; i < affd->nr_sets; i++) {
 		unsigned int nr_masks, this_vecs = affd->set_size[i];
-		struct cpumask *result = group_cpus_evenly(this_vecs, &nr_masks);
+		struct cpumask *result;
+
+		if (affd->mask)
+			result = group_mask_cpus_evenly(this_vecs, affd->mask,
+							&nr_masks);
+		else
+			result = group_cpus_evenly(this_vecs, &nr_masks);
 
 		if (!result) {
 			kfree(masks);
@@ -115,7 +121,9 @@ unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
 	if (resv > minvec)
 		return 0;
 
-	if (affd->calc_sets) {
+	if (affd->mask) {
+		set_vecs = cpumask_weight(affd->mask);
+	} else if (affd->calc_sets) {
 		set_vecs = maxvec - resv;
 	} else {
 		cpus_read_lock();
Signature · 1 line
2.51.0
#7 lore raw

PATCH v10 5/13 blk-mq: add blk_mq_{online|possible}_queue_affinity

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Introduce blk_mq_{online|possible}_queue_affinity, which returns the queue-to-CPU mapping constraints defined by the block layer. This allows other subsystems (e.g., IRQ affinity setup) to respect block layer requirements.

It is necessary to provide versions for both the online and possible CPU masks because some drivers want to spread their I/O queues only across online CPUs, while others prefer to use all possible CPUs. And the mask used needs to match with the number of queues requested
(see blk_num_{online|possible}_queues).

---
 block/blk-mq-cpumap.c  | 24 ++++++++++++++++++++++++
 include/linux/blk-mq.h |  2 ++
 2 files changed, 26 insertions(+)
block/blk-mq-cpumap.c +24 -0
index 705da074ad6c..8244ecf87835 100644
@@ -26,6 +26,30 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
 	return min_not_zero(num, max_queues);
 }
 
+/**
+ * blk_mq_possible_queue_affinity - Return block layer queue affinity
+ *
+ * Returns an affinity mask that represents the queue-to-CPU mapping
+ * requested by the block layer based on possible CPUs.
+ */
+const struct cpumask *blk_mq_possible_queue_affinity(void)
+{
+	return cpu_possible_mask;
+}
+EXPORT_SYMBOL_GPL(blk_mq_possible_queue_affinity);
+
+/**
+ * blk_mq_online_queue_affinity - Return block layer queue affinity
+ *
+ * Returns an affinity mask that represents the queue-to-CPU mapping
+ * requested by the block layer based on online CPUs.
+ */
+const struct cpumask *blk_mq_online_queue_affinity(void)
+{
+	return cpu_online_mask;
+}
+EXPORT_SYMBOL_GPL(blk_mq_online_queue_affinity);
+
 /**
  * blk_mq_num_possible_queues - Calc nr of queues for multiqueue devices
  * @max_queues:	The maximum number of queues the hardware/driver
include/linux/blk-mq.h +2 -0
index 18a2388ba581..ebc45557aee8 100644
@@ -969,6 +969,8 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
 void blk_mq_unfreeze_queue_non_owner(struct request_queue *q);
 void blk_freeze_queue_start_non_owner(struct request_queue *q);
 
+const struct cpumask *blk_mq_possible_queue_affinity(void);
+const struct cpumask *blk_mq_online_queue_affinity(void);
 unsigned int blk_mq_num_possible_queues(unsigned int max_queues);
 unsigned int blk_mq_num_online_queues(unsigned int max_queues);
 void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
Signature · 1 line
2.51.0
#8 lore raw

PATCH v10 6/13 nvme-pci: use block layer helpers to constrain queue affinity

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Ensure that IRQ affinity setup also respects the queue-to-CPU mapping constraints provided by the block layer. This allows the NVMe driver to avoid assigning interrupts to CPUs that the block layer has excluded (e.g., isolated CPUs).

---
 drivers/nvme/host/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +1 -0
index b78ba239c8ea..8e05ad06283e 100644
@@ -2862,6 +2862,7 @@ static int nvme_setup_irqs(struct nvme_dev *dev, unsigned int nr_io_queues)
 		.pre_vectors	= 1,
 		.calc_sets	= nvme_calc_irq_sets,
 		.priv		= dev,
+		.mask		= blk_mq_possible_queue_affinity(),
 	};
 	unsigned int irq_queues, poll_queues;
 	unsigned int flags = PCI_IRQ_ALL_TYPES | PCI_IRQ_AFFINITY;
Signature · 1 line
2.51.0
Reviewed-by on v10 6/13
#9 lore raw

Re: [PATCH v10 06/13] nvme-pci: use block layer helpers to constrain queue affinity

Aaron,

Quoted 4 lines

Ensure that IRQ affinity setup also respects the queue-to-CPU mapping constraints provided by the block layer. This allows the NVMe driver to avoid assigning interrupts to CPUs that the block layer has excluded (e.g., isolated CPUs).

Signature · 1 line
Martin K. Petersen
#10 lore raw

PATCH v10 7/13 scsi: Use block layer helpers to constrain queue affinity

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Ensure that IRQ affinity setup also respects the queue-to-CPU mapping constraints provided by the block layer. This allows the SCSI drivers to avoid assigning interrupts to CPUs that the block layer has excluded (e.g., isolated CPUs).

Only convert drivers which are already using the pci_alloc_irq_vectors_affinity with the PCI_IRQ_AFFINITY flag set. Because these drivers are enabled to let the IRQ core code to set the affinity. Also don't update qla2xxx because the nvme-fabrics code is not ready yet.

---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c    | 1 +
 drivers/scsi/megaraid/megaraid_sas_base.c | 5 ++++-
 drivers/scsi/mpi3mr/mpi3mr_fw.c           | 6 +++++-
 drivers/scsi/mpt3sas/mpt3sas_base.c       | 5 ++++-
 drivers/scsi/pm8001/pm8001_init.c         | 1 +
 5 files changed, 15 insertions(+), 3 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +1 -0
index f69efc6494b8..d1f689224e7b 100644
@@ -2605,6 +2605,7 @@ static int interrupt_preinit_v3_hw(struct hisi_hba *hisi_hba)
 	struct pci_dev *pdev = hisi_hba->pci_dev;
 	struct irq_affinity desc = {
 		.pre_vectors = BASE_VECTORS_V3_HW,
+		.mask = blk_mq_online_queue_affinity(),
 	};
 
 	min_msi = MIN_AFFINE_VECTORS_V3_HW;
drivers/scsi/megaraid/megaraid_sas_base.c +4 -1
index ac71ea4898b2..7e2a3c187ee0 100644
@@ -5925,7 +5925,10 @@ static int
 __megasas_alloc_irq_vectors(struct megasas_instance *instance)
 {
 	int i, irq_flags;
-	struct irq_affinity desc = { .pre_vectors = instance->low_latency_index_start };
+	struct irq_affinity desc = {
+		.pre_vectors = instance->low_latency_index_start,
+		.mask = blk_mq_online_queue_affinity(),
+	};
 	struct irq_affinity *descp = &desc;
 
 	irq_flags = PCI_IRQ_MSIX;
drivers/scsi/mpi3mr/mpi3mr_fw.c +5 -1
index c744210cc901..f9b8b3639c64 100644
@@ -830,7 +830,11 @@ static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
 	int max_vectors, min_vec;
 	int retval;
 	int i;
-	struct irq_affinity desc = { .pre_vectors =  1, .post_vectors = 1 };
+	struct irq_affinity desc = {
+		.pre_vectors =  1,
+		.post_vectors = 1,
+		.mask = blk_mq_online_queue_affinity(),
+	};
 
 	if (mrioc->is_intr_info_set)
 		return 0;
drivers/scsi/mpt3sas/mpt3sas_base.c +4 -1
index 79052f2accbd..91e1622b5b77 100644
@@ -3370,7 +3370,10 @@ static int
 _base_alloc_irq_vectors(struct MPT3SAS_ADAPTER *ioc)
 {
 	int i, irq_flags = PCI_IRQ_MSIX;
-	struct irq_affinity desc = { .pre_vectors = ioc->high_iops_queues };
+	struct irq_affinity desc = {
+		.pre_vectors = ioc->high_iops_queues,
+		.mask = blk_mq_online_queue_affinity(),
+	};
 	struct irq_affinity *descp = &desc;
 	/*
 	 * Don't allocate msix vectors for poll_queues.
drivers/scsi/pm8001/pm8001_init.c +1 -0
index e93ea76b565e..6360fa95bcf4 100644
@@ -978,6 +978,7 @@ static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
 		 */
 		struct irq_affinity desc = {
 			.pre_vectors = 1,
+			.mask = blk_mq_online_queue_affinity(),
 		};
 		rc = pci_alloc_irq_vectors_affinity(
 				pm8001_ha->pdev, 2, PM8001_MAX_MSIX_VEC,
Signature · 1 line
2.51.0
Reviewed-by on v10 7/13
#11 lore raw

Re: [PATCH v10 07/13] scsi: Use block layer helpers to constrain queue affinity

Aaron,

Quoted 10 lines

Ensure that IRQ affinity setup also respects the queue-to-CPU mapping constraints provided by the block layer. This allows the SCSI drivers to avoid assigning interrupts to CPUs that the block layer has excluded (e.g., isolated CPUs).

Only convert drivers which are already using the pci_alloc_irq_vectors_affinity with the PCI_IRQ_AFFINITY flag set. Because these drivers are enabled to let the IRQ core code to set the affinity. Also don't update qla2xxx because the nvme-fabrics code is not ready yet.

Signature · 1 line
Martin K. Petersen
#12 lore raw

PATCH v10 8/13 virtio: blk/scsi: use block layer helpers to constrain queue affinity

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Ensure that IRQ affinity setup also respects the queue-to-CPU mapping constraints provided by the block layer. This allows the virtio drivers to avoid assigning interrupts to CPUs that the block layer has excluded (e.g., isolated CPUs).

---
 drivers/block/virtio_blk.c | 4 +++-
 drivers/scsi/virtio_scsi.c | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +3 -1
index b1c9a27fe00f..9d737510454b 100644
@@ -964,7 +964,9 @@ static int init_vq(struct virtio_blk *vblk)
 	unsigned short num_vqs;
 	unsigned short num_poll_vqs;
 	struct virtio_device *vdev = vblk->vdev;
-	struct irq_affinity desc = { 0, };
+	struct irq_affinity desc = {
+		.mask = blk_mq_possible_queue_affinity(),
+	};
 
 	err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ,
 				   struct virtio_blk_config, num_queues,
drivers/scsi/virtio_scsi.c +4 -1
index 0ed8558dad72..520a7da5386e 100644
@@ -849,7 +849,10 @@ static int virtscsi_init(struct virtio_device *vdev,
 	u32 num_vqs, num_poll_vqs, num_req_vqs;
 	struct virtqueue_info *vqs_info;
 	struct virtqueue **vqs;
-	struct irq_affinity desc = { .pre_vectors = 2 };
+	struct irq_affinity desc = {
+		.pre_vectors = 2,
+		.mask = blk_mq_possible_queue_affinity(),
+	};
 
 	num_req_vqs = vscsi->num_queues;
 	num_vqs = num_req_vqs + VIRTIO_SCSI_VQ_BASE;
Signature · 1 line
2.51.0
Reviewed-by on v10 8/13
#13 lore raw

Re: [PATCH v10 08/13] virtio: blk/scsi: use block layer helpers to constrain queue affinity

Aaron,

Quoted 4 lines

Ensure that IRQ affinity setup also respects the queue-to-CPU mapping constraints provided by the block layer. This allows the virtio drivers to avoid assigning interrupts to CPUs that the block layer has excluded (e.g., isolated CPUs).

Signature · 1 line
Martin K. Petersen
#14 lore raw

PATCH v10 9/13 isolation: Introduce io_queue isolcpus type

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Multiqueue drivers spread I/O queues across all CPUs for optimal performance. However, these drivers are not aware of CPU isolation requirements and will distribute queues without considering the isolcpus configuration.

Introduce a new isolcpus mask that allows users to define which CPUs should have I/O queues assigned. This is similar to managed_irq, but intended for drivers that do not use the managed IRQ infrastructure

---
 include/linux/sched/isolation.h | 1 +
 kernel/sched/isolation.c        | 7 +++++++
 2 files changed, 8 insertions(+)
include/linux/sched/isolation.h +1 -0
index dc3975ff1b2e..7b266fc2a405 100644
@@ -18,6 +18,7 @@ enum hk_type {
 	HK_TYPE_MANAGED_IRQ,
 	/* Inverse of boot-time nohz_full= or isolcpus=nohz arguments */
 	HK_TYPE_KERNEL_NOISE,
+	HK_TYPE_IO_QUEUE,
 	HK_TYPE_MAX,
 
 	/*
kernel/sched/isolation.c +7 -0
index ef152d401fe2..3406e3024fd4 100644
@@ -16,6 +16,7 @@ enum hk_flags {
 	HK_FLAG_DOMAIN		= BIT(HK_TYPE_DOMAIN),
 	HK_FLAG_MANAGED_IRQ	= BIT(HK_TYPE_MANAGED_IRQ),
 	HK_FLAG_KERNEL_NOISE	= BIT(HK_TYPE_KERNEL_NOISE),
+	HK_FLAG_IO_QUEUE	= BIT(HK_TYPE_IO_QUEUE),
 };
 
 DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
@@ -340,6 +341,12 @@ static int __init housekeeping_isolcpus_setup(char *str)
 			continue;
 		}
 
+		if (!strncmp(str, "io_queue,", 9)) {
+			str += 9;
+			flags |= HK_FLAG_IO_QUEUE;
+			continue;
+		}
+
 		/*
 		 * Skip unknown sub-parameter and validate that it is not
 		 * containing an invalid character.
Signature · 1 line
2.51.0
Reviewed-by on v10 9/13
#15 lore raw

Re: [PATCH v10 09/13] isolation: Introduce io_queue isolcpus type

Aaron,

Quoted 8 lines

Multiqueue drivers spread I/O queues across all CPUs for optimal performance. However, these drivers are not aware of CPU isolation requirements and will distribute queues without considering the isolcpus configuration.

Introduce a new isolcpus mask that allows users to define which CPUs should have I/O queues assigned. This is similar to managed_irq, but intended for drivers that do not use the managed IRQ infrastructure

Signature · 1 line
Martin K. Petersen
#16 lore raw

PATCH v10 10/13 blk-mq: use hk cpus only when isolcpus=io_queue is enabled

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

Extend the capabilities of the generic CPU to hardware queue (hctx) mapping code, so it maps houskeeping CPUs and isolated CPUs to the hardware queues evenly.

A hctx is only operational when there is at least one online housekeeping CPU assigned (aka active_hctx). Thus, check the final mapping that there is no hctx which has only offline housekeeing CPU and online isolated CPUs.

Example mapping result:

16 online CPUs

isolcpus=io_queue,2-3,6-7,12-13

Queue mapping:
hctx0: default 0 2
hctx1: default 1 3
hctx2: default 4 6
hctx3: default 5 7
hctx4: default 8 12
hctx5: default 9 13
hctx6: default 10
hctx7: default 11
hctx8: default 14
hctx9: default 15

IRQ mapping:

        irq 42 affinity 0 effective 0  nvme0q0
        irq 43 affinity 0 effective 0  nvme0q1
        irq 44 affinity 1 effective 1  nvme0q2
        irq 45 affinity 4 effective 4  nvme0q3
        irq 46 affinity 5 effective 5  nvme0q4
        irq 47 affinity 8 effective 8  nvme0q5
        irq 48 affinity 9 effective 9  nvme0q6
        irq 49 affinity 10 effective 10  nvme0q7
        irq 50 affinity 11 effective 11  nvme0q8
        irq 51 affinity 14 effective 14  nvme0q9
        irq 52 affinity 15 effective 15  nvme0q10

A corner case is when the number of online CPUs and present CPUs differ and the driver asks for less queues than online CPUs, e.g.

8 online CPUs, 16 possible CPUs

isolcpus=io_queue,2-3,6-7,12-13
virtio_blk.num_request_queues=2

Queue mapping:

        hctx0: default 0 1 2 3 4 5 6 7 8 12 13
        hctx1: default 9 10 11 14 15

IRQ mapping

        irq 27 affinity 0 effective 0 virtio0-config
        irq 28 affinity 0-1,4-5,8 effective 5 virtio0-req.0
        irq 29 affinity 9-11,14-15 effective 0 virtio0-req.1

Noteworthy is that for the normal/default configuration (!isoclpus) the mapping will change for systems which have non hyperthreading CPUs. The main assignment loop will completely rely that group_mask_cpus_evenly to do the right thing. The old code would distribute the CPUs linearly over the hardware context:

queue mapping for /dev/nvme0n1

        hctx0: default 0 8
        hctx1: default 1 9
        hctx2: default 2 10
        hctx3: default 3 11
        hctx4: default 4 12
        hctx5: default 5 13
        hctx6: default 6 14
        hctx7: default 7 15

The assign each hardware context the map generated by the group_mask_cpus_evenly function:

queue mapping for /dev/nvme0n1
hctx0: default 0 1
hctx1: default 2 3
hctx2: default 4 5
hctx3: default 6 7
hctx4: default 8 9
hctx5: default 10 11
hctx6: default 12 13
hctx7: default 14 15

In case of hyperthreading CPUs, the resulting map stays the same.

[atomlin: Fixed absolute vs. relative hardware queue index mix-up in
blk_mq_map_queues and validation checks; fixed typographical errors.]

---
 block/blk-mq-cpumap.c | 175 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 157 insertions(+), 18 deletions(-)
block/blk-mq-cpumap.c +157 -18
index 8244ecf87835..8d09af49a142 100644
@@ -22,7 +22,18 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
 {
 	unsigned int num;
 
-	num = cpumask_weight(mask);
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE)) {
+		const struct cpumask *hk_mask;
+		struct cpumask avail_mask;
+
+		hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+		cpumask_and(&avail_mask, mask, hk_mask);
+
+		num = cpumask_weight(&avail_mask);
+	} else {
+		num = cpumask_weight(mask);
+	}
+
 	return min_not_zero(num, max_queues);
 }
 
@@ -31,9 +42,13 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
  *
  * Returns an affinity mask that represents the queue-to-CPU mapping
  * requested by the block layer based on possible CPUs.
+ * This helper takes isolcpus settings into account.
  */
 const struct cpumask *blk_mq_possible_queue_affinity(void)
 {
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE))
+		return housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+
 	return cpu_possible_mask;
 }
 EXPORT_SYMBOL_GPL(blk_mq_possible_queue_affinity);
@@ -46,6 +61,14 @@ EXPORT_SYMBOL_GPL(blk_mq_possible_queue_affinity);
  */
 const struct cpumask *blk_mq_online_queue_affinity(void)
 {
+	/*
+	 * Return the stable housekeeping mask if enabled. Callers (e.g.,
+	 * the IRQ affinity core) are responsible for safely intersecting
+	 * this with a local snapshot of the online mask.
+	 */
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE))
+		return housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+
 	return cpu_online_mask;
 }
 EXPORT_SYMBOL_GPL(blk_mq_online_queue_affinity);
@@ -57,7 +80,8 @@ EXPORT_SYMBOL_GPL(blk_mq_online_queue_affinity);
  *		ignored.
  *
  * Calculates the number of queues to be used for a multiqueue
- * device based on the number of possible CPUs.
+ * device based on the number of possible CPUs. This helper
+ * takes isolcpus settings into account.
  */
 unsigned int blk_mq_num_possible_queues(unsigned int max_queues)
 {
@@ -72,7 +96,8 @@ EXPORT_SYMBOL_GPL(blk_mq_num_possible_queues);
  *		ignored.
  *
  * Calculates the number of queues to be used for a multiqueue
- * device based on the number of online CPUs.
+ * device based on the number of online CPUs. This helper
+ * takes isolcpus settings into account.
  */
 unsigned int blk_mq_num_online_queues(unsigned int max_queues)
 {
@@ -80,23 +105,104 @@ unsigned int blk_mq_num_online_queues(unsigned int max_queues)
 }
 EXPORT_SYMBOL_GPL(blk_mq_num_online_queues);
 
+static bool blk_mq_validate(struct blk_mq_queue_map *qmap,
+			    const struct cpumask *active_hctx)
+{
+	/*
+	 * Verify if the mapping is usable when housekeeping
+	 * configuration is enabled
+	 */
+
+	for (int queue = 0; queue < qmap->nr_queues; queue++) {
+		int cpu;
+
+		if (cpumask_test_cpu(queue, active_hctx)) {
+			/*
+			 * This hctx has at least one online CPU thus it
+			 * is able to serve any assigned isolated CPU.
+			 */
+			continue;
+		}
+
+		/*
+		 * There is no housekeeping online CPU for this hctx, all
+		 * good as long as all non-housekeeping CPUs are also
+		 * offline.
+		 */
+		for_each_online_cpu(cpu) {
+			if (qmap->mq_map[cpu] != qmap->queue_offset + queue)
+				continue;
+
+			pr_warn("Unable to create a usable CPU-to-queue mapping with the given constraints\n");
+			return false;
+		}
+	}
+
+	return true;
+}
+
+static void blk_mq_map_fallback(struct blk_mq_queue_map *qmap)
+{
+	unsigned int cpu;
+
+	/*
+	 * Map all CPUs to the first hctx to ensure at least one online
+	 * CPU is serving it.
+	 */
+	for_each_possible_cpu(cpu)
+		qmap->mq_map[cpu] = 0;
+}
+
 void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
 {
-	const struct cpumask *masks;
+	struct cpumask *masks __free(kfree) = NULL;
+	const struct cpumask *constraint;
 	unsigned int queue, cpu, nr_masks;
+	cpumask_var_t active_hctx;
 
-	masks = group_cpus_evenly(qmap->nr_queues, &nr_masks);
-	if (!masks) {
-		for_each_possible_cpu(cpu)
-			qmap->mq_map[cpu] = qmap->queue_offset;
-		return;
-	}
+	if (!zalloc_cpumask_var(&active_hctx, GFP_KERNEL))
+		goto fallback;
+
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE))
+		constraint = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+	else
+		constraint = cpu_possible_mask;
+
+	/* Map CPUs to the hardware contexts (hctx) */
+	masks = group_mask_cpus_evenly(qmap->nr_queues, constraint, &nr_masks);
+	if (!masks)
+		goto free_fallback;
 
 	for (queue = 0; queue < qmap->nr_queues; queue++) {
-		for_each_cpu(cpu, &masks[queue % nr_masks])
+		unsigned int idx = (qmap->queue_offset + queue) % nr_masks;
+
+		for_each_cpu(cpu, &masks[idx]) {
 			qmap->mq_map[cpu] = qmap->queue_offset + queue;
+
+			if (cpu_online(cpu))
+				cpumask_set_cpu(queue, active_hctx);
+		}
+	}
+
+	/* Map any unassigned CPU evenly to the hardware contexts (hctx) */
+	queue = cpumask_first(active_hctx);
+	for_each_cpu_andnot(cpu, cpu_possible_mask, constraint) {
+		qmap->mq_map[cpu] = qmap->queue_offset + queue;
+		queue = cpumask_next_wrap(queue, active_hctx);
 	}
-	kfree(masks);
+
+	if (!blk_mq_validate(qmap, active_hctx))
+		goto free_fallback;
+
+	free_cpumask_var(active_hctx);
+
+	return;
+
+free_fallback:
+	free_cpumask_var(active_hctx);
+
+fallback:
+	blk_mq_map_fallback(qmap);
 }
 EXPORT_SYMBOL_GPL(blk_mq_map_queues);
 
@@ -133,24 +239,57 @@ void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,
 			  struct device *dev, unsigned int offset)
 
 {
-	const struct cpumask *mask;
+	cpumask_var_t active_hctx, mask;
 	unsigned int queue, cpu;
 
 	if (!dev->bus->irq_get_affinity)
 		goto fallback;
 
+	if (!zalloc_cpumask_var(&active_hctx, GFP_KERNEL))
+		goto fallback;
+
+	if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) {
+		free_cpumask_var(active_hctx);
+		goto fallback;
+	}
+
+	/* Map CPUs to the hardware contexts (hctx) */
 	for (queue = 0; queue < qmap->nr_queues; queue++) {
-		mask = dev->bus->irq_get_affinity(dev, queue + offset);
-		if (!mask)
-			goto fallback;
+		const struct cpumask *affinity_mask;
+
+		affinity_mask = dev->bus->irq_get_affinity(dev, offset + queue);
+		if (!affinity_mask)
+			goto free_fallback;
 
-		for_each_cpu(cpu, mask)
+		for_each_cpu(cpu, affinity_mask) {
 			qmap->mq_map[cpu] = qmap->queue_offset + queue;
+
+			cpumask_set_cpu(cpu, mask);
+			if (cpu_online(cpu))
+				cpumask_set_cpu(queue, active_hctx);
+		}
 	}
 
+	/* Map any unassigned CPU evenly to the hardware contexts (hctx) */
+	queue = cpumask_first(active_hctx);
+	for_each_cpu_andnot(cpu, cpu_possible_mask, mask) {
+		qmap->mq_map[cpu] = qmap->queue_offset + queue;
+		queue = cpumask_next_wrap(queue, active_hctx);
+	}
+
+	if (!blk_mq_validate(qmap, active_hctx))
+		goto free_fallback;
+
+	free_cpumask_var(active_hctx);
+	free_cpumask_var(mask);
+
 	return;
 
+free_fallback:
+	free_cpumask_var(active_hctx);
+	free_cpumask_var(mask);
+
 fallback:
-	blk_mq_map_queues(qmap);
+	blk_mq_map_fallback(qmap);
 }
 EXPORT_SYMBOL_GPL(blk_mq_map_hw_queues);
Signature · 1 line
2.51.0
#17 lore raw

Re: [PATCH v10 10/13] blk-mq: use hk cpus only when isolcpus=io_queue is enabled

Quoted 105 lines · Aaron Tomlin

From: Daniel Wagner <[email protected]>

Extend the capabilities of the generic CPU to hardware queue (hctx) mapping code, so it maps houskeeping CPUs and isolated CPUs to the hardware queues evenly.

A hctx is only operational when there is at least one online housekeeping CPU assigned (aka active_hctx). Thus, check the final mapping that there is no hctx which has only offline housekeeing CPU and online isolated CPUs.

Example mapping result:

16 online CPUs

   isolcpus=io_queue,2-3,6-7,12-13

Queue mapping:
hctx0: default 0 2
hctx1: default 1 3
hctx2: default 4 6
hctx3: default 5 7
hctx4: default 8 12
hctx5: default 9 13
hctx6: default 10
hctx7: default 11
hctx8: default 14
hctx9: default 15

IRQ mapping:

         irq 42 affinity 0 effective 0  nvme0q0
         irq 43 affinity 0 effective 0  nvme0q1
         irq 44 affinity 1 effective 1  nvme0q2
         irq 45 affinity 4 effective 4  nvme0q3
         irq 46 affinity 5 effective 5  nvme0q4
         irq 47 affinity 8 effective 8  nvme0q5
         irq 48 affinity 9 effective 9  nvme0q6
         irq 49 affinity 10 effective 10  nvme0q7
         irq 50 affinity 11 effective 11  nvme0q8
         irq 51 affinity 14 effective 14  nvme0q9
         irq 52 affinity 15 effective 15  nvme0q10

A corner case is when the number of online CPUs and present CPUs differ and the driver asks for less queues than online CPUs, e.g.

8 online CPUs, 16 possible CPUs

   isolcpus=io_queue,2-3,6-7,12-13
   virtio_blk.num_request_queues=2

Queue mapping:

         hctx0: default 0 1 2 3 4 5 6 7 8 12 13
         hctx1: default 9 10 11 14 15

IRQ mapping

         irq 27 affinity 0 effective 0 virtio0-config
         irq 28 affinity 0-1,4-5,8 effective 5 virtio0-req.0
         irq 29 affinity 9-11,14-15 effective 0 virtio0-req.1

Noteworthy is that for the normal/default configuration (!isoclpus) the mapping will change for systems which have non hyperthreading CPUs. The main assignment loop will completely rely that group_mask_cpus_evenly to do the right thing. The old code would distribute the CPUs linearly over the hardware context:

queue mapping for /dev/nvme0n1

         hctx0: default 0 8
         hctx1: default 1 9
         hctx2: default 2 10
         hctx3: default 3 11
         hctx4: default 4 12
         hctx5: default 5 13
         hctx6: default 6 14
         hctx7: default 7 15

The assign each hardware context the map generated by the group_mask_cpus_evenly function:

queue mapping for /dev/nvme0n1
hctx0: default 0 1
hctx1: default 2 3
hctx2: default 4 5
hctx3: default 6 7
hctx4: default 8 9
hctx5: default 10 11
hctx6: default 12 13
hctx7: default 14 15

In case of hyperthreading CPUs, the resulting map stays the same.

[atomlin: Fixed absolute vs. relative hardware queue index mix-up in
blk_mq_map_queues and validation checks; fixed typographical errors.]

---
  block/blk-mq-cpumap.c | 175 +++++++++++++++++++++++++++++++++++++-----
  1 file changed, 157 insertions(+), 18 deletions(-)
block/blk-mq-cpumap.c +0 -0
index 8244ecf87835..8d09af49a142 100644
@@ -22,7 +22,18 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
  {
  	unsigned int num;

block/blk-mq-cpumap.c static unsigned int blk_mq_num_queues(const struct cpumask *mask, · line 32

Quoted 10 lines
block/blk-mq-cpumap.c +8 -1
 
-	num = cpumask_weight(mask);
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE)) {
+		const struct cpumask *hk_mask;
+		struct cpumask avail_mask;
+
+		hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+		cpumask_and(&avail_mask, mask, hk_mask);
+
+		num = cpumask_weight(&avail_mask);

As said before by Ming Lei, struct cpumask can be rather big in size if NR_CPUS is large. I will suggest using cpumask_weight_and() instead which will eliminate the need of the local variables.

Cheers,
Longman

#18 lore raw

Re: [PATCH v10 10/13] blk-mq: use hk cpus only when isolcpus=io_queue is enabled

Quoted 12 lines · Waiman Long
Quoted 12 lines
block/blk-mq-cpumap.c +4 -1
index 8244ecf87835..8d09af49a142 100644
@@ -22,7 +22,18 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
  {
  	unsigned int num;
-	num = cpumask_weight(mask);
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE)) {
+		const struct cpumask *hk_mask;
+		struct cpumask avail_mask;
+
Quoted 8 lines

block/blk-mq-cpumap.c static unsigned int blk_mq_num_queues(const struct cpumask *mask, · line 32

Quoted 4 lines
block/blk-mq-cpumap.c +4 -0
+		hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+		cpumask_and(&avail_mask, mask, hk_mask);
+
+		num = cpumask_weight(&avail_mask);

As said before by Ming Lei, struct cpumask can be rather big in size if NR_CPUS is large. I will suggest using cpumask_weight_and() instead which will eliminate the need of the local variables.

Hi Longman,

I agree. Also, it perfectly circumvents the need for the temporary local mask while achieving the exact same intersection count.

Kind regards,

Signature · 1 line
Aaron Tomlin
#19 lore raw

PATCH v10 11/13 blk-mq: prevent offlining hk CPUs with associated online isolated CPUs

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

When isolcpus=io_queue is enabled, and the last housekeeping CPU for a given hctx goes offline, there would be no CPU left to handle I/O. To prevent I/O stalls, prevent offlining housekeeping CPUs that are still serving isolated CPUs.

When isolcpus=io_queue is enabled and the last housekeeping CPU for a given hctx goes offline, no CPU would be left to handle I/O. To prevent I/O stalls, disallow offlining housekeeping CPUs that are still serving isolated CPUs.

---
 block/blk-mq.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
block/blk-mq.c +42 -0
index 3da2215b2912..8671f2170880 100644
@@ -3699,6 +3699,43 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)
 	return data.has_rq;
 }
 
+static bool blk_mq_hctx_can_offline_hk_cpu(struct blk_mq_hw_ctx *hctx,
+					   unsigned int this_cpu)
+{
+	const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+
+	for (int i = 0; i < hctx->nr_ctx; i++) {
+		struct blk_mq_ctx *ctx = hctx->ctxs[i];
+
+		if (ctx->cpu == this_cpu)
+			continue;
+
+		/*
+		 * Check if this context has at least one online
+		 * housekeeping CPU; in this case the hardware context is
+		 * usable.
+		 */
+		if (cpumask_test_cpu(ctx->cpu, hk_mask) &&
+		    cpu_online(ctx->cpu))
+			break;
+
+		/*
+		 * The context doesn't have any online housekeeping CPUs,
+		 * but there might be an online isolated CPU mapped to
+		 * it.
+		 */
+		if (cpu_is_offline(ctx->cpu))
+			continue;
+
+		pr_warn("%s: trying to offline hctx%d but there is still an online isolcpu CPU %d mapped to it\n",
+			hctx->queue->disk->disk_name,
+			hctx->queue_num, ctx->cpu);
+		return false;
+	}
+
+	return true;
+}
+
 static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx,
 		unsigned int this_cpu)
 {
@@ -3731,6 +3768,11 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
 			struct blk_mq_hw_ctx, cpuhp_online);
 	int ret = 0;
 
+	if (housekeeping_enabled(HK_TYPE_IO_QUEUE)) {
+		if (!blk_mq_hctx_can_offline_hk_cpu(hctx, cpu))
+			return -EINVAL;
+	}
+
 	if (!hctx->nr_ctx || blk_mq_hctx_has_online_cpu(hctx, cpu))
 		return 0;
 
Signature · 1 line
2.51.0
#20 lore raw

PATCH v10 12/13 genirq/affinity: Restrict managed IRQ affinity to housekeeping CPUs

In reply to Aaron Tomlin

At present, the managed interrupt spreading algorithm distributes vectors across all available CPUs within a given node or system. On systems employing CPU isolation (e.g., "isolcpus=io_queue"), this behaviour defeats the primary purpose of isolation by routing hardware interrupts (such as NVMe completion queues) directly to isolated cores.

Update irq_create_affinity_masks() to respect the housekeeping CPU mask. Introduce irq_spread_hk_filter() to intersect the natively calculated affinity mask with the HK_TYPE_IO_QUEUE mask, thereby keeping managed interrupts off isolated CPUs.

To ensure strict isolation whilst guaranteeing a valid routing destination:

1. Fallback mechanism: Should the initial spreading logic assign a vector exclusively to isolated CPUs (resulting in an empty intersection), the filter safely falls back to the system's online housekeeping CPUs.

2. Hotplug safety: The fallback utilises data_race(cpu_online_mask) instead of allocating a local cpumask snapshot. This circumvents CONFIG_CPUMASK_OFFSTACK stack bloat hazards on high-core-count systems. Furthermore, it prevents deadlocks with concurrent CPU hotplug operations (e.g., during storage driver error recovery) by eliminating the need to hold the CPU hotplug read lock.

3. Fast-path optimisation: The filtering logic is conditionally executed only if housekeeping is enabled, thereby ensuring zero overhead for standard configurations.

---
 kernel/irq/affinity.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
kernel/irq/affinity.c +25 -1
index 076a5ef1e306..dd9e7f5fbdec 100644
@@ -8,6 +8,24 @@
 #include <linux/slab.h>
 #include <linux/cpu.h>
 #include <linux/group_cpus.h>
+#include <linux/sched/isolation.h>
+
+/**
+ * irq_spread_hk_filter - Restrict an interrupt affinity mask to housekeeping CPUs
+ * @mask:            The interrupt affinity mask to filter (in/out)
+ * @hk_mask:         The system's housekeeping CPU mask
+ *
+ * Intersects @mask with @hk_mask to keep interrupts off isolated CPUs.
+ * If this intersection is empty (meaning all targeted CPUs were isolated),
+ * it falls back to the online housekeeping CPUs to guarantee a valid
+ * routing destination.
+ */
+static void irq_spread_hk_filter(struct cpumask *mask,
+				 const struct cpumask *hk_mask)
+{
+	if (!cpumask_and(mask, mask, hk_mask))
+		cpumask_and(mask, hk_mask, data_race(cpu_online_mask));
+}
 
 static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)
 {
@@ -27,6 +45,8 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 {
 	unsigned int affvecs, curvec, usedvecs, i;
 	struct irq_affinity_desc *masks = NULL;
+	const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_IO_QUEUE);
+	bool hk_enabled = housekeeping_enabled(HK_TYPE_IO_QUEUE);
 
 	/*
 	 * Determine the number of vectors which need interrupt affinities
@@ -83,8 +103,12 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 			return NULL;
 		}
 
-		for (int j = 0; j < nr_masks; j++)
+		for (int j = 0; j < nr_masks; j++) {
 			cpumask_copy(&masks[curvec + j].mask, &result[j]);
+			if (hk_enabled)
+				irq_spread_hk_filter(&masks[curvec + j].mask,
+						     hk_mask);
+		}
 		kfree(result);
 
 		curvec += nr_masks;
Signature · 1 line
2.51.0
#21 lore raw

PATCH v10 13/13 docs: add io_queue flag to isolcpus

In reply to Aaron Tomlin

From: Daniel Wagner <[email protected]>

The io_queue flag informs multiqueue device drivers where to place hardware queues. Document this new flag in the isolcpus command-line argument description.

---
 .../admin-guide/kernel-parameters.txt         | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +21 -1
index 03a550630644..9ed7c3ecd158 100644
@@ -2816,7 +2816,6 @@ Kernel parameters
 			  "number of CPUs in system - 1".
 
 			managed_irq
-
 			  Isolate from being targeted by managed interrupts
 			  which have an interrupt mask containing isolated
 			  CPUs. The affinity of managed interrupts is
@@ -2839,6 +2838,27 @@ Kernel parameters
 			  housekeeping CPUs has no influence on those
 			  queues.
 
+			io_queue
+			  Isolate from I/O queue work caused by multiqueue
+			  device drivers. Restrict the placement of
+			  queues to housekeeping CPUs only, ensuring that
+			  all I/O work is processed by a housekeeping CPU.
+
+			  The io_queue configuration takes precedence
+			  over managed_irq. When io_queue is used,
+			  managed_irq placement constrains have no
+			  effect.
+
+			  Note: Offlining housekeeping CPUS which serve
+			  isolated CPUs will be rejected. Isolated CPUs
+			  need to be offlined before offlining the
+			  housekeeping CPUs.
+
+			  Note: When an isolated CPU issues an I/O request,
+			  it is forwarded to a housekeeping CPU. This will
+			  trigger a software interrupt on the completion
+			  path.
+
 			The format of <cpu-list> is described above.
 
 	iucv=		[HW,NET]
Signature · 1 line
2.51.0
#22 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 27 lines · Aaron Tomlin

From: Daniel Wagner <[email protected]>

The io_queue flag informs multiqueue device drivers where to place hardware queues. Document this new flag in the isolcpus command-line argument description.

---
 .../admin-guide/kernel-parameters.txt         | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +0 -1
index 03a550630644..9ed7c3ecd158 100644
@@ -2816,7 +2816,6 @@ Kernel parameters
 			  "number of CPUs in system - 1".
 
 			managed_irq
-
 			  Isolate from being targeted by managed interrupts
 			  which have an interrupt mask containing isolated
 			  CPUs. The affinity of managed interrupts is

Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 2845

Quoted 8 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -2839,6 +2838,27 @@ Kernel parameters
 			  housekeeping CPUs has no influence on those
 			  queues.
 
+			io_queue
+			  Isolate from I/O queue work caused by multiqueue
+			  device drivers. Restrict the placement of
+			  queues to housekeeping CPUs only, ensuring that
+			  all I/O work is processed by a housekeeping CPU.

All these can be supported by managed_irq already, please document the thing which io_queue solves, and managed_irq can't cover, so user can know how to choose between the two command lines.

Restrict the placement of queues to housekeeping CPUs only looks totally stale, please see patch 10, in which isolated CPUs are spread too.

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
+
+			  The io_queue configuration takes precedence
+			  over managed_irq. When io_queue is used,
+			  managed_irq placement constrains have no
+			  effect.

Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 2860

Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10 -0
+
+			  Note: Offlining housekeeping CPUS which serve
+			  isolated CPUs will be rejected. Isolated CPUs
+			  need to be offlined before offlining the
+			  housekeeping CPUs.
+
+			  Note: When an isolated CPU issues an I/O request,
+			  it is forwarded to a housekeeping CPU. This will
+			  trigger a software interrupt on the completion
+			  path.

io_queue doesn't touch io completion code path, which is more implementation details, so not sure if the above Note is needed.

Thanks,
Ming

#23 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 8 lines · Ming Lei

On Wed, Apr 01, 2026 at 06:23:12PM -0400, Aaron Tomlin wrote:

All these can be supported by managed_irq already, please document the thing which io_queue solves, and managed_irq can't cover, so user can know how to choose between the two command lines.

Restrict the placement of queues to housekeeping CPUs only looks totally stale, please see patch 10, in which isolated CPUs are spread too.

Dear Ming,

Thank you for your careful review of the documentation and for raising these excellent points. I completely agree that the administrator guide must be as unambiguous as possible.

Regarding your first point on the distinction between managed_irq and io_queue, you are entirely correct that the documentation must explicitly guide the user in their choice. I shall revise the text to clarify that where managed_irq solely restricts the affinity of hardware interrupts at the interrupt controller level, io_queue governs the block layer multi-queue mapping algorithm itself. I will add a clear explanation that io_queue is required for users who utilise polling queues, which do not rely on interrupts, or specific drivers that do not use the managed interrupt infrastructure. Without io_queue, the block layer would still assign these polling duties to isolated CPUs, thereby breaking the isolation.

Every logical CPU, including the isolated ones, must logically map to a hardware context in order to submit input and output requests, saying they are completely restricted is indeed stale and technically inaccurate. The isolation mechanism actually ensures that the hardware contexts themselves are serviced by the housekeeping CPUs, while the isolated CPUs are simply mapped onto these housekeeping queues for submission purposes. I will rewrite this paragraph to accurately reflect this topology, ensuring it aligns perfectly with the behaviour introduced in patch 10.

Quoted 10 lines
Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10 -0
+
+			  The io_queue configuration takes precedence
+			  over managed_irq. When io_queue is used,
+			  managed_irq placement constrains have no
+			  effect.
+
+			  Note: Offlining housekeeping CPUS which serve
+			  isolated CPUs will be rejected. Isolated CPUs
+			  need to be offlined before offlining the
+			  housekeeping CPUs.
Quoted 8 lines

Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 2860

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
+
+			  Note: When an isolated CPU issues an I/O request,
+			  it is forwarded to a housekeeping CPU. This will
+			  trigger a software interrupt on the completion
+			  path.

io_queue doesn't touch io completion code path, which is more implementation details, so not sure if the above Note is needed.

Possibly the original author intended to suggest that the software interrupt is sent to the isolated CPU?

To achieve absolute zero disturbance, an isolated CPU must either entirely abstain from submitting standard I/O, or it must exclusively utilise polling queues, where the CPU actively checks for completions and entirely bypasses the interrupt and softirq mechanisms.

Kind regards,

Signature · 1 line
Aaron Tomlin
#24 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 16 lines · Aaron Tomlin
Quoted 8 lines · Ming Lei

On Wed, Apr 01, 2026 at 06:23:12PM -0400, Aaron Tomlin wrote:

All these can be supported by managed_irq already, please document the thing which io_queue solves, and managed_irq can't cover, so user can know how to choose between the two command lines.

Restrict the placement of queues to housekeeping CPUs only looks totally stale, please see patch 10, in which isolated CPUs are spread too.

Dear Ming,

Thank you for your careful review of the documentation and for raising these excellent points. I completely agree that the administrator guide must be as unambiguous as possible.

Quoted 11 lines

Regarding your first point on the distinction between managed_irq and io_queue, you are entirely correct that the documentation must explicitly guide the user in their choice. I shall revise the text to clarify that where managed_irq solely restricts the affinity of hardware interrupts at the interrupt controller level, io_queue governs the block layer multi-queue mapping algorithm itself. I will add a clear explanation that io_queue is required for users who utilise polling queues, which do not rely on interrupts, or specific drivers that do not use the managed interrupt infrastructure. Without io_queue, the block layer would still assign these polling duties to isolated CPUs, thereby breaking the isolation.

I don't think there is such breaking isolation thing. For iopoll, if applications won't submit polled IO on isolated CPUs, everything is just fine. If they do it, IO may be reaped from isolated CPUs, that is just their choice, anything is wrong?

Quoted 9 lines

Every logical CPU, including the isolated ones, must logically map to a hardware context in order to submit input and output requests, saying they are completely restricted is indeed stale and technically inaccurate. The isolation mechanism actually ensures that the hardware contexts themselves are serviced by the housekeeping CPUs, while the isolated CPUs are simply mapped onto these housekeeping queues for submission purposes. I will rewrite this paragraph to accurately reflect this topology, ensuring it aligns perfectly with the behaviour introduced in patch 10.

I am not sure if the above words is helpful from administrator viewpoint about the two kernel parameters.

IMO, only two differences from this viewpoint:

1) io_queue may reduce nr_hw_queues

2) when application submits IO from isolated CPUs, io_queue can complete IO from housekeeping CPUs.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Documentation/admin-guide/kernel-parameters.txt +10 -0
+
+			  The io_queue configuration takes precedence
+			  over managed_irq. When io_queue is used,
+			  managed_irq placement constrains have no
+			  effect.
+
+			  Note: Offlining housekeeping CPUS which serve
+			  isolated CPUs will be rejected. Isolated CPUs
+			  need to be offlined before offlining the
+			  housekeeping CPUs.
Quoted 8 lines

Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 2860

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
+
+			  Note: When an isolated CPU issues an I/O request,
+			  it is forwarded to a housekeeping CPU. This will
+			  trigger a software interrupt on the completion
+			  path.

io_queue doesn't touch io completion code path, which is more implementation details, so not sure if the above Note is needed.

Quoted 2 lines

Possibly the original author intended to suggest that the software interrupt is sent to the isolated CPU?

I meant this point can't be found in the patches.

Thanks,
Ming

#25 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 4 lines · Ming Lei

I don't think there is such breaking isolation thing. For iopoll, if applications won't submit polled IO on isolated CPUs, everything is just fine. If they do it, IO may be reaped from isolated CPUs, that is just their choice, anything is wrong?

Hi Ming,

Thank you for your follow up. You make a fair point regarding polling queues and application choice; if an application explicitly binds to an isolated CPU and submits polled operations, it is indeed actively electing to utilise that core and accept the resulting behaviour.

However, the architectural challenge arises from how the kernel handles these queues structurally when the application does not explicitly make that choice. Because poll queues never utilise interrupts, they are completely invisible to the managed interrupt subsystem.

If we were to rely exclusively on the managed irq flag, the block layer would blindly map these non interrupt driven polling queues to isolated CPUs. If a general background storage operation were then routed to that queue, the isolated core would be forced to spin actively in a tight loop waiting for the hardware completion. This would completely monopolise the core and destroy any real time isolation guarantees without the user space application ever having requested it.

This illustrates precisely why the io queue flag is a mechanical necessity. Its primary objective is to act as a comprehensive block layer isolation boundary. It structurally restricts both hardware queue placement and managed interrupt affinity strictly to housekeeping CPUs, ensuring that no storage queue operations of any kind are mapped to an isolated CPU.

To achieve this reliably, this series expands the struct irq affinity structure to incorporate a new CPU mask [1]. This mask is explicitly set to the result of blk mq online queue affinity. By passing this housekeeping mask directly through the interrupt affinity parameters, we ensure that the native affinity calculation is strictly bounded to non isolated CPUs from the moment the device probes.

This structural enhancement allows device drivers to seamlessly inherit the isolation constraints without requiring bespoke, driver specific logic. A clear example of this application can be seen in the modifications to the Broadcom MPI3 Storage Controller [2]. By leveraging the expanded struct irq affinity, the driver guarantees that its queues and corresponding managed interrupts are perfectly aligned with the system housekeeping configuration, completely avoiding the isolated CPUs during allocation.

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

I hope this better illustrates the mechanical necessity of the io_queue flag and the corresponding changes to the interrupt affinity structures.

Quoted 12 lines
Quoted 8 lines

Every logical CPU, including the isolated ones, must logically map to a hardware context in order to submit input and output requests, saying they are completely restricted is indeed stale and technically inaccurate. The isolation mechanism actually ensures that the hardware contexts themselves are serviced by the housekeeping CPUs, while the isolated CPUs are simply mapped onto these housekeeping queues for submission purposes. I will rewrite this paragraph to accurately reflect this topology, ensuring it aligns perfectly with the behaviour introduced in patch 10.

I am not sure if the above words is helpful from administrator viewpoint about the two kernel parameters.

Quoted 6 lines

IMO, only two differences from this viewpoint:

1) io_queue may reduce nr_hw_queues

2) when application submits IO from isolated CPUs, io_queue can complete IO from housekeeping CPUs.

Acknowledged.

Kind regards,

Signature · 1 line
Aaron Tomlin
#26 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 19 lines · Aaron Tomlin
Quoted 4 lines · Ming Lei

I don't think there is such breaking isolation thing. For iopoll, if applications won't submit polled IO on isolated CPUs, everything is just fine. If they do it, IO may be reaped from isolated CPUs, that is just their choice, anything is wrong?

Hi Ming,

Thank you for your follow up. You make a fair point regarding polling queues and application choice; if an application explicitly binds to an isolated CPU and submits polled operations, it is indeed actively electing to utilise that core and accept the resulting behaviour.

However, the architectural challenge arises from how the kernel handles these queues structurally when the application does not explicitly make that choice. Because poll queues never utilise interrupts, they are completely invisible to the managed interrupt subsystem.

Quoted 4 lines

If we were to rely exclusively on the managed irq flag, the block layer would blindly map these non interrupt driven polling queues to isolated CPUs. If a general background storage operation were then routed to that queue, the isolated core would be forced to spin actively in a tight

How can the isolated core be scheduled for running polling task?

Who triggered it?

Quoted 3 lines

loop waiting for the hardware completion. This would completely monopolise the core and destroy any real time isolation guarantees without the user space application ever having requested it.

No.

IOPOLL queue doesn't have interrupt, and the ->poll() is only run from the submission context. So if you don't submitted polled IO on isolated CPU cores, everything is just fine. This is simpler than irq IO actually.

Quoted 22 lines

This illustrates precisely why the io queue flag is a mechanical necessity. Its primary objective is to act as a comprehensive block layer isolation boundary. It structurally restricts both hardware queue placement and managed interrupt affinity strictly to housekeeping CPUs, ensuring that no storage queue operations of any kind are mapped to an isolated CPU.

To achieve this reliably, this series expands the struct irq affinity structure to incorporate a new CPU mask [1]. This mask is explicitly set to the result of blk mq online queue affinity. By passing this housekeeping mask directly through the interrupt affinity parameters, we ensure that the native affinity calculation is strictly bounded to non isolated CPUs from the moment the device probes.

This structural enhancement allows device drivers to seamlessly inherit the isolation constraints without requiring bespoke, driver specific logic. A clear example of this application can be seen in the modifications to the Broadcom MPI3 Storage Controller [2]. By leveraging the expanded struct irq affinity, the driver guarantees that its queues and corresponding managed interrupts are perfectly aligned with the system housekeeping configuration, completely avoiding the isolated CPUs during allocation.

Quoted 5 lines

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

I hope this better illustrates the mechanical necessity of the io_queue flag and the corresponding changes to the interrupt affinity structures.

Can you share one example in which managed irq can't address?

Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

Every logical CPU, including the isolated ones, must logically map to a hardware context in order to submit input and output requests, saying they are completely restricted is indeed stale and technically inaccurate. The isolation mechanism actually ensures that the hardware contexts themselves are serviced by the housekeeping CPUs, while the isolated CPUs are simply mapped onto these housekeeping queues for submission purposes. I will rewrite this paragraph to accurately reflect this topology, ensuring it aligns perfectly with the behaviour introduced in patch 10.

I am not sure if the above words is helpful from administrator viewpoint about the two kernel parameters.

Quoted 8 lines
Quoted 6 lines

IMO, only two differences from this viewpoint:

1) io_queue may reduce nr_hw_queues

2) when application submits IO from isolated CPUs, io_queue can complete IO from housekeeping CPUs.

Acknowledged.

Are there other major differences besides the two mentioned above?

Thanks,
Ming

#27 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 8 lines · Ming Lei

How can the isolated core be scheduled for running polling task?

Who triggered it?

Quoted 3 lines

loop waiting for the hardware completion. This would completely monopolise the core and destroy any real time isolation guarantees without the user space application ever having requested it.

Quoted 5 lines

No.

IOPOLL queue doesn't have interrupt, and the ->poll() is only run from the submission context. So if you don't submitted polled IO on isolated CPU cores, everything is just fine. This is simpler than irq IO actually.

Yes, you are entirely correct. The ->iopoll() is indeed executed strictly within the submission context. In the example below, the file operations iopoll callback is iocb_bio_iopoll():

      // file->f_op->iopoll(&rw->kiocb, iob, poll_flags)
      iocb_bio_iopoll(&rw->kiocb, iob, poll_flags)
      {
        struct bio *bio

        bio = READ_ONCE(kiocb->private)
        if (bio)
          bio_poll(bio, iob, flags)
            if (queue_is_mq(q))
              blk_mq_poll(q, cookie, iob, flags)
              {
                if (!blk_mq_can_poll(q))
                  return 0

                blk_hctx_poll(q, q->queue_hw_ctx[cookie], iob, flags)
                {
                    int ret

                    do {
                        ret = q->mq_ops->poll(hctx, iob)
                        if (ret > 0)
                            return ret
                        if (task_sigpending(current))
                            return 1
                        if (ret < 0 || (flags & BLK_POLL_ONESHOT))
                            break
                        cpu_relax()
                    } while (!need_resched())

                    return 0
                }
              }

If an application on an isolated CPU does not explicitly submit a polled I/O request, it will not poll. Thank you for correcting me on this.

Quoted 1 line

Can you share one example in which managed irq can't address?

Without io_queue, the block layer maps isolated CPUs to these queues, and the device will fire unmanaged interrupts that can freely land on isolated CPUs, thereby breaking isolation. By applying the constraint via io_queue at the block layer, we restrict the hardware queue count and map the isolated CPUs to the housekeeping queues, ensuring isolation is maintained regardless of whether the driver uses managed interrupts.

Does the above help?

Quoted 11 lines
Quoted 9 lines
Quoted 7 lines

IMO, only two differences from this viewpoint:

1) io_queue may reduce nr_hw_queues

2) when application submits IO from isolated CPUs, io_queue can complete IO from housekeeping CPUs.

Acknowledged.

Are there other major differences besides the two mentioned above?

I believe the above is sufficient. Please let me know your thoughts.

Kind regards,

Signature · 1 line
Aaron Tomlin
#28 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 52 lines · Aaron Tomlin
Quoted 8 lines · Ming Lei

How can the isolated core be scheduled for running polling task?

Who triggered it?

Quoted 3 lines

loop waiting for the hardware completion. This would completely monopolise the core and destroy any real time isolation guarantees without the user space application ever having requested it.

Quoted 5 lines

No.

IOPOLL queue doesn't have interrupt, and the ->poll() is only run from the submission context. So if you don't submitted polled IO on isolated CPU cores, everything is just fine. This is simpler than irq IO actually.

Yes, you are entirely correct. The ->iopoll() is indeed executed strictly within the submission context. In the example below, the file operations iopoll callback is iocb_bio_iopoll():

      // file->f_op->iopoll(&rw->kiocb, iob, poll_flags)
      iocb_bio_iopoll(&rw->kiocb, iob, poll_flags)
      {
        struct bio *bio

        bio = READ_ONCE(kiocb->private)
        if (bio)
          bio_poll(bio, iob, flags)
            if (queue_is_mq(q))
              blk_mq_poll(q, cookie, iob, flags)
              {
                if (!blk_mq_can_poll(q))
                  return 0

                blk_hctx_poll(q, q->queue_hw_ctx[cookie], iob, flags)
                {
                    int ret

                    do {
                        ret = q->mq_ops->poll(hctx, iob)
                        if (ret > 0)
                            return ret
                        if (task_sigpending(current))
                            return 1
                        if (ret < 0 || (flags & BLK_POLL_ONESHOT))
                            break
                        cpu_relax()
                    } while (!need_resched())

                    return 0
                }
              }
Quoted 2 lines

If an application on an isolated CPU does not explicitly submit a polled I/O request, it will not poll. Thank you for correcting me on this.

Great, you finally get the point.

Quoted 5 lines
Quoted 2 lines

Can you share one example in which managed irq can't address?

Without io_queue, the block layer maps isolated CPUs to these queues, and the device will fire unmanaged interrupts that can freely land on isolated

For unmanaged interrupts, user can set irq affinity on housekeeping cpus from /proc or kernel command line.

Why is unmanaged interrupts involved with this patchset?

Quoted 6 lines

CPUs, thereby breaking isolation. By applying the constraint via io_queue at the block layer, we restrict the hardware queue count and map the isolated CPUs to the housekeeping queues, ensuring isolation is maintained regardless of whether the driver uses managed interrupts.

Does the above help?

As I mentioned, managed irq already covers it:

- typically application submits IO from housekeeping CPUs, which is mapped to one hardware, which effective interrupt affinity excludes isolated CPUs if possible.

I'd suggest to share some real problems you found instead of something imaginary.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

IMO, only two differences from this viewpoint:

1) io_queue may reduce nr_hw_queues

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

2) when application submits IO from isolated CPUs, io_queue can complete IO from housekeeping CPUs.

Acknowledged.

Are there other major differences besides the two mentioned above?

I believe the above is sufficient. Please let me know your thoughts.

Both two are small improvement, not bug fixes. However the user has to pay the cost of potential failing of offlining CPU. Not mention the little complicated change: 19 files changed, 378 insertions(+), 48 deletions(-)

But I won't object if you can update the commit log/kernel command line doc and fix the issue found in review.

Thanks,
Ming

#29 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 4 lines · Ming Lei

For unmanaged interrupts, user can set irq affinity on housekeeping cpus from /proc or kernel command line.

Why is unmanaged interrupts involved with this patchset?

Thank you for your continued engagement and for ultimately supporting the progression of this series.

To clarify the handling of unmanaged interrupts, while it is entirely true that an administrator could attempt to manually configure "irqaffinity=" or via procfs after the fact, this series actively address unmanaged interrupts.

Quoted 7 lines
Quoted 6 lines

CPUs, thereby breaking isolation. By applying the constraint via io_queue at the block layer, we restrict the hardware queue count and map the isolated CPUs to the housekeeping queues, ensuring isolation is maintained regardless of whether the driver uses managed interrupts.

Does the above help?

Quoted 8 lines

As I mentioned, managed irq already covers it:

- typically application submits IO from housekeeping CPUs, which is mapped to one hardware, which effective interrupt affinity excludes isolated CPUs if possible.

I'd suggest to share some real problems you found instead of something imaginary.

If we trace how mpi3mr sets up its ISRs, it relies heavily on the core grouping logic:

mpi3mr_setup_isr
{
unsigned int irq_flags = PCI_IRQ_MSIX

struct irq_affinity desc = { .pre_vectors = 1, .post_vectors = 1, }

  pci_alloc_irq_vectors_affinity(mrioc->pdev, min_vec,
                                 max_vectors, irq_flags, &desc)
  {
    if (flags & PCI_IRQ_MSIX) {
      // affd != NULL
      __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, affd, flags)
      {
        for (;;) {

          msix_capability_init(dev, entries, nvec, affd)
          {
            msix_setup_interrupts(dev, entries, nvec, affd)
            {
              // affd
              irq_create_affinity_masks(nvec, affd)
              {
                for (i = 0, usedvecs = 0; i < affd->nr_sets; i++) {
                  unsigned int nr_masks, this_vecs = affd->set_size[i]
                  struct cpumask *result = group_cpus_evenly(this_vecs,
                                                             &nr_masks)
                  if (!result) {
                    kfree(masks)
                    return NULL
                  }

                  for (int j = 0; j < nr_masks; j++)
                    cpumask_copy(&masks[curvec + j].mask, &result[j])
                  kfree(result);

                  curvec += nr_masks
                  usedvecs += nr_masks
                }
              }
            }
          }
        }
      }
    }

}
}

The critical issue lies at the invocation of group_cpus_evenly(). Without this patchset, the core logic lacks the necessary constraints to respect CPU isolation. It is entirely possible, and indeed happens in practice, for an isolated CPU to be assigned to a CPU mask group.

The newer implementation of irq_create_affinity_masks() introduced by this series resolves this. It considers the new CPU mask added to the IRQ affinity descriptor. When group_mask_cpus_evenly() is called, this mask is evaluated [1], guaranteeing that isolated CPUs are entirely excluded from the mask groups.

[1]: https://lore.kernel.org/lkml/[email protected]/

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

IMO, only two differences from this viewpoint:

1) io_queue may reduce nr_hw_queues

2) when application submits IO from isolated CPUs, io_queue can complete IO from housekeeping CPUs.

Acknowledged.

Are there other major differences besides the two mentioned above?

Quoted 8 lines
Quoted 1 line

I believe the above is sufficient. Please let me know your thoughts.

Both two are small improvement, not bug fixes. However the user has to pay the cost of potential failing of offlining CPU. Not mention the little complicated change: 19 files changed, 378 insertions(+), 48 deletions(-)

But I won't object if you can update the commit log/kernel command line doc and fix the issue found in review.

Thank you again for your rigorous review, patience, and invaluable guidance.

Kind regards,

Signature · 1 line
Aaron Tomlin
#30 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 77 lines · Aaron Tomlin
Quoted 4 lines · Ming Lei

For unmanaged interrupts, user can set irq affinity on housekeeping cpus from /proc or kernel command line.

Why is unmanaged interrupts involved with this patchset?

Thank you for your continued engagement and for ultimately supporting the progression of this series.

To clarify the handling of unmanaged interrupts, while it is entirely true that an administrator could attempt to manually configure "irqaffinity=" or via procfs after the fact, this series actively address unmanaged interrupts.

Quoted 7 lines
Quoted 6 lines

CPUs, thereby breaking isolation. By applying the constraint via io_queue at the block layer, we restrict the hardware queue count and map the isolated CPUs to the housekeeping queues, ensuring isolation is maintained regardless of whether the driver uses managed interrupts.

Does the above help?

Quoted 8 lines

As I mentioned, managed irq already covers it:

- typically application submits IO from housekeeping CPUs, which is mapped to one hardware, which effective interrupt affinity excludes isolated CPUs if possible.

I'd suggest to share some real problems you found instead of something imaginary.

If we trace how mpi3mr sets up its ISRs, it relies heavily on the core grouping logic:

mpi3mr_setup_isr
{
unsigned int irq_flags = PCI_IRQ_MSIX

struct irq_affinity desc = { .pre_vectors = 1, .post_vectors = 1, }

  pci_alloc_irq_vectors_affinity(mrioc->pdev, min_vec,
                                 max_vectors, irq_flags, &desc)
  {
    if (flags & PCI_IRQ_MSIX) {
      // affd != NULL
      __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, affd, flags)
      {
        for (;;) {

          msix_capability_init(dev, entries, nvec, affd)
          {
            msix_setup_interrupts(dev, entries, nvec, affd)
            {
              // affd
              irq_create_affinity_masks(nvec, affd)
              {
                for (i = 0, usedvecs = 0; i < affd->nr_sets; i++) {
                  unsigned int nr_masks, this_vecs = affd->set_size[i]
                  struct cpumask *result = group_cpus_evenly(this_vecs,
                                                             &nr_masks)
                  if (!result) {
                    kfree(masks)
                    return NULL
                  }

                  for (int j = 0; j < nr_masks; j++)
                    cpumask_copy(&masks[curvec + j].mask, &result[j])
                  kfree(result);

                  curvec += nr_masks
                  usedvecs += nr_masks
                }
              }
            }
          }
        }
      }
    }
Quoted 7 lines

}
}

The critical issue lies at the invocation of group_cpus_evenly(). Without this patchset, the core logic lacks the necessary constraints to respect CPU isolation. It is entirely possible, and indeed happens in practice, for an isolated CPU to be assigned to a CPU mask group.

It is one bug report? No, because it doesn't show any trouble from user viewpoint.

Sebastian explains/shows how "isolcpus=managed_irq" works perfectly in the following link:

https://lore.kernel.org/all/[email protected]/

You have reviewed it...

What matters is that IO won't interrupt isolated CPU.

Quoted 8 lines

The newer implementation of irq_create_affinity_masks() introduced by this series resolves this. It considers the new CPU mask added to the IRQ affinity descriptor. When group_mask_cpus_evenly() is called, this mask is evaluated [1], guaranteeing that isolated CPUs are entirely excluded from the mask groups.

[1]: https://lore.kernel.org/lkml/[email protected]/

Not at all.

isolated CPU is still included in each group's cpu mask, please see patch 9:

https://lore.kernel.org/linux-block/[email protected]/T/#m59df0689ef144f5361535ce59c9ed5923d6e21d5

Thanks,
Ming

#31 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 7 lines · Ming Lei
Quoted 4 lines

The critical issue lies at the invocation of group_cpus_evenly(). Without this patchset, the core logic lacks the necessary constraints to respect CPU isolation. It is entirely possible, and indeed happens in practice, for an isolated CPU to be assigned to a CPU mask group.

It is one bug report? No, because it doesn't show any trouble from user viewpoint.

Hi Ming,

The lack of a formal bug report does not negate the fact that the current behaviour silently breaks the fundamental contract of CPU isolation from the administrator's perspective.

To illustrate the user-visible impact, the following demonstrates the difference between relying on isolcpus=managed_irq and isolcpus=io_queue under 7.0.0-rc3-00065-gd80965e205a5, which includes this series.

The Broadcom MPI3 Storage Controller driver allocates a full complement of 48 operational queue pairs. Consequently, a number of MSI-X vectors are generated and mapped directly onto the isolated cores thereby breaching isolation.

    # uname -r
    7.0.0-rc3-00065-gd80965e205a5
    # tr ' ' '\n' < /proc/cmdline | grep isolcpus=
    isolcpus=managed_irq,domain,2-47
    # cat /sys/devices/system/cpu/isolated
    2-47
    # dmesg | grep -A 6 'MSI-X vectors supported:'
    [   2.981705] mpi3mr0: MSI-X vectors supported: 128, no of cores: 48,
    [   2.981705] mpi3mr0: MSI-X vectors requested: 49 poll_queues 0
    [   3.001915] mpi3mr0: trying to create 48 operational queue pairs
    [   3.011214] mpi3mr0: allocating operational queues through segmented queues 
    [   3.101903] mpi3mr0: successfully created 48 operational queue pairs(default/polled) queue = (2/0)
    [   3.111468] mpi3mr0: controller initialization completed successfully
    # awk '/mpi3mr0/ { print $1" "$NF }' /proc/interrupts
    78: mpi3mr0-msix0
    79: mpi3mr0-msix1
    80: mpi3mr0-msix2
    81: mpi3mr0-msix3
    82: mpi3mr0-msix4
    83: mpi3mr0-msix5
    84: mpi3mr0-msix6
    85: mpi3mr0-msix7
    86: mpi3mr0-msix8
    87: mpi3mr0-msix9
    88: mpi3mr0-msix10
    89: mpi3mr0-msix11
    90: mpi3mr0-msix12
    ...
    122: mpi3mr0-msix44
    123: mpi3mr0-msix45
    124: mpi3mr0-msix46
    125: mpi3mr0-msix47
    126: mpi3mr0-msix48
    # grep -H '' /proc/irq/{119,120,121,122}/{effective,smp}_affinity_list
    /proc/irq/119/effective_affinity_list:42
    /proc/irq/119/smp_affinity_list:42
    /proc/irq/120/effective_affinity_list:43
    /proc/irq/120/smp_affinity_list:43
    /proc/irq/121/effective_affinity_list:44
    /proc/irq/121/smp_affinity_list:44
    /proc/irq/122/effective_affinity_list:45
    /proc/irq/122/smp_affinity_list:45

Now with isolcpus=io_queue,2-47 the allocation is structurally restricted at the source. The driver creates only two operational queues, confining all resulting interrupts exclusively to housekeeping CPUs (0 and 1):

    # uname -r
    7.0.0-rc3-00065-gd80965e205a5
    # tr ' ' '\n' < /proc/cmdline | grep isolcpus=
    isolcpus=io_queue,domain,2-47
    # cat /sys/devices/system/cpu/isolated
    2-47
    # dmesg | grep -A 6 'MSI-X vectors supported:'
    [   3.284850] mpi3mr0: MSI-X vectors supported: 128, no of cores: 48,
    [   3.284851] mpi3mr0: MSI-X vectors requested: 49 poll_queues 0
    [   3.305492] mpi3mr0: allocated vectors (3) are less than configured (49)
    [   3.316528] mpi3mr0: trying to create 2 operational queue pairs
    [   3.328013] mpi3mr0: allocating operational queues through segmented queues
    [   3.340697] mpi3mr0: successfully created 2 operational queue pairs(default/polled) queue = (2/0)
    [   3.350664] mpi3mr0: controller initialization completed successfully
    # awk '/mpi3mr0/ { print $1" "$NF }' /proc/interrupts
    79: mpi3mr0-msix0
    80: mpi3mr0-msix1
    81: mpi3mr0-msix2
    # grep -H '' /proc/irq/{79,80,81}/{effective,smp}_affinity_list
    /proc/irq/79/effective_affinity_list:1
    /proc/irq/79/smp_affinity_list:1
    /proc/irq/80/effective_affinity_list:1
    /proc/irq/80/smp_affinity_list:1
    /proc/irq/81/effective_affinity_list:0
    /proc/irq/81/smp_affinity_list:0
Quoted 8 lines

Sebastian explains/shows how "isolcpus=managed_irq" works perfectly in the following link:

https://lore.kernel.org/all/[email protected]/

You have reviewed it...

What matters is that IO won't interrupt isolated CPU.

The isolcpus=managed_irq acts as a "best effort" avoidance algorithm rather than a strict, unbreakable constraint. This is indicated in the proposed changes to Documentation/core-api/irq/managed_irq.rst [1].

[1]: https://lore.kernel.org/all/[email protected]/

The following is an excerpt of irq_do_set_affinity().

- File: kernel/irq/manage.c

232 int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force) 233 {
234 struct cpumask *tmp_mask = this_cpu_ptr(&__tmp_mask);
:
262 if (irqd_affinity_is_managed(data) &&
263 housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) {
264 const struct cpumask *hk_mask;
265
266 hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ);
267
268 cpumask_and(tmp_mask, mask, hk_mask);
269 if (!cpumask_intersects(tmp_mask, cpu_online_mask))
270 prog_mask = mask;
271 else
272 prog_mask = tmp_mask;
273 } else {
274 prog_mask = mask;
275 }

1. If the requested mask consists only of isolated CPUs (e.g., 2-47), it will have zero intersection with the hk_mask (which contains only the housekeeping CPUs). Consequently, the resulting tmp_mask becomes completely empty.

2. Because the tmp_mask is empty, it cannot intersect with the cpu_online_mask.

3. The kernel triggers this fallback path. It abandons the empty, filtered tmp_mask and reverts back to the originally requested mask, which only contains isolated CPUs. Consequently, the interrupt is routed directly to an isolated CPU, proving that managed_irq cannot guarantee isolation.

Quoted 6 lines
Quoted 6 lines

The newer implementation of irq_create_affinity_masks() introduced by this series resolves this. It considers the new CPU mask added to the IRQ affinity descriptor. When group_mask_cpus_evenly() is called, this mask is evaluated [1], guaranteeing that isolated CPUs are entirely excluded from the mask groups.

Quoted 6 lines
Quoted 1 line

[1]: https://lore.kernel.org/lkml/[email protected]/

Not at all.

isolated CPU is still included in each group's cpu mask, please see patch 9:

You are entirely correct. The actual structural exclusion preventing the interrupts from landing on those cores occurs subsequently via irq_spread_hk_filter() in irq_create_affinity_masks() as per patch 12 [2].

[2]: https://lore.kernel.org/lkml/[email protected]/

Kind regards,

Signature · 1 line
Aaron Tomlin
#32 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 62 lines · Aaron Tomlin
Quoted 7 lines · Ming Lei
Quoted 4 lines

The critical issue lies at the invocation of group_cpus_evenly(). Without this patchset, the core logic lacks the necessary constraints to respect CPU isolation. It is entirely possible, and indeed happens in practice, for an isolated CPU to be assigned to a CPU mask group.

It is one bug report? No, because it doesn't show any trouble from user viewpoint.

Hi Ming,

The lack of a formal bug report does not negate the fact that the current behaviour silently breaks the fundamental contract of CPU isolation from the administrator's perspective.

To illustrate the user-visible impact, the following demonstrates the difference between relying on isolcpus=managed_irq and isolcpus=io_queue under 7.0.0-rc3-00065-gd80965e205a5, which includes this series.

The Broadcom MPI3 Storage Controller driver allocates a full complement of 48 operational queue pairs. Consequently, a number of MSI-X vectors are generated and mapped directly onto the isolated cores thereby breaching isolation.

    # uname -r
    7.0.0-rc3-00065-gd80965e205a5
    # tr ' ' '\n' < /proc/cmdline | grep isolcpus=
    isolcpus=managed_irq,domain,2-47
    # cat /sys/devices/system/cpu/isolated
    2-47
    # dmesg | grep -A 6 'MSI-X vectors supported:'
    [   2.981705] mpi3mr0: MSI-X vectors supported: 128, no of cores: 48,
    [   2.981705] mpi3mr0: MSI-X vectors requested: 49 poll_queues 0
    [   3.001915] mpi3mr0: trying to create 48 operational queue pairs
    [   3.011214] mpi3mr0: allocating operational queues through segmented queues 
    [   3.101903] mpi3mr0: successfully created 48 operational queue pairs(default/polled) queue = (2/0)
    [   3.111468] mpi3mr0: controller initialization completed successfully
    # awk '/mpi3mr0/ { print $1" "$NF }' /proc/interrupts
    78: mpi3mr0-msix0
    79: mpi3mr0-msix1
    80: mpi3mr0-msix2
    81: mpi3mr0-msix3
    82: mpi3mr0-msix4
    83: mpi3mr0-msix5
    84: mpi3mr0-msix6
    85: mpi3mr0-msix7
    86: mpi3mr0-msix8
    87: mpi3mr0-msix9
    88: mpi3mr0-msix10
    89: mpi3mr0-msix11
    90: mpi3mr0-msix12
    ...
    122: mpi3mr0-msix44
    123: mpi3mr0-msix45
    124: mpi3mr0-msix46
    125: mpi3mr0-msix47
    126: mpi3mr0-msix48
Quoted 9 lines
    # grep -H '' /proc/irq/{119,120,121,122}/{effective,smp}_affinity_list
    /proc/irq/119/effective_affinity_list:42
    /proc/irq/119/smp_affinity_list:42
    /proc/irq/120/effective_affinity_list:43
    /proc/irq/120/smp_affinity_list:43
    /proc/irq/121/effective_affinity_list:44
    /proc/irq/121/smp_affinity_list:44
    /proc/irq/122/effective_affinity_list:45
    /proc/irq/122/smp_affinity_list:45

But typical applications aren't supposed to submit IOs from these isolated CPUs, so in reality, it isn't a big deal.

Quoted 42 lines

Now with isolcpus=io_queue,2-47 the allocation is structurally restricted at the source. The driver creates only two operational queues, confining all resulting interrupts exclusively to housekeeping CPUs (0 and 1):

    # uname -r
    7.0.0-rc3-00065-gd80965e205a5
    # tr ' ' '\n' < /proc/cmdline | grep isolcpus=
    isolcpus=io_queue,domain,2-47
    # cat /sys/devices/system/cpu/isolated
    2-47
    # dmesg | grep -A 6 'MSI-X vectors supported:'
    [   3.284850] mpi3mr0: MSI-X vectors supported: 128, no of cores: 48,
    [   3.284851] mpi3mr0: MSI-X vectors requested: 49 poll_queues 0
    [   3.305492] mpi3mr0: allocated vectors (3) are less than configured (49)
    [   3.316528] mpi3mr0: trying to create 2 operational queue pairs
    [   3.328013] mpi3mr0: allocating operational queues through segmented queues
    [   3.340697] mpi3mr0: successfully created 2 operational queue pairs(default/polled) queue = (2/0)
    [   3.350664] mpi3mr0: controller initialization completed successfully
    # awk '/mpi3mr0/ { print $1" "$NF }' /proc/interrupts
    79: mpi3mr0-msix0
    80: mpi3mr0-msix1
    81: mpi3mr0-msix2
    # grep -H '' /proc/irq/{79,80,81}/{effective,smp}_affinity_list
    /proc/irq/79/effective_affinity_list:1
    /proc/irq/79/smp_affinity_list:1
    /proc/irq/80/effective_affinity_list:1
    /proc/irq/80/smp_affinity_list:1
    /proc/irq/81/effective_affinity_list:0
    /proc/irq/81/smp_affinity_list:0
Quoted 5 lines

Sebastian explains/shows how "isolcpus=managed_irq" works perfectly in the following link:

https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
Quoted 3 lines

You have reviewed it...

What matters is that IO won't interrupt isolated CPU.

The isolcpus=managed_irq acts as a "best effort" avoidance algorithm rather than a strict, unbreakable constraint. This is indicated in the proposed changes to Documentation/core-api/irq/managed_irq.rst [1].

Yes, it is "best effort", but isolated cpu is only take as effective CPU for the hw queue's irq iff all others are offline. Which is just fine for typical use cases, in which IO isn't submitted from isolated CPU.

Thanks,
Ming

#33 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 9 lines · Ming Lei
Quoted 5 lines
Quoted 1 line

What matters is that IO won't interrupt isolated CPU.

The isolcpus=managed_irq acts as a "best effort" avoidance algorithm rather than a strict, unbreakable constraint. This is indicated in the proposed changes to Documentation/core-api/irq/managed_irq.rst [1].

Yes, it is "best effort", but isolated cpu is only take as effective CPU for the hw queue's irq iff all others are offline. Which is just fine for typical use cases, in which IO isn't submitted from isolated CPU.

Couldn't we tackle this by limiting the number of managed interrupts the device asks for and then limiting the CPUs it could be bound to?

So if have house keeping CPUs 0/1 and isolated 2-63 then managed_irq= is futile since it use 64 interrupts and map each to one CPU. Even if the device supports less it would map them evenly across available CPUs.

If the user wishes to initiate I/O from all CPUs but not be bother by interrupts we could limit the device to ask for 2 interrupts instead of 64 (with the consequence of more queue sharing) and then limit those two interrupts to CPU 0 and 1 instead to CPU 0-31 and 32-63 like it would be now the case.

Wouldn't that be what the io_queue flag tries to do?

Quoted 2 lines

Thanks,
Ming

Sebastian

#34 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 19 lines · Sebastian Andrzej Siewior
Quoted 9 lines · Ming Lei
Quoted 5 lines
Quoted 1 line

What matters is that IO won't interrupt isolated CPU.

The isolcpus=managed_irq acts as a "best effort" avoidance algorithm rather than a strict, unbreakable constraint. This is indicated in the proposed changes to Documentation/core-api/irq/managed_irq.rst [1].

Yes, it is "best effort", but isolated cpu is only take as effective CPU for the hw queue's irq iff all others are offline. Which is just fine for typical use cases, in which IO isn't submitted from isolated CPU.

Couldn't we tackle this by limiting the number of managed interrupts the device asks for and then limiting the CPUs it could be bound to?

So if have house keeping CPUs 0/1 and isolated 2-63 then managed_irq= is futile since it use 64 interrupts and map each to one CPU. Even if the device supports less it would map them evenly across available CPUs.

Quoted 7 lines

If the user wishes to initiate I/O from all CPUs but not be bother by interrupts we could limit the device to ask for 2 interrupts instead of 64 (with the consequence of more queue sharing) and then limit those two interrupts to CPU 0 and 1 instead to CPU 0-31 and 32-63 like it would be now the case.

Wouldn't that be what the io_queue flag tries to do?

Yes, that is why I call it one optimization, however it does introduce cost of CPU offline failure, please see patch 11.

Thanks,
Ming Lei

#35 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

In reply to Sebastian Andrzej Siewior
Quoted 18 lines · Sebastian Andrzej Siewior
Quoted 9 lines · Ming Lei
Quoted 5 lines
Quoted 1 line

What matters is that IO won't interrupt isolated CPU.

The isolcpus=managed_irq acts as a "best effort" avoidance algorithm rather than a strict, unbreakable constraint. This is indicated in the proposed changes to Documentation/core-api/irq/managed_irq.rst [1].

Yes, it is "best effort", but isolated cpu is only take as effective CPU for the hw queue's irq iff all others are offline. Which is just fine for typical use cases, in which IO isn't submitted from isolated CPU.

Couldn't we tackle this by limiting the number of managed interrupts the device asks for and then limiting the CPUs it could be bound to?

So if have house keeping CPUs 0/1 and isolated 2-63 then managed_irq= is futile since it use 64 interrupts and map each to one CPU. Even if the device supports less it would map them evenly across available CPUs.

Quoted 8 lines

If the user wishes to initiate I/O from all CPUs but not be bother by interrupts we could limit the device to ask for 2 interrupts instead of 64 (with the consequence of more queue sharing) and then limit those two interrupts to CPU 0 and 1 instead to CPU 0-31 and 32-63 like it would be now the case.

Wouldn't that be what the io_queue flag tries to do?

Hi Sebastian,

Indeed, you are spot on.

What you have described is precisely the architectural mechanism that this patchset implements to resolve the issue:

1. Rather than permitting the device driver to blindly allocate 64 queues (and 64 MSI-X vectors) for a 64-core system, the "isolcpus=io_queue" intercepts this at the block layer. It throttles the hardware queue allocation to match the number of online housekeeping CPUs (2 queues in your example). As you rightly noted, this results in the isolated CPUs sharing those submission queues.

2. Once those two queues have been allocated, the new irq_spread_hk_filter() strictly confines their hardware completion interrupts to CPUs 0 and 1.

By structurally enforcing both of these constraints at initialisation, "isolcpus=io_queue" entirely prevents the vector exhaustion observed on large topologies. Furthermore, it provides an absolute guarantee that hardware completion interrupts will never be routed to the isolated CPUs, even when an application submits I/O from them.

Kind regards,

Signature · 1 line
Aaron Tomlin
#36 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

In reply to Ming Lei
Quoted 2 lines · Ming Lei

But typical applications aren't supposed to submit IOs from these isolated CPUs, so in reality, it isn't a big deal.

Hi Ming,

While that may be true for general-purpose workloads, it is a fundamentally incorrect assumption for the highly specialised environments that actually rely on strict CPU isolation, such as High-Frequency Trading (HFT).

The requirement in these strict environments is not that the isolated CPU performs zero I/O. Rather, the requirement is that the isolated CPU must be shielded from the unpredictable latency of the hardware completion interrupt.

Kind regards,

Signature · 1 line
Aaron Tomlin
#37 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 6 lines · Aaron Tomlin
Quoted 2 lines · Ming Lei

But typical applications aren't supposed to submit IOs from these isolated CPUs, so in reality, it isn't a big deal.

Hi Ming,

Quoted 8 lines

While that may be true for general-purpose workloads, it is a fundamentally incorrect assumption for the highly specialised environments that actually rely on strict CPU isolation, such as High-Frequency Trading (HFT).

The requirement in these strict environments is not that the isolated CPU performs zero I/O. Rather, the requirement is that the isolated CPU must be shielded from the unpredictable latency of the hardware completion interrupt.

Again it is just your opinion, not a bug report, may not be a fact, right? Which kind of HFT application submits IO from isolated CPU?

However, as I mentioned, I don't object this patchset, but you have to fix all wrong comment & document & bug found in review first.

Thanks,
Ming

#38 lore raw

Re: [PATCH v10 13/13] docs: add io_queue flag to isolcpus

Quoted 2 lines · Ming Lei

However, as I mentioned, I don't object this patchset, but you have to fix all wrong comment & document & bug found in review first.

Hi Ming,

Understood.

Kind regards,

Signature · 1 line
Aaron Tomlin