🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
8 messages
8 total messages Started by Jakub Kicinski Wed, 18 Nov 2026 02:38
[PATCH net-next 0/6] eth: bnxt_en: allocate memory on the right NUMA node
#18268
Author: Jakub Kicinski
Date: Wed, 18 Nov 2026 02:38
41 lines
9177 bytes
Teach bnxt to allocate the memory touched by the fast path
on the NUMA node where NAPI is being serviced.

On modern systems the PCIe controller is part of the CPU.
On NUMA systems we get to pick which NUMA node the queue and NAPI
related memory will get allocated from. Allocating SW state on
the node where NAPI will run is just common sense.
For memory touched by both device and the CPU we need to pick
which side will pay the extra price (either device or CPU
will have to "reach" futher). This series allocates all state
and all descriptor rings on the NAPI CPU.

Testing a dual-IO-die AMD Venice CPU, where NIC is on node 1
and with NAPI+kperf pinned to node 0, this series gives:
 placing page pools on the right node:    -5.1% CPU load
 placing page pools and completion rings: -8.9% CPU load

Moving SW state is in the noise in a tight-loop kperf banchmark
as the state fits in the cache, anyway.

This series was the motivation for cleaning up the DMA API
allocations with explicit NUMA node:
commit a0aa9ceca03f ("Merge tag 'dma_alloc_coherent_node' of git://git.kernel.org/pub/scm/linux/kernel/git/kuba/linux")

Jakub Kicinski (6):
  eth: bnxt_en: order event data before setting the sp_event bit
  eth: bnxt_en: follow explicitly set IRQ affinity when placing page
    pool
  eth: bnxt_en: allocate per-queue SW state on the queue's NUMA node
  eth: bnxt_en: explicitly keep device-only memory on the device's node
  eth: bnxt_en: allocate fast path DMA rings on the queue's NUMA node
  eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA
    node

 drivers/net/ethernet/broadcom/bnxt/bnxt.h |   7 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 203 ++++++++++++++--------
 2 files changed, 141 insertions(+), 69 deletions(-)

-- 
2.56.1
[PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
#18269
Author: Jakub Kicinski
Date: Wed, 18 Nov 2026 02:39
162 lines
13536 bytes
The driver picks the NUMA node for each Rx ring's page pool with
cpumask_local_spread() at open. IRQ affinity configured by the user
is already recorded by the driver and persists across close/open
cycles. Use it instead of cpumask_local_spread().

The affinity notifier runs without any of the locks held by
the allocation paths, and copying a multi-word cpumask is not atomic.
Like for the TPH Steering Tag, have the notifier compute the node
(of the first online CPU in the mask) and publish it with WRITE_ONCE().

Queue restart (bnxt_queue_mem_alloc()) needs to resolve the NUMA
node instead of copying the nid of the old page pool.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |  5 +++
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 48 +++++++++++++++++++----
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 41d05efd6307..86fc2e8a5816 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -2488,6 +2488,11 @@ struct bnxt {
 	 * rather than being our own default placement.
 	 */
 	unsigned long		*ring_affinity_set;
+	/* Node of the first online CPU in the mask configured from
+	 * the outside, NUMA_NO_NODE if none. Written by the affinity
+	 * notifier, read locklessly by the allocation paths.
+	 */
+	int			*ring_nid;
 	int			max_irqs;
 	int			total_irqs;
 	int			ulp_num_msix_want;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 5ad2a3033505..8e8ee02ca8d9 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -3818,6 +3818,21 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
 	return 0;
 }
 
+/* Node of the CPU expected to service cp ring @n. If the IRQ affinity was
+ * configured from the outside (by the user or irqbalance) the affinity
+ * notifier recorded the node to use, otherwise follow our default spread.
+ */
+static int bnxt_cp_num_to_node(struct bnxt *bp, int n)
+{
+	int nid = READ_ONCE(bp->ring_nid[n]);
+	unsigned int cpu;
+
+	if (nid != NUMA_NO_NODE)
+		return nid;
+	cpu = cpumask_local_spread(n, dev_to_node(&bp->pdev->dev));
+	return cpu_to_node(cpu);
+}
+
 static void bnxt_free_one_tpa_info(struct bnxt *bp,
 				   struct bnxt_rx_ring_info *rxr)
 {
@@ -4020,8 +4035,7 @@ static int bnxt_alloc_rx_agg_bmap(struct bnxt *bp, struct bnxt_rx_ring_info *rxr
 
 static int bnxt_alloc_rx_rings(struct bnxt *bp)
 {
-	int numa_node = dev_to_node(&bp->pdev->dev);
-	int i, rc = 0, agg_rings = 0, cpu;
+	int i, rc = 0, agg_rings = 0;
 
 	if (!bp->rx_ring)
 		return -ENOMEM;
@@ -4036,8 +4050,7 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)
 
 		ring = &rxr->rx_ring_struct;
 
-		cpu = cpumask_local_spread(i, numa_node);
-		cpu_node = cpu_to_node(cpu);
+		cpu_node = bnxt_cp_num_to_node(bp, i);
 		netdev_dbg(bp->dev, "Allocating page pool for rx_ring[%d] on numa_node: %d\n",
 			   i, cpu_node);
 		rc = bnxt_alloc_rx_page_pool(bp, rxr, cpu_node);
@@ -11870,6 +11883,8 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,
 				     const cpumask_t *mask)
 {
 	struct bnxt_irq *irq;
+	unsigned int cpu;
+	int nid;
 	u16 tag;
 
 	irq = container_of(notify, struct bnxt_irq, affinity_notify);
@@ -11877,6 +11892,14 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,
 	cpumask_copy(irq->bp->ring_cpu_mask[irq->ring_nr], mask);
 	set_bit(irq->ring_nr, irq->bp->ring_affinity_set);
 
+	/* Allocation paths don't hold any lock which would exclude us,
+	 * publish the node to allocate on instead of making them parse
+	 * the mask while it may be getting overwritten.
+	 */
+	cpu = cpumask_first_and(mask, cpu_online_mask);
+	nid = cpu < nr_cpu_ids ? cpu_to_node(cpu) : NUMA_NO_NODE;
+	WRITE_ONCE(irq->bp->ring_nid[irq->ring_nr], nid);
+
 #ifdef CONFIG_RFS_ACCEL
 	if (irq->bp->dev->rx_cpu_rmap && irq->ring_nr < irq->bp->rx_nr_rings) {
 		int err;
@@ -11954,9 +11977,16 @@ static int bnxt_alloc_ring_cpu_masks(struct bnxt *bp)
 	if (!bp->ring_affinity_set)
 		return -ENOMEM;
 
-	for (i = 0; i < bp->max_irqs; i++)
+	bp->ring_nid = kmalloc_array(bp->max_irqs, sizeof(*bp->ring_nid),
+				     GFP_KERNEL);
+	if (!bp->ring_nid)
+		return -ENOMEM;
+
+	for (i = 0; i < bp->max_irqs; i++) {
 		if (!zalloc_cpumask_var(&bp->ring_cpu_mask[i], GFP_KERNEL))
 			return -ENOMEM;
+		bp->ring_nid[i] = NUMA_NO_NODE;
+	}
 
 	return 0;
 }
@@ -11971,6 +12001,8 @@ static void bnxt_free_ring_cpu_masks(struct bnxt *bp)
 	for (i = 0; i < bp->max_irqs; i++)
 		free_cpumask_var(bp->ring_cpu_mask[i]);
 
+	kfree(bp->ring_nid);
+	bp->ring_nid = NULL;
 	bitmap_free(bp->ring_affinity_set);
 	bp->ring_affinity_set = NULL;
 	kfree(bp->ring_cpu_mask);
@@ -12066,6 +12098,7 @@ static int bnxt_request_irq(struct bnxt *bp)
 		if (!test_bit(i, bp->ring_affinity_set) ||
 		    !cpumask_intersects(cpu_mask, cpu_online_mask)) {
 			clear_bit(i, bp->ring_affinity_set);
+			WRITE_ONCE(bp->ring_nid[i], NUMA_NO_NODE);
 			cpumask_clear(cpu_mask);
 			cpumask_set_cpu(cpumask_local_spread(i, numa_node),
 					cpu_mask);
@@ -16431,7 +16464,7 @@ static int bnxt_queue_mem_alloc(struct net_device *dev,
 	struct bnxt_rx_ring_info *rxr, *clone;
 	struct bnxt *bp = netdev_priv(dev);
 	struct bnxt_ring_struct *ring;
-	int rc;
+	int nid, rc;
 
 	if (!bp->rx_ring)
 		return -ENETDOWN;
@@ -16452,7 +16485,8 @@ static int bnxt_queue_mem_alloc(struct net_device *dev,
 	clone->rx_tpa = NULL;
 	clone->rx_tpa_idx_map = NULL;
 
-	rc = bnxt_alloc_rx_page_pool(bp, clone, rxr->page_pool->p.nid);
+	nid = bnxt_cp_num_to_node(bp, idx);
+	rc = bnxt_alloc_rx_page_pool(bp, clone, nid);
 	if (rc)
 		return rc;
 
-- 
2.56.1
[PATCH net-next 4/6] eth: bnxt_en: explicitly keep device-only memory on the device's node
#18270
Author: Jakub Kicinski
Date: Wed, 18 Nov 2026 02:39
40 lines
9295 bytes
Context memory (and the FW crash dump buffer which reuses the same
helpers) is used by the device, once set up the host only touches it
on the slow path (diagnostics, FW trace). Pass the device's node to
bnxt_alloc_ring() rather than NUMA_NO_NODE to make it clear that this
memory is not meant to follow any queue.

Ring page tables are only read by the device, annotate their
allocation so that they stay put once the ring pages start following
the queue.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 7c694d8e99f5..f98507944350 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -3779,6 +3779,7 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem,
 
 		if (rmem->flags & BNXT_RMEM_USE_FULL_PAGE_FLAG)
 			pg_tbl_size = rmem->page_size;
+		/* Only read by the device, keep it on the device's node */
 		rmem->pg_tbl = dma_alloc_coherent(&pdev->dev, pg_tbl_size,
 						  &rmem->pg_tbl_map,
 						  GFP_KERNEL);
@@ -9218,7 +9219,8 @@ static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
 	rmem->flags = BNXT_RMEM_VALID_PTE_FLAG;
 	if (rmem->depth >= 1)
 		rmem->flags |= BNXT_RMEM_USE_FULL_PAGE_FLAG;
-	return bnxt_alloc_ring(bp, rmem, NUMA_NO_NODE);
+	/* Host only uses it on the slow path, keep it on the device's node */
+	return bnxt_alloc_ring(bp, rmem, dev_to_node(&bp->pdev->dev));
 }
 
 static int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp,
-- 
2.56.1
Re: [PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
#18503
Author: Björn Töpel
Date: Wed, 18 Nov 2026 12:32
19 lines
8649 bytes
Jakub Kicinski <kuba@kernel.org> writes:

> The driver picks the NUMA node for each Rx ring's page pool with
> cpumask_local_spread() at open. IRQ affinity configured by the user
> is already recorded by the driver and persists across close/open
> cycles. Use it instead of cpumask_local_spread().
>
> The affinity notifier runs without any of the locks held by
> the allocation paths, and copying a multi-word cpumask is not atomic.
> Like for the TPH Steering Tag, have the notifier compute the node
> (of the first online CPU in the mask) and publish it with WRITE_ONCE().
>
> Queue restart (bnxt_queue_mem_alloc()) needs to resolve the NUMA
> node instead of copying the nid of the old page pool.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Björn Töpel <bjorn@kernel.org>
Re: [PATCH net-next 4/6] eth: bnxt_en: explicitly keep device-only memory on the device's node
#18508
Author: Björn Töpel
Date: Wed, 18 Nov 2026 12:38
16 lines
8336 bytes
Jakub Kicinski <kuba@kernel.org> writes:

> Context memory (and the FW crash dump buffer which reuses the same
> helpers) is used by the device, once set up the host only touches it
> on the slow path (diagnostics, FW trace). Pass the device's node to
> bnxt_alloc_ring() rather than NUMA_NO_NODE to make it clear that this
> memory is not meant to follow any queue.
>
> Ring page tables are only read by the device, annotate their
> allocation so that they stay put once the ring pages start following
> the queue.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Björn Töpel <bjorn@kernel.org>
Re: [PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
#18565
Author: Joe Damato
Date: Wed, 18 Nov 2026 14:42
22 lines
12321 bytes
On Tue, Nov 17, 2026 at 06:39:01PM -0800, Jakub Kicinski wrote:
> The driver picks the NUMA node for each Rx ring's page pool with
> cpumask_local_spread() at open. IRQ affinity configured by the user
> is already recorded by the driver and persists across close/open
> cycles. Use it instead of cpumask_local_spread().
> 
> The affinity notifier runs without any of the locks held by
> the allocation paths, and copying a multi-word cpumask is not atomic.
> Like for the TPH Steering Tag, have the notifier compute the node
> (of the first online CPU in the mask) and publish it with WRITE_ONCE().
> 
> Queue restart (bnxt_queue_mem_alloc()) needs to resolve the NUMA
> node instead of copying the nid of the old page pool.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt.h |  5 +++
>  drivers/net/ethernet/broadcom/bnxt/bnxt.c | 48 +++++++++++++++++++----
>  2 files changed, 46 insertions(+), 7 deletions(-)

Reviewed-by: Joe Damato <joe@dama.to>
Re: [PATCH net-next 4/6] eth: bnxt_en: explicitly keep device-only memory on the device's node
#18570
Author: Joe Damato
Date: Wed, 18 Nov 2026 14:50
18 lines
12046 bytes
On Tue, Nov 17, 2026 at 06:39:03PM -0800, Jakub Kicinski wrote:
> Context memory (and the FW crash dump buffer which reuses the same
> helpers) is used by the device, once set up the host only touches it
> on the slow path (diagnostics, FW trace). Pass the device's node to
> bnxt_alloc_ring() rather than NUMA_NO_NODE to make it clear that this
> memory is not meant to follow any queue.
> 
> Ring page tables are only read by the device, annotate their
> allocation so that they stay put once the ring pages start following
> the queue.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Joe Damato <joe@dama.to>
Re: [PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
#18930
Author: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 03:21
147 lines
13729 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] After a CPU hotplug event, bp->ring_nid[] can hold a stale
  node, and the open path allocates from that stale value before…

--

eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool

Each Rx ring's page pool used to get its NUMA node from
cpumask_local_spread(). This patch uses the node recorded by the IRQ
affinity notifier instead, published through a new bp->ring_nid[]
array. Queue restart now looks up the node again rather than copying
the old page pool's nid.

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index 5ad2a3033505d..8e8ee02ca8d9b 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -3818,6 +3818,21 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
>  	return 0;
>  }
>  
> +/* Node of the CPU expected to service cp ring @n. If the IRQ affinity was
> + * configured from the outside (by the user or irqbalance) the affinity
> + * notifier recorded the node to use, otherwise follow our default spread.
> + */
> +static int bnxt_cp_num_to_node(struct bnxt *bp, int n)
> +{
> +	int nid = READ_ONCE(bp->ring_nid[n]);
> +	unsigned int cpu;
> +
> +	if (nid != NUMA_NO_NODE)
> +		return nid;
> +	cpu = cpumask_local_spread(n, dev_to_node(&bp->pdev->dev));
> +	return cpu_to_node(cpu);
> +}
> +

[ ... ]

> @@ -4036,8 +4050,7 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)
>  
>  		ring = &rxr->rx_ring_struct;
>  
> -		cpu = cpumask_local_spread(i, numa_node);
> -		cpu_node = cpu_to_node(cpu);
> +		cpu_node = bnxt_cp_num_to_node(bp, i);
>  		netdev_dbg(bp->dev, "Allocating page pool for rx_ring[%d] on numa_node: %d\n",
>  			   i, cpu_node);
>  		rc = bnxt_alloc_rx_page_pool(bp, rxr, cpu_node);

[ ... ]

> @@ -11877,6 +11892,14 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,
>  	cpumask_copy(irq->bp->ring_cpu_mask[irq->ring_nr], mask);
>  	set_bit(irq->ring_nr, irq->bp->ring_affinity_set);
>  
> +	/* Allocation paths don't hold any lock which would exclude us,
> +	 * publish the node to allocate on instead of making them parse
> +	 * the mask while it may be getting overwritten.
> +	 */
> +	cpu = cpumask_first_and(mask, cpu_online_mask);
> +	nid = cpu < nr_cpu_ids ? cpu_to_node(cpu) : NUMA_NO_NODE;
> +	WRITE_ONCE(irq->bp->ring_nid[irq->ring_nr], nid);
> +

[ ... ]

> @@ -12066,6 +12098,7 @@ static int bnxt_request_irq(struct bnxt *bp)
>  		if (!test_bit(i, bp->ring_affinity_set) ||
>  		    !cpumask_intersects(cpu_mask, cpu_online_mask)) {
>  			clear_bit(i, bp->ring_affinity_set);
> +			WRITE_ONCE(bp->ring_nid[i], NUMA_NO_NODE);
>  			cpumask_clear(cpu_mask);
>  			cpumask_set_cpu(cpumask_local_spread(i, numa_node),
>  					cpu_mask);

[Severity: Medium]
Can ring_nid[i] already be stale when bnxt_alloc_rx_rings() reads it?

A real node is only recorded in bnxt_irq_affinity_notify(). It is
computed once, from cpumask_first_and(mask, cpu_online_mask).

When those CPUs go offline later, the IRQ core moves the IRQ through
migrate_one_irq()->irq_do_set_affinity(). That path does not schedule
the affinity notify work, so ring_nid[i] keeps the old node.
bnxt_cp_num_to_node() returns any value that isn't NUMA_NO_NODE as-is.

The reset added here is in bnxt_request_irq(). In __bnxt_open_nic(),
the allocations run before it:

__bnxt_open_nic()
    rc = bnxt_alloc_mem(bp, irq_re_init);
        bnxt_alloc_rx_rings()
            bnxt_cp_num_to_node()    <- returns stale ring_nid[i]
    ...
    rc = bnxt_request_irq(bp);
        WRITE_ONCE(bp->ring_nid[i], NUMA_NO_NODE);

Suppose ring i's IRQ affinity is set to CPUs on node X, all of those
CPUs go offline, and the interface is closed and reopened. Would the
page pool, the Rx/agg descriptor rings and the agg bitmap for ring i
then be placed on node X, while the IRQ hint goes to
cpumask_local_spread(i, numa_node)?

This branch uses irq_update_affinity_hint(), so no notifier runs
afterwards to fix the placement for the rest of the open cycle. Before
this patch, the allocation and the IRQ hint both came from
cpumask_local_spread() and matched.

There is a related case when the mask spans nodes and only its first
online CPU goes offline. ring_nid[i] keeps the old node until
irq_set_affinity_and_hint() in the next bnxt_request_irq() fires the
notifier again. That also happens after bnxt_alloc_mem() has already
used the value.

Later in the series, "eth: bnxt_en: allocate fast path DMA rings on the
queue's NUMA node" and "eth: bnxt_en: allocate per-queue SW state on the
queue's NUMA node" use the same value for more allocations: cp rings,
Tx rings, tx_push, stats and TPA info.

"eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA
node" restarts Rx queues only from the notifier. That covers the
spanning-mask case, but only for Rx page pools. It does not cover the
case where all CPUs in the mask go offline, because no notifier runs
there.

The new comment on ring_nid in bnxt.h says the field is "Written by the
affinity notifier". bnxt_alloc_ring_cpu_masks() and bnxt_request_irq()
also write it. After hotplug, the value is also not guaranteed to be
the node of an online CPU in the mask.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118023905.3050661-1-kuba%40kernel.org
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads