AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/10 18:46 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": [
    "BLOCK",
    "SMP",
    "CPU_ISOLATION"
  ],
  "FocusSymbols": [
    "blk_mq_map_queues",
    "blk_mq_map_hw_queues",
    "group_mask_cpus_evenly",
    "irq_create_affinity_masks",
    "irq_calc_affinity_vectors",
    "blk_mq_hctx_notify_offline"
  ],
  "KMSANReasoning": "The patch introduces the `managed_irq_strict` isolation feature to restrict blk-mq queue mappings and managed interrupt affinities to housekeeping CPUs.\n\nAll dynamically allocated data structures and bitmaps (such as `active_hctx`, `masks`, and temporary cpumask variables) are allocated using zeroing helpers (`bitmap_zalloc`, `zalloc_cpumask_var`, `kzalloc_objs`). All local variables and loop indices are initialized before use. Furthermore, no data is copied to user space, so there is no risk of kernel info-leaks.\n\nAny potential bugs introduced by these changes (such as out-of-bounds CPU indexing, incorrect bitmap sizes, or CPU hotplug ordering deadlocks) are detectable by standard debug tooling, KASAN, and LOCKDEP. There are no uninitialized memory risks that would require dedicated KMSAN fuzzing.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series introduces strict managed IRQ isolation (HK_TYPE_MANAGED_IRQ_STRICT / isolcpus=managed_irq_strict) and significantly modifies the CPU-to-queue mapping and affinity distribution algorithms in blk-mq, irq affinity, and lib/group_cpus. The changes touch reachable core block device queue configuration paths (blk_mq_map_queues, blk_mq_map_hw_queues), IRQ affinity calculations (irq_create_affinity_masks, irq_calc_affinity_vectors), group CPU distribution logic (group_mask_cpus_evenly), and CPU offline hotplug handling (blk_mq_hctx_notify_offline).",
  "WorthFuzzing": true
}

1/1 2026/09/10 18:46 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 24c7e4613986e22c25a1ad02542ffe3894b880e0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Thu Sep 10 18:46:03 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt\nindex 68647ff4bdd24..eb608e5139a69 100644\n--- a/Documentation/admin-guide/kernel-parameters.txt\n+++ b/Documentation/admin-guide/kernel-parameters.txt\n@@ -2822,7 +2822,6 @@ Kernel parameters\n \t\t\t  \"number of CPUs in system - 1\".\n \n \t\t\tmanaged_irq\n-\n \t\t\t  Isolate from being targeted by managed interrupts\n \t\t\t  which have an interrupt mask containing isolated\n \t\t\t  CPUs. The affinity of managed interrupts is\n@@ -2845,6 +2844,42 @@ Kernel parameters\n \t\t\t  housekeeping CPUs has no influence on those\n \t\t\t  queues.\n \n+\t\t\tmanaged_irq_strict\n+\t\t\t  Strictly restrict multiqueue hardware queue\n+\t\t\t  allocation and managed interrupt affinity to\n+\t\t\t  housekeeping CPUs. Unlike the best-effort\n+\t\t\t  managed_irq flag, this option guarantees that\n+\t\t\t  managed interrupts and multiqueue block device\n+\t\t\t  queues are never created for or mapped to isolated\n+\t\t\t  CPUs.\n+\n+\t\t\t  In the block layer (blk-mq), device queue allocation\n+\t\t\t  and CPU-to-queue mappings are restricted to\n+\t\t\t  housekeeping CPUs. For devices using managed\n+\t\t\t  interrupts, hardware completion interrupts are routed\n+\t\t\t  exclusively to housekeeping cores, shielding isolated\n+\t\t\t  CPUs from I/O interruptions even if they initiated the\n+\t\t\t  request.\n+\n+\t\t\t  If both managed_irq and managed_irq_strict are\n+\t\t\t  specified, managed_irq_strict takes precedence.\n+\n+\t\t\t  Note: Using managed_irq_strict restricts the number\n+\t\t\t  of allocated hardware queues to match the number of\n+\t\t\t  housekeeping CPUs for single-set drivers. This\n+\t\t\t  prevents MSI-X vector exhaustion and forces isolated\n+\t\t\t  CPUs to share submission queues.\n+\n+\t\t\t  Note: Offlining housekeeping CPUs which serve\n+\t\t\t  isolated CPUs will fail. The isolated CPUs must\n+\t\t\t  be offlined before offlining the housekeeping\n+\t\t\t  CPUs.\n+\n+\t\t\t  Note: When I/O is submitted by an application on\n+\t\t\t  an isolated CPU, the hardware completion\n+\t\t\t  interrupt is handled entirely by a housekeeping\n+\t\t\t  CPU.\n+\n \t\t\tThe format of \u003ccpu-list\u003e is described above.\n \n \tiucv=\t\t[HW,NET]\ndiff --git a/Documentation/core-api/housekeeping.rst b/Documentation/core-api/housekeeping.rst\nindex ccb0a88b9cb36..6d08c71e6c0eb 100644\n--- a/Documentation/core-api/housekeeping.rst\n+++ b/Documentation/core-api/housekeeping.rst\n@@ -23,7 +23,7 @@ CPU. It is simply a CPU that can execute housekeeping work. There must\n always be at least one online housekeeping CPU at any time. The CPUs that\n are not\tisolated are automatically assigned as housekeeping.\n \n-Housekeeping is currently divided in four features described\n+Housekeeping is currently divided in five features described\n by the ``enum hk_type type``:\n \n 1.\tHK_TYPE_DOMAIN matches the work moved away by scheduler domain\n@@ -44,6 +44,10 @@ by the ``enum hk_type type``:\n \tto HK_TYPE_DOMAIN except it ignores the isolation performed by\n \tcpusets.\n \n+5.\tHK_TYPE_MANAGED_IRQ_STRICT matches the multiqueue block devices and\n+\tmanaged IRQs strictly restricted to housekeeping CPUs through\n+\t``isolcpus=managed_irq_strict``.\n+\n \n Housekeeping cpumasks\n =================================\ndiff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c\nindex 705da074ad6c7..cec5b26bd57c7 100644\n--- a/block/blk-mq-cpumap.c\n+++ b/block/blk-mq-cpumap.c\n@@ -22,8 +22,15 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,\n {\n \tunsigned int num;\n \n-\tnum = cpumask_weight(mask);\n-\treturn min_not_zero(num, max_queues);\n+\tif (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))\n+\t\tnum = cpumask_weight_and(mask, housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT));\n+\telse\n+\t\tnum = cpumask_weight(mask);\n+\t/*\n+\t * Ensure that a count of zero does not inadvertently result in\n+\t * allocating the maximum number of queues.\n+\t */\n+\treturn min_not_zero(num ?: 1U, max_queues);\n }\n \n /**\n@@ -33,7 +40,8 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,\n  *\t\tignored.\n  *\n  * Calculates the number of queues to be used for a multiqueue\n- * device based on the number of possible CPUs.\n+ * device based on the number of possible CPUs. This helper\n+ * takes isolcpus settings into account.\n  */\n unsigned int blk_mq_num_possible_queues(unsigned int max_queues)\n {\n@@ -48,7 +56,8 @@ EXPORT_SYMBOL_GPL(blk_mq_num_possible_queues);\n  *\t\tignored.\n  *\n  * Calculates the number of queues to be used for a multiqueue\n- * device based on the number of online CPUs.\n+ * device based on the number of online CPUs. This helper\n+ * takes isolcpus settings into account.\n  */\n unsigned int blk_mq_num_online_queues(unsigned int max_queues)\n {\n@@ -56,23 +65,81 @@ unsigned int blk_mq_num_online_queues(unsigned int max_queues)\n }\n EXPORT_SYMBOL_GPL(blk_mq_num_online_queues);\n \n+static void blk_mq_map_fallback(struct blk_mq_queue_map *qmap)\n+{\n+\tunsigned int cpu;\n+\n+\t/*\n+\t * Map all CPUs to the first hctx of this specific map, respecting\n+\t * the map's boundaries so secondary maps do not route into the default map.\n+\t */\n+\tfor_each_possible_cpu(cpu)\n+\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset;\n+}\n+\n void blk_mq_map_queues(struct blk_mq_queue_map *qmap)\n {\n-\tconst struct cpumask *masks;\n+\tstruct cpumask *masks;\n+\tconst struct cpumask *constraint;\n \tunsigned int queue, cpu, nr_masks;\n+\tunsigned long *active_hctx;\n \n-\tmasks = group_cpus_evenly(qmap-\u003enr_queues, \u0026nr_masks);\n-\tif (!masks) {\n-\t\tfor_each_possible_cpu(cpu)\n-\t\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset;\n-\t\treturn;\n-\t}\n+\tactive_hctx = bitmap_zalloc(qmap-\u003enr_queues, GFP_KERNEL);\n+\tif (!active_hctx)\n+\t\tgoto fallback;\n \n-\tfor (queue = 0; queue \u003c qmap-\u003enr_queues; queue++) {\n-\t\tfor_each_cpu(cpu, \u0026masks[queue % nr_masks])\n+\tif (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))\n+\t\tconstraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);\n+\telse\n+\t\tconstraint = cpu_possible_mask;\n+\n+\t/* Map CPUs to the hardware contexts (hctx) */\n+\tmasks = group_mask_cpus_evenly(qmap-\u003enr_queues, constraint, \u0026nr_masks);\n+\tif (!masks)\n+\t\tgoto free_fallback_hctx;\n+\n+\t/*\n+\t * Iterate directly over the generated CPU masks.\n+\t * Calculate the final, highest hardware queue index that maps to this\n+\t * mask. This skips all intermediate overwrites and safely evaluates\n+\t * active_hctx only for queues that survive the mapping.\n+\t */\n+\tfor (unsigned int idx = 0; idx \u003c nr_masks; idx++) {\n+\t\tqueue = qmap-\u003enr_queues - 1 -\n+\t\t\t((qmap-\u003enr_queues - 1 - idx) % nr_masks);\n+\n+\t\tfor_each_cpu(cpu, \u0026masks[idx])\n \t\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset + queue;\n+\n+\t\t__set_bit(queue, active_hctx);\n+\t}\n+\n+\t/*\n+\t * If the active_hctx bitmap is empty, attempting to route unassigned\n+\t * CPUs will map them out-of-bounds. Fall back instead.\n+\t */\n+\tif (bitmap_empty(active_hctx, qmap-\u003enr_queues))\n+\t\tgoto free_fallback;\n+\n+\t/* Map any unassigned CPU evenly to the hardware contexts (hctx) */\n+\tqueue = find_first_bit(active_hctx, qmap-\u003enr_queues);\n+\tfor_each_cpu_andnot(cpu, cpu_possible_mask, constraint) {\n+\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset + queue;\n+\t\tqueue = find_next_bit_wrap(active_hctx, qmap-\u003enr_queues, queue + 1);\n \t}\n+\n+\tkfree(masks);\n+\tbitmap_free(active_hctx);\n+\n+\treturn;\n+\n+free_fallback:\n \tkfree(masks);\n+free_fallback_hctx:\n+\tbitmap_free(active_hctx);\n+\n+fallback:\n+\tblk_mq_map_fallback(qmap);\n }\n EXPORT_SYMBOL_GPL(blk_mq_map_queues);\n \n@@ -109,24 +176,84 @@ void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,\n \t\t\t  struct device *dev, unsigned int offset)\n \n {\n-\tconst struct cpumask *mask;\n+\tcpumask_var_t mask;\n+\tconst struct cpumask *constraint;\n+\tunsigned long *active_hctx;\n \tunsigned int queue, cpu;\n \n \tif (!dev-\u003ebus-\u003eirq_get_affinity)\n+\t\tgoto map_software;\n+\n+\tactive_hctx = bitmap_zalloc(qmap-\u003enr_queues, GFP_KERNEL);\n+\tif (!active_hctx)\n \t\tgoto fallback;\n \n+\tif (!zalloc_cpumask_var(\u0026mask, GFP_KERNEL)) {\n+\t\tbitmap_free(active_hctx);\n+\t\tgoto fallback;\n+\t}\n+\n+\tif (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))\n+\t\tconstraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);\n+\telse\n+\t\tconstraint = cpu_possible_mask;\n+\n+\t/* Map CPUs to the hardware contexts (hctx) */\n \tfor (queue = 0; queue \u003c qmap-\u003enr_queues; queue++) {\n-\t\tmask = dev-\u003ebus-\u003eirq_get_affinity(dev, queue + offset);\n-\t\tif (!mask)\n-\t\t\tgoto fallback;\n+\t\tconst struct cpumask *affinity_mask;\n+\n+\t\taffinity_mask = dev-\u003ebus-\u003eirq_get_affinity(dev, offset + queue);\n+\t\tif (!affinity_mask)\n+\t\t\tgoto free_map_software;\n \n-\t\tfor_each_cpu(cpu, mask)\n+\t\tfor_each_cpu(cpu, affinity_mask) {\n \t\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset + queue;\n+\t\t\tcpumask_set_cpu(cpu, mask);\n+\t\t}\n \t}\n \n+\t/*\n+\t * Evaluate active_hctx after mapping to handle overlapping masks.\n+\t * This ensures queues that were overwritten do not falsely pass validation.\n+\t */\n+\tfor_each_cpu(cpu, mask) {\n+\t\tif (cpumask_test_cpu(cpu, constraint)) {\n+\t\t\tqueue = qmap-\u003emq_map[cpu] - qmap-\u003equeue_offset;\n+\t\t\t__set_bit(queue, active_hctx);\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * If no assigned CPU matches the constraint, the active_hctx\n+\t * bitmap will be empty. Fall back instead of routing out of bounds.\n+\t */\n+\tif (bitmap_empty(active_hctx, qmap-\u003enr_queues))\n+\t\tgoto free_fallback;\n+\n+\t/* Map any unassigned CPU evenly to the hardware contexts (hctx) */\n+\tqueue = find_first_bit(active_hctx, qmap-\u003enr_queues);\n+\tfor_each_cpu_andnot(cpu, cpu_possible_mask, mask) {\n+\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset + queue;\n+\t\tqueue = find_next_bit_wrap(active_hctx, qmap-\u003enr_queues, queue + 1);\n+\t}\n+\n+\tbitmap_free(active_hctx);\n+\tfree_cpumask_var(mask);\n+\n \treturn;\n \n+free_fallback:\n+\tbitmap_free(active_hctx);\n+\tfree_cpumask_var(mask);\n+\n fallback:\n+\tblk_mq_map_fallback(qmap);\n+\treturn;\n+\n+free_map_software:\n+\tfree_cpumask_var(mask);\n+\tbitmap_free(active_hctx);\n+map_software:\n \tblk_mq_map_queues(qmap);\n }\n EXPORT_SYMBOL_GPL(blk_mq_map_hw_queues);\ndiff --git a/block/blk-mq.c b/block/blk-mq.c\nindex a26a11c73ee3e..6e903e1310e9f 100644\n--- a/block/blk-mq.c\n+++ b/block/blk-mq.c\n@@ -3690,6 +3690,64 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)\n \treturn data.has_rq;\n }\n \n+static bool blk_mq_hctx_can_offline_hk_cpu(struct blk_mq_hw_ctx *hctx,\n+\t\t\t\t\t   unsigned int this_cpu)\n+{\n+\tconst struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);\n+\tint cpu, fallback_isolated_cpu = -1;\n+\n+\t/*\n+\t * During system suspend or hibernation, tasks are frozen and all\n+\t * CPUs are being taken offline. Allow offlining to proceed so\n+\t * suspend is not aborted.\n+\t */\n+\tif (cpuhp_tasks_frozen)\n+\t\treturn true;\n+\n+\t/*\n+\t * If the CPU being offlined is not a housekeeping CPU,\n+\t * offlining it will not strand isolated CPUs. Allow it.\n+\t */\n+\tif (!cpumask_test_cpu(this_cpu, hk_mask))\n+\t\treturn true;\n+\t/*\n+\t * If this CPU is not mapped to this specific hardware context,\n+\t * offlining it will not affect the context's I/O routing. Allow it.\n+\t */\n+\tif (blk_mq_map_queue_type(hctx-\u003equeue, hctx-\u003etype, this_cpu) != hctx)\n+\t\treturn true;\n+\t/*\n+\t * Iterate over all online CPUs and manually check their mapping.\n+\t * We cannot use hctx-\u003ecpumask here because blk_mq_map_swqueue()\n+\t * intentionally strips isolated CPUs from it to prevent kworker\n+\t * routing.\n+\t */\n+\tfor_each_online_cpu(cpu) {\n+\t\tstruct blk_mq_hw_ctx *h;\n+\n+\t\tif (cpu == this_cpu)\n+\t\t\tcontinue;\n+\n+\t\th = blk_mq_map_queue_type(hctx-\u003equeue, hctx-\u003etype, cpu);\n+\t\tif (h != hctx)\n+\t\t\tcontinue;\n+\n+\t\tif (cpumask_test_cpu(cpu, hk_mask))\n+\t\t\treturn true;\n+\n+\t\tif (fallback_isolated_cpu == -1)\n+\t\t\tfallback_isolated_cpu = cpu;\n+\t}\n+\n+\tif (fallback_isolated_cpu != -1) {\n+\t\tpr_warn(\"blk-mq: cannot offline CPU %u: online isolated CPU %d is still mapped to hctx%u\\n\",\n+\t\t\tthis_cpu, fallback_isolated_cpu, hctx-\u003equeue_num);\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx,\n \t\tunsigned int this_cpu)\n {\n@@ -3722,6 +3780,11 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)\n \t\t\tstruct blk_mq_hw_ctx, cpuhp_online);\n \tint ret = 0;\n \n+\tif (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT)) {\n+\t\tif (!blk_mq_hctx_can_offline_hk_cpu(hctx, cpu))\n+\t\t\treturn -EINVAL;\n+\t}\n+\n \tif (!hctx-\u003enr_ctx || blk_mq_hctx_has_online_cpu(hctx, cpu))\n \t\treturn 0;\n \ndiff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c\nindex 9bd3f5b868bcd..ec165b57182d3 100644\n--- a/drivers/scsi/aacraid/comminit.c\n+++ b/drivers/scsi/aacraid/comminit.c\n@@ -469,8 +469,7 @@ void aac_define_int_mode(struct aac_dev *dev)\n \t}\n \n \t/* Don't bother allocating more MSI-X vectors than cpus */\n-\tmsi_count = min(dev-\u003emax_msix,\n-\t\t(unsigned int)num_online_cpus());\n+\tmsi_count = blk_mq_num_online_queues(dev-\u003emax_msix);\n \n \tdev-\u003emax_msix = msi_count;\n \ndiff --git a/include/linux/group_cpus.h b/include/linux/group_cpus.h\nindex 9d4e5ab6c314b..defab4123a82f 100644\n--- a/include/linux/group_cpus.h\n+++ b/include/linux/group_cpus.h\n@@ -10,5 +10,8 @@\n #include \u003clinux/cpu.h\u003e\n \n struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks);\n+struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,\n+\t\t\t\t       const struct cpumask *mask,\n+\t\t\t\t       unsigned int *nummasks);\n \n #endif\ndiff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h\nindex cf0fd03dd7a24..bda3003ce86fa 100644\n--- a/include/linux/sched/isolation.h\n+++ b/include/linux/sched/isolation.h\n@@ -18,6 +18,7 @@ enum hk_type {\n \tHK_TYPE_MANAGED_IRQ,\n \t/* Inverse of boot-time nohz_full= or isolcpus=nohz arguments */\n \tHK_TYPE_KERNEL_NOISE,\n+\tHK_TYPE_MANAGED_IRQ_STRICT,\n \tHK_TYPE_MAX,\n \n \t/*\ndiff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c\nindex 78f2418a89252..7796882a567ac 100644\n--- a/kernel/irq/affinity.c\n+++ b/kernel/irq/affinity.c\n@@ -8,6 +8,7 @@\n #include \u003clinux/slab.h\u003e\n #include \u003clinux/cpu.h\u003e\n #include \u003clinux/group_cpus.h\u003e\n+#include \u003clinux/sched/isolation.h\u003e\n \n static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)\n {\n@@ -25,8 +26,10 @@ static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)\n struct irq_affinity_desc *\n irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)\n {\n-\tunsigned int affvecs, curvec, usedvecs, i;\n+\tunsigned int affvecs, curvec, usedvecs, i, j;\n \tstruct irq_affinity_desc *masks = NULL;\n+\tconst struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);\n+\tbool hk_enabled = housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT);\n \n \t/*\n \t * Determine the number of vectors which need interrupt affinities\n@@ -70,19 +73,29 @@ irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)\n \t */\n \tfor (i = 0, usedvecs = 0; i \u003c affd-\u003enr_sets; i++) {\n \t\tunsigned int nr_masks, this_vecs = affd-\u003eset_size[i];\n-\t\tstruct cpumask *result = group_cpus_evenly(this_vecs, \u0026nr_masks);\n+\t\tstruct cpumask *result;\n+\t\tconst struct cpumask *mask;\n \n+\t\tif (hk_enabled)\n+\t\t\tmask = hk_mask;\n+\t\telse\n+\t\t\tmask = cpu_possible_mask;\n+\n+\t\tresult = group_mask_cpus_evenly(this_vecs, mask,\n+\t\t\t\t\t\t\u0026nr_masks);\n \t\tif (!result) {\n \t\t\tkfree(masks);\n \t\t\treturn NULL;\n \t\t}\n-\n-\t\tfor (int j = 0; j \u003c nr_masks; j++)\n+\t\tfor (j = 0; j \u003c nr_masks; j++)\n \t\t\tcpumask_copy(\u0026masks[curvec + j].mask, \u0026result[j]);\n+\t\tfor (j = nr_masks; j \u003c this_vecs; j++)\n+\t\t\tcpumask_copy(\u0026masks[curvec + j].mask, mask);\n+\n \t\tkfree(result);\n \n-\t\tcurvec += nr_masks;\n-\t\tusedvecs += nr_masks;\n+\t\tcurvec += this_vecs;\n+\t\tusedvecs += this_vecs;\n \t}\n \n \t/* Fill out vectors at the end that don't need affinity */\n@@ -117,8 +130,10 @@ unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,\n \n \tif (affd-\u003ecalc_sets)\n \t\tset_vecs = maxvec - resv;\n+\telse if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))\n+\t\tset_vecs = cpumask_weight(housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT));\n \telse\n \t\tset_vecs = cpumask_weight(cpu_possible_mask);\n \n-\treturn resv + min(set_vecs, maxvec - resv);\n+\treturn max(minvec, resv + min(set_vecs, maxvec - resv));\n }\ndiff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c\nindex 156025ef81b75..7e9e78a18fb9f 100644\n--- a/kernel/sched/isolation.c\n+++ b/kernel/sched/isolation.c\n@@ -17,6 +17,7 @@ enum hk_flags {\n \tHK_FLAG_DOMAIN\t\t= BIT(HK_TYPE_DOMAIN),\n \tHK_FLAG_MANAGED_IRQ\t= BIT(HK_TYPE_MANAGED_IRQ),\n \tHK_FLAG_KERNEL_NOISE\t= BIT(HK_TYPE_KERNEL_NOISE),\n+\tHK_FLAG_MANAGED_IRQ_STRICT = BIT(HK_TYPE_MANAGED_IRQ_STRICT),\n };\n \n DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);\n@@ -354,6 +355,12 @@ static int __init housekeeping_isolcpus_setup(char *str)\n \t\t\tcontinue;\n \t\t}\n \n+\t\tif (!strncmp(str, \"managed_irq_strict,\", 19)) {\n+\t\t\tstr += 19;\n+\t\t\tflags |= HK_FLAG_MANAGED_IRQ_STRICT;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\t/*\n \t\t * Skip unknown sub-parameter and validate that it is not\n \t\t * containing an invalid character.\n@@ -369,9 +376,20 @@ static int __init housekeeping_isolcpus_setup(char *str)\n \t\t}\n \n \t\tpr_info(\"isolcpus: Skipped unknown flag %.*s\\n\", len, par);\n+\t\tif (!*str)\n+\t\t\tbreak;\n \t\tstr++;\n \t}\n \n+\t/*\n+\t * managed_irq_strict is a strict superset of managed_irq.\n+\t * Ensure that HK_FLAG_MANAGED_IRQ is also set so that subsystems\n+\t * relying on managed interrupt isolation (e.g. Hyper-V VMBus channel\n+\t * distribution and CPU hotplug IRQ restoration) continue to function.\n+\t */\n+\tif (flags \u0026 HK_FLAG_MANAGED_IRQ_STRICT)\n+\t\tflags |= HK_FLAG_MANAGED_IRQ;\n+\n \t/* Default behaviour for isolcpus without flags */\n \tif (!flags)\n \t\tflags |= HK_FLAG_DOMAIN | HK_FLAG_DOMAIN_BOOT;\ndiff --git a/lib/group_cpus.c b/lib/group_cpus.c\nindex e6e18d7a49bba..75bd082e00bf4 100644\n--- a/lib/group_cpus.c\n+++ b/lib/group_cpus.c\n@@ -9,8 +9,6 @@\n #include \u003clinux/sort.h\u003e\n #include \u003clinux/group_cpus.h\u003e\n \n-#ifdef CONFIG_SMP\n-\n static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,\n \t\t\t\tunsigned int cpus_per_grp)\n {\n@@ -564,22 +562,114 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)\n \t*nummasks = min(nr_present + nr_others, numgrps);\n \treturn masks;\n }\n-#else /* CONFIG_SMP */\n-struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)\n+EXPORT_SYMBOL_GPL(group_cpus_evenly);\n+\n+/**\n+ * group_mask_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality\n+ * @numgrps: number of cpumasks to create\n+ * @mask: CPUs to consider for the grouping\n+ * @nummasks: number of initialized cpumasks\n+ *\n+ * Return: cpumask array if successful, NULL otherwise. Only the CPUs\n+ * marked in the mask will be considered for the grouping. And each\n+ * element includes CPUs assigned to this group. nummasks contains the\n+ * number of initialized masks which can be less than numgrps.\n+ *\n+ * Try to put close CPUs from viewpoint of CPU and NUMA locality into\n+ * the same group.\n+ *\n+ * We guarantee in the resulting grouping that all CPUs specified in the\n+ * provided mask are covered, and no same CPU is assigned to multiple\n+ * groups.\n+ */\n+struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,\n+\t\t\t\t       const struct cpumask *mask,\n+\t\t\t\t       unsigned int *nummasks)\n {\n-\tstruct cpumask *masks;\n+\tunsigned int curgrp = 0, nr_present = 0, nr_others = 0;\n+\tcpumask_var_t *node_to_cpumask;\n+\tcpumask_var_t nmsk, local_mask, npresmsk;\n+\tint ret = -ENOMEM;\n+\tstruct cpumask *masks = NULL;\n \n \tif (numgrps == 0)\n \t\treturn NULL;\n \n+\tif (!zalloc_cpumask_var(\u0026nmsk, GFP_KERNEL))\n+\t\treturn NULL;\n+\n+\tif (!zalloc_cpumask_var(\u0026local_mask, GFP_KERNEL))\n+\t\tgoto fail_nmsk;\n+\n+\tif (!zalloc_cpumask_var(\u0026npresmsk, GFP_KERNEL))\n+\t\tgoto fail_local_mask;\n+\n+\tnode_to_cpumask = alloc_node_to_cpumask();\n+\tif (!node_to_cpumask)\n+\t\tgoto fail_npresmsk;\n+\n \tmasks = kzalloc_objs(*masks, numgrps);\n \tif (!masks)\n-\t\treturn NULL;\n+\t\tgoto fail_node_to_cpumask;\n+\n+\tbuild_node_to_cpumask(node_to_cpumask);\n+\n+\t/*\n+\t * Create a stable snapshot of the mask. The grouping algorithm\n+\t * requires the CPU count to remain constant across its multiple\n+\t * passes. This prevents allocation failures if the caller passes a\n+\t * dynamic mask (e.g., cpu_online_mask) that changes concurrently.\n+\t */\n+\tcpumask_copy(local_mask, mask);\n \n-\t/* assign all CPUs(cpu 0) to the 1st group only */\n-\tcpumask_copy(\u0026masks[0], cpu_possible_mask);\n-\t*nummasks = 1;\n+\t/*\n+\t * Grouping present CPUs first. We intersect the provided mask with\n+\t * cpu_present_mask to ensure that we prioritise physically\n+\t * available CPUs for the initial distribution.\n+\t */\n+\tcpumask_and(npresmsk, local_mask, cpu_present_mask);\n+\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\n+\t\t\t\t  npresmsk, nmsk, masks);\n+\tif (ret \u003c 0)\n+\t\tgoto fail_node_to_cpumask;\n+\tnr_present = ret;\n+\n+\t/*\n+\t * Allocate non-present CPUs starting from the next group to be\n+\t * handled. If the grouping of present CPUs already exhausted the\n+\t * group space, assign the non-present CPUs to the already\n+\t * allocated out groups.\n+\t */\n+\tif (nr_present \u003e= numgrps)\n+\t\tcurgrp = 0;\n+\telse\n+\t\tcurgrp = nr_present;\n+\tcpumask_andnot(npresmsk, local_mask, npresmsk);\n+\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\n+\t\t\t\t  npresmsk, nmsk, masks);\n+\tif (ret \u003e= 0)\n+\t\tnr_others = ret;\n+\n+fail_node_to_cpumask:\n+\tfree_node_to_cpumask(node_to_cpumask);\n+\n+fail_npresmsk:\n+\tfree_cpumask_var(npresmsk);\n+\n+fail_local_mask:\n+\tfree_cpumask_var(local_mask);\n+\n+fail_nmsk:\n+\tfree_cpumask_var(nmsk);\n+\tif (ret \u003c 0) {\n+\t\tkfree(masks);\n+\t\treturn NULL;\n+\t}\n+\t*nummasks = min(nr_present + nr_others, numgrps);\n+\tif (*nummasks == 0) {\n+\t\tkfree(masks);\n+\t\treturn NULL;\n+\t}\n \treturn masks;\n }\n-#endif /* CONFIG_SMP */\n-EXPORT_SYMBOL_GPL(group_cpus_evenly);\n+EXPORT_SYMBOL_GPL(group_mask_cpus_evenly);\n"
}

2/1 2026/09/10 18:46 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BLOCK",
    "SMP",
    "CPU_ISOLATION"
  ],
  "FocusSymbols": [
    "blk_mq_map_queues",
    "blk_mq_map_hw_queues",
    "group_mask_cpus_evenly",
    "irq_create_affinity_masks",
    "irq_calc_affinity_vectors",
    "blk_mq_hctx_notify_offline"
  ],
  "Reasoning": "The patch series introduces strict managed IRQ isolation (HK_TYPE_MANAGED_IRQ_STRICT / isolcpus=managed_irq_strict) and significantly modifies the CPU-to-queue mapping and affinity distribution algorithms in blk-mq, irq affinity, and lib/group_cpus. The changes touch reachable core block device queue configuration paths (blk_mq_map_queues, blk_mq_map_hw_queues), IRQ affinity calculations (irq_create_affinity_masks, irq_calc_affinity_vectors), group CPU distribution logic (group_mask_cpus_evenly), and CPU offline hotplug handling (blk_mq_hctx_notify_offline).",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 24c7e4613986e22c25a1ad02542ffe3894b880e0
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Sep 10 18:46:03 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 68647ff4bdd24..eb608e5139a69 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2822,7 +2822,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
@@ -2845,6 +2844,42 @@ Kernel parameters
 			  housekeeping CPUs has no influence on those
 			  queues.
 
+			managed_irq_strict
+			  Strictly restrict multiqueue hardware queue
+			  allocation and managed interrupt affinity to
+			  housekeeping CPUs. Unlike the best-effort
+			  managed_irq flag, this option guarantees that
+			  managed interrupts and multiqueue block device
+			  queues are never created for or mapped to isolated
+			  CPUs.
+
+			  In the block layer (blk-mq), device queue allocation
+			  and CPU-to-queue mappings are restricted to
+			  housekeeping CPUs. For devices using managed
+			  interrupts, hardware completion interrupts are routed
+			  exclusively to housekeeping cores, shielding isolated
+			  CPUs from I/O interruptions even if they initiated the
+			  request.
+
+			  If both managed_irq and managed_irq_strict are
+			  specified, managed_irq_strict takes precedence.
+
+			  Note: Using managed_irq_strict restricts the number
+			  of allocated hardware queues to match the number of
+			  housekeeping CPUs for single-set drivers. This
+			  prevents MSI-X vector exhaustion and forces isolated
+			  CPUs to share submission queues.
+
+			  Note: Offlining housekeeping CPUs which serve
+			  isolated CPUs will fail. The isolated CPUs must
+			  be offlined before offlining the housekeeping
+			  CPUs.
+
+			  Note: When I/O is submitted by an application on
+			  an isolated CPU, the hardware completion
+			  interrupt is handled entirely by a housekeeping
+			  CPU.
+
 			The format of <cpu-list> is described above.
 
 	iucv=		[HW,NET]
diff --git a/Documentation/core-api/housekeeping.rst b/Documentation/core-api/housekeeping.rst
index ccb0a88b9cb36..6d08c71e6c0eb 100644
--- a/Documentation/core-api/housekeeping.rst
+++ b/Documentation/core-api/housekeeping.rst
@@ -23,7 +23,7 @@ CPU. It is simply a CPU that can execute housekeeping work. There must
 always be at least one online housekeeping CPU at any time. The CPUs that
 are not	isolated are automatically assigned as housekeeping.
 
-Housekeeping is currently divided in four features described
+Housekeeping is currently divided in five features described
 by the ``enum hk_type type``:
 
 1.	HK_TYPE_DOMAIN matches the work moved away by scheduler domain
@@ -44,6 +44,10 @@ by the ``enum hk_type type``:
 	to HK_TYPE_DOMAIN except it ignores the isolation performed by
 	cpusets.
 
+5.	HK_TYPE_MANAGED_IRQ_STRICT matches the multiqueue block devices and
+	managed IRQs strictly restricted to housekeeping CPUs through
+	``isolcpus=managed_irq_strict``.
+
 
 Housekeeping cpumasks
 =================================
diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 705da074ad6c7..cec5b26bd57c7 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -22,8 +22,15 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
 {
 	unsigned int num;
 
-	num = cpumask_weight(mask);
-	return min_not_zero(num, max_queues);
+	if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		num = cpumask_weight_and(mask, housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT));
+	else
+		num = cpumask_weight(mask);
+	/*
+	 * Ensure that a count of zero does not inadvertently result in
+	 * allocating the maximum number of queues.
+	 */
+	return min_not_zero(num ?: 1U, max_queues);
 }
 
 /**
@@ -33,7 +40,8 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
  *		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)
 {
@@ -48,7 +56,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)
 {
@@ -56,23 +65,81 @@ unsigned int blk_mq_num_online_queues(unsigned int max_queues)
 }
 EXPORT_SYMBOL_GPL(blk_mq_num_online_queues);
 
+static void blk_mq_map_fallback(struct blk_mq_queue_map *qmap)
+{
+	unsigned int cpu;
+
+	/*
+	 * Map all CPUs to the first hctx of this specific map, respecting
+	 * the map's boundaries so secondary maps do not route into the default map.
+	 */
+	for_each_possible_cpu(cpu)
+		qmap->mq_map[cpu] = qmap->queue_offset;
+}
+
 void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
 {
-	const struct cpumask *masks;
+	struct cpumask *masks;
+	const struct cpumask *constraint;
 	unsigned int queue, cpu, nr_masks;
+	unsigned long *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;
-	}
+	active_hctx = bitmap_zalloc(qmap->nr_queues, GFP_KERNEL);
+	if (!active_hctx)
+		goto fallback;
 
-	for (queue = 0; queue < qmap->nr_queues; queue++) {
-		for_each_cpu(cpu, &masks[queue % nr_masks])
+	if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		constraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);
+	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_hctx;
+
+	/*
+	 * Iterate directly over the generated CPU masks.
+	 * Calculate the final, highest hardware queue index that maps to this
+	 * mask. This skips all intermediate overwrites and safely evaluates
+	 * active_hctx only for queues that survive the mapping.
+	 */
+	for (unsigned int idx = 0; idx < nr_masks; idx++) {
+		queue = qmap->nr_queues - 1 -
+			((qmap->nr_queues - 1 - idx) % nr_masks);
+
+		for_each_cpu(cpu, &masks[idx])
 			qmap->mq_map[cpu] = qmap->queue_offset + queue;
+
+		__set_bit(queue, active_hctx);
+	}
+
+	/*
+	 * If the active_hctx bitmap is empty, attempting to route unassigned
+	 * CPUs will map them out-of-bounds. Fall back instead.
+	 */
+	if (bitmap_empty(active_hctx, qmap->nr_queues))
+		goto free_fallback;
+
+	/* Map any unassigned CPU evenly to the hardware contexts (hctx) */
+	queue = find_first_bit(active_hctx, qmap->nr_queues);
+	for_each_cpu_andnot(cpu, cpu_possible_mask, constraint) {
+		qmap->mq_map[cpu] = qmap->queue_offset + queue;
+		queue = find_next_bit_wrap(active_hctx, qmap->nr_queues, queue + 1);
 	}
+
+	kfree(masks);
+	bitmap_free(active_hctx);
+
+	return;
+
+free_fallback:
 	kfree(masks);
+free_fallback_hctx:
+	bitmap_free(active_hctx);
+
+fallback:
+	blk_mq_map_fallback(qmap);
 }
 EXPORT_SYMBOL_GPL(blk_mq_map_queues);
 
@@ -109,24 +176,84 @@ 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 mask;
+	const struct cpumask *constraint;
+	unsigned long *active_hctx;
 	unsigned int queue, cpu;
 
 	if (!dev->bus->irq_get_affinity)
+		goto map_software;
+
+	active_hctx = bitmap_zalloc(qmap->nr_queues, GFP_KERNEL);
+	if (!active_hctx)
 		goto fallback;
 
+	if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) {
+		bitmap_free(active_hctx);
+		goto fallback;
+	}
+
+	if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		constraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);
+	else
+		constraint = cpu_possible_mask;
+
+	/* 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_map_software;
 
-		for_each_cpu(cpu, mask)
+		for_each_cpu(cpu, affinity_mask) {
 			qmap->mq_map[cpu] = qmap->queue_offset + queue;
+			cpumask_set_cpu(cpu, mask);
+		}
 	}
 
+	/*
+	 * Evaluate active_hctx after mapping to handle overlapping masks.
+	 * This ensures queues that were overwritten do not falsely pass validation.
+	 */
+	for_each_cpu(cpu, mask) {
+		if (cpumask_test_cpu(cpu, constraint)) {
+			queue = qmap->mq_map[cpu] - qmap->queue_offset;
+			__set_bit(queue, active_hctx);
+		}
+	}
+
+	/*
+	 * If no assigned CPU matches the constraint, the active_hctx
+	 * bitmap will be empty. Fall back instead of routing out of bounds.
+	 */
+	if (bitmap_empty(active_hctx, qmap->nr_queues))
+		goto free_fallback;
+
+	/* Map any unassigned CPU evenly to the hardware contexts (hctx) */
+	queue = find_first_bit(active_hctx, qmap->nr_queues);
+	for_each_cpu_andnot(cpu, cpu_possible_mask, mask) {
+		qmap->mq_map[cpu] = qmap->queue_offset + queue;
+		queue = find_next_bit_wrap(active_hctx, qmap->nr_queues, queue + 1);
+	}
+
+	bitmap_free(active_hctx);
+	free_cpumask_var(mask);
+
 	return;
 
+free_fallback:
+	bitmap_free(active_hctx);
+	free_cpumask_var(mask);
+
 fallback:
+	blk_mq_map_fallback(qmap);
+	return;
+
+free_map_software:
+	free_cpumask_var(mask);
+	bitmap_free(active_hctx);
+map_software:
 	blk_mq_map_queues(qmap);
 }
 EXPORT_SYMBOL_GPL(blk_mq_map_hw_queues);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a26a11c73ee3e..6e903e1310e9f 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3690,6 +3690,64 @@ 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_MANAGED_IRQ_STRICT);
+	int cpu, fallback_isolated_cpu = -1;
+
+	/*
+	 * During system suspend or hibernation, tasks are frozen and all
+	 * CPUs are being taken offline. Allow offlining to proceed so
+	 * suspend is not aborted.
+	 */
+	if (cpuhp_tasks_frozen)
+		return true;
+
+	/*
+	 * If the CPU being offlined is not a housekeeping CPU,
+	 * offlining it will not strand isolated CPUs. Allow it.
+	 */
+	if (!cpumask_test_cpu(this_cpu, hk_mask))
+		return true;
+	/*
+	 * If this CPU is not mapped to this specific hardware context,
+	 * offlining it will not affect the context's I/O routing. Allow it.
+	 */
+	if (blk_mq_map_queue_type(hctx->queue, hctx->type, this_cpu) != hctx)
+		return true;
+	/*
+	 * Iterate over all online CPUs and manually check their mapping.
+	 * We cannot use hctx->cpumask here because blk_mq_map_swqueue()
+	 * intentionally strips isolated CPUs from it to prevent kworker
+	 * routing.
+	 */
+	for_each_online_cpu(cpu) {
+		struct blk_mq_hw_ctx *h;
+
+		if (cpu == this_cpu)
+			continue;
+
+		h = blk_mq_map_queue_type(hctx->queue, hctx->type, cpu);
+		if (h != hctx)
+			continue;
+
+		if (cpumask_test_cpu(cpu, hk_mask))
+			return true;
+
+		if (fallback_isolated_cpu == -1)
+			fallback_isolated_cpu = cpu;
+	}
+
+	if (fallback_isolated_cpu != -1) {
+		pr_warn("blk-mq: cannot offline CPU %u: online isolated CPU %d is still mapped to hctx%u\n",
+			this_cpu, fallback_isolated_cpu, hctx->queue_num);
+		return false;
+	}
+
+	return true;
+}
+
 static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx,
 		unsigned int this_cpu)
 {
@@ -3722,6 +3780,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_MANAGED_IRQ_STRICT)) {
+		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;
 
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 9bd3f5b868bcd..ec165b57182d3 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -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;
 
diff --git a/include/linux/group_cpus.h b/include/linux/group_cpus.h
index 9d4e5ab6c314b..defab4123a82f 100644
--- a/include/linux/group_cpus.h
+++ b/include/linux/group_cpus.h
@@ -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
diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
index cf0fd03dd7a24..bda3003ce86fa 100644
--- a/include/linux/sched/isolation.h
+++ b/include/linux/sched/isolation.h
@@ -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_MANAGED_IRQ_STRICT,
 	HK_TYPE_MAX,
 
 	/*
diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index 78f2418a89252..7796882a567ac 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -8,6 +8,7 @@
 #include <linux/slab.h>
 #include <linux/cpu.h>
 #include <linux/group_cpus.h>
+#include <linux/sched/isolation.h>
 
 static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)
 {
@@ -25,8 +26,10 @@ static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)
 struct irq_affinity_desc *
 irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 {
-	unsigned int affvecs, curvec, usedvecs, i;
+	unsigned int affvecs, curvec, usedvecs, i, j;
 	struct irq_affinity_desc *masks = NULL;
+	const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);
+	bool hk_enabled = housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT);
 
 	/*
 	 * Determine the number of vectors which need interrupt affinities
@@ -70,19 +73,29 @@ 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;
+		const struct cpumask *mask;
 
+		if (hk_enabled)
+			mask = hk_mask;
+		else
+			mask = cpu_possible_mask;
+
+		result = group_mask_cpus_evenly(this_vecs, mask,
+						&nr_masks);
 		if (!result) {
 			kfree(masks);
 			return NULL;
 		}
-
-		for (int j = 0; j < nr_masks; j++)
+		for (j = 0; j < nr_masks; j++)
 			cpumask_copy(&masks[curvec + j].mask, &result[j]);
+		for (j = nr_masks; j < this_vecs; j++)
+			cpumask_copy(&masks[curvec + j].mask, mask);
+
 		kfree(result);
 
-		curvec += nr_masks;
-		usedvecs += nr_masks;
+		curvec += this_vecs;
+		usedvecs += this_vecs;
 	}
 
 	/* Fill out vectors at the end that don't need affinity */
@@ -117,8 +130,10 @@ unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
 
 	if (affd->calc_sets)
 		set_vecs = maxvec - resv;
+	else if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		set_vecs = cpumask_weight(housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT));
 	else
 		set_vecs = cpumask_weight(cpu_possible_mask);
 
-	return resv + min(set_vecs, maxvec - resv);
+	return max(minvec, resv + min(set_vecs, maxvec - resv));
 }
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 156025ef81b75..7e9e78a18fb9f 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -17,6 +17,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_MANAGED_IRQ_STRICT = BIT(HK_TYPE_MANAGED_IRQ_STRICT),
 };
 
 DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
@@ -354,6 +355,12 @@ static int __init housekeeping_isolcpus_setup(char *str)
 			continue;
 		}
 
+		if (!strncmp(str, "managed_irq_strict,", 19)) {
+			str += 19;
+			flags |= HK_FLAG_MANAGED_IRQ_STRICT;
+			continue;
+		}
+
 		/*
 		 * Skip unknown sub-parameter and validate that it is not
 		 * containing an invalid character.
@@ -369,9 +376,20 @@ static int __init housekeeping_isolcpus_setup(char *str)
 		}
 
 		pr_info("isolcpus: Skipped unknown flag %.*s\n", len, par);
+		if (!*str)
+			break;
 		str++;
 	}
 
+	/*
+	 * managed_irq_strict is a strict superset of managed_irq.
+	 * Ensure that HK_FLAG_MANAGED_IRQ is also set so that subsystems
+	 * relying on managed interrupt isolation (e.g. Hyper-V VMBus channel
+	 * distribution and CPU hotplug IRQ restoration) continue to function.
+	 */
+	if (flags & HK_FLAG_MANAGED_IRQ_STRICT)
+		flags |= HK_FLAG_MANAGED_IRQ;
+
 	/* Default behaviour for isolcpus without flags */
 	if (!flags)
 		flags |= HK_FLAG_DOMAIN | HK_FLAG_DOMAIN_BOOT;
diff --git a/lib/group_cpus.c b/lib/group_cpus.c
index e6e18d7a49bba..75bd082e00bf4 100644
--- a/lib/group_cpus.c
+++ b/lib/group_cpus.c
@@ -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,114 @@ 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)
+EXPORT_SYMBOL_GPL(group_cpus_evenly);
+
+/**
+ * group_mask_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality
+ * @numgrps: number of cpumasks to create
+ * @mask: CPUs to consider for the grouping
+ * @nummasks: number of initialized cpumasks
+ *
+ * Return: cpumask array if successful, NULL otherwise. Only the CPUs
+ * marked in the mask will be considered for the grouping. And each
+ * element includes CPUs assigned to this group. nummasks contains the
+ * number of initialized masks which can be less than numgrps.
+ *
+ * Try to put close CPUs from viewpoint of CPU and NUMA locality into
+ * the same group.
+ *
+ * We guarantee in the resulting grouping that all CPUs specified in the
+ * provided mask are covered, and no same CPU is assigned to multiple
+ * groups.
+ */
+struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,
+				       const struct cpumask *mask,
+				       unsigned int *nummasks)
 {
-	struct cpumask *masks;
+	unsigned int curgrp = 0, nr_present = 0, nr_others = 0;
+	cpumask_var_t *node_to_cpumask;
+	cpumask_var_t nmsk, local_mask, npresmsk;
+	int ret = -ENOMEM;
+	struct cpumask *masks = NULL;
 
 	if (numgrps == 0)
 		return NULL;
 
+	if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
+		return NULL;
+
+	if (!zalloc_cpumask_var(&local_mask, GFP_KERNEL))
+		goto fail_nmsk;
+
+	if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL))
+		goto fail_local_mask;
+
+	node_to_cpumask = alloc_node_to_cpumask();
+	if (!node_to_cpumask)
+		goto fail_npresmsk;
+
 	masks = kzalloc_objs(*masks, numgrps);
 	if (!masks)
-		return NULL;
+		goto fail_node_to_cpumask;
+
+	build_node_to_cpumask(node_to_cpumask);
+
+	/*
+	 * Create a stable snapshot of the mask. The grouping algorithm
+	 * requires the CPU count to remain constant across its multiple
+	 * passes. This prevents allocation failures if the caller passes a
+	 * dynamic mask (e.g., cpu_online_mask) that changes concurrently.
+	 */
+	cpumask_copy(local_mask, mask);
 
-	/* assign all CPUs(cpu 0) to the 1st group only */
-	cpumask_copy(&masks[0], cpu_possible_mask);
-	*nummasks = 1;
+	/*
+	 * Grouping present CPUs first. We intersect the provided mask with
+	 * cpu_present_mask to ensure that we prioritise physically
+	 * available CPUs for the initial distribution.
+	 */
+	cpumask_and(npresmsk, local_mask, cpu_present_mask);
+	ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
+				  npresmsk, nmsk, masks);
+	if (ret < 0)
+		goto fail_node_to_cpumask;
+	nr_present = ret;
+
+	/*
+	 * Allocate non-present CPUs starting from the next group to be
+	 * handled. If the grouping of present CPUs already exhausted the
+	 * group space, assign the non-present CPUs to the already
+	 * allocated out groups.
+	 */
+	if (nr_present >= numgrps)
+		curgrp = 0;
+	else
+		curgrp = nr_present;
+	cpumask_andnot(npresmsk, local_mask, npresmsk);
+	ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
+				  npresmsk, nmsk, masks);
+	if (ret >= 0)
+		nr_others = ret;
+
+fail_node_to_cpumask:
+	free_node_to_cpumask(node_to_cpumask);
+
+fail_npresmsk:
+	free_cpumask_var(npresmsk);
+
+fail_local_mask:
+	free_cpumask_var(local_mask);
+
+fail_nmsk:
+	free_cpumask_var(nmsk);
+	if (ret < 0) {
+		kfree(masks);
+		return NULL;
+	}
+	*nummasks = min(nr_present + nr_others, numgrps);
+	if (*nummasks == 0) {
+		kfree(masks);
+		return NULL;
+	}
 	return masks;
 }
-#endif /* CONFIG_SMP */
-EXPORT_SYMBOL_GPL(group_cpus_evenly);
+EXPORT_SYMBOL_GPL(group_mask_cpus_evenly);

3/2 2026/09/10 18:46 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 10901
							output: 20
							thoughts: 711
						

Thoughts:
**Analyzing the Managed IRQ Strict Patch Series**

Okay, let's dive into this patch series. My initial impression is that it's focused on introducing and supporting a "managed_irq_strict" feature, which seems to tightly control the interaction between interrupts and CPU affinity, potentially for performance isolation.

First, I need to understand what this feature actually *does*, and then I need to figure out *why* this change is needed, and *how* this change works.

From the diff overview, it's clear this touches a wide range of subsystems: documentation, block layer (blk-mq), SCSI (aacraid), interrupt handling, and CPU isolation/housekeeping. The documentation changes immediately flag the intent. There's a new kernel parameter and a housekeeping type defined for "managed_irq_strict".

In the block layer, changes in `blk-mq-cpumap.c` look substantial. Functions like `blk_mq_num_queues()`, `blk_mq_map_queues()`, and `blk_mq_map_hw_queues()` are being modified to incorporate this new `HK_TYPE_MANAGED_IRQ_STRICT`. It appears that the block layer is now going to enforce the new constraints. The new helper `blk_mq_map_fallback()` is interesting, and the `group_mask_cpus_evenly()` function is central to distributing resources across CPUs; I'll need to look closely at that.

The changes in `blk-mq.c`, specifically the new helper `blk_mq_hctx_can_offline_hk_cpu()` suggest some careful consideration is being given to offlining CPUs.

The SCSI driver (`aacraid`) is also being modified. The update in `aac_define_int_mode()` is interesting as it now relies on `blk_mq_num_online_queues()`. This indicates a potential connection between interrupt configuration and block layer queueing.

On the interrupt side, `irq_create_affinity_masks()` and `irq_calc_affinity_vectors()` in `kernel/irq/affinity.c` are clearly the core of this. They are making use of this new `group_mask_cpus_evenly` and `HK_TYPE_MANAGED_IRQ_STRICT`. This is where the rubber meets the road. I need to understand exactly how the affinity masks are being calculated and how `HK_TYPE_MANAGED_IRQ_STRICT` influences that calculation.

The `kernel/sched/isolation.c` changes, with the new `HK_FLAG_MANAGED_IRQ_STRICT` and the parser for `managed_irq_strict`, confirm this is being driven by the CPU isolation mechanism.

Finally, the `lib/group_cpus.c` refactoring, specifically the new `group_mask_cpus_evenly` function, which I suspect is the keystone for this whole system. I'll probably need to understand this new function in detail, looking for details on how it balances the interrupts, queues, and online CPUs.

My next step is to start grepping for `HK_TYPE_MANAGED_IRQ_STRICT` and `group_mask_cpus_evenly` across the entire kernel to gain a clearer picture of the control flow and impact of these changes. I'll need to pay attention to how the interaction between interrupt handling, the block layer, and CPU isolation works under this regime. There is a high chance of unexpected interactions, so I am going to have to test it in several environments to see its actual behavior.



4/2 2026/09/10 18:46 tool grepper
0m Args:
{
  "Expression": "group_cpus_evenly"
}

Results:
{
  "Output": "drivers/virtio/virtio_vdpa.c=274=create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)\n--\ndrivers/virtio/virtio_vdpa.c-301-\t\tint j;\ndrivers/virtio/virtio_vdpa.c:302:\t\tstruct cpumask *result = group_cpus_evenly(this_vecs, \u0026nr_masks);\ndrivers/virtio/virtio_vdpa.c-303-\n--\nfs/fuse/virtio_fs.c=881=static void virtio_fs_map_queues(struct virtio_device *vdev, struct virtio_fs *fs)\n--\nfs/fuse/virtio_fs.c-903-\t/* Attempt to map evenly in groups over the CPUs */\nfs/fuse/virtio_fs.c:904:\tmasks = group_cpus_evenly(fs-\u003enum_request_queues, \u0026nr_masks);\nfs/fuse/virtio_fs.c-905-\t/* If even this fails we default to all CPUs use first request queue */\n--\ninclude/linux/group_cpus.h-11-\ninclude/linux/group_cpus.h:12:struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks);\ninclude/linux/group_cpus.h-13-struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,\n--\nlib/group_cpus.c=357=static bool __try_group_cluster_cpus(unsigned int ncpus,\n--\nlib/group_cpus.c-401-\nlib/group_cpus.c:402:static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps,\nlib/group_cpus.c-403-\t\t\t       cpumask_var_t *node_to_cpumask,\n--\nlib/group_cpus.c-469-/**\nlib/group_cpus.c:470: * group_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality\nlib/group_cpus.c-471- * @numgrps: number of groups\n--\nlib/group_cpus.c-485- */\nlib/group_cpus.c:486:struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)\nlib/group_cpus.c-487-{\n--\nlib/group_cpus.c-527-\t/* grouping present CPUs first */\nlib/group_cpus.c:528:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-529-\t\t\t\t  npresmsk, nmsk, masks);\n--\nlib/group_cpus.c-544-\tcpumask_andnot(npresmsk, cpu_possible_mask, npresmsk);\nlib/group_cpus.c:545:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-546-\t\t\t\t  npresmsk, nmsk, masks);\n--\nlib/group_cpus.c-564-}\nlib/group_cpus.c:565:EXPORT_SYMBOL_GPL(group_cpus_evenly);\nlib/group_cpus.c-566-\n--\nlib/group_cpus.c=585=struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,\n--\nlib/group_cpus.c-630-\tcpumask_and(npresmsk, local_mask, cpu_present_mask);\nlib/group_cpus.c:631:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-632-\t\t\t\t  npresmsk, nmsk, masks);\n--\nlib/group_cpus.c-647-\tcpumask_andnot(npresmsk, local_mask, npresmsk);\nlib/group_cpus.c:648:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-649-\t\t\t\t  npresmsk, nmsk, masks);\n"
}

5/2 2026/09/10 18:46 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 13516
							output: 36
							thoughts: 23
						

Thoughts:
Here's my take on the thought process, as if it were my own:

**Diving into `group_cpus_evenly`**

Okay, so we need to revisit the CPU grouping logic. My initial hunch is that something's not quite right with how we're distributing cores, so I'm immediately zeroing in on `lib/group_cpus.c` and specifically the `group_cpus_evenly` function. This is the likely culprit for any imbalance or unexpected behavior in CPU allocation, given the problem we're seeing. It's the core of how we attempt to achieve fair distribution, so it's the natural first place to dig. Let's see if we can spot anything that stands out regarding round robin or load balancing. Perhaps a boundary condition isn't handled correctly, or some optimization is backfiring. Time to dive into the code and start looking for the root cause.



6/2 2026/09/10 18:46 tool read-file
0m Args:
{
  "File": "lib/group_cpus.c",
  "FirstLine": 480,
  "LineCount": 90
}

Results:
{
  "Contents": " 480:\t *\t1) allocate present CPUs on these groups evenly first\n 481:\t *\t2) allocate other possible CPUs on these groups evenly\n 482:\t *\n 483:\t * We guarantee in the resulted grouping that all CPUs are covered, and\n 484:\t * no same CPU is assigned to multiple groups\n 485:\t */\n 486:\tstruct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)\n 487:\t{\n 488:\t\tunsigned int curgrp = 0, nr_present = 0, nr_others = 0;\n 489:\t\tcpumask_var_t *node_to_cpumask;\n 490:\t\tcpumask_var_t nmsk, npresmsk;\n 491:\t\tint ret = -ENOMEM;\n 492:\t\tstruct cpumask *masks = NULL;\n 493:\t\n 494:\t\tif (numgrps == 0)\n 495:\t\t\treturn NULL;\n 496:\t\n 497:\t\tif (!zalloc_cpumask_var(\u0026nmsk, GFP_KERNEL))\n 498:\t\t\treturn NULL;\n 499:\t\n 500:\t\tif (!zalloc_cpumask_var(\u0026npresmsk, GFP_KERNEL))\n 501:\t\t\tgoto fail_nmsk;\n 502:\t\n 503:\t\tnode_to_cpumask = alloc_node_to_cpumask();\n 504:\t\tif (!node_to_cpumask)\n 505:\t\t\tgoto fail_npresmsk;\n 506:\t\n 507:\t\tmasks = kzalloc_objs(*masks, numgrps);\n 508:\t\tif (!masks)\n 509:\t\t\tgoto fail_node_to_cpumask;\n 510:\t\n 511:\t\tbuild_node_to_cpumask(node_to_cpumask);\n 512:\t\n 513:\t\t/*\n 514:\t\t * Make a local cache of 'cpu_present_mask', so the two stages\n 515:\t\t * spread can observe consistent 'cpu_present_mask' without holding\n 516:\t\t * cpu hotplug lock, then we can reduce deadlock risk with cpu\n 517:\t\t * hotplug code.\n 518:\t\t *\n 519:\t\t * Here CPU hotplug may happen when reading `cpu_present_mask`, and\n 520:\t\t * we can live with the case because it only affects that hotplug\n 521:\t\t * CPU is handled in the 1st or 2nd stage, and either way is correct\n 522:\t\t * from API user viewpoint since 2-stage spread is sort of\n 523:\t\t * optimization.\n 524:\t\t */\n 525:\t\tcpumask_copy(npresmsk, data_race(cpu_present_mask));\n 526:\t\n 527:\t\t/* grouping present CPUs first */\n 528:\t\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\n 529:\t\t\t\t\t  npresmsk, nmsk, masks);\n 530:\t\tif (ret \u003c 0)\n 531:\t\t\tgoto fail_node_to_cpumask;\n 532:\t\tnr_present = ret;\n 533:\t\n 534:\t\t/*\n 535:\t\t * Allocate non present CPUs starting from the next group to be\n 536:\t\t * handled. If the grouping of present CPUs already exhausted the\n 537:\t\t * group space, assign the non present CPUs to the already\n 538:\t\t * allocated out groups.\n 539:\t\t */\n 540:\t\tif (nr_present \u003e= numgrps)\n 541:\t\t\tcurgrp = 0;\n 542:\t\telse\n 543:\t\t\tcurgrp = nr_present;\n 544:\t\tcpumask_andnot(npresmsk, cpu_possible_mask, npresmsk);\n 545:\t\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\n 546:\t\t\t\t\t  npresmsk, nmsk, masks);\n 547:\t\tif (ret \u003e= 0)\n 548:\t\t\tnr_others = ret;\n 549:\t\n 550:\t fail_node_to_cpumask:\n 551:\t\tfree_node_to_cpumask(node_to_cpumask);\n 552:\t\n 553:\t fail_npresmsk:\n 554:\t\tfree_cpumask_var(npresmsk);\n 555:\t\n 556:\t fail_nmsk:\n 557:\t\tfree_cpumask_var(nmsk);\n 558:\t\tif (ret \u003c 0) {\n 559:\t\t\tkfree(masks);\n 560:\t\t\treturn NULL;\n 561:\t\t}\n 562:\t\t*nummasks = min(nr_present + nr_others, numgrps);\n 563:\t\treturn masks;\n 564:\t}\n 565:\tEXPORT_SYMBOL_GPL(group_cpus_evenly);\n 566:\t\n 567:\t/**\n 568:\t * group_mask_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality\n 569:\t * @numgrps: number of cpumasks to create\n"
}

7/2 2026/09/10 18:46 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 15185
							output: 37
							thoughts: 68
						

Thoughts:
Here's my take on those thoughts:

**Analyzing Queue Mapping in the Block Layer**

Okay, so the `blk_mq_map_queues` function in `block/blk-mq-cpumap.c` is being updated to call `group_mask_cpus_evenly`. That's interesting, I want to take a look and see how this change impacts the queue mapping strategy. Let's dig into the surrounding code in `block/blk-mq-cpumap.c`, focusing specifically around the `blk_mq_map_queues` function. My main focus is understanding how this new call to `group_mask_cpus_evenly` fits into the CPU affinity and queue distribution logic. I need to understand if this is related to a particular configuration option or if it's a general improvement to the load balancing algorithm.



8/2 2026/09/10 18:46 tool read-file
0m Args:
{
  "File": "block/blk-mq-cpumap.c",
  "FirstLine": 60,
  "LineCount": 90
}

Results:
{
  "Contents": "  60:\t * takes isolcpus settings into account.\n  61:\t */\n  62:\tunsigned int blk_mq_num_online_queues(unsigned int max_queues)\n  63:\t{\n  64:\t\treturn blk_mq_num_queues(cpu_online_mask, max_queues);\n  65:\t}\n  66:\tEXPORT_SYMBOL_GPL(blk_mq_num_online_queues);\n  67:\t\n  68:\tstatic void blk_mq_map_fallback(struct blk_mq_queue_map *qmap)\n  69:\t{\n  70:\t\tunsigned int cpu;\n  71:\t\n  72:\t\t/*\n  73:\t\t * Map all CPUs to the first hctx of this specific map, respecting\n  74:\t\t * the map's boundaries so secondary maps do not route into the default map.\n  75:\t\t */\n  76:\t\tfor_each_possible_cpu(cpu)\n  77:\t\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset;\n  78:\t}\n  79:\t\n  80:\tvoid blk_mq_map_queues(struct blk_mq_queue_map *qmap)\n  81:\t{\n  82:\t\tstruct cpumask *masks;\n  83:\t\tconst struct cpumask *constraint;\n  84:\t\tunsigned int queue, cpu, nr_masks;\n  85:\t\tunsigned long *active_hctx;\n  86:\t\n  87:\t\tactive_hctx = bitmap_zalloc(qmap-\u003enr_queues, GFP_KERNEL);\n  88:\t\tif (!active_hctx)\n  89:\t\t\tgoto fallback;\n  90:\t\n  91:\t\tif (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))\n  92:\t\t\tconstraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);\n  93:\t\telse\n  94:\t\t\tconstraint = cpu_possible_mask;\n  95:\t\n  96:\t\t/* Map CPUs to the hardware contexts (hctx) */\n  97:\t\tmasks = group_mask_cpus_evenly(qmap-\u003enr_queues, constraint, \u0026nr_masks);\n  98:\t\tif (!masks)\n  99:\t\t\tgoto free_fallback_hctx;\n 100:\t\n 101:\t\t/*\n 102:\t\t * Iterate directly over the generated CPU masks.\n 103:\t\t * Calculate the final, highest hardware queue index that maps to this\n 104:\t\t * mask. This skips all intermediate overwrites and safely evaluates\n 105:\t\t * active_hctx only for queues that survive the mapping.\n 106:\t\t */\n 107:\t\tfor (unsigned int idx = 0; idx \u003c nr_masks; idx++) {\n 108:\t\t\tqueue = qmap-\u003enr_queues - 1 -\n 109:\t\t\t\t((qmap-\u003enr_queues - 1 - idx) % nr_masks);\n 110:\t\n 111:\t\t\tfor_each_cpu(cpu, \u0026masks[idx])\n 112:\t\t\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset + queue;\n 113:\t\n 114:\t\t\t__set_bit(queue, active_hctx);\n 115:\t\t}\n 116:\t\n 117:\t\t/*\n 118:\t\t * If the active_hctx bitmap is empty, attempting to route unassigned\n 119:\t\t * CPUs will map them out-of-bounds. Fall back instead.\n 120:\t\t */\n 121:\t\tif (bitmap_empty(active_hctx, qmap-\u003enr_queues))\n 122:\t\t\tgoto free_fallback;\n 123:\t\n 124:\t\t/* Map any unassigned CPU evenly to the hardware contexts (hctx) */\n 125:\t\tqueue = find_first_bit(active_hctx, qmap-\u003enr_queues);\n 126:\t\tfor_each_cpu_andnot(cpu, cpu_possible_mask, constraint) {\n 127:\t\t\tqmap-\u003emq_map[cpu] = qmap-\u003equeue_offset + queue;\n 128:\t\t\tqueue = find_next_bit_wrap(active_hctx, qmap-\u003enr_queues, queue + 1);\n 129:\t\t}\n 130:\t\n 131:\t\tkfree(masks);\n 132:\t\tbitmap_free(active_hctx);\n 133:\t\n 134:\t\treturn;\n 135:\t\n 136:\tfree_fallback:\n 137:\t\tkfree(masks);\n 138:\tfree_fallback_hctx:\n 139:\t\tbitmap_free(active_hctx);\n 140:\t\n 141:\tfallback:\n 142:\t\tblk_mq_map_fallback(qmap);\n 143:\t}\n 144:\tEXPORT_SYMBOL_GPL(blk_mq_map_queues);\n 145:\t\n 146:\t/**\n 147:\t * blk_mq_hw_queue_to_node - Look up the memory node for a hardware queue index\n 148:\t * @qmap: CPU to hardware queue map.\n 149:\t * @index: hardware queue index.\n"
}

9/2 2026/09/10 18:46 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 16846
							output: 22
							thoughts: 88
						

Thoughts:
Here's my thought process, as if I were considering this code:

**Analyzing Block Device Queue Mapping**

Okay, so I'm looking at `blk_mq_map_queues`. This is triggered during block device initialization, which makes sense – it's where the queues get set up or potentially reconfigured, right? Devices like virtio-blk, loop, NVMe, SCSI, and even null_blk use this function. Seems like a pretty central piece of the block layer.

Now, my next move is to understand the calling contexts more deeply. I need to trace *exactly* who's calling `blk_mq_map_queues` and `blk_mq_map_hw_queues`. Knowing the call graph will really clarify how the queue mapping process works within the broader block I/O framework. I suspect there are variations between different device drivers and initialization paths, but knowing the core function calls will give me a great starting point for understanding their similarities and differences. Let's dig in and see where these functions live in the grand scheme of things!



10/2 2026/09/10 18:46 tool grepper
0m Args:
{
  "Expression": "blk_mq_map_queues"
}

Results:
{
  "Output": "block/blk-mq-cpumap.c=68=static void blk_mq_map_fallback(struct blk_mq_queue_map *qmap)\n--\nblock/blk-mq-cpumap.c-79-\nblock/blk-mq-cpumap.c:80:void blk_mq_map_queues(struct blk_mq_queue_map *qmap)\nblock/blk-mq-cpumap.c-81-{\n--\nblock/blk-mq-cpumap.c-143-}\nblock/blk-mq-cpumap.c:144:EXPORT_SYMBOL_GPL(blk_mq_map_queues);\nblock/blk-mq-cpumap.c-145-\n--\nblock/blk-mq-cpumap.c=175=void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,\n--\nblock/blk-mq-cpumap.c-256-map_software:\nblock/blk-mq-cpumap.c:257:\tblk_mq_map_queues(qmap);\nblock/blk-mq-cpumap.c-258-}\n--\nblock/blk-mq.c=4813=static void blk_mq_update_queue_map(struct blk_mq_tag_set *set)\n--\nblock/blk-mq.c-4815-\t/*\nblock/blk-mq.c:4816:\t * blk_mq_map_queues() and multiple .map_queues() implementations\nblock/blk-mq.c-4817-\t * expect that set-\u003emap[HCTX_TYPE_DEFAULT].nr_queues is set to the\n--\nblock/blk-mq.c-4845-\t\tBUG_ON(set-\u003enr_maps \u003e 1);\nblock/blk-mq.c:4846:\t\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_DEFAULT]);\nblock/blk-mq.c-4847-\t}\n--\ndrivers/block/null_blk/main.c=1543=static void null_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/block/null_blk/main.c-1591-\t\tqoff += map-\u003enr_queues;\ndrivers/block/null_blk/main.c:1592:\t\tblk_mq_map_queues(map);\ndrivers/block/null_blk/main.c-1593-\t}\n--\ndrivers/block/rnbd/rnbd-clt.c=1168=static void rnbd_rdma_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/block/rnbd/rnbd-clt.c-1176-\tset-\u003emap[HCTX_TYPE_READ].queue_offset = 0;\ndrivers/block/rnbd/rnbd-clt.c:1177:\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_DEFAULT]);\ndrivers/block/rnbd/rnbd-clt.c:1178:\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_READ]);\ndrivers/block/rnbd/rnbd-clt.c-1179-\n--\ndrivers/block/rnbd/rnbd-clt.c-1184-\t\t\tset-\u003emap[HCTX_TYPE_READ].nr_queues;\ndrivers/block/rnbd/rnbd-clt.c:1185:\t\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_POLL]);\ndrivers/block/rnbd/rnbd-clt.c-1186-\t\tpr_info(\"[session=%s] mapped %d/%d/%d default/read/poll queues.\\n\",\n--\ndrivers/block/virtio_blk.c=1165=static void virtblk_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/block/virtio_blk.c-1185-\t\tif (i == HCTX_TYPE_POLL)\ndrivers/block/virtio_blk.c:1186:\t\t\tblk_mq_map_queues(\u0026set-\u003emap[i]);\ndrivers/block/virtio_blk.c-1187-\t\telse\n--\ndrivers/nvme/host/fabrics.c=1158=void nvmf_map_queues(struct blk_mq_tag_set *set, struct nvme_ctrl *ctrl,\n--\ndrivers/nvme/host/fabrics.c-1181-\ndrivers/nvme/host/fabrics.c:1182:\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_DEFAULT]);\ndrivers/nvme/host/fabrics.c:1183:\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_READ]);\ndrivers/nvme/host/fabrics.c-1184-\tif (opts-\u003enr_poll_queues \u0026\u0026 io_queues[HCTX_TYPE_POLL]) {\n--\ndrivers/nvme/host/fabrics.c-1189-\t\t\tio_queues[HCTX_TYPE_READ];\ndrivers/nvme/host/fabrics.c:1190:\t\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_POLL]);\ndrivers/nvme/host/fabrics.c-1191-\t}\n--\ndrivers/nvme/host/fc.c=2839=static void nvme_fc_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/nvme/host/fc.c-2856-\t\telse\ndrivers/nvme/host/fc.c:2857:\t\t\tblk_mq_map_queues(map);\ndrivers/nvme/host/fc.c-2858-\t}\n--\ndrivers/nvme/host/pci.c=690=static void nvme_pci_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/nvme/host/pci.c-712-\t\telse\ndrivers/nvme/host/pci.c:713:\t\t\tblk_mq_map_queues(map);\ndrivers/nvme/host/pci.c-714-\t\tqoff += map-\u003enr_queues;\n--\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c=3374=static void hisi_sas_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c-3395-\t\tif (i == HCTX_TYPE_POLL)\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c:3396:\t\t\tblk_mq_map_queues(qmap);\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c-3397-\t\telse\n--\ndrivers/scsi/leapraid/leapraid_os.c=1708=static void leapraid_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/leapraid/leapraid_os.c-1739-\t\t\tqueue_map-\u003equeue_offset = queue_offset;\ndrivers/scsi/leapraid/leapraid_os.c:1740:\t\t\tblk_mq_map_queues(queue_map);\ndrivers/scsi/leapraid/leapraid_os.c-1741-\t\t\tbreak;\n--\ndrivers/scsi/megaraid/megaraid_sas_base.c=3191=static void megasas_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/megaraid/megaraid_sas_base.c-3223-\t\tmap-\u003equeue_offset = qoff;\ndrivers/scsi/megaraid/megaraid_sas_base.c:3224:\t\tblk_mq_map_queues(map);\ndrivers/scsi/megaraid/megaraid_sas_base.c-3225-\t}\n--\ndrivers/scsi/mpi3mr/mpi3mr_os.c=4214=static void mpi3mr_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/mpi3mr/mpi3mr_os.c-4244-\t\telse\ndrivers/scsi/mpi3mr/mpi3mr_os.c:4245:\t\t\tblk_mq_map_queues(map);\ndrivers/scsi/mpi3mr/mpi3mr_os.c-4246-\n--\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c=13152=static void scsih_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c-13185-\t\telse\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c:13186:\t\t\tblk_mq_map_queues(map);\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c-13187-\n--\ndrivers/scsi/pm8001/pm8001_init.c=101=static void pm8001_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/pm8001/pm8001_init.c-111-\ndrivers/scsi/pm8001/pm8001_init.c:112:\tblk_mq_map_queues(qmap);\ndrivers/scsi/pm8001/pm8001_init.c-113-}\n--\ndrivers/scsi/qla2xxx/qla_os.c=8267=static void qla2xxx_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/qla2xxx/qla_os.c-8272-\tif (USER_CTRL_IRQ(vha-\u003ehw) || !vha-\u003ehw-\u003emqiobase)\ndrivers/scsi/qla2xxx/qla_os.c:8273:\t\tblk_mq_map_queues(qmap);\ndrivers/scsi/qla2xxx/qla_os.c-8274-\telse\n--\ndrivers/scsi/scsi_debug.c=9007=static void sdebug_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/scsi_debug.c-9029-\t\tmap-\u003equeue_offset = qoff;\ndrivers/scsi/scsi_debug.c:9030:\t\tblk_mq_map_queues(map);\ndrivers/scsi/scsi_debug.c-9031-\n--\ndrivers/scsi/scsi_lib.c=2035=static void scsi_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/scsi/scsi_lib.c-2040-\t\treturn shost-\u003ehostt-\u003emap_queues(shost);\ndrivers/scsi/scsi_lib.c:2041:\tblk_mq_map_queues(\u0026set-\u003emap[HCTX_TYPE_DEFAULT]);\ndrivers/scsi/scsi_lib.c-2042-}\n--\ndrivers/scsi/smartpqi/smartpqi_init.c=6612=static void pqi_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/smartpqi/smartpqi_init.c-6619-\telse\ndrivers/scsi/smartpqi/smartpqi_init.c:6620:\t\tblk_mq_map_queues(\u0026shost-\u003etag_set.map[HCTX_TYPE_DEFAULT]);\ndrivers/scsi/smartpqi/smartpqi_init.c-6621-}\n--\ndrivers/scsi/virtio_scsi.c=730=static void virtscsi_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/virtio_scsi.c-750-\t\tif (i == HCTX_TYPE_POLL)\ndrivers/scsi/virtio_scsi.c:751:\t\t\tblk_mq_map_queues(map);\ndrivers/scsi/virtio_scsi.c-752-\t\telse\n--\ndrivers/ufs/core/ufshcd.c=3049=static void ufshcd_map_queues(struct Scsi_Host *shost)\n--\ndrivers/ufs/core/ufshcd.c-3070-\ndrivers/ufs/core/ufshcd.c:3071:\t\tblk_mq_map_queues(map);\ndrivers/ufs/core/ufshcd.c-3072-\t\tqueue_offset += map-\u003enr_queues;\n--\ninclude/linux/blk-mq.h=973=unsigned int blk_mq_num_online_queues(unsigned int max_queues);\ninclude/linux/blk-mq.h:974:void blk_mq_map_queues(struct blk_mq_queue_map *qmap);\ninclude/linux/blk-mq.h-975-void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,\n"
}

11/2 2026/09/10 18:46 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 20585
							output: 24
							thoughts: 54
						

Thoughts:
Here's my take on those thoughts:

**Analyzing `blk_mq_map_hw_queues` Usage**

Okay, so I'm digging into `blk_mq_map_hw_queues`. I know that function is used within the block layer, and I need to understand its broader implications. Let's see... the fact that `virtio-blk`, `virtio-scsi`, and `nvme` all call it is definitely significant. That suggests it's a critical piece for mapping hardware queues, particularly for devices that interface with the block layer but aren't necessarily directly attached storage. Given its role in multiple virtualization and NVMe contexts, I'd say its pretty important. I want to fully understand the scope of that function. Now, I need to methodically trace all the calls to it, understand the context of each call, and see how that maps into the larger I/O queueing strategy. It's time to dig into the call sites.



12/2 2026/09/10 18:46 tool grepper
0m Args:
{
  "Expression": "blk_mq_map_hw_queues"
}

Results:
{
  "Output": "block/blk-mq-cpumap.c=154=int blk_mq_hw_queue_to_node(struct blk_mq_queue_map *qmap, unsigned int index)\n--\nblock/blk-mq-cpumap.c-166-/**\nblock/blk-mq-cpumap.c:167: * blk_mq_map_hw_queues - Create CPU to hardware queue mapping\nblock/blk-mq-cpumap.c-168- * @qmap:\tCPU to hardware queue map\n--\nblock/blk-mq-cpumap.c-174- */\nblock/blk-mq-cpumap.c:175:void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,\nblock/blk-mq-cpumap.c-176-\t\t\t  struct device *dev, unsigned int offset)\n--\nblock/blk-mq-cpumap.c-258-}\nblock/blk-mq-cpumap.c:259:EXPORT_SYMBOL_GPL(blk_mq_map_hw_queues);\n--\ndrivers/block/virtio_blk.c=1165=static void virtblk_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/block/virtio_blk.c-1187-\t\telse\ndrivers/block/virtio_blk.c:1188:\t\t\tblk_mq_map_hw_queues(\u0026set-\u003emap[i],\ndrivers/block/virtio_blk.c-1189-\t\t\t\t\t     \u0026vblk-\u003evdev-\u003edev, 0);\n--\ndrivers/nvme/host/pci.c=690=static void nvme_pci_map_queues(struct blk_mq_tag_set *set)\n--\ndrivers/nvme/host/pci.c-710-\t\tif (i != HCTX_TYPE_POLL \u0026\u0026 offset)\ndrivers/nvme/host/pci.c:711:\t\t\tblk_mq_map_hw_queues(map, dev-\u003edev, offset);\ndrivers/nvme/host/pci.c-712-\t\telse\n--\ndrivers/scsi/fnic/fnic_main.c=747=void fnic_mq_map_queues_cpus(struct Scsi_Host *host)\n--\ndrivers/scsi/fnic/fnic_main.c-768-\ndrivers/scsi/fnic/fnic_main.c:769:\tblk_mq_map_hw_queues(qmap, \u0026l_pdev-\u003edev, FNIC_PCI_OFFSET);\ndrivers/scsi/fnic/fnic_main.c-770-}\n--\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c=3374=static void hisi_sas_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c-3397-\t\telse\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c:3398:\t\t\tblk_mq_map_hw_queues(qmap, hisi_hba-\u003edev,\ndrivers/scsi/hisi_sas/hisi_sas_v3_hw.c-3399-\t\t\t\t\t     BASE_VECTORS_V3_HW);\n--\ndrivers/scsi/leapraid/leapraid_os.c=1708=static void leapraid_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/leapraid/leapraid_os.c-1733-\t\t\tWARN_ON_ONCE(!queue_map-\u003enr_queues);\ndrivers/scsi/leapraid/leapraid_os.c:1734:\t\t\tblk_mq_map_hw_queues(queue_map,\ndrivers/scsi/leapraid/leapraid_os.c-1735-\t\t\t\t\t     \u0026adapter-\u003epdev-\u003edev, 0);\n--\ndrivers/scsi/leapraid/leapraid_os.c-1743-\t\t\tqueue_map-\u003equeue_offset = queue_offset;\ndrivers/scsi/leapraid/leapraid_os.c:1744:\t\t\tblk_mq_map_hw_queues(queue_map,\ndrivers/scsi/leapraid/leapraid_os.c-1745-\t\t\t\t\t     \u0026adapter-\u003epdev-\u003edev, 0);\n--\ndrivers/scsi/megaraid/megaraid_sas_base.c=3191=static void megasas_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/megaraid/megaraid_sas_base.c-3207-\tmap-\u003equeue_offset = 0;\ndrivers/scsi/megaraid/megaraid_sas_base.c:3208:\tblk_mq_map_hw_queues(map, \u0026instance-\u003epdev-\u003edev, offset);\ndrivers/scsi/megaraid/megaraid_sas_base.c-3209-\tqoff += map-\u003enr_queues;\n--\ndrivers/scsi/mpi3mr/mpi3mr_os.c=4214=static void mpi3mr_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/mpi3mr/mpi3mr_os.c-4242-\t\tif (i != HCTX_TYPE_POLL)\ndrivers/scsi/mpi3mr/mpi3mr_os.c:4243:\t\t\tblk_mq_map_hw_queues(map, \u0026mrioc-\u003epdev-\u003edev, offset);\ndrivers/scsi/mpi3mr/mpi3mr_os.c-4244-\t\telse\n--\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c=13152=static void scsih_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c-13183-\t\tif (i != HCTX_TYPE_POLL)\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c:13184:\t\t\tblk_mq_map_hw_queues(map, \u0026ioc-\u003epdev-\u003edev, offset);\ndrivers/scsi/mpt3sas/mpt3sas_scsih.c-13185-\t\telse\n--\ndrivers/scsi/pm8001/pm8001_init.c=101=static void pm8001_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/pm8001/pm8001_init.c-107-\tif (pm8001_ha-\u003enumber_of_intr \u003e 1) {\ndrivers/scsi/pm8001/pm8001_init.c:108:\t\tblk_mq_map_hw_queues(qmap, \u0026pm8001_ha-\u003epdev-\u003edev, 1);\ndrivers/scsi/pm8001/pm8001_init.c-109-\t\treturn;\n--\ndrivers/scsi/qla2xxx/qla_nvme.c=916=static void qla_nvme_map_queues(struct nvme_fc_local_port *lport,\n--\ndrivers/scsi/qla2xxx/qla_nvme.c-920-\ndrivers/scsi/qla2xxx/qla_nvme.c:921:\tblk_mq_map_hw_queues(map, \u0026vha-\u003ehw-\u003epdev-\u003edev, vha-\u003eirq_offset);\ndrivers/scsi/qla2xxx/qla_nvme.c-922-}\n--\ndrivers/scsi/qla2xxx/qla_os.c=8267=static void qla2xxx_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/qla2xxx/qla_os.c-8274-\telse\ndrivers/scsi/qla2xxx/qla_os.c:8275:\t\tblk_mq_map_hw_queues(qmap, \u0026vha-\u003ehw-\u003epdev-\u003edev,\ndrivers/scsi/qla2xxx/qla_os.c-8276-\t\t\t\t       vha-\u003eirq_offset);\n--\ndrivers/scsi/smartpqi/smartpqi_init.c=6612=static void pqi_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/smartpqi/smartpqi_init.c-6616-\tif (!ctrl_info-\u003edisable_managed_interrupts)\ndrivers/scsi/smartpqi/smartpqi_init.c:6617:\t\tblk_mq_map_hw_queues(\u0026shost-\u003etag_set.map[HCTX_TYPE_DEFAULT],\ndrivers/scsi/smartpqi/smartpqi_init.c-6618-\t\t\t\t       \u0026ctrl_info-\u003epci_dev-\u003edev, 0);\n--\ndrivers/scsi/virtio_scsi.c=730=static void virtscsi_map_queues(struct Scsi_Host *shost)\n--\ndrivers/scsi/virtio_scsi.c-752-\t\telse\ndrivers/scsi/virtio_scsi.c:753:\t\t\tblk_mq_map_hw_queues(map, \u0026vscsi-\u003evdev-\u003edev, 2);\ndrivers/scsi/virtio_scsi.c-754-\t}\n--\ninclude/linux/blk-mq.h=974=void blk_mq_map_queues(struct blk_mq_queue_map *qmap);\ninclude/linux/blk-mq.h:975:void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,\ninclude/linux/blk-mq.h-976-\t\t\t  struct device *dev, unsigned int offset);\n"
}

13/2 2026/09/10 18:46 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 23390
							output: 26
							thoughts: 2316
						

Thoughts:
**Analysis of CPU and IRQ Affinity Changes**

Okay, let's break this down. This patch is making some pretty significant changes to how we handle CPU affinity, particularly related to block device queues and IRQ assignment, with a focus on a "managed IRQ strict" mode.

First, I see the introduction of `group_mask_cpus_evenly()`, and crucially, the export of `group_mask_cpus_evenly()`. This is immediately interesting because it suggests a new primitive for distributing work across CPUs, and because it's exported it is likely called in different subsystems.

Then, the changes to `blk-mq-cpumap.c` are where it gets really interesting. `blk_mq_map_queues()` has been *completely* rewritten. This isn't just a tweak; it's a fundamental change in the algorithm for assigning queues to CPUs. The before-and-after code block clearly shows that we've gone from a simple division with modulo to a more complex bitmap allocation and iterative assignment. The use of `group_mask_cpus_evenly()`, `bitmap_zalloc`, and bit manipulations makes this a prime target for fuzzing. The fact that this function is called on every block device setup, even without the `HK_TYPE_MANAGED_IRQ_STRICT` setting, is a key point. This *new* algorithm is now running. Similarly, `blk_mq_map_hw_queues()` gets a similar treatment. The modification here also affects a large number of block devices, increasing the chances that something goes wrong!

In `blk-mq.c`, the new `blk_mq_hctx_can_offline_hk_cpu()` function is called during CPU hotplug, and its presence, along with the check added in `blk_mq_hctx_notify_offline()` suggests a new level of rigor when offlining CPUs in the "managed IRQ strict" context. This increases the attack surface for fuzzing, given that hotplug events are easily generated.

Looking at `kernel/irq/affinity.c`, the patch uses `group_mask_cpus_evenly()` for allocating affinity masks for IRQs. Again, a key point, because we're introducing new logic around MSI-X IRQ allocation, and it calls `group_mask_cpus_evenly()` again. The changes to `irq_calc_affinity_vectors()` further reinforce the need for testing around the "managed IRQ strict" mode.

Finally, the addition of the `managed_irq_strict` parameter in `isolation.c` and the update to `aac_define_int_mode()` in the RAID driver further increase the complexity and reach of the modified code.

**Reachability and Fuzzing**

Given the reachability of the modified code through block device setup (null_blk, loop, virtio-blk, nvme, scsi_debug, ramdisk), IRQ allocation, and the CPU hotplug path, I'd say this is *absolutely* worth fuzzing. The patch touches core subsystems: block layer, IRQ management, and CPU affinity. Even without the strict mode, the changed `blk_mq_map_queues` is *always* executed.

**Focus Symbols**

The following functions are critical for fuzzing and will be used as FocusSymbols:

*   `blk_mq_map_queues`
*   `blk_mq_map_hw_queues`
*   `group_mask_cpus_evenly`
*   `irq_create_affinity_masks`
*   `irq_calc_affinity_vectors`
*   `blk_mq_hctx_notify_offline`
*   `blk_mq_hctx_can_offline_hk_cpu`



14/2 2026/09/10 18:47 tool grepper
0m Args:
{
  "Expression": "group_cpus",
  "PathPrefix": "lib/"
}

Results:
{
  "Output": "lib/Makefile=329=obj-$(CONFIG_PARMAN) += parman.o\nlib/Makefile-330-\nlib/Makefile:331:obj-y += group_cpus.o\nlib/Makefile-332-\n--\nlib/group_cpus.c-9-#include \u003clinux/sort.h\u003e\nlib/group_cpus.c:10:#include \u003clinux/group_cpus.h\u003e\nlib/group_cpus.c-11-\n--\nlib/group_cpus.c=357=static bool __try_group_cluster_cpus(unsigned int ncpus,\n--\nlib/group_cpus.c-401-\nlib/group_cpus.c:402:static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps,\nlib/group_cpus.c-403-\t\t\t       cpumask_var_t *node_to_cpumask,\n--\nlib/group_cpus.c-469-/**\nlib/group_cpus.c:470: * group_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality\nlib/group_cpus.c-471- * @numgrps: number of groups\n--\nlib/group_cpus.c-485- */\nlib/group_cpus.c:486:struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)\nlib/group_cpus.c-487-{\n--\nlib/group_cpus.c-527-\t/* grouping present CPUs first */\nlib/group_cpus.c:528:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-529-\t\t\t\t  npresmsk, nmsk, masks);\n--\nlib/group_cpus.c-544-\tcpumask_andnot(npresmsk, cpu_possible_mask, npresmsk);\nlib/group_cpus.c:545:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-546-\t\t\t\t  npresmsk, nmsk, masks);\n--\nlib/group_cpus.c-564-}\nlib/group_cpus.c:565:EXPORT_SYMBOL_GPL(group_cpus_evenly);\nlib/group_cpus.c-566-\n--\nlib/group_cpus.c=585=struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,\n--\nlib/group_cpus.c-630-\tcpumask_and(npresmsk, local_mask, cpu_present_mask);\nlib/group_cpus.c:631:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-632-\t\t\t\t  npresmsk, nmsk, masks);\n--\nlib/group_cpus.c-647-\tcpumask_andnot(npresmsk, local_mask, npresmsk);\nlib/group_cpus.c:648:\tret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,\nlib/group_cpus.c-649-\t\t\t\t  npresmsk, nmsk, masks);\n"
}

15/2 2026/09/10 18:47 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 27421
							output: 17
							thoughts: 16
						

Thoughts:
Here's my take on those thoughts, tailored for an expert audience:

**Kernel Isolation Configuration: Deep Dive**

Okay, so I'm thinking, before I dive too deep into the `isolation.c` code, it's always smart to double-check the Kconfig. I want to make sure I understand the conditional compilation and dependencies involved. Specifically, I need to verify how `kernel/sched/isolation.c` is actually being built into the kernel image. Are there any particular Kconfig options that enable or disable the isolation features I'm interested in? I'm anticipating that there are, I mean, it is the `isolation.c` file. More likely I'll be able to work out the intended use case here. I don't want to waste time chasing down a path that isn't enabled in my current configuration. What are the build requirements and any dependencies this might have on other parts of the scheduler or other kernel subsystems? Time to get the lay of the land before I start dissecting the implementation.



16/2 2026/09/10 18:47 tool grepper
0m Args:
{
  "Expression": "isolation\\.o"
}

Results:
{
  "Output": "mm/Makefile=117=obj-$(CONFIG_PAGE_OWNER) += page_owner.o\nmm/Makefile:118:obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o\nmm/Makefile-119-obj-$(CONFIG_ZSMALLOC)\t+= zsmalloc.o\n"
}

17/2 2026/09/10 18:47 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 27759
							output: 23
							thoughts: 23
						

Thoughts:
Here's my thought process, as requested:

**Navigating the Kernel Build System for `isolation.c`**

Okay, so I need to figure out how `isolation.c` is compiled and linked into the kernel. My first instinct, as always, is to dive into the Makefiles. Since this is a core kernel module or part of the core, I'm pretty sure it's handled at a fairly high level within the build system. So, I'll start by checking either `kernel/sched/Makefile` – since "isolation" might be related to CPU isolation or scheduling – or the main `kernel/Makefile`. Either of those should point me in the right direction, or at least help me trace the inclusion path to see where `isolation.c` is ultimately managed within the build process. From there, I can figure out dependencies, compile flags, and all the nitty-gritty details. Let's start with `kernel/sched/Makefile` first, and if that comes up empty, I'll switch over to `kernel/Makefile`. This is a classic "divide and conquer" approach to debugging the build system.



18/2 2026/09/10 18:47 tool grepper
0m Args:
{
  "Expression": "isolation",
  "PathPrefix": "kernel/"
}

Results:
{
  "Output": "kernel/bpf/cpumap.c-16-/*\nkernel/bpf/cpumap.c:17: * This is a scalability and isolation mechanism, that allow\nkernel/bpf/cpumap.c-18- * separating the early driver network XDP layer, from the rest of the\n--\nkernel/cgroup/cpuset-internal.h-11-#include \u003clinux/union_find.h\u003e\nkernel/cgroup/cpuset-internal.h:12:#include \u003clinux/sched/isolation.h\u003e\nkernel/cgroup/cpuset-internal.h-13-\n--\nkernel/cgroup/cpuset.c-35-#include \u003clinux/oom.h\u003e\nkernel/cgroup/cpuset.c:36:#include \u003clinux/sched/isolation.h\u003e\nkernel/cgroup/cpuset.c-37-#include \u003clinux/wait.h\u003e\n--\nkernel/cpu.c-11-#include \u003clinux/sched/hotplug.h\u003e\nkernel/cpu.c:12:#include \u003clinux/sched/isolation.h\u003e\nkernel/cpu.c-13-#include \u003clinux/sched/task.h\u003e\n--\nkernel/irq/affinity.c-10-#include \u003clinux/group_cpus.h\u003e\nkernel/irq/affinity.c:11:#include \u003clinux/sched/isolation.h\u003e\nkernel/irq/affinity.c-12-\n--\nkernel/irq/cpuhotplug.c-14-#include \u003clinux/irq.h\u003e\nkernel/irq/cpuhotplug.c:15:#include \u003clinux/sched/isolation.h\u003e\nkernel/irq/cpuhotplug.c-16-\n--\nkernel/irq/cpuhotplug.c=206=static void irq_restore_affinity_of_irq(struct irq_desc *desc, unsigned int cpu)\n--\nkernel/irq/cpuhotplug.c-221-\t * mask. No point in trying to move it around unless the\nkernel/irq/cpuhotplug.c:222:\t * isolation mechanism requests to move it to an upcoming\nkernel/irq/cpuhotplug.c-223-\t * housekeeping CPU.\n--\nkernel/irq/manage.c-20-#include \u003clinux/sched/task.h\u003e\nkernel/irq/manage.c:21:#include \u003clinux/sched/isolation.h\u003e\nkernel/irq/manage.c-22-#include \u003cuapi/linux/sched/types.h\u003e\n--\nkernel/kthread.c-29-#include \u003clinux/numa.h\u003e\nkernel/kthread.c:30:#include \u003clinux/sched/isolation.h\u003e\nkernel/kthread.c-31-#include \u003ctrace/events/sched.h\u003e\n--\nkernel/kthread.c=787=int kthreadd(void *unused)\n--\nkernel/kthread.c-833- * Similar to kthread_bind_mask() except that the affinity is not a requirement\nkernel/kthread.c:834: * but rather a preference that can be constrained by CPU isolation or CPU hotplug.\nkernel/kthread.c-835- * Must be called before the first wakeup of the kthread.\n--\nkernel/liveupdate/kexec_handover.c-26-#include \u003clinux/memblock.h\u003e\nkernel/liveupdate/kexec_handover.c:27:#include \u003clinux/page-isolation.h\u003e\nkernel/liveupdate/kexec_handover.c-28-#include \u003clinux/unaligned.h\u003e\n--\nkernel/rcu/sync.c=57=static void rcu_sync_func(struct rcu_head *rhp)\n--\nkernel/rcu/sync.c-99- *\nkernel/rcu/sync.c:100: * When called in isolation, rcu_sync_enter() must wait for a grace\nkernel/rcu/sync.c-101- * period, however, closely spaced calls to rcu_sync_enter() can\n--\nkernel/rcu/tree.c-60-#include \u003clinux/slab.h\u003e\nkernel/rcu/tree.c:61:#include \u003clinux/sched/isolation.h\u003e\nkernel/rcu/tree.c-62-#include \u003clinux/sched/clock.h\u003e\n--\nkernel/rcu/update.c-41-#include \u003clinux/rcupdate_wait.h\u003e\nkernel/rcu/update.c:42:#include \u003clinux/sched/isolation.h\u003e\nkernel/rcu/update.c-43-#include \u003clinux/kprobes.h\u003e\n--\nkernel/sched/build_policy.c-18-#include \u003clinux/sched/hotplug.h\u003e\nkernel/sched/build_policy.c:19:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/build_policy.c-20-#include \u003clinux/sched/posix-timers.h\u003e\n--\nkernel/sched/build_utility.c-14-#include \u003clinux/sched/debug.h\u003e\nkernel/sched/build_utility.c:15:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/build_utility.c-16-#include \u003clinux/sched/loadavg.h\u003e\n--\nkernel/sched/build_utility.c-100-#ifdef CONFIG_CPU_ISOLATION\nkernel/sched/build_utility.c:101:# include \"isolation.c\"\nkernel/sched/build_utility.c-102-#endif\n--\nkernel/sched/core.c-35-#include \u003clinux/sched/init.h\u003e\nkernel/sched/core.c:36:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/core.c-37-#include \u003clinux/sched/loadavg.h\u003e\n--\nkernel/sched/ext/ext.c-12-#include \u003clinux/sched/clock.h\u003e\nkernel/sched/ext/ext.c:13:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/ext/ext.c-14-#include \u003clinux/suspend.h\u003e\n--\nkernel/sched/ext/ext.c=7885=static s32 scx_enable(struct scx_enable_cmd *cmd, struct bpf_link *link)\n--\nkernel/sched/ext/ext.c-7890-\tif (housekeeping_enabled(HK_TYPE_DOMAIN_BOOT)) {\nkernel/sched/ext/ext.c:7891:\t\tpr_err(\"sched_ext: Not compatible with \\\"isolcpus=\\\" domain isolation\\n\");\nkernel/sched/ext/ext.c-7892-\t\treturn -EINVAL;\n--\nkernel/sched/fair.c-39-#include \u003clinux/sched/cputime.h\u003e\nkernel/sched/fair.c:40:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/fair.c-41-#include \u003clinux/sched/nohz.h\u003e\n--\nkernel/sched/isolation.c-9- */\nkernel/sched/isolation.c:10:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/isolation.c-11-#include \u003clinux/llist.h\u003e\n--\nkernel/sched/isolation.c=329=static int __init housekeeping_isolcpus_setup(char *str)\n--\nkernel/sched/isolation.c-386-\t * Ensure that HK_FLAG_MANAGED_IRQ is also set so that subsystems\nkernel/sched/isolation.c:387:\t * relying on managed interrupt isolation (e.g. Hyper-V VMBus channel\nkernel/sched/isolation.c-388-\t * distribution and CPU hotplug IRQ restoration) continue to function.\n--\nkernel/sched/rt.c=778=static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)\n--\nkernel/sched/rt.c-789-\t * potentially leaving other CPUs indefinitely throttled.  If\nkernel/sched/rt.c:790:\t * isolation is really required, the user will turn the throttle\nkernel/sched/rt.c-791-\t * off to kill the perturbations it causes anyway.  Meanwhile,\n--\nkernel/sched/topology.c-5-\nkernel/sched/topology.c:6:#include \u003clinux/sched/isolation.h\u003e\nkernel/sched/topology.c-7-#include \u003clinux/sched/clock.h\u003e\n--\nkernel/time/hrtimer.c-41-#include \u003clinux/sched/debug.h\u003e\nkernel/time/hrtimer.c:42:#include \u003clinux/sched/isolation.h\u003e\nkernel/time/hrtimer.c-43-#include \u003clinux/timer.h\u003e\n--\nkernel/time/timer_migration.c-12-#include \u003ctrace/events/ipi.h\u003e\nkernel/time/timer_migration.c:13:#include \u003clinux/sched/isolation.h\u003e\nkernel/time/timer_migration.c-14-\n--\nkernel/time/timer_migration.c=441=static inline bool tmigr_is_not_available(struct tmigr_cpu *tmc)\n--\nkernel/time/timer_migration.c-455- *\nkernel/time/timer_migration.c:456: * This function returns false during early boot and the isolation logic is\nkernel/time/timer_migration.c-457- * enabled only after isolated CPUs are marked as unavailable at late boot.\n--\nkernel/time/timer_migration.c-460- * should be ensured by the callers of this function: implicitly from hotplug\nkernel/time/timer_migration.c:461: * callbacks and explicitly in tmigr_init_isolation() and\nkernel/time/timer_migration.c-462- * tmigr_isolated_exclude_cpumask().\n--\nkernel/time/timer_migration.c=1599=int tmigr_isolated_exclude_cpumask(struct cpumask *exclude_cpumask)\n--\nkernel/time/timer_migration.c-1657-\nkernel/time/timer_migration.c:1658:static int __init tmigr_init_isolation(void)\nkernel/time/timer_migration.c-1659-{\n--\nkernel/time/timer_migration.c-1673-}\nkernel/time/timer_migration.c:1674:late_initcall(tmigr_init_isolation);\nkernel/time/timer_migration.c-1675-\n--\nkernel/trace/ring_buffer.c-7-#include \u003clinux/ring_buffer_types.h\u003e\nkernel/trace/ring_buffer.c:8:#include \u003clinux/sched/isolation.h\u003e\nkernel/trace/ring_buffer.c-9-#include \u003clinux/trace_recursion.h\u003e\n--\nkernel/trace/ring_buffer.c=4361=rb_irq_work_queue(struct rb_irq_work *irq_work)\n--\nkernel/trace/ring_buffer.c-4369-\t/*\nkernel/trace/ring_buffer.c:4370:\t * If CPU isolation is not active, cpu is always the current\nkernel/trace/ring_buffer.c-4371-\t * CPU, and the following is equivallent to irq_work_queue().\n--\nkernel/trace/trace_events_user.c-54- * Stores the system name, tables, and locks for a group of events. This\nkernel/trace/trace_events_user.c:55: * allows isolation for events by various means.\nkernel/trace/trace_events_user.c-56- */\n--\nkernel/watchdog.c-31-#include \u003clinux/sched/debug.h\u003e\nkernel/watchdog.c:32:#include \u003clinux/sched/isolation.h\u003e\nkernel/watchdog.c-33-\n--\nkernel/workqueue.c-52-#include \u003clinux/uaccess.h\u003e\nkernel/workqueue.c:53:#include \u003clinux/sched/isolation.h\u003e\nkernel/workqueue.c-54-#include \u003clinux/sched/debug.h\u003e\n"
}

19/2 2026/09/10 18:47 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 30991
							output: 20
							thoughts: 17
						

Thoughts:
Here's my summary, as though I'm thinking it:

**Digging into CPU Isolation Configuration**

Alright, time to dive into this CPU isolation business. First things first, let's see what the Kconfig file has to say about `CONFIG_CPU_ISOLATION`. I need to understand exactly how this feature is defined and controlled within the kernel's configuration system. I want to confirm what options are available and how they're exposed to the end-user. I'll be looking for things like dependencies, default values, and any associated help text. Knowing the underlying configuration options is crucial for me to grasp the scope and implications of isolating CPUs. This will help me build and test the kernel, with the configuration options properly set for my testing.



20/2 2026/09/10 18:47 tool grepper
0m Args:
{
  "Expression": "config CPU_ISOLATION"
}

Results:
{
  "Output": "init/Kconfig=764=endmenu # \"CPU/Task time and stats accounting\"\ninit/Kconfig-765-\ninit/Kconfig:766:config CPU_ISOLATION\ninit/Kconfig-767-\tbool \"CPU isolation\"\n"
}

21/2 2026/09/10 18:47 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 31264
							output: 32
							thoughts: 17
						

Thoughts:
Here's my take on the thought process, as requested:

**Diving into `init/Kconfig`**

Okay, so I'm thinking, "Where's the best place to start getting a handle on this particular aspect of the configuration?" Let's zero in on `init/Kconfig`. I've got a hunch that's where the heart of this functionality is defined. Now, since I'm familiar with this area, I can probably get to the critical parts more efficiently. No need to read the whole file line-by-line; I'll start around line 766. I'm hoping that specific section contains the key to what I'm looking for and that reading it should provide the needed clarity.



22/2 2026/09/10 18:47 tool read-file
0m Args:
{
  "File": "init/Kconfig",
  "FirstLine": 760,
  "LineCount": 20
}

Results:
{
  "Contents": " 760:\t\t  used for, say Y.\n 761:\t\n 762:\t\t  Say N if unsure.\n 763:\t\n 764:\tendmenu # \"CPU/Task time and stats accounting\"\n 765:\t\n 766:\tconfig CPU_ISOLATION\n 767:\t\tbool \"CPU isolation\"\n 768:\t\tdepends on SMP\n 769:\t\tdefault y\n 770:\t\thelp\n 771:\t\t  Make sure that CPUs running critical tasks are not disturbed by\n 772:\t\t  any source of \"noise\" such as unbound workqueues, timers, kthreads...\n 773:\t\t  Unbound jobs get offloaded to housekeeping CPUs. This is driven by\n 774:\t\t  the \"isolcpus=\" boot parameter.\n 775:\t\n 776:\t\t  Say Y if unsure.\n 777:\t\n 778:\tsource \"kernel/rcu/Kconfig\"\n 779:\t\n"
}

23/2 2026/09/10 18:47 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 31738
							output: 267
							thoughts: 609
						

Thoughts:
**Analyzing Potential Fuzzing Targets in a Kernel Patch**

Okay, let's break this down. We have a patch series here, and my task is to determine if it's worth fuzzing. First, the configuration options: `BLOCK`, `SMP`, and `CPU_ISOLATION`. Those seem reasonable preconditions for this kind of work, nothing unexpected there.

Now, let's dive into the focus symbols. I'm seeing: `blk_mq_map_queues`, `blk_mq_map_hw_queues`, `blk_mq_num_queues`, `blk_mq_hctx_notify_offline`, `group_mask_cpus_evenly`, `irq_create_affinity_masks`, and `irq_calc_affinity_vectors`. The key question is, are any of these ubiquitous? They are not, and that is a good thing. We need to find the part of the code that it is not already being tested.

`blk_mq_map_queues` is involved in setting up block queues – block device creation, essentially. `blk_mq_map_hw_queues` is specific to multi-queue hardware, like virtio-blk and NVMe. `blk_mq_hctx_notify_offline` relates to CPU hotplug, which is always interesting for fuzzing. `group_mask_cpus_evenly` is called by a few of the others, `blk_mq_map_queues` and `irq_create_affinity_masks`, and the `irq_*` symbols are for device interrupt handling.

Now, checking the requirements: `WorthFuzzing` should be true. The reasoning is solid. The patch introduces strict managed IRQ isolation (`HK_TYPE_MANAGED_IRQ_STRICT` / `isolcpus=managed_irq_strict`) and refactors CPU-to-hardware-queue mapping, affinity calculation, and hotplug. That impacts core block and IRQ subsystems, including queue mapping, CPU mask iteration, bitmap allocation, and CPU hotplug verification. These are all areas that are complex and error-prone, making them prime targets. The `FocusSymbols` are all listed, and the `EnableConfigs` are all valid.

Alright, seems we have a green light. Time to call `set-results`.



24/2 2026/09/10 18:47 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BLOCK",
    "SMP",
    "CPU_ISOLATION"
  ],
  "FocusSymbols": [
    "blk_mq_map_queues",
    "blk_mq_map_hw_queues",
    "group_mask_cpus_evenly",
    "irq_create_affinity_masks",
    "irq_calc_affinity_vectors",
    "blk_mq_hctx_notify_offline"
  ],
  "Reasoning": "The patch series introduces strict managed IRQ isolation (HK_TYPE_MANAGED_IRQ_STRICT / isolcpus=managed_irq_strict) and significantly modifies the CPU-to-queue mapping and affinity distribution algorithms in blk-mq, irq affinity, and lib/group_cpus. The changes touch reachable core block device queue configuration paths (blk_mq_map_queues, blk_mq_map_hw_queues), IRQ affinity calculations (irq_create_affinity_masks, irq_calc_affinity_vectors), group CPU distribution logic (group_mask_cpus_evenly), and CPU offline hotplug handling (blk_mq_hctx_notify_offline).",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BLOCK",
    "SMP",
    "CPU_ISOLATION"
  ],
  "FocusSymbols": [
    "blk_mq_map_queues",
    "blk_mq_map_hw_queues",
    "group_mask_cpus_evenly",
    "irq_create_affinity_masks",
    "irq_calc_affinity_vectors",
    "blk_mq_hctx_notify_offline"
  ],
  "Reasoning": "The patch series introduces strict managed IRQ isolation (HK_TYPE_MANAGED_IRQ_STRICT / isolcpus=managed_irq_strict) and significantly modifies the CPU-to-queue mapping and affinity distribution algorithms in blk-mq, irq affinity, and lib/group_cpus. The changes touch reachable core block device queue configuration paths (blk_mq_map_queues, blk_mq_map_hw_queues), IRQ affinity calculations (irq_create_affinity_masks, irq_calc_affinity_vectors), group CPU distribution logic (group_mask_cpus_evenly), and CPU offline hotplug handling (blk_mq_hctx_notify_offline).",
  "WorthFuzzing": true
}

25/1 2026/09/10 18:47 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

26/2 2026/09/10 18:47 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch introduces the `managed_irq_strict` isolation feature to restrict blk-mq queue mappings and managed interrupt affinities to housekeeping CPUs.\n\nAll dynamically allocated data structures and bitmaps (such as `active_hctx`, `masks`, and temporary cpumask variables) are allocated using zeroing helpers (`bitmap_zalloc`, `zalloc_cpumask_var`, `kzalloc_objs`). All local variables and loop indices are initialized before use. Furthermore, no data is copied to user space, so there is no risk of kernel info-leaks.\n\nAny potential bugs introduced by these changes (such as out-of-bounds CPU indexing, incorrect bitmap sizes, or CPU hotplug ordering deadlocks) are detectable by standard debug tooling, KASAN, and LOCKDEP. There are no uninitialized memory risks that would require dedicated KMSAN fuzzing.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 24c7e4613986e22c25a1ad02542ffe3894b880e0
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Sep 10 18:46:03 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 68647ff4bdd24..eb608e5139a69 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2822,7 +2822,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
@@ -2845,6 +2844,42 @@ Kernel parameters
 			  housekeeping CPUs has no influence on those
 			  queues.
 
+			managed_irq_strict
+			  Strictly restrict multiqueue hardware queue
+			  allocation and managed interrupt affinity to
+			  housekeeping CPUs. Unlike the best-effort
+			  managed_irq flag, this option guarantees that
+			  managed interrupts and multiqueue block device
+			  queues are never created for or mapped to isolated
+			  CPUs.
+
+			  In the block layer (blk-mq), device queue allocation
+			  and CPU-to-queue mappings are restricted to
+			  housekeeping CPUs. For devices using managed
+			  interrupts, hardware completion interrupts are routed
+			  exclusively to housekeeping cores, shielding isolated
+			  CPUs from I/O interruptions even if they initiated the
+			  request.
+
+			  If both managed_irq and managed_irq_strict are
+			  specified, managed_irq_strict takes precedence.
+
+			  Note: Using managed_irq_strict restricts the number
+			  of allocated hardware queues to match the number of
+			  housekeeping CPUs for single-set drivers. This
+			  prevents MSI-X vector exhaustion and forces isolated
+			  CPUs to share submission queues.
+
+			  Note: Offlining housekeeping CPUs which serve
+			  isolated CPUs will fail. The isolated CPUs must
+			  be offlined before offlining the housekeeping
+			  CPUs.
+
+			  Note: When I/O is submitted by an application on
+			  an isolated CPU, the hardware completion
+			  interrupt is handled entirely by a housekeeping
+			  CPU.
+
 			The format of <cpu-list> is described above.
 
 	iucv=		[HW,NET]
diff --git a/Documentation/core-api/housekeeping.rst b/Documentation/core-api/housekeeping.rst
index ccb0a88b9cb36..6d08c71e6c0eb 100644
--- a/Documentation/core-api/housekeeping.rst
+++ b/Documentation/core-api/housekeeping.rst
@@ -23,7 +23,7 @@ CPU. It is simply a CPU that can execute housekeeping work. There must
 always be at least one online housekeeping CPU at any time. The CPUs that
 are not	isolated are automatically assigned as housekeeping.
 
-Housekeeping is currently divided in four features described
+Housekeeping is currently divided in five features described
 by the ``enum hk_type type``:
 
 1.	HK_TYPE_DOMAIN matches the work moved away by scheduler domain
@@ -44,6 +44,10 @@ by the ``enum hk_type type``:
 	to HK_TYPE_DOMAIN except it ignores the isolation performed by
 	cpusets.
 
+5.	HK_TYPE_MANAGED_IRQ_STRICT matches the multiqueue block devices and
+	managed IRQs strictly restricted to housekeeping CPUs through
+	``isolcpus=managed_irq_strict``.
+
 
 Housekeeping cpumasks
 =================================
diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 705da074ad6c7..cec5b26bd57c7 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -22,8 +22,15 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
 {
 	unsigned int num;
 
-	num = cpumask_weight(mask);
-	return min_not_zero(num, max_queues);
+	if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		num = cpumask_weight_and(mask, housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT));
+	else
+		num = cpumask_weight(mask);
+	/*
+	 * Ensure that a count of zero does not inadvertently result in
+	 * allocating the maximum number of queues.
+	 */
+	return min_not_zero(num ?: 1U, max_queues);
 }
 
 /**
@@ -33,7 +40,8 @@ static unsigned int blk_mq_num_queues(const struct cpumask *mask,
  *		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)
 {
@@ -48,7 +56,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)
 {
@@ -56,23 +65,81 @@ unsigned int blk_mq_num_online_queues(unsigned int max_queues)
 }
 EXPORT_SYMBOL_GPL(blk_mq_num_online_queues);
 
+static void blk_mq_map_fallback(struct blk_mq_queue_map *qmap)
+{
+	unsigned int cpu;
+
+	/*
+	 * Map all CPUs to the first hctx of this specific map, respecting
+	 * the map's boundaries so secondary maps do not route into the default map.
+	 */
+	for_each_possible_cpu(cpu)
+		qmap->mq_map[cpu] = qmap->queue_offset;
+}
+
 void blk_mq_map_queues(struct blk_mq_queue_map *qmap)
 {
-	const struct cpumask *masks;
+	struct cpumask *masks;
+	const struct cpumask *constraint;
 	unsigned int queue, cpu, nr_masks;
+	unsigned long *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;
-	}
+	active_hctx = bitmap_zalloc(qmap->nr_queues, GFP_KERNEL);
+	if (!active_hctx)
+		goto fallback;
 
-	for (queue = 0; queue < qmap->nr_queues; queue++) {
-		for_each_cpu(cpu, &masks[queue % nr_masks])
+	if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		constraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);
+	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_hctx;
+
+	/*
+	 * Iterate directly over the generated CPU masks.
+	 * Calculate the final, highest hardware queue index that maps to this
+	 * mask. This skips all intermediate overwrites and safely evaluates
+	 * active_hctx only for queues that survive the mapping.
+	 */
+	for (unsigned int idx = 0; idx < nr_masks; idx++) {
+		queue = qmap->nr_queues - 1 -
+			((qmap->nr_queues - 1 - idx) % nr_masks);
+
+		for_each_cpu(cpu, &masks[idx])
 			qmap->mq_map[cpu] = qmap->queue_offset + queue;
+
+		__set_bit(queue, active_hctx);
+	}
+
+	/*
+	 * If the active_hctx bitmap is empty, attempting to route unassigned
+	 * CPUs will map them out-of-bounds. Fall back instead.
+	 */
+	if (bitmap_empty(active_hctx, qmap->nr_queues))
+		goto free_fallback;
+
+	/* Map any unassigned CPU evenly to the hardware contexts (hctx) */
+	queue = find_first_bit(active_hctx, qmap->nr_queues);
+	for_each_cpu_andnot(cpu, cpu_possible_mask, constraint) {
+		qmap->mq_map[cpu] = qmap->queue_offset + queue;
+		queue = find_next_bit_wrap(active_hctx, qmap->nr_queues, queue + 1);
 	}
+
+	kfree(masks);
+	bitmap_free(active_hctx);
+
+	return;
+
+free_fallback:
 	kfree(masks);
+free_fallback_hctx:
+	bitmap_free(active_hctx);
+
+fallback:
+	blk_mq_map_fallback(qmap);
 }
 EXPORT_SYMBOL_GPL(blk_mq_map_queues);
 
@@ -109,24 +176,84 @@ 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 mask;
+	const struct cpumask *constraint;
+	unsigned long *active_hctx;
 	unsigned int queue, cpu;
 
 	if (!dev->bus->irq_get_affinity)
+		goto map_software;
+
+	active_hctx = bitmap_zalloc(qmap->nr_queues, GFP_KERNEL);
+	if (!active_hctx)
 		goto fallback;
 
+	if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) {
+		bitmap_free(active_hctx);
+		goto fallback;
+	}
+
+	if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		constraint = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);
+	else
+		constraint = cpu_possible_mask;
+
+	/* 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_map_software;
 
-		for_each_cpu(cpu, mask)
+		for_each_cpu(cpu, affinity_mask) {
 			qmap->mq_map[cpu] = qmap->queue_offset + queue;
+			cpumask_set_cpu(cpu, mask);
+		}
 	}
 
+	/*
+	 * Evaluate active_hctx after mapping to handle overlapping masks.
+	 * This ensures queues that were overwritten do not falsely pass validation.
+	 */
+	for_each_cpu(cpu, mask) {
+		if (cpumask_test_cpu(cpu, constraint)) {
+			queue = qmap->mq_map[cpu] - qmap->queue_offset;
+			__set_bit(queue, active_hctx);
+		}
+	}
+
+	/*
+	 * If no assigned CPU matches the constraint, the active_hctx
+	 * bitmap will be empty. Fall back instead of routing out of bounds.
+	 */
+	if (bitmap_empty(active_hctx, qmap->nr_queues))
+		goto free_fallback;
+
+	/* Map any unassigned CPU evenly to the hardware contexts (hctx) */
+	queue = find_first_bit(active_hctx, qmap->nr_queues);
+	for_each_cpu_andnot(cpu, cpu_possible_mask, mask) {
+		qmap->mq_map[cpu] = qmap->queue_offset + queue;
+		queue = find_next_bit_wrap(active_hctx, qmap->nr_queues, queue + 1);
+	}
+
+	bitmap_free(active_hctx);
+	free_cpumask_var(mask);
+
 	return;
 
+free_fallback:
+	bitmap_free(active_hctx);
+	free_cpumask_var(mask);
+
 fallback:
+	blk_mq_map_fallback(qmap);
+	return;
+
+free_map_software:
+	free_cpumask_var(mask);
+	bitmap_free(active_hctx);
+map_software:
 	blk_mq_map_queues(qmap);
 }
 EXPORT_SYMBOL_GPL(blk_mq_map_hw_queues);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a26a11c73ee3e..6e903e1310e9f 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3690,6 +3690,64 @@ 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_MANAGED_IRQ_STRICT);
+	int cpu, fallback_isolated_cpu = -1;
+
+	/*
+	 * During system suspend or hibernation, tasks are frozen and all
+	 * CPUs are being taken offline. Allow offlining to proceed so
+	 * suspend is not aborted.
+	 */
+	if (cpuhp_tasks_frozen)
+		return true;
+
+	/*
+	 * If the CPU being offlined is not a housekeeping CPU,
+	 * offlining it will not strand isolated CPUs. Allow it.
+	 */
+	if (!cpumask_test_cpu(this_cpu, hk_mask))
+		return true;
+	/*
+	 * If this CPU is not mapped to this specific hardware context,
+	 * offlining it will not affect the context's I/O routing. Allow it.
+	 */
+	if (blk_mq_map_queue_type(hctx->queue, hctx->type, this_cpu) != hctx)
+		return true;
+	/*
+	 * Iterate over all online CPUs and manually check their mapping.
+	 * We cannot use hctx->cpumask here because blk_mq_map_swqueue()
+	 * intentionally strips isolated CPUs from it to prevent kworker
+	 * routing.
+	 */
+	for_each_online_cpu(cpu) {
+		struct blk_mq_hw_ctx *h;
+
+		if (cpu == this_cpu)
+			continue;
+
+		h = blk_mq_map_queue_type(hctx->queue, hctx->type, cpu);
+		if (h != hctx)
+			continue;
+
+		if (cpumask_test_cpu(cpu, hk_mask))
+			return true;
+
+		if (fallback_isolated_cpu == -1)
+			fallback_isolated_cpu = cpu;
+	}
+
+	if (fallback_isolated_cpu != -1) {
+		pr_warn("blk-mq: cannot offline CPU %u: online isolated CPU %d is still mapped to hctx%u\n",
+			this_cpu, fallback_isolated_cpu, hctx->queue_num);
+		return false;
+	}
+
+	return true;
+}
+
 static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx,
 		unsigned int this_cpu)
 {
@@ -3722,6 +3780,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_MANAGED_IRQ_STRICT)) {
+		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;
 
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 9bd3f5b868bcd..ec165b57182d3 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -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;
 
diff --git a/include/linux/group_cpus.h b/include/linux/group_cpus.h
index 9d4e5ab6c314b..defab4123a82f 100644
--- a/include/linux/group_cpus.h
+++ b/include/linux/group_cpus.h
@@ -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
diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
index cf0fd03dd7a24..bda3003ce86fa 100644
--- a/include/linux/sched/isolation.h
+++ b/include/linux/sched/isolation.h
@@ -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_MANAGED_IRQ_STRICT,
 	HK_TYPE_MAX,
 
 	/*
diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index 78f2418a89252..7796882a567ac 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -8,6 +8,7 @@
 #include <linux/slab.h>
 #include <linux/cpu.h>
 #include <linux/group_cpus.h>
+#include <linux/sched/isolation.h>
 
 static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)
 {
@@ -25,8 +26,10 @@ static void default_calc_sets(struct irq_affinity *affd, unsigned int affvecs)
 struct irq_affinity_desc *
 irq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)
 {
-	unsigned int affvecs, curvec, usedvecs, i;
+	unsigned int affvecs, curvec, usedvecs, i, j;
 	struct irq_affinity_desc *masks = NULL;
+	const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);
+	bool hk_enabled = housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT);
 
 	/*
 	 * Determine the number of vectors which need interrupt affinities
@@ -70,19 +73,29 @@ 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;
+		const struct cpumask *mask;
 
+		if (hk_enabled)
+			mask = hk_mask;
+		else
+			mask = cpu_possible_mask;
+
+		result = group_mask_cpus_evenly(this_vecs, mask,
+						&nr_masks);
 		if (!result) {
 			kfree(masks);
 			return NULL;
 		}
-
-		for (int j = 0; j < nr_masks; j++)
+		for (j = 0; j < nr_masks; j++)
 			cpumask_copy(&masks[curvec + j].mask, &result[j]);
+		for (j = nr_masks; j < this_vecs; j++)
+			cpumask_copy(&masks[curvec + j].mask, mask);
+
 		kfree(result);
 
-		curvec += nr_masks;
-		usedvecs += nr_masks;
+		curvec += this_vecs;
+		usedvecs += this_vecs;
 	}
 
 	/* Fill out vectors at the end that don't need affinity */
@@ -117,8 +130,10 @@ unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
 
 	if (affd->calc_sets)
 		set_vecs = maxvec - resv;
+	else if (housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT))
+		set_vecs = cpumask_weight(housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT));
 	else
 		set_vecs = cpumask_weight(cpu_possible_mask);
 
-	return resv + min(set_vecs, maxvec - resv);
+	return max(minvec, resv + min(set_vecs, maxvec - resv));
 }
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 156025ef81b75..7e9e78a18fb9f 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -17,6 +17,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_MANAGED_IRQ_STRICT = BIT(HK_TYPE_MANAGED_IRQ_STRICT),
 };
 
 DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
@@ -354,6 +355,12 @@ static int __init housekeeping_isolcpus_setup(char *str)
 			continue;
 		}
 
+		if (!strncmp(str, "managed_irq_strict,", 19)) {
+			str += 19;
+			flags |= HK_FLAG_MANAGED_IRQ_STRICT;
+			continue;
+		}
+
 		/*
 		 * Skip unknown sub-parameter and validate that it is not
 		 * containing an invalid character.
@@ -369,9 +376,20 @@ static int __init housekeeping_isolcpus_setup(char *str)
 		}
 
 		pr_info("isolcpus: Skipped unknown flag %.*s\n", len, par);
+		if (!*str)
+			break;
 		str++;
 	}
 
+	/*
+	 * managed_irq_strict is a strict superset of managed_irq.
+	 * Ensure that HK_FLAG_MANAGED_IRQ is also set so that subsystems
+	 * relying on managed interrupt isolation (e.g. Hyper-V VMBus channel
+	 * distribution and CPU hotplug IRQ restoration) continue to function.
+	 */
+	if (flags & HK_FLAG_MANAGED_IRQ_STRICT)
+		flags |= HK_FLAG_MANAGED_IRQ;
+
 	/* Default behaviour for isolcpus without flags */
 	if (!flags)
 		flags |= HK_FLAG_DOMAIN | HK_FLAG_DOMAIN_BOOT;
diff --git a/lib/group_cpus.c b/lib/group_cpus.c
index e6e18d7a49bba..75bd082e00bf4 100644
--- a/lib/group_cpus.c
+++ b/lib/group_cpus.c
@@ -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,114 @@ 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)
+EXPORT_SYMBOL_GPL(group_cpus_evenly);
+
+/**
+ * group_mask_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality
+ * @numgrps: number of cpumasks to create
+ * @mask: CPUs to consider for the grouping
+ * @nummasks: number of initialized cpumasks
+ *
+ * Return: cpumask array if successful, NULL otherwise. Only the CPUs
+ * marked in the mask will be considered for the grouping. And each
+ * element includes CPUs assigned to this group. nummasks contains the
+ * number of initialized masks which can be less than numgrps.
+ *
+ * Try to put close CPUs from viewpoint of CPU and NUMA locality into
+ * the same group.
+ *
+ * We guarantee in the resulting grouping that all CPUs specified in the
+ * provided mask are covered, and no same CPU is assigned to multiple
+ * groups.
+ */
+struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,
+				       const struct cpumask *mask,
+				       unsigned int *nummasks)
 {
-	struct cpumask *masks;
+	unsigned int curgrp = 0, nr_present = 0, nr_others = 0;
+	cpumask_var_t *node_to_cpumask;
+	cpumask_var_t nmsk, local_mask, npresmsk;
+	int ret = -ENOMEM;
+	struct cpumask *masks = NULL;
 
 	if (numgrps == 0)
 		return NULL;
 
+	if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
+		return NULL;
+
+	if (!zalloc_cpumask_var(&local_mask, GFP_KERNEL))
+		goto fail_nmsk;
+
+	if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL))
+		goto fail_local_mask;
+
+	node_to_cpumask = alloc_node_to_cpumask();
+	if (!node_to_cpumask)
+		goto fail_npresmsk;
+
 	masks = kzalloc_objs(*masks, numgrps);
 	if (!masks)
-		return NULL;
+		goto fail_node_to_cpumask;
+
+	build_node_to_cpumask(node_to_cpumask);
+
+	/*
+	 * Create a stable snapshot of the mask. The grouping algorithm
+	 * requires the CPU count to remain constant across its multiple
+	 * passes. This prevents allocation failures if the caller passes a
+	 * dynamic mask (e.g., cpu_online_mask) that changes concurrently.
+	 */
+	cpumask_copy(local_mask, mask);
 
-	/* assign all CPUs(cpu 0) to the 1st group only */
-	cpumask_copy(&masks[0], cpu_possible_mask);
-	*nummasks = 1;
+	/*
+	 * Grouping present CPUs first. We intersect the provided mask with
+	 * cpu_present_mask to ensure that we prioritise physically
+	 * available CPUs for the initial distribution.
+	 */
+	cpumask_and(npresmsk, local_mask, cpu_present_mask);
+	ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
+				  npresmsk, nmsk, masks);
+	if (ret < 0)
+		goto fail_node_to_cpumask;
+	nr_present = ret;
+
+	/*
+	 * Allocate non-present CPUs starting from the next group to be
+	 * handled. If the grouping of present CPUs already exhausted the
+	 * group space, assign the non-present CPUs to the already
+	 * allocated out groups.
+	 */
+	if (nr_present >= numgrps)
+		curgrp = 0;
+	else
+		curgrp = nr_present;
+	cpumask_andnot(npresmsk, local_mask, npresmsk);
+	ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
+				  npresmsk, nmsk, masks);
+	if (ret >= 0)
+		nr_others = ret;
+
+fail_node_to_cpumask:
+	free_node_to_cpumask(node_to_cpumask);
+
+fail_npresmsk:
+	free_cpumask_var(npresmsk);
+
+fail_local_mask:
+	free_cpumask_var(local_mask);
+
+fail_nmsk:
+	free_cpumask_var(nmsk);
+	if (ret < 0) {
+		kfree(masks);
+		return NULL;
+	}
+	*nummasks = min(nr_present + nr_others, numgrps);
+	if (*nummasks == 0) {
+		kfree(masks);
+		return NULL;
+	}
 	return masks;
 }
-#endif /* CONFIG_SMP */
-EXPORT_SYMBOL_GPL(group_cpus_evenly);
+EXPORT_SYMBOL_GPL(group_mask_cpus_evenly);

27/3 2026/09/10 18:47 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 10113
							output: 33
							thoughts: 751
						

Thoughts:
**Analyzing the Patch Series for KMSAN Fuzzing Necessity**

Okay, let's break this down. The first order of business is to assess this patch series. My initial thought is to determine if a dedicated KMSAN fuzzing session is warranted. I need to understand the scope and nature of the changes to make that call.

I'm seeing a multi-file patch, so let's dig into the details. The file list includes: `Documentation/admin-guide/kernel-parameters.txt`, `Documentation/core-api/housekeeping.rst`, `block/blk-mq-cpumap.c`, `block/blk-mq.c`, `drivers/scsi/aacraid/comminit.c`, `include/linux/group_cpus.h`, `include/linux/sched/isolation.h`, `kernel/irq/affinity.c`, `kernel/sched/isolation.c`, and `lib/group_cpus.c`. That's a pretty diverse set of areas impacted.

The core of the change appears to be introducing a new housekeeping isolation type, `HK_TYPE_MANAGED_IRQ_STRICT`, and the corresponding `isolcpus=managed_irq_strict` kernel parameter. The purpose seems to be restricting multiqueue hardware queue allocation and managed interrupt affinity to housekeeping CPUs. This immediately raises a flag. Any time you're messing with CPU affinity and interrupt handling, you need to be extra careful about race conditions and memory access patterns.

Now, let's look at the specific file modifications. In `blk-mq-cpumap.c`, I'm seeing changes in how queue numbers are calculated (`blk_mq_num_queues`), how CPU mapping is handled (`blk_mq_map_fallback`, `blk_mq_map_queues`, `blk_mq_map_hw_queues`), and how active contexts are managed. The code appears to be incorporating the `HK_TYPE_MANAGED_IRQ_STRICT` check and using `cpumask_weight_and` and `cpumask_weight` functions. I see `bitmap_zalloc` usage and manipulations of masks, which always bear close scrutiny for off-by-one errors or memory management issues.

In `blk-mq.c`, the changes revolve around checking CPU offlining rules for housekeeping CPUs and notifying offlines via `blk_mq_hctx_can_offline_hk_cpu` and `blk_mq_hctx_notify_offline`. This adds another level of complexity, potentially introducing race conditions when dealing with CPU hotplug.

`drivers/scsi/aacraid/comminit.c` looks straightforward—it now uses `blk_mq_num_online_queues` to get MSI count. However, the changes in `kernel/irq/affinity.c` are a point of greater concern. I'm seeing `group_mask_cpus_evenly` being used and potentially allocated and copied masks. Specifically, the function `irq_create_affinity_masks` with calls to `kcalloc` or `kzalloc` raises my eyebrows, as does the handling of `HK_TYPE_MANAGED_IRQ_STRICT` within `irq_calc_affinity_vectors`. Any time you are dealing with masks, allocation of memory, and copying, that deserves very close attention. I need to go back and check the allocation in `irq_create_affinity_masks` function. Memory corruption or data races here could be subtle and extremely difficult to debug.

Overall, given the involvement with CPU affinity, interrupt management, mask manipulations, and the block layer, I'm leaning toward a KMSAN fuzzing session. The potential for memory corruption or race conditions, while not certain, is high enough to warrant the effort. I'll need to focus the fuzzing on the areas modified in `blk-mq-cpumap.c`, `blk-mq.c`, and especially `kernel/irq/affinity.c` and make sure it is tested with appropriate configurations such as `isolcpus=managed_irq_strict`.



28/3 2026/09/10 18:47 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "kcalloc.*masks",
  "PathPrefix": "kernel/irq/affinity.c"
}

Results:
{
  "error": "no matches"
}

29/3 2026/09/10 18:47 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 11786
							output: 35
							thoughts: 28
						

Thoughts:
Here's my summary, as if I were thinking these thoughts:

**Examining Interrupt Affinity Mask Allocation**

Alright, let's dive into the guts of how interrupt affinity masks are handled in the kernel. I need to refresh my memory on the specifics of how these masks are allocated and initialized. Let's start by looking at `kernel/irq/affinity.c`, specifically around line 25. That should show me where the `masks` variable, or whatever it's called, is actually brought into existence and how its memory is managed. I want to see if they're statically allocated, dynamically allocated with `kmalloc` or similar, or potentially handled through some more intricate memory management scheme. That initial allocation strategy is key to understanding the resource usage and potential bottlenecks related to interrupt affinity. This initial analysis should provide a good jumping-off point to look at how these masks are updated later, and in what contexts.



30/3 2026/09/10 18:47 tool read-file
0m Args:
{
  "File": "kernel/irq/affinity.c",
  "FirstLine": 25,
  "LineCount": 60
}

Results:
{
  "Contents": "  25:\t */\n  26:\tstruct irq_affinity_desc *\n  27:\tirq_create_affinity_masks(unsigned int nvecs, struct irq_affinity *affd)\n  28:\t{\n  29:\t\tunsigned int affvecs, curvec, usedvecs, i, j;\n  30:\t\tstruct irq_affinity_desc *masks = NULL;\n  31:\t\tconst struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_STRICT);\n  32:\t\tbool hk_enabled = housekeeping_enabled(HK_TYPE_MANAGED_IRQ_STRICT);\n  33:\t\n  34:\t\t/*\n  35:\t\t * Determine the number of vectors which need interrupt affinities\n  36:\t\t * assigned. If the pre/post request exhausts the available vectors\n  37:\t\t * then nothing to do here except for invoking the calc_sets()\n  38:\t\t * callback so the device driver can adjust to the situation.\n  39:\t\t */\n  40:\t\tif (nvecs \u003e affd-\u003epre_vectors + affd-\u003epost_vectors)\n  41:\t\t\taffvecs = nvecs - affd-\u003epre_vectors - affd-\u003epost_vectors;\n  42:\t\telse\n  43:\t\t\taffvecs = 0;\n  44:\t\n  45:\t\t/*\n  46:\t\t * Simple invocations do not provide a calc_sets() callback. Install\n  47:\t\t * the generic one.\n  48:\t\t */\n  49:\t\tif (!affd-\u003ecalc_sets)\n  50:\t\t\taffd-\u003ecalc_sets = default_calc_sets;\n  51:\t\n  52:\t\t/* Recalculate the sets */\n  53:\t\taffd-\u003ecalc_sets(affd, affvecs);\n  54:\t\n  55:\t\tif (WARN_ON_ONCE(affd-\u003enr_sets \u003e IRQ_AFFINITY_MAX_SETS))\n  56:\t\t\treturn NULL;\n  57:\t\n  58:\t\t/* Nothing to assign? */\n  59:\t\tif (!affvecs)\n  60:\t\t\treturn NULL;\n  61:\t\n  62:\t\tmasks = kzalloc_objs(*masks, nvecs);\n  63:\t\tif (!masks)\n  64:\t\t\treturn NULL;\n  65:\t\n  66:\t\t/* Fill out vectors at the beginning that don't need affinity */\n  67:\t\tfor (curvec = 0; curvec \u003c affd-\u003epre_vectors; curvec++)\n  68:\t\t\tcpumask_copy(\u0026masks[curvec].mask, irq_default_affinity);\n  69:\t\n  70:\t\t/*\n  71:\t\t * Spread on present CPUs starting from affd-\u003epre_vectors. If we\n  72:\t\t * have multiple sets, build each sets affinity mask separately.\n  73:\t\t */\n  74:\t\tfor (i = 0, usedvecs = 0; i \u003c affd-\u003enr_sets; i++) {\n  75:\t\t\tunsigned int nr_masks, this_vecs = affd-\u003eset_size[i];\n  76:\t\t\tstruct cpumask *result;\n  77:\t\t\tconst struct cpumask *mask;\n  78:\t\n  79:\t\t\tif (hk_enabled)\n  80:\t\t\t\tmask = hk_mask;\n  81:\t\t\telse\n  82:\t\t\t\tmask = cpu_possible_mask;\n  83:\t\n  84:\t\t\tresult = group_mask_cpus_evenly(this_vecs, mask,\n"
}

31/3 2026/09/10 18:47 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 12945
							output: 37
							thoughts: 172
						

Thoughts:
**My Initial Thoughts on CPU Mask Allocation**

Okay, so I see this line: `masks = kzalloc_objs(*masks, nvecs);` Right away, I understand that `masks` is being allocated and zeroed out. That's good practice, minimizes potential issues. I'm always looking for that clean initialization. Now, I want to see how this is being used in the grand scheme of things, so I'm going to look at `group_mask_cpus_evenly` in `lib/group_cpus.c`.

Aha, similar pattern: `masks = kzalloc_objs(*masks, numgrps);` Looks like `masks` is initialized with `kzalloc_objs` again. Further digging into this function, I see multiple `zalloc_cpumask_var` calls: `zalloc_cpumask_var(&nmsk, GFP_KERNEL)`, `zalloc_cpumask_var(&local_mask, GFP_KERNEL)`, and `zalloc_cpumask_var(&npresmsk, GFP_KERNEL)`. This strongly suggests that we're dealing with bitmasks related to CPUs, and these are all being allocated dynamically, likely based on the current CPU topology or some other runtime parameter. Also, `node_to_cpumask = alloc_node_to_cpumask();` appears. Interesting, a dedicated function for allocating this. I'll need to understand this to have a complete picture.

So next, I will need to look at `alloc_node_to_cpumask` in `lib/group_cpus.c` to see how it works. That looks like the key to understanding how these masks are connected to nodes.



32/3 2026/09/10 18:47 tool grepper
0m Args:
{
  "Expression": "alloc_node_to_cpumask",
  "PathPrefix": "lib/group_cpus.c"
}

Results:
{
  "Output": "lib/group_cpus.c=12=static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk,\n--\nlib/group_cpus.c-42-\nlib/group_cpus.c:43:static cpumask_var_t *alloc_node_to_cpumask(void)\nlib/group_cpus.c-44-{\n--\nlib/group_cpus.c=486=struct cpumask *group_cpus_evenly(unsigned int numgrps, unsigned int *nummasks)\n--\nlib/group_cpus.c-502-\nlib/group_cpus.c:503:\tnode_to_cpumask = alloc_node_to_cpumask();\nlib/group_cpus.c-504-\tif (!node_to_cpumask)\n--\nlib/group_cpus.c=585=struct cpumask *group_mask_cpus_evenly(unsigned int numgrps,\n--\nlib/group_cpus.c-606-\nlib/group_cpus.c:607:\tnode_to_cpumask = alloc_node_to_cpumask();\nlib/group_cpus.c-608-\tif (!node_to_cpumask)\n"
}

33/3 2026/09/10 18:47 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 13860
							output: 35
							thoughts: 17
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into `alloc_node_to_cpumask`**

Alright, time to dig into the `alloc_node_to_cpumask` implementation. I need to understand its nuances. Given my understanding of NUMA architectures and memory management, I want to see how this function handles the mapping of memory allocation requests to specific CPU masks within a node. I'm particularly interested in how it interacts with the underlying kernel's memory allocation mechanisms and how it factors in NUMA balancing and policy settings. I'll likely be looking for potential bottlenecks, race conditions, or optimization opportunities in the core logic, considering the impact of thread affinity, and memory bandwidth considerations. Essentially, I'm expecting this function to be a critical piece of the puzzle, and I intend to understand it thoroughly.



34/3 2026/09/10 18:47 tool read-file
0m Args:
{
  "File": "lib/group_cpus.c",
  "FirstLine": 43,
  "LineCount": 40
}

Results:
{
  "Contents": "  43:\tstatic cpumask_var_t *alloc_node_to_cpumask(void)\n  44:\t{\n  45:\t\tcpumask_var_t *masks;\n  46:\t\tint node;\n  47:\t\n  48:\t\tmasks = kzalloc_objs(cpumask_var_t, nr_node_ids);\n  49:\t\tif (!masks)\n  50:\t\t\treturn NULL;\n  51:\t\n  52:\t\tfor (node = 0; node \u003c nr_node_ids; node++) {\n  53:\t\t\tif (!zalloc_cpumask_var(\u0026masks[node], GFP_KERNEL))\n  54:\t\t\t\tgoto out_unwind;\n  55:\t\t}\n  56:\t\n  57:\t\treturn masks;\n  58:\t\n  59:\tout_unwind:\n  60:\t\twhile (--node \u003e= 0)\n  61:\t\t\tfree_cpumask_var(masks[node]);\n  62:\t\tkfree(masks);\n  63:\t\treturn NULL;\n  64:\t}\n  65:\t\n  66:\tstatic void free_node_to_cpumask(cpumask_var_t *masks)\n  67:\t{\n  68:\t\tint node;\n  69:\t\n  70:\t\tfor (node = 0; node \u003c nr_node_ids; node++)\n  71:\t\t\tfree_cpumask_var(masks[node]);\n  72:\t\tkfree(masks);\n  73:\t}\n  74:\t\n  75:\tstatic void build_node_to_cpumask(cpumask_var_t *masks)\n  76:\t{\n  77:\t\tint cpu;\n  78:\t\n  79:\t\tfor_each_possible_cpu(cpu)\n  80:\t\t\tcpumask_set_cpu(cpu, masks[cpu_to_node(cpu)]);\n  81:\t}\n  82:\t\n"
}

35/3 2026/09/10 18:47 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 14610
							output: 206
							thoughts: 899
						

Thoughts:
**KMSAN Applicability Assessment: No Need Here**

Okay, let's break this down. My main concern is always uninitialized memory, info leaks to userspace, and `copy_to_user` calls. I've gone through the code, meticulously checking for those vulnerabilities.

First, I didn't see anything that transmits kernel structures to user space – no `copy_to_user`, no `put_user`, no netlink, no ioctls involved in this patch at all. Good. Then I looked for conditional logic or branching that might depend on uninitialized variables or struct fields. Every relevant variable, like the `active_hctx` bitmap, is either zeroed (`bitmap_zalloc`) or allocated with a zero-initializing function (`kzalloc_objs`, `zalloc_cpumask_var`). Local variables are explicitly initialized before use, too. I've checked all of the routines and there aren't any sneaky initializations. All allocations use zeroing functions like `kzalloc` or `zalloc`, preventing reads from uninitialized memory.

The code changes are primarily centered around CPU mapping, CPU masks, IRQ affinity, and block layer queue mapping, with no user-kernel data copying. No uninitialized memory usage, no information leaks, and nothing that would trigger KMSAN. Any typical memory corruptions or out-of-bounds accesses, null pointer dereferences, or deadlock problems would be caught by KASAN and LOCKDEP. I even double-checked the diff against the relevant files: `Documentation/admin-guide/kernel-parameters.txt`, `Documentation/core-api/housekeeping.rst`, the block layer files, the AACRAID driver, and the relevant include and lib files.

So, am I missing anything? No, not really. This patch is adding CPU isolation for managed IRQs and multiqueue block devices. It's touching queue and IRQ affinity mapping algorithms, and CPU offline checks, but all memory allocations use zero-initializing routines. Crucially, there's no data being passed to userspace. All of these issues fall squarely into the purview of KASAN, UBSAN, and LOCKDEP. KMSAN is just not applicable here.

Therefore, `NeedsKMSAN` should be false. Let's call `set-results`.



36/3 2026/09/10 18:47 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch introduces the `managed_irq_strict` isolation feature to restrict blk-mq queue mappings and managed interrupt affinities to housekeeping CPUs.\n\nAll dynamically allocated data structures and bitmaps (such as `active_hctx`, `masks`, and temporary cpumask variables) are allocated using zeroing helpers (`bitmap_zalloc`, `zalloc_cpumask_var`, `kzalloc_objs`). All local variables and loop indices are initialized before use. Furthermore, no data is copied to user space, so there is no risk of kernel info-leaks.\n\nAny potential bugs introduced by these changes (such as out-of-bounds CPU indexing, incorrect bitmap sizes, or CPU hotplug ordering deadlocks) are detectable by standard debug tooling, KASAN, and LOCKDEP. There are no uninitialized memory risks that would require dedicated KMSAN fuzzing.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch introduces the `managed_irq_strict` isolation feature to restrict blk-mq queue mappings and managed interrupt affinities to housekeeping CPUs.\n\nAll dynamically allocated data structures and bitmaps (such as `active_hctx`, `masks`, and temporary cpumask variables) are allocated using zeroing helpers (`bitmap_zalloc`, `zalloc_cpumask_var`, `kzalloc_objs`). All local variables and loop indices are initialized before use. Furthermore, no data is copied to user space, so there is no risk of kernel info-leaks.\n\nAny potential bugs introduced by these changes (such as out-of-bounds CPU indexing, incorrect bitmap sizes, or CPU hotplug ordering deadlocks) are detectable by standard debug tooling, KASAN, and LOCKDEP. There are no uninitialized memory risks that would require dedicated KMSAN fuzzing.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)