From: sashiko-bot@kernel.org
To: "Kris Pan" <kris.pan@intel.com>
Cc: linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org,
linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 05/10] genirq: Reapply unmanaged IRQ affinity on isolation changes
Date: Tue, 01 Dec 2026 03:41:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-242460@kernel.org> (raw)
In-Reply-To: <20261130033709.2704805-6-kris.pan@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] genirq: trapped auto-placed IRQ not moved in
irq_reapply_affinity()
- [Low] genirq: dead and inverted trapped checks in
irq_isolation_needs_reapply()
--
commit 14a3c1ca3828631268f1df40b6be7e180646bfa2
Author: Kris Pan <kris.pan@intel.com>
genirq: Reapply unmanaged IRQ affinity on isolation changes
This commit tracks changes to the runtime-isolated CPU set and walks active
unmanaged interrupt descriptors to reapply their requested affinity masks when
affected by an isolation update.
> diff --git a/kernel/irq/isolation.c b/kernel/irq/isolation.c
> index af7244ce181a4..4ff45da90f909 100644
> --- a/kernel/irq/isolation.c
> +++ b/kernel/irq/isolation.c
[ ... ]
> @@ -221,3 +239,248 @@ bool irq_isolation_widen_mask_full(struct irq_desc *desc,
> return !cpumask_empty(out) && !cpumask_subset(out, mask);
> }
>
> +/*
> + * Return true when @changed contains a CPU which left a runtime-isolated
> + * partition and is part of @affinity. Such a CPU was filtered out before
> + * and is a valid target again.
> + *
> + * Must be called under RCU read lock.
> + */
> +static bool irq_reapply_restores_target(const struct cpumask *changed,
> + const struct cpumask *affinity)
> +{
> + unsigned int cpu;
> +
> + for_each_cpu_and(cpu, changed, affinity) {
> + if (!housekeeping_runtime_isolated_cpu(cpu))
> + return true;
> + }
> +
> + return false;
> +}
> +
> +/**
> + * irq_isolation_needs_reapply - Does @changed affect this interrupt?
> + * @desc: Interrupt descriptor, desc->lock held
> + * @changed: Old/current difference of the runtime-isolated set
> + *
> + * A change may isolate a CPU the interrupt is running on, take a CPU out
> + * of the requested mask, return a CPU to it, move the programmed mask, or
> + * leave an emergency fallback outside the request while isolation is
> + * going away. Only the interrupts where one of those applies have to be
> + * re-applied; everything else keeps its programming untouched. A CPU
> + * which enters isolation while it sits in the request changes the policy
> + * mask even when the chip already targets another member, so a registered
> + * notifier has to run and the reverse map has to drop it. An automatic
> + * placement which sits outside its request is in the emergency fallback;
> + * its mask follows the housekeeping set, so every change reaches it.
> + *
> + * Returns: true when the interrupt has to be re-applied.
> + */
> +bool irq_isolation_needs_reapply(struct irq_desc *desc,
> + const struct cpumask *changed)
> +{
> + struct irq_data *data = &desc->irq_data;
> + const struct cpumask *eff, *affinity;
> + bool restored, trapped = false;
> + bool unaffected, needs_restore, notify_changed;
> +
> + lockdep_assert_held(&desc->lock);
> + WARN_ON_ONCE(!changed);
> +
> + eff = irq_data_get_effective_affinity_mask(data);
> + affinity = desc->irq_common_data.affinity;
> +
> + rcu_read_lock();
> +
> + /*
> + * An automatic placement may be stuck on an isolated CPU, or
> + * parked outside its request after the isolation went away.
> + *
> + * While isolation is active, an automatic placement which sits
> + * outside its request is in the emergency fallback: its programmed
> + * mask is derived from the housekeeping set, not from the request,
> + * so every isolation change can change it. Converge it even when
> + * the change does not touch the current CPU.
> + */
> + if (irq_affinity_is_auto(desc)) {
> + if (irq_isolation_active())
> + trapped = cpumask_empty(eff) ||
> + housekeeping_runtime_isolated_intersects(eff) ||
> + (!cpumask_empty(eff) &&
> + !cpumask_intersects(eff, affinity));
> + else
> + trapped = !cpumask_empty(eff) &&
> + !cpumask_intersects(eff, affinity);
> + }
> +
> + /*
> + * A CPU which left a runtime-isolated partition is a valid target
> + * again. Hand the full requested mask to the irqchip again even
> + * when the current effective mask still intersects it, so a chip
> + * which can place the interrupt on another target includes the
> + * returning CPU, and so that the notifier and the IRQ threads see
> + * the restored request. The request itself is never changed.
> + */
> + restored = irq_reapply_restores_target(changed, affinity);
> +
> + /*
> + * A CPU which enters isolation changes the policy mask even if the
> + * chip is not delivering on it: the request loses a target, so a
> + * consumer which follows the programmed mask has to be told.
> + * Only the notifier consumer needs the update, and only it gets
> + * the chip reprogrammed; an interrupt without a notifier keeps its
> + * current target and does not pay for a hardware write. While a
> + * move is queued, the pending mask carries the newest request and
> + * is the mask the notifier reports.
> + */
> + notify_changed = desc->affinity_notify &&
> + (cpumask_intersects(changed, affinity) ||
> + (irq_move_pending(data) &&
> + cpumask_intersects(changed,
> + irq_desc_get_pending_mask(desc))));
> +
> + rcu_read_unlock();
> +
> + /*
> + * A CPU which just left a runtime-isolated partition must pull back
> + * an interrupt that was displaced away from it, even while other
> + * partitions remain active.
> + */
> + if (cpumask_intersects(changed, affinity) &&
> + !cpumask_intersects(eff, affinity))
> + trapped = true;
> +
> + /*
> + * An empty effective mask means the chip does not report its
> + * programming; treat the programmed placement as unaffected here
> + * and let @trapped, @restored and @notify_changed decide. A
> + * change which does not touch the effective CPU and does not
> + * change the request leaves the chip alone.
> + */
> + unaffected = cpumask_empty(eff) || !cpumask_intersects(changed, eff);
[Severity: Low]
Are the two trapped assignments in irq_isolation_needs_reapply() doing what
their comments describe?
In the irq_affinity_is_auto(desc) block, starting the OR chain with
cpumask_empty(eff) makes the later !cpumask_empty(eff) check dead code and
marks every automatic interrupt as trapped on chips that do not report
effective affinity, which conflicts with the comment on unaffected below.
In the second trapped check:
if (cpumask_intersects(changed, affinity) &&
!cpumask_intersects(eff, affinity))
trapped = true;
any CPU in changed & affinity that left isolation already sets restored = true
via irq_reapply_restores_target(changed, affinity). This check therefore only
changes the result when every CPU in changed & affinity entered isolation, and
because it also omits !cpumask_empty(eff), it triggers a reapply for explicit
interrupts without a notifier when eff is empty or was previously displaced
outside affinity.
> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 25f42256aeabf..76c8cb679f4cc 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -354,6 +354,66 @@ static int irq_try_set_affinity(struct irq_data *data,
> return ret;
> }
>
> +#ifdef CONFIG_CPU_ISOLATION
> +/*
> + * Reapply the requested affinity after a global isolation change.
> + * Does not set IRQD_AFFINITY_SET.
> + */
> +void irq_reapply_affinity(struct irq_desc *desc, const struct cpumask *changed)
> +{
> + struct irq_chip *chip = irq_desc_get_chip(desc);
> + struct irq_data *data = &desc->irq_data;
> +
> + lockdep_assert_held(&desc->lock);
> +
> + if (!chip || !chip->irq_set_affinity)
> + return;
> + if (!irq_isolation_can_filter(data))
> + return;
> + if (irqd_affinity_is_managed(data))
> + return;
> + if (!irqd_can_balance(data))
> + return;
> + if (!irqd_is_activated(data))
> + return;
> +
> + /*
> + * The caller holds desc->lock, so the query sees a stable request
> + * and effective mask. Skip interrupts which cannot be affected by
> + * the changed set; the pre-check in the caller is only advisory
> + * and avoids taking desc->lock for clearly inactive descriptors.
> + */
> + if (changed && !irq_isolation_needs_reapply(desc, changed))
> + return;
> +
> + if (desc->istate & IRQS_SUSPENDED)
> + return;
> +
> + if (irq_can_move_pcntxt(data)) {
> +#ifdef CONFIG_GENERIC_PENDING_IRQ
> + if (irqd_is_setaffinity_pending(data))
> + goto pending;
> +#endif
> + irq_try_set_affinity(data, desc->irq_common_data.affinity,
> + false);
> + return;
> + }
[Severity: Medium]
Can an automatic interrupt that was redirected to a fallback housekeeping CPU
remain trapped on that CPU when the fallback CPU is later isolated?
If all online CPUs in desc->irq_common_data.affinity (say CPU 2) are isolated,
irq_isolation_select_mask() redirects the effective affinity to a fallback
housekeeping CPU (say CPU 0) while keeping desc->irq_common_data.affinity as
{CPU 2}. If CPU 2 is then taken offline, migrate_one_irq() sees that the
effective mask {CPU 0} is still online and leaves affinity untouched. When
CPU 2 leaves the isolated set and CPU 0 enters isolation,
irq_isolation_needs_reapply() marks the interrupt trapped and
irq_reapply_affinity() calls irq_try_set_affinity() with {CPU 2}, but
irq_isolation_select_mask() returns early because {CPU 2} no longer intersects
the runtime-isolated mask:
kernel/irq/isolation.c:irq_isolation_select_mask() {
...
housekeeping_runtime_isolated(out);
cpumask_andnot(out, src, out);
if (cpumask_equal(out, src)) {
rcu_read_unlock();
return false;
}
auto_placed = irq_affinity_is_auto(irq_data_to_desc(data));
if (!cpumask_intersects(out, cpu_online_mask) && auto_placed)
irq_isolation_fallback_mask(data, src, out);
...
}
irq_do_set_affinity() then intersects {CPU 2} with cpu_online_mask and fails
with -EINVAL (or skips the -ENOSPC widening path because prog_mask == mask when
affinity is online but out of vectors), leaving the interrupt programmed on the
newly isolated CPU 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130033709.2704805-1-kris.pan@intel.com?part=5
next prev parent reply other threads:[~2026-12-01 3:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 3:36 [RFC PATCH 00/10] genirq/cpuset: Evict unmanaged IRQs from runtime-isolated CPUs Kris Pan
2026-11-30 3:36 ` [RFC PATCH 01/10] genirq: Add IRQCHIP_AFFINITY_FILTERABLE flag Kris Pan
2026-11-30 3:37 ` [RFC PATCH 02/10] sched/isolation: Add runtime isolation helpers Kris Pan
2026-11-30 3:37 ` [RFC PATCH 03/10] genirq: Track automatic vs. explicit affinity provenance Kris Pan
2026-11-30 3:37 ` [RFC PATCH 04/10] genirq: Filter unmanaged IRQ affinity against runtime isolation Kris Pan
2026-11-30 3:37 ` [RFC PATCH 05/10] genirq: Reapply unmanaged IRQ affinity on isolation changes Kris Pan
2026-12-01 3:41 ` sashiko-bot [this message]
2026-11-30 3:37 ` [RFC PATCH 06/10] genirq: Align affinity notifiers and IRQ threads with isolation Kris Pan
2026-12-01 3:41 ` sashiko-bot
2026-11-30 3:37 ` [RFC PATCH 07/10] genirq: Handle runtime isolation across hotplug and suspend Kris Pan
2026-12-01 3:41 ` sashiko-bot
2026-11-30 3:37 ` [RFC PATCH 08/10] x86/apic: Support runtime IRQ isolation Kris Pan
2026-12-01 3:41 ` sashiko-bot
2026-11-30 3:37 ` [RFC PATCH 09/10] sched/isolation: Publish runtime isolation to genirq Kris Pan
2026-11-30 3:37 ` [RFC PATCH 10/10] net: Keep core-managed IRQ affinity automatic Kris Pan
2026-12-01 3:41 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-242460@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kris.pan@intel.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox