From: Kris Pan <kris.pan@intel.com>
To: tglx@kernel.org, maz@kernel.org
Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
hpa@zytor.com, x86@kernel.org, peterz@infradead.org,
frederic@kernel.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, longman@redhat.com, tj@kernel.org,
corbet@lwn.net, linux-doc@vger.kernel.org, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, joro@8bytes.org, will@kernel.org,
robin.murphy@arm.com, dwmw2@infradead.org,
baolu.lu@linux.intel.com, vasant.hegde@amd.com,
suravee.suthikulpanit@amd.com, iommu@lists.linux.dev,
haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
linux-hyperv@vger.kernel.org, bhelgaas@google.com,
lpieralisi@kernel.org, linux-pci@vger.kernel.org,
steve.wahl@hpe.com, bigeasy@linutronix.de, clrkwllms@kernel.org,
linux-rt-devel@lists.linux.dev, radu@rendec.net,
linux-kernel@vger.kernel.org, Kris Pan <kris.pan@intel.com>
Subject: [RFC PATCH 03/10] genirq: Track automatic vs. explicit affinity provenance
Date: Mon, 30 Nov 2026 11:37:01 +0800 [thread overview]
Message-ID: <20261130033709.2704805-4-kris.pan@intel.com> (raw)
In-Reply-To: <20261130033709.2704805-1-kris.pan@intel.com>
Runtime IRQ isolation has to distinguish an automatically placed
interrupt from one which was pinned explicitly: only the former may be
redirected to other housekeeping CPUs when its requested targets become
isolated.
Record the provenance in a private descriptor state bit,
IRQS_AFFINITY_AUTO, in desc->istate next to IRQS_SYSFS. istate is
genirq-private, so the public IRQ_* space in include/linux/irq.h and
the status_use_accessors word stay untouched, irq_modify_status()
cannot reach the bit, and it survives free_irq()/request_irq(). The
bit is set or cleared by the descriptor setup, by the managed affinity
descriptor update and by irq_setup_affinity().
In-kernel irq_set_affinity_and_hint() describes automatic placement:
drivers use it to bind a queue, not to exclude other CPUs. A bare
irq_set_affinity() is an explicit pin, the safe default for a per-CPU
PMU or an architecture timer which needs the interrupt on one CPU.
Core code which manages an affinity on a driver's behalf marks it
automatic with irq_set_affinity_auto(); the helper is not exported, so
a module cannot opt in by accident. A /proc/irq/N/smp_affinity write,
irq_force_affinity() and a bare irq_set_affinity() clear the bit;
subsequent filtering does not redirect them to unrelated housekeeping
CPUs, so only their cross-mask fallback is lost.
No behaviour change: the bit is recorded, not read.
Signed-off-by: Kris Pan <kris.pan@intel.com>
---
include/linux/interrupt.h | 8 ++++
kernel/irq/debugfs.c | 1 +
kernel/irq/internals.h | 17 ++++++++
kernel/irq/irqdesc.c | 9 +++++
kernel/irq/manage.c | 85 +++++++++++++++++++++++++++++++++++----
5 files changed, 112 insertions(+), 8 deletions(-)
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index ee2dd5349697d..58ec0acf82772 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -318,6 +318,8 @@ struct irq_affinity_desc {
extern cpumask_var_t irq_default_affinity;
extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
+/* Core-internal only; drivers must use irq_set_affinity_and_hint() */
+int irq_set_affinity_auto(unsigned int irq, const struct cpumask *cpumask);
extern int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask);
extern int irq_can_set_affinity(unsigned int irq);
@@ -382,6 +384,12 @@ static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
return -EINVAL;
}
+static inline int irq_set_affinity_auto(unsigned int irq,
+ const struct cpumask *m)
+{
+ return -EINVAL;
+}
+
static inline int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
{
return 0;
diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c
index 3bdc5a388ea5f..515c01754f1f0 100644
--- a/kernel/irq/debugfs.c
+++ b/kernel/irq/debugfs.c
@@ -154,6 +154,7 @@ static const struct irq_bit_descr irqdesc_istates[] = {
BIT_MASK_DESCR(IRQS_PENDING),
BIT_MASK_DESCR(IRQS_SUSPENDED),
BIT_MASK_DESCR(IRQS_NMI),
+ BIT_MASK_DESCR(IRQS_AFFINITY_AUTO),
};
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
index 703a062be8783..06cfa77409022 100644
--- a/kernel/irq/internals.h
+++ b/kernel/irq/internals.h
@@ -64,6 +64,7 @@ enum {
* IRQS_SUSPENDED - irq is suspended
* IRQS_NMI - irq line is used to deliver NMIs
* IRQS_SYSFS - descriptor has been added to sysfs
+ * IRQS_AFFINITY_AUTO - affinity placement was chosen automatically
*/
enum {
IRQS_AUTODETECT = 0x00000001,
@@ -77,8 +78,24 @@ enum {
IRQS_TIMINGS = 0x00001000,
IRQS_NMI = 0x00002000,
IRQS_SYSFS = 0x00004000,
+ IRQS_AFFINITY_AUTO = 0x00008000,
};
+static inline bool irq_affinity_is_auto(struct irq_desc *desc)
+{
+ return desc->istate & IRQS_AFFINITY_AUTO;
+}
+
+static inline void irq_affinity_set_auto(struct irq_desc *desc)
+{
+ desc->istate |= IRQS_AFFINITY_AUTO;
+}
+
+static inline void irq_affinity_clr_auto(struct irq_desc *desc)
+{
+ desc->istate &= ~IRQS_AFFINITY_AUTO;
+}
+
#include "debug.h"
#include "settings.h"
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 7cbcc3fb9e6d4..4f578f8d497fd 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -138,6 +138,7 @@ static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node,
irq_settings_clr_and_set(desc, ~0, _IRQ_DEFAULT_INIT_FLAGS);
irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
+ irq_affinity_set_auto(desc);
desc->handle_irq = handle_bad_irq;
desc->depth = 1;
desc->irq_count = 0;
@@ -519,6 +520,7 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node,
}
for (i = 0; i < cnt; i++) {
+ bool managed = affinity && affinity->is_managed;
const struct cpumask *mask = NULL;
unsigned int flags = 0;
@@ -536,6 +538,13 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node,
desc = alloc_desc(start + i, node, flags, mask, owner);
if (!desc)
goto err;
+ /*
+ * A managed interrupt is placed by the block layer and does
+ * not take part in the runtime isolation filter. It must
+ * not be reported as automatically placed.
+ */
+ if (managed)
+ irq_affinity_clr_auto(desc);
irq_insert_desc(start + i, desc);
irq_sysfs_add(start + i, desc);
irq_add_debugfs_entry(start + i, desc);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index ec3ecb0e48cec..4f5c776e8c5de 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -452,6 +452,10 @@ int irq_update_affinity_desc(unsigned int irq, struct irq_affinity_desc *affinit
}
cpumask_copy(desc->irq_common_data.affinity, &affinity->mask);
+ if (!affinity->is_managed)
+ irq_affinity_set_auto(desc);
+ else
+ irq_affinity_clr_auto(desc);
/* Restore the activation state */
if (activated)
@@ -461,16 +465,40 @@ int irq_update_affinity_desc(unsigned int irq, struct irq_affinity_desc *affinit
return -EINVAL;
}
+enum irq_affinity_origin {
+ IRQ_AFFINITY_SET_AUTO,
+ IRQ_AFFINITY_CLEAR_AUTO,
+};
+
static int __irq_set_affinity(unsigned int irq, const struct cpumask *mask,
- bool force)
+ bool force, enum irq_affinity_origin origin)
{
struct irq_desc *desc = irq_to_desc(irq);
+ bool old_auto;
+ int ret;
if (!desc)
return -EINVAL;
guard(raw_spinlock_irqsave)(&desc->lock);
- return irq_set_affinity_locked(irq_desc_get_irq_data(desc), mask, force);
+ old_auto = irq_affinity_is_auto(desc);
+ switch (origin) {
+ case IRQ_AFFINITY_SET_AUTO:
+ irq_affinity_set_auto(desc);
+ break;
+ case IRQ_AFFINITY_CLEAR_AUTO:
+ irq_affinity_clr_auto(desc);
+ break;
+ }
+
+ ret = irq_set_affinity_locked(irq_desc_get_irq_data(desc), mask, force);
+ if (ret) {
+ if (old_auto)
+ irq_affinity_set_auto(desc);
+ else
+ irq_affinity_clr_auto(desc);
+ }
+ return ret;
}
/**
@@ -479,13 +507,38 @@ static int __irq_set_affinity(unsigned int irq, const struct cpumask *mask,
* @cpumask: cpumask
*
* Fails if cpumask does not contain an online CPU
+ *
+ * The affinity is recorded as an explicit request and is not redirected
+ * by runtime IRQ isolation. This is the safe default for a driver which
+ * needs the interrupt on a specific CPU, for example a per-CPU PMU or an
+ * architecture timer. A driver which binds a queue for load spreading
+ * uses irq_set_affinity_and_hint() instead, which keeps the placement
+ * automatic.
*/
int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
{
- return __irq_set_affinity(irq, cpumask, false);
+ return __irq_set_affinity(irq, cpumask, false, IRQ_AFFINITY_CLEAR_AUTO);
}
EXPORT_SYMBOL_GPL(irq_set_affinity);
+/**
+ * irq_set_affinity_auto - Program an automatically placed irq affinity
+ * @irq: Interrupt to set affinity
+ * @cpumask: cpumask
+ *
+ * Same as irq_set_affinity(), but records the request as automatic
+ * placement, so runtime IRQ isolation may move the interrupt off a CPU
+ * which later becomes isolated.
+ *
+ * Not exported: it is for core code which manages a device's affinity on
+ * the driver's behalf, not for drivers themselves. A driver which wants
+ * automatic placement uses irq_set_affinity_and_hint().
+ */
+int irq_set_affinity_auto(unsigned int irq, const struct cpumask *cpumask)
+{
+ return __irq_set_affinity(irq, cpumask, false, IRQ_AFFINITY_SET_AUTO);
+}
+
/**
* irq_force_affinity - Force the irq affinity of a given irq
* @irq: Interrupt to set affinity
@@ -499,11 +552,12 @@ EXPORT_SYMBOL_GPL(irq_set_affinity);
*/
int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
{
- return __irq_set_affinity(irq, cpumask, true);
+ return __irq_set_affinity(irq, cpumask, true, IRQ_AFFINITY_CLEAR_AUTO);
}
EXPORT_SYMBOL_GPL(irq_force_affinity);
-int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m, bool setaffinity)
+int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m,
+ bool setaffinity)
{
int ret = -EINVAL;
@@ -512,8 +566,8 @@ int __irq_apply_affinity_hint(unsigned int irq, const struct cpumask *m, bool se
ret = 0;
}
- if (!ret && m && setaffinity)
- __irq_set_affinity(irq, m, false);
+ if (!ret && setaffinity && m)
+ __irq_set_affinity(irq, m, false, IRQ_AFFINITY_SET_AUTO);
return ret;
}
EXPORT_SYMBOL_GPL(__irq_apply_affinity_hint);
@@ -595,6 +649,8 @@ int irq_setup_affinity(struct irq_desc *desc)
{
struct cpumask *set = irq_default_affinity;
int node = irq_desc_get_node(desc);
+ bool old_auto, set_auto;
+ int ret;
static DEFINE_RAW_SPINLOCK(mask_lock);
static struct cpumask mask;
@@ -628,7 +684,20 @@ int irq_setup_affinity(struct irq_desc *desc)
if (cpumask_intersects(&mask, nodemask))
cpumask_and(&mask, &mask, nodemask);
}
- return irq_do_set_affinity(&desc->irq_data, &mask, false);
+ /*
+ * Read IRQD_AFFINITY_SET after the block above: it may have been
+ * cleared because the requested targets are offline, in which case
+ * this placement is automatic again.
+ */
+ old_auto = irq_affinity_is_auto(desc);
+ set_auto = !irqd_has_set(&desc->irq_data, IRQD_AFFINITY_SET) &&
+ !irqd_affinity_is_managed(&desc->irq_data);
+ if (set_auto)
+ irq_affinity_set_auto(desc);
+ ret = irq_do_set_affinity(&desc->irq_data, &mask, false);
+ if (ret && set_auto && !old_auto)
+ irq_affinity_clr_auto(desc);
+ return ret;
}
#else
/* Wrapper for ALPHA specific affinity selector magic */
--
2.43.0
next prev parent reply other threads:[~2026-11-30 3:40 UTC|newest]
Thread overview: 11+ 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 ` Kris Pan [this message]
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-11-30 3:37 ` [RFC PATCH 06/10] genirq: Align affinity notifiers and IRQ threads with isolation Kris Pan
2026-11-30 3:37 ` [RFC PATCH 07/10] genirq: Handle runtime isolation across hotplug and suspend Kris Pan
2026-11-30 3:37 ` [RFC PATCH 08/10] x86/apic: Support runtime IRQ isolation Kris Pan
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
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=20261130033709.2704805-4-kris.pan@intel.com \
--to=kris.pan@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=bigeasy@linutronix.de \
--cc=bp@alien8.de \
--cc=clrkwllms@kernel.org \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=dwmw2@infradead.org \
--cc=edumazet@kernel.org \
--cc=frederic@kernel.org \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=juri.lelli@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--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=longman@redhat.com \
--cc=lpieralisi@kernel.org \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=radu@rendec.net \
--cc=robin.murphy@arm.com \
--cc=steve.wahl@hpe.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=vasant.hegde@amd.com \
--cc=vincent.guittot@linaro.org \
--cc=wei.liu@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/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