From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4821606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com 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 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" 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" 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 From: Kris Pan 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 Subject: [RFC PATCH 10/10] net: Keep core-managed IRQ affinity automatic Date: Mon, 30 Nov 2026 11:37:08 +0800 Message-ID: <20261130033709.2704805-11-kris.pan@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130033709.2704805-1-kris.pan@intel.com> References: <20261130033709.2704805-1-kris.pan@intel.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 #include +#include #include /* @@ -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 #include #include +#include #include #include #include @@ -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