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…@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