🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24357

[RFC PATCH 10/10] net: Keep core-managed IRQ affinity automatic

#24357
From: Kris Pan
Date: Mon, 30 Nov 2026 03:37
161 lines
15888 bytes
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
Technical Details
Message-ID: <20261130033709.2704805-11-kris.pan@intel.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373826-linux-kernel-netdev=dewy.ru
References: <20261130033709.2704805-1-kris.pan@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373826-linux-kernel-netdev=dewy.ru
From: kris.pan@intel.com (Kris Pan)
Newsgroups: linux.kernel.netdev
Subject: [RFC PATCH 10/10] net: Keep core-managed IRQ affinity automatic
Date: Mon, 30 Nov 2026 11:37:08 +0800
Organization: Usenet Network
Message-ID: <20261130033709.2704805-11-kris.pan@intel.com>
References: <20261130033709.2704805-1-kris.pan@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1324187"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TQm0K0O+j6WAvp5IlHItStTdVDI= sha256:d88+DM95qKynATYa+hpoOGgDuIOhc1cwHQfQgRcBTec=
	sha1:t1st5hYOW61qc4ABrdBPgJF29vo= sha256:zk//ly9kf2V5R2jMwbmJsp752+GZlV4ZCPzqEm02toc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 34A81125FBC; Mon, 30 Nov 2026 06:42:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.152
X-Spam-Status: No, score=-3.152 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=intel.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 2qBoMe8Qf2Sn;
	Mon, 30 Nov 2026 06:42:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-373826-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=intel.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 1A455125D6D; Mon, 30 Nov 2026 06:42:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id CA9EE27111; Mon, 30 Nov 2026 03:41:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1796010102;
	b=B4Z545RVoPOgdZPZcwpU3vtutZlfgZuBG3mEXgwzTnRzry3tCP2xeOTg+YdzY+LW0bwB
	 W5qOu6xRgh4pGYWz3Hs81GitXixnLO2aFMZMgIsMr4bEYuzbKwkIQGr3P3MkwnZuU5G+r
	 iQWYJfz2RmCRJJzNcRYHFiBftoGnMzPmw2Qtl+PQSRVLLZEwauhKl1FcxFuO7EyU5dUTC
	 MfkORcPBoBXkWSBXArMurGQyYeU1wmZ4/5pXjXBIG2DtEvIqsjUi+I7rx77vsXv7CFHbD
	 P7bS2y2elpAiyufptZ0q6hcxZoscd+95xAoPJ+ezdUjHezjiYqAdiyExqiBX4XsKGFA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796010102;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
	 X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-IronPort-AV:X-IronPort-AV:
	 Received:X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=3r4n60gRSMROGWbfiKBkVJXBbG5pHuH0acZgExZVuLw=;
	b=soKvsv0xquS8DSiALrW7rhuDgPPXH4q8CXsOjL/zV+/rL2EKnsV2hPZZXPcQoX/x3jxy
	 juoafEw0cta8XfBEd2WIwaYp0ggJjwNNhGWKl7L1t5dLTcwvnenuI/MreBtGgyjK11LPF
	 jllUMfhpeFz0CcKdjiQLXbaFPScydgUEZnaQE++yE1wBKyZl2W4BxMgDp10u92HNwhneH
	 qoQ5VKuK7XCa6rDN3NTfe/VhXWs1RjjNxBd+P8LNEqIfzdRSvxxj/26beWRvnc3/xjqSv
	 7wSdaKDpS5gWQHh9OEozhiP2zpKU9qY6w5ibqIwtJru61Y0Lk2YHluKZ1W9Ubzrorbg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=V5jcudx3;
	dmarc=pass header.from=intel.com;
	spf=pass smtp.mailfrom=intel.com;
	arc=fail smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B4699606A686;
	Mon, 30 Nov 2026 03:41:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=V5jcudx3
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796010101;
	b=qWct7MW3JOfCKwOMvvdyM1R/DHZO+TgQKH1r5BieSqTNM/tuwsOYfbUWPlHrqfn/xrH0
	 pBhp+aqdiJTjb74VwmIFeUSib0iaU1C7IRbtZ9OAorMoZEiFfmdN3VhjBRoUKrHLg80Ci
	 ZavcEgewkxhhwF5HvWt4yQErW4drqqQo9GcU7JK6HZfePgIopxsTraLePjrNp+2G3Equ/
	 Qh4ge8L69dATD7f+KRSN8SMkMAeLaFWPIOnerVNiClm3lIdIJZvbtd8zbnTDZUBNLhr6a
	 +pgpxL7s13AovfiDRzVCCLJ1M9cuSOc0bCt5N6qE27W3koUs/kEtYsKW50TAurK/t8g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796010101;
	h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID:
	 X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID:
	 X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=3r4n60gRSMROGWbfiKBkVJXBbG5pHuH0acZgExZVuLw=;
	b=fAH8cd3bk+vQDVtShAh9zemoTlIeampZsvbfMdgX3scrxL3Wm/GED+xOxrMLXWt6Z0Rk
	 1wGXnnzlwKAl06my/k8MJ9Wl9FU9KcmqG5P/ONjQ3v+teO7gWajkPnkVQQUZmwwbawVK9
	 67HQb6duJMd4gpy/yoXhXVeu6v9ZdKA6fsEsgDPhZxkj5sAnbJ9Lj79SSb7q2/vf1lQxB
	 IJmVAGH44Kfqft/GeLGj87qIOxm2+WdbXdRdN36yGkRYVD6SqPtfvjuY5IKrxTxLJ5TNB
	 V58PlblHJVqCybJTOvHn5GE0/ITON+WCLPbNJ/VDE+wjP/6rxa/t3tw8pYttsGdzD6A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=intel.com;
	spf=pass smtp.mailfrom=intel.com;
	dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=V5jcudx3;
	arc=none smtp.remote-ip=192.198.163.19
X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4821606A32E;
	Mon, 30 Nov 2026 03:41:40 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4821606A32E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1796010101; x=1827546101;
  h=from:to:cc:subject:date:message-id:in-reply-to:
   references:mime-version:content-transfer-encoding;
  bh=8N9Y3NhxxrOxL779w60sumHiDWhsERumRDgJzNUPZTM=;
  b=V5jcudx3Cr9qoJOa6013fPcuhCbODoyiLFTWzwBgBSG3WKtm8Pjar7qi
   GVBnP+jdCmoDVS7a6dmTFp+SW/lBw88WByNeWMRTRjtbZZ8STcUSuf3h0
   rkCMCBFbny+GvUv8/5OVLguEodQAmXivkQw4DY6Ox48A6RNv3oQ8u6lt6
   9Kb7eB0T8TAjr7uoP5AKkCeM74WJH6L3NQcS1UQsgO5NMX0Gi2tQI+BqQ
   xOKK90DyHGkaq039lCeaxVtav3x8EX2jN0Ey3zqtapPM7n7yTDS6xInMo
   hsOXACti2XnUYU9w6tlcQ2LXqirJFH/AjTAKqLteHVW00axz2Xk05c5zw
   g==;
X-CSE-ConnectionGUID: 2k/23kY4SQaghh2Yh1ep6Q==
X-CSE-MsgGUID: H1/K7iizRD6l9z6n0H+98g==
X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4848502"
X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; 
   d="scan'208";a="4848502"
X-Received: from fmviesa005.fm.intel.com ([10.60.135.145])
  by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 19:41:40 -0800
X-CSE-ConnectionGUID: bxCFG0EoREWZoLU0zj56/Q==
X-CSE-MsgGUID: T+Mba6TNQbCVKQ99jzVGKQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; 
   d="scan'208";a="12951127"
X-Received: from pankris-x299-ud4-pro.bj.intel.com ([10.238.152.122])
  by fmviesa005.fm.intel.com with ESMTP; 29 Nov 2026 19:41:31 -0800
X-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>
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261130033709.2704805-1-kris.pan@intel.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list