Netdev List
 help / color / mirror / Atom feed
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 10/10] net: Keep core-managed IRQ affinity automatic
Date: Mon, 30 Nov 2026 11:37:08 +0800	[thread overview]
Message-ID: <20261130033709.2704805-11-kris.pan@intel.com> (raw)
In-Reply-To: <20261130033709.2704805-1-kris.pan@intel.com>

napi_restore_config() re-applies the affinity which netdev stored for a
NAPI instance.  After the genirq provenance change a bare
irq_set_affinity() is an explicit pin, which would stop runtime IRQ
isolation from moving a queue off a CPU handed to an isolated
partition.

Use irq_set_affinity_auto(), the non-exported helper which records the
request as automatic placement.  It is core-only on purpose: drivers
keep using irq_set_affinity_and_hint() or let netdev manage the
affinity through netif_set_affinity_auto().

The affinity notifier reports the requested mask, which netdev stores
as the affinity to restore.  ARFS steering must follow the mask which
the core asks the chip to program instead: runtime isolation may filter
the request or relocate it when its last online target is gone.  Feed
irq_copy_programmed_affinity() into cpu_rmap_update() while runtime
isolation is active and fall back to the notified mask otherwise.
Without isolation the programmed target still tracks the request, so
the upstream behaviour is kept.

The effective affinity is deliberately not used here: on chips with
IRQD_SINGLE_TARGET it describes one CPU, and a reverse map which covers
several CPUs would collapse to that single entry.  The helper reports
the mask which the policy asked the chip to program: the right input
for a multi-CPU map.

Take the snapshot under desc->lock: the helper runs concurrently with
the reapply path, which may queue a move and update the pending mask.
While a move is pending the newest request lives there, and the
descriptor affinity only follows when it completes.  The legacy
irq_cpu_rmap_add() glue in lib/cpu_rmap.c consumes the same notifier
for mlx5, sfc and others; it needs the same mask.  A driver which
registers its own irq_affinity_notify callback replaces that glue and
is not converted here; bnxt does so for its TPH and aRFS steering and
would have to take the same snapshot itself.

Initial queue placement is unaffected: default descriptor setup and
the driver hint path (irq_set_affinity_and_hint()) already record
automatic placement.  napi_restore_config() is the only place where
net/core re-applies a stored automatic affinity with a bare
irq_set_affinity() call, which is why only that call site changes.

Signed-off-by: Kris Pan <kris.pan@intel.com>
---
 lib/cpu_rmap.c | 32 +++++++++++++++++++++++++++++++-
 net/core/dev.c | 24 ++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
index c86ab6e55d178..f2e9a3ac135f4 100644
--- a/lib/cpu_rmap.c
+++ b/lib/cpu_rmap.c
@@ -6,6 +6,7 @@
 
 #include <linux/cpu_rmap.h>
 #include <linux/interrupt.h>
+#include <linux/irq.h>
 #include <linux/export.h>
 
 /*
@@ -264,11 +265,40 @@ irq_cpu_rmap_notify(struct irq_affinity_notify *notify, const cpumask_t *mask)
 {
 	struct irq_glue *glue =
 		container_of(notify, struct irq_glue, notify);
+	const struct cpumask *prog;
+	cpumask_var_t prog_mask;
+	bool allocated;
 	int rc;
 
-	rc = cpu_rmap_update(glue->rmap, glue->index, mask);
+	prog = mask;
+	allocated = false;
+	/*
+	 * Runtime IRQ isolation may program a mask which differs from the
+	 * requested one.  A reverse map describes the CPUs the chip is
+	 * asked to use, so take the filtered mask while isolation is
+	 * active; without it the upstream behaviour of using the notified
+	 * mask is kept.  Check the static key before allocating the
+	 * snapshot buffer, so a system which never isolates keeps the
+	 * allocation out of the notifier path.
+	 */
+	if (irq_isolation_active()) {
+		allocated = alloc_cpumask_var(&prog_mask, GFP_KERNEL);
+		if (allocated &&
+		    irq_copy_programmed_affinity(notify->irq, prog_mask))
+			prog = prog_mask;
+	}
+
+	/*
+	 * The notifier reports the requested mask.  The reverse map has to
+	 * use the mask which was programmed instead: runtime IRQ isolation
+	 * may have filtered the request, or relocated it when the request
+	 * lost its last online target.
+	 */
+	rc = cpu_rmap_update(glue->rmap, glue->index, prog);
 	if (rc)
 		pr_warn("irq_cpu_rmap_notify: update failed: %d\n", rc);
+	if (allocated)
+		free_cpumask_var(prog_mask);
 }
 
 /**
diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1dbfdf..50d41ad09add9 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -88,6 +88,7 @@
 #include <linux/sockios.h>
 #include <linux/errno.h>
 #include <linux/interrupt.h>
+#include <linux/irq.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
@@ -7593,6 +7594,9 @@ netif_napi_irq_notify(struct irq_affinity_notify *notify,
 		container_of(notify, struct napi_struct, notify);
 #ifdef CONFIG_RFS_ACCEL
 	struct cpu_rmap *rmap = napi->dev->rx_cpu_rmap;
+	const struct cpumask *prog;
+	cpumask_var_t prog_mask;
+	bool allocated;
 	int err;
 #endif
 
@@ -7601,7 +7605,23 @@ netif_napi_irq_notify(struct irq_affinity_notify *notify,
 
 #ifdef CONFIG_RFS_ACCEL
 	if (napi->dev->rx_cpu_rmap_auto) {
-		err = cpu_rmap_update(rmap, napi->napi_rmap_idx, mask);
+		/*
+		 * The notifier reports the requested mask; the reverse map
+		 * has to describe the CPUs the chip is asked to use, which
+		 * runtime IRQ isolation may have filtered or relocated.
+		 */
+		prog = mask;
+		allocated = false;
+		/* See irq_cpu_rmap_notify(). */
+		if (irq_isolation_active()) {
+			allocated = alloc_cpumask_var(&prog_mask, GFP_KERNEL);
+			if (allocated &&
+			    irq_copy_programmed_affinity(napi->irq, prog_mask))
+				prog = prog_mask;
+		}
+		err = cpu_rmap_update(rmap, napi->napi_rmap_idx, prog);
+		if (allocated)
+			free_cpumask_var(prog_mask);
 		if (err)
 			netdev_warn(napi->dev, "RMAP update failed (%d)\n",
 				    err);
@@ -7752,7 +7772,7 @@ static void napi_restore_config(struct napi_struct *n)
 
 	if (n->dev->irq_affinity_auto &&
 	    test_bit(NAPI_STATE_HAS_NOTIFIER, &n->state))
-		irq_set_affinity(n->irq, &n->config->affinity_mask);
+		irq_set_affinity_auto(n->irq, &n->config->affinity_mask);
 
 	/* a NAPI ID might be stored in the config, if so use it. if not, use
 	 * napi_hash_add to generate one for us.
-- 
2.43.0


      parent reply	other threads:[~2026-11-30  3:41 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 ` [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-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 ` Kris Pan [this message]

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-11-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