eth: bnxt_en: allocate memory on the right NUMA node
Jakub Kicinski
maintainercover eth: bnxt_en: allocate memory on the right NUMA node
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(-)
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH 1/6 eth: bnxt_en: order event data before setting the sp_event bit
Callers of bnxt_queue_sp_work() may store data for bnxt_sp_task() right before raising the event, e.g. the IRQ affinity notifier publishes the new TPH Steering Tag. set_bit() is not ordered, so on weakly ordered architectures the event bit may become visible first. If bnxt_sp_task() is already running it can consume the event and read the stale data. The queue_work() which follows only re-runs the task with the event bit already cleared, so the update is lost.
Add smp_mb__before_atomic() before setting the bit, it pairs with the fully ordered test_and_clear_bit() in bnxt_sp_task().
Reported by an LLM reviewer while working on subsequent patches. Very unlikely to matter in practice.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -0
@@ -394,6 +394,10 @@ static void __bnxt_queue_sp_work(struct bnxt *bp)static void bnxt_queue_sp_work (struct bnxt *bp,unsigned int event) { +/* Make the data the event carries visible before the event bit, +* pairs with test_and_clear_bit() in bnxt_sp_task(). +*/ +smp_mb__before_atomic ();set_bit (event, &bp->sp_event);__bnxt_queue_sp_work (bp); }
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH 2/6 eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
In reply to Jakub KicinskiThe 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.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 5 +++ drivers/net/ethernet/broadcom/bnxt/bnxt.c | 48 +++++++++++++++++++---- 2 files changed, 46 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.h +5 -0
@@ -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;
drivers/net/ethernet/broadcom/bnxt/bnxt.c +41 -7
110 lines not on this page · raw message
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH 3/6 eth: bnxt_en: allocate per-queue SW state on the queue's NUMA node
In reply to Jakub KicinskiAllocate the SW rings, agg bitmap, TPA state, completion ring page arrays, completion sub-ring structs, SW stats and the SW USO header buffer on the NUMA node of the CPU which will service the queue. This lowers the cost of cache misses for NAPI fast path (and xmit, for Tx).
Previous change already allocated the page pools on the right node.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 ++++++++++++++--------- 1 file changed, 52 insertions(+), 35 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +52 -35
@@ -3765,7 +3765,8 @@ static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem) } } -static int bnxt_alloc_ring (struct bnxt *bp,struct bnxt_ring_mem_info *rmem) +static int bnxt_alloc_ring (struct bnxt *bp,struct bnxt_ring_mem_info *rmem, +int nid) {struct pci_dev *pdev = bp->pdev;u64 valid_bit =0 ;
@@ -3810,8 +3811,9 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem) } } +/* Only the SW ring follows @nid, DMA memory is on the device's node */ if (rmem->vmem_size) { - *rmem->vmem =vzalloc (rmem->vmem_size); + *rmem->vmem =vzalloc_node (rmem->vmem_size, nid);if (!(*rmem->vmem))return -ENOMEM ; }
@@ -3862,25 +3864,27 @@ static void bnxt_free_tpa_info(struct bnxt *bp) }static int bnxt_alloc_one_tpa_info (struct bnxt *bp, -struct bnxt_rx_ring_info *rxr) +struct bnxt_rx_ring_info *rxr,int nid) {struct rx_agg_cmp *agg;int i; - rxr->rx_tpa = kzalloc_objs(struct bnxt_tpa_info, - bp->max_tpa_roundup_size); + rxr->rx_tpa =kcalloc_node (bp->max_tpa_roundup_size, +sizeof (*rxr->rx_tpa),GFP_KERNEL , nid);if (!rxr->rx_tpa)return -ENOMEM ;if (!(bp->flags &BNXT_FLAG_CHIP_P5_PLUS ))return 0 ;for (i =0 ; i < bp->max_tpa_roundup_size; i++) { - agg =kzalloc_objs (*agg,MAX_SKB_FRAGS ); + agg =kcalloc_node (MAX_SKB_FRAGS ,sizeof (*agg), +GFP_KERNEL , nid);if (!agg)return -ENOMEM ; rxr->rx_tpa[i].agg_arr = agg; } - rxr->rx_tpa_idx_map =kzalloc_obj (*rxr->rx_tpa_idx_map); + rxr->rx_tpa_idx_map =kzalloc_node (sizeof (*rxr->rx_tpa_idx_map), +GFP_KERNEL , nid);if (!rxr->rx_tpa_idx_map)return -ENOMEM ;
@@ -3907,8 +3911,10 @@ static int bnxt_alloc_tpa_info(struct bnxt *bp)for (i =0 ; i < bp->rx_nr_rings; i++) {struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; +int nid; - rc =bnxt_alloc_one_tpa_info (bp, rxr); + nid =bnxt_cp_num_to_node (bp, i); + rc =bnxt_alloc_one_tpa_info (bp, rxr, nid);if (rc)return rc; }
@@ -4020,13 +4026,14 @@ static void bnxt_enable_rx_page_pool(struct bnxt_rx_ring_info *rxr)page_pool_enable_direct_recycling (rxr->page_pool, &rxr->bnapi->napi); } -static int bnxt_alloc_rx_agg_bmap (struct bnxt *bp,struct bnxt_rx_ring_info *rxr) +static int bnxt_alloc_rx_agg_bmap (struct bnxt *bp, +struct bnxt_rx_ring_info *rxr,int nid) {u16 mem_size; rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask +1 ; mem_size = rxr->rx_agg_bmap_size /8 ; - rxr->rx_agg_bmap =kzalloc (mem_size,GFP_KERNEL ); + rxr->rx_agg_bmap =kzalloc_node (mem_size,GFP_KERNEL , nid);if (!rxr->rx_agg_bmap)return -ENOMEM ;
@@ -4070,19 +4077,19 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)return rc; } - rc =bnxt_alloc_ring (bp, &ring->ring_mem); + rc =bnxt_alloc_ring (bp, &ring->ring_mem, cpu_node);if (rc)return rc; ring->grp_idx = i;if (agg_rings) { ring = &rxr->rx_agg_ring_struct; - rc =bnxt_alloc_ring (bp, &ring->ring_mem); + rc =bnxt_alloc_ring (bp, &ring->ring_mem, cpu_node);if (rc)return rc; ring->grp_idx = i; - rc =bnxt_alloc_rx_agg_bmap (bp, rxr); + rc =bnxt_alloc_rx_agg_bmap (bp, rxr, cpu_node);if (rc)return rc; }
@@ -4107,9 +4114,9 @@ static void bnxt_free_tx_inline_buf(struct bnxt_tx_ring_info *txr,static int bnxt_alloc_tx_inline_buf (struct bnxt_tx_ring_info *txr,struct pci_dev *pdev, -unsigned int size) +unsigned int size,int nid) { - txr->tx_inline_buf =kmalloc (size,GFP_KERNEL ); + txr->tx_inline_buf =kmalloc_node (size,GFP_KERNEL , nid);if (!txr->tx_inline_buf)return -ENOMEM ;
@@ -4183,11 +4190,13 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)for (i =0 , j =0 ; i < bp->tx_nr_rings; i++) {struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];struct bnxt_ring_struct *ring; +int nid;u8 qidx; ring = &txr->tx_ring_struct; - rc =bnxt_alloc_ring (bp, &ring->ring_mem); + nid =bnxt_cp_num_to_node (bp, txr->bnapi->index); + rc =bnxt_alloc_ring (bp, &ring->ring_mem, nid);if (rc)return rc;
@@ -4213,7 +4222,7 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)if (!(bp->flags &BNXT_FLAG_UDP_GSO_CAP )) { rc =bnxt_alloc_tx_inline_buf (txr, pdev,BNXT_SW_USO_MAX_SEGS * -TSO_HEADER_SIZE ); +TSO_HEADER_SIZE , nid);if (rc)return rc; }
@@ -4240,12 +4249,15 @@ static void bnxt_free_cp_arrays(struct bnxt_cp_ring_info *cpr) ring->ring_mem.dma_arr =NULL ; } -static int bnxt_alloc_cp_arrays (struct bnxt_cp_ring_info *cpr,int n) +static int bnxt_alloc_cp_arrays (struct bnxt_cp_ring_info *cpr,int n, +int nid) { - cpr->cp_desc_ring =kzalloc_objs (*cpr->cp_desc_ring, n); + cpr->cp_desc_ring =kcalloc_node (n,sizeof (*cpr->cp_desc_ring), +GFP_KERNEL , nid);if (!cpr->cp_desc_ring)return -ENOMEM ; - cpr->cp_desc_mapping =kzalloc_objs (*cpr->cp_desc_mapping, n); + cpr->cp_desc_mapping =kcalloc_node (n,sizeof (*cpr->cp_desc_mapping), +GFP_KERNEL , nid);if (!cpr->cp_desc_mapping)return -ENOMEM ;return 0 ;
@@ -4272,11 +4284,12 @@ static int bnxt_alloc_all_cp_arrays(struct bnxt *bp)for (i =0 ; i < bp->cp_nr_rings; i++) {struct bnxt_napi *bnapi = bp->bnapi[i]; -int rc; +int nid, rc;if (!bnapi)continue ; - rc =bnxt_alloc_cp_arrays (&bnapi->cp_ring, n); + nid =bnxt_cp_num_to_node (bp, i); + rc =bnxt_alloc_cp_arrays (&bnapi->cp_ring, n, nid);if (rc)return rc; }
@@ -4321,13 +4334,13 @@ static void bnxt_free_cp_rings(struct bnxt *bp) }static int bnxt_alloc_cp_sub_ring (struct bnxt *bp, -struct bnxt_cp_ring_info *cpr) +struct bnxt_cp_ring_info *cpr,int nid) {struct bnxt_ring_mem_info *rmem;struct bnxt_ring_struct *ring;int rc; - rc =bnxt_alloc_cp_arrays (cpr, bp->cp_nr_pages); + rc =bnxt_alloc_cp_arrays (cpr, bp->cp_nr_pages, nid);if (rc) {bnxt_free_cp_arrays (cpr);return -ENOMEM ;
@@ -4339,7 +4352,7 @@ static int bnxt_alloc_cp_sub_ring(struct bnxt *bp, rmem->pg_arr = (void **)cpr->cp_desc_ring; rmem->dma_arr = cpr->cp_desc_mapping; rmem->flags =BNXT_RMEM_RING_PTE_FLAG ; - rc =bnxt_alloc_ring (bp, rmem); + rc =bnxt_alloc_ring (bp, rmem,NUMA_NO_NODE );if (rc) {bnxt_free_ring (bp, rmem);bnxt_free_cp_arrays (cpr);
@@ -4360,7 +4373,7 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp)struct bnxt_napi *bnapi = bp->bnapi[i];struct bnxt_cp_ring_info *cpr, *cpr2;struct bnxt_ring_struct *ring; -int cp_count =0 , k; +int cp_count =0 , k, nid;int rx =0 , tx =0 ;if (!bnapi)
@@ -4370,7 +4383,7 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp) cpr->bnapi = bnapi; ring = &cpr->cp_ring_struct; - rc =bnxt_alloc_ring (bp, &ring->ring_mem); + rc =bnxt_alloc_ring (bp, &ring->ring_mem,NUMA_NO_NODE );if (rc)return rc;
@@ -4392,14 +4405,16 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp) tx =1 ; } - cpr->cp_ring_arr =kzalloc_objs (*cpr, cp_count); + nid =bnxt_cp_num_to_node (bp, i); + cpr->cp_ring_arr =kcalloc_node (cp_count,sizeof (*cpr), +GFP_KERNEL , nid);if (!cpr->cp_ring_arr)return -ENOMEM ; cpr->cp_ring_count = cp_count;for (k =0 ; k < cp_count; k++) { cpr2 = &cpr->cp_ring_arr[k]; - rc =bnxt_alloc_cp_sub_ring (bp, cpr2); + rc =bnxt_alloc_cp_sub_ring (bp, cpr2, nid);if (rc)return rc; cpr2->bnapi = bnapi;
@@ -5411,8 +5426,10 @@ static int bnxt_alloc_stats(struct bnxt *bp)for (i =0 ; i < bp->cp_nr_rings; i++) {struct bnxt_napi *bnapi = bp->bnapi[i];struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; +int nid =bnxt_cp_num_to_node (bp, i); - cpr->sw_stats =kzalloc_obj (*cpr->sw_stats); + cpr->sw_stats =kzalloc_node (sizeof (*cpr->sw_stats),GFP_KERNEL , + nid);if (!cpr->sw_stats)return -ENOMEM ;
@@ -9201,7 +9218,7 @@ 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); +return bnxt_alloc_ring (bp, rmem,NUMA_NO_NODE ); } static int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp,
@@ -16501,23 +16518,23 @@ static int bnxt_queue_mem_alloc(struct net_device *dev, goto err_rxq_info_unreg; ring = &clone->rx_ring_struct; - rc =bnxt_alloc_ring (bp, &ring->ring_mem); + rc =bnxt_alloc_ring (bp, &ring->ring_mem, nid);if (rc) goto err_free_rx_ring;if (bp->flags &BNXT_FLAG_AGG_RINGS ) { ring = &clone->rx_agg_ring_struct; - rc =bnxt_alloc_ring (bp, &ring->ring_mem); + rc =bnxt_alloc_ring (bp, &ring->ring_mem, nid);if (rc) goto err_free_rx_agg_ring; - rc =bnxt_alloc_rx_agg_bmap (bp, clone); + rc =bnxt_alloc_rx_agg_bmap (bp, clone, nid);if (rc) goto err_free_rx_agg_ring; }if (bp->flags &BNXT_FLAG_TPA ) { - rc =bnxt_alloc_one_tpa_info (bp, clone); + rc =bnxt_alloc_one_tpa_info (bp, clone, nid);if (rc) goto err_free_tpa_info; }
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH 4/6 eth: bnxt_en: explicitly keep device-only memory on the device's node
In reply to Jakub KicinskiContext 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.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -1
@@ -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,
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH 5/6 eth: bnxt_en: allocate fast path DMA rings on the queue's NUMA node
In reply to Jakub KicinskiDescriptor rings, completion rings, NQs and the TX push buffer are accessed by the host in the fast path, and so is the SW state around them, which we already allocate on the node of the CPU expected to service the queue. The DMA memory itself comes from the device's node, though, as that's what dma_alloc_coherent() always uses.
Use dma_alloc_coherent_node() for the ring pages and the TX push buffer. Pass the queue's node for completion rings and NQs as well, they used NUMA_NO_NODE so far since @nid only affected the SW rings.
Ring page tables are only read by the device, keep them on the device's node.
Note that queue restart only reallocates the Rx descriptor rings. Completion rings, NQs and Tx rings will follow IRQ affinity changes only on the next full reconfiguration.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +12 -12
@@ -3790,10 +3790,10 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem,for (i =0 ; i < rmem->nr_pages; i++) {u64 extra_bits = valid_bit; - rmem->pg_arr[i] =dma_alloc_coherent (&pdev->dev, - rmem->page_size, - &rmem->dma_arr[i], -GFP_KERNEL ); + rmem->pg_arr[i] =dma_alloc_coherent_node (&pdev->dev, + rmem->page_size, + &rmem->dma_arr[i], +GFP_KERNEL , nid);if (!rmem->pg_arr[i])return -ENOMEM ;
@@ -3812,7 +3812,6 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem, } } -/* Only the SW ring follows @nid, DMA memory is on the device's node */ if (rmem->vmem_size) { *rmem->vmem =vzalloc_node (rmem->vmem_size, nid);if (!(*rmem->vmem))
@@ -4208,10 +4207,11 @@ static int bnxt_alloc_tx_rings(struct bnxt *bp)/* One pre-allocated DMA buffer to backup * TX push operation */ - txr->tx_push =dma_alloc_coherent (&pdev->dev, - bp->tx_push_size, - &txr->tx_push_mapping, -GFP_KERNEL ); + txr->tx_push = +dma_alloc_coherent_node (&pdev->dev, + bp->tx_push_size, + &txr->tx_push_mapping, +GFP_KERNEL , nid);if (!txr->tx_push)return -ENOMEM ;
@@ -4353,7 +4353,7 @@ static int bnxt_alloc_cp_sub_ring(struct bnxt *bp, rmem->pg_arr = (void **)cpr->cp_desc_ring; rmem->dma_arr = cpr->cp_desc_mapping; rmem->flags =BNXT_RMEM_RING_PTE_FLAG ; - rc =bnxt_alloc_ring (bp, rmem,NUMA_NO_NODE ); + rc =bnxt_alloc_ring (bp, rmem, nid);if (rc) {bnxt_free_ring (bp, rmem);bnxt_free_cp_arrays (cpr);
@@ -4384,7 +4384,8 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp) cpr->bnapi = bnapi; ring = &cpr->cp_ring_struct; - rc =bnxt_alloc_ring (bp, &ring->ring_mem,NUMA_NO_NODE ); + nid =bnxt_cp_num_to_node (bp, i); + rc =bnxt_alloc_ring (bp, &ring->ring_mem, nid);if (rc)return rc;
@@ -4406,7 +4407,6 @@ static int bnxt_alloc_cp_rings(struct bnxt *bp) tx =1 ; } - nid =bnxt_cp_num_to_node (bp, i); cpr->cp_ring_arr =kcalloc_node (cp_count,sizeof (*cpr),GFP_KERNEL , nid);if (!cpr->cp_ring_arr)
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH 6/6 eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
In reply to Jakub KicinskiRx queue memory is allocated on the node of the CPU servicing the queue when the device is opened. On a running device it only follows IRQ affinity changes if TPH is enabled, as a side effect of the queue restart which applies the new TPH Steering Tag.
Schedule the affinity update work whenever the device supports the queue API, not just when TPH Steering Tag changed. Queue restart places all the memory it reallocates, other than the ring page tables, on the page pool's node, so compare the page pool's nid to decide if the queue has to move.
Since we need queue state of the currently allocated queue to compare nid - check that the device is still up after errors.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 46 ++++++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -1
@@ -2656,7 +2656,7 @@ struct bnxt {#define BNXT_RING_COAL_NOW_SP_EVENT 17#define BNXT_FW_RESET_NOTIFY_SP_EVENT 18#define BNXT_FW_EXCEPTION_SP_EVENT 19 -#define BNXT_TPH_UPDATE_SP_EVENT 20 +#define BNXT_IRQ_AFFINITY_SP_EVENT 20#define BNXT_LINK_CFG_CHANGE_SP_EVENT 21#define BNXT_THERMAL_THRESHOLD_SP_EVENT 22#define BNXT_FW_ECHO_REQUEST_SP_EVENT 23
drivers/net/ethernet/broadcom/bnxt/bnxt.c +28 -18
87 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH net-next 1/6] eth: bnxt_en: order event data before setting the sp_event bit
In reply to Jakub KicinskiQuoted 24 lines · Jakub Kicinski
Callers of
bnxt_queue_sp_work()may store data forbnxt_sp_task()right before raising the event, e.g. the IRQ affinity notifier publishes the new TPH Steering Tag.set_bit()is not ordered, so on weakly ordered architectures the event bit may become visible first. Ifbnxt_sp_task()is already running it can consume the event and read the stale data. Thequeue_work()which follows only re-runs the task with the event bit already cleared, so the update is lost.Add
smp_mb__before_atomic()before setting the bit, it pairs with the fully orderedtest_and_clear_bit()inbnxt_sp_task().Reported by an LLM reviewer while working on subsequent patches. Very unlikely to matter in practice.
Signed-off-by Jakub Kicinski <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void __bnxt_queue_sp_work(struct bnxt *bp) · line 402
Quoted 9 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-0@@ -394,6 +394,10 @@ static void __bnxt_queue_sp_work(struct bnxt *bp)static void bnxt_queue_sp_work (struct bnxt *bp,unsigned int event) { +/* Make the data the event carries visible before the event bit, +* pairs with test_and_clear_bit() in bnxt_sp_task(). +*/ +smp_mb__before_atomic ();set_bit (event, &bp->sp_event);__bnxt_queue_sp_work (bp);
There are direct callers of __bnxt_queue_sp_work(), that'll miss the fence. Fixup those callers?
Björn
Re: [PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
In reply to Jakub KicinskiQuoted 10 lines · Jakub Kicinski
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 ofcpumask_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().
Quoted 4 lines
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 <[email protected]>
Re: [PATCH net-next 3/6] eth: bnxt_en: allocate per-queue SW state on the queue's NUMA node
In reply to Jakub KicinskiQuoted 8 lines · Jakub Kicinski
Allocate the SW rings, agg bitmap, TPA state, completion ring page arrays, completion sub-ring structs, SW stats and the SW USO header buffer on the NUMA node of the CPU which will service the queue. This lowers the cost of cache misses for NAPI fast path (and xmit, for Tx).
Previous change already allocated the page pools on the right node.
Signed-off-by Jakub Kicinski <[email protected]>
Re: [PATCH net-next 4/6] eth: bnxt_en: explicitly keep device-only memory on the device's node
In reply to Jakub KicinskiQuoted 11 lines · Jakub Kicinski
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 thanNUMA_NO_NODEto 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 <[email protected]>
Re: [PATCH net-next 5/6] eth: bnxt_en: allocate fast path DMA rings on the queue's NUMA node
In reply to Jakub KicinskiQuoted 10 lines · Jakub Kicinski
Descriptor rings, completion rings, NQs and the TX push buffer are accessed by the host in the fast path, and so is the SW state around them, which we already allocate on the node of the CPU expected to service the queue. The DMA memory itself comes from the device's node, though, as that's what
dma_alloc_coherent()always uses.Use
dma_alloc_coherent_node()for the ring pages and the TX push buffer. Pass the queue's node for completion rings and NQs as well, they usedNUMA_NO_NODEso far since @nid only affected the SW rings.
Quoted 8 lines
Ring page tables are only read by the device, keep them on the device's node.
Note that queue restart only reallocates the Rx descriptor rings. Completion rings, NQs and Tx rings will follow IRQ affinity changes only on the next full reconfiguration.
Signed-off-by Jakub Kicinski <[email protected]>
Re: [PATCH net-next 6/6] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
In reply to Jakub KicinskiQuoted 11 lines · Jakub Kicinski
Rx queue memory is allocated on the node of the CPU servicing the queue when the device is opened. On a running device it only follows IRQ affinity changes if TPH is enabled, as a side effect of the queue restart which applies the new TPH Steering Tag.
Schedule the affinity update work whenever the device supports the queue API, not just when TPH Steering Tag changed. Queue restart places all the memory it reallocates, other than the ring page tables, on the page pool's node, so compare the page pool's nid to decide if the queue has to move.
Quoted 4 lines
Since we need queue state of the currently allocated queue to compare nid - check that the device is still up after errors.
Signed-off-by Jakub Kicinski <[email protected]>
Re: [PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
In reply to Jakub KicinskiQuoted 10 lines · Jakub Kicinski
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 ofcpumask_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().
Quoted 8 lines
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 <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 5 +++ drivers/net/ethernet/broadcom/bnxt/bnxt.c | 48 +++++++++++++++++++---- 2 files changed, 46 insertions(+), 7 deletions(-)
Re: [PATCH net-next 3/6] eth: bnxt_en: allocate per-queue SW state on the queue's NUMA node
In reply to Jakub KicinskiQuoted 11 lines · Jakub Kicinski
Allocate the SW rings, agg bitmap, TPA state, completion ring page arrays, completion sub-ring structs, SW stats and the SW USO header buffer on the NUMA node of the CPU which will service the queue. This lowers the cost of cache misses for NAPI fast path (and xmit, for Tx).
Previous change already allocated the page pools on the right node.
Signed-off-by Jakub Kicinski <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 ++++++++++++++--------- 1 file changed, 52 insertions(+), 35 deletions(-)
Re: [PATCH net-next 4/6] eth: bnxt_en: explicitly keep device-only memory on the device's node
In reply to Jakub KicinskiQuoted 6 lines · Jakub Kicinski
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 thanNUMA_NO_NODEto make it clear that this memory is not meant to follow any queue.
Quoted 8 lines
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 <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Re: [PATCH net-next 5/6] eth: bnxt_en: allocate fast path DMA rings on the queue's NUMA node
In reply to Jakub KicinskiQuoted 13 lines · Jakub Kicinski
Descriptor rings, completion rings, NQs and the TX push buffer are accessed by the host in the fast path, and so is the SW state around them, which we already allocate on the node of the CPU expected to service the queue. The DMA memory itself comes from the device's node, though, as that's what
dma_alloc_coherent()always uses.Use
dma_alloc_coherent_node()for the ring pages and the TX push buffer. Pass the queue's node for completion rings and NQs as well, they usedNUMA_NO_NODEso far since @nid only affected the SW rings.Ring page tables are only read by the device, keep them on the device's node.
Quoted 8 lines
Note that queue restart only reallocates the Rx descriptor rings. Completion rings, NQs and Tx rings will follow IRQ affinity changes only on the next full reconfiguration.
Signed-off-by Jakub Kicinski <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Re: [PATCH net-next 6/6] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
In reply to Jakub KicinskiQuoted 29 lines · Jakub Kicinski
Rx queue memory is allocated on the node of the CPU servicing the queue when the device is opened. On a running device it only follows IRQ affinity changes if TPH is enabled, as a side effect of the queue restart which applies the new TPH Steering Tag.
Schedule the affinity update work whenever the device supports the queue API, not just when TPH Steering Tag changed. Queue restart places all the memory it reallocates, other than the ring page tables, on the page pool's node, so compare the page pool's nid to decide if the queue has to move.
Since we need queue state of the currently allocated queue to compare nid - check that the device is still up after errors.
Signed-off-by Jakub Kicinski <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 46 ++++++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-)drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-1@@ -11931,18 +11931,17 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify, }#endif -if (!irq->bp->tph_mode)
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify, · line 11941
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6
-2+/* Only Rx queues can be restarted to follow the IRQ */ +if (!BNXT_SUPPORTS_QUEUE_API (irq->bp) || + irq->ring_nr >= irq->bp->rx_nr_rings)return ; -if (irq->ring_nr >= irq->bp->rx_nr_rings) -return ; +if (irq->bp->tph_mode && + !pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +cpumask_first (mask), &tag))
nit: this one is tough. i feel like this is super dense when wrapped this way, but i am not sure if there is any way to avoid this without making the code uglier.
Michael Chan
maintainerRe: [PATCH net-next 6/6] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
In reply to Jakub KicinskiQuoted 17 lines · Jakub Kicinski
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5
-1@@ -14673,6 +14675,8 @@ static void bnxt_tph_update(struct bnxt *bp) goto unlock;for (i =0 ; i < bp->rx_nr_rings; i++) { +struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; +bool new_tag = false, new_node = false;struct bnxt_irq *irq;int map_idx, err;u16 tag;@@ -14680,20 +14684,26 @@ static void bnxt_tph_update(struct bnxt *bp) map_idx =bnxt_cp_num_to_irq_num (bp, i); irq = &bp->irq_tbl[map_idx]; tag =READ_ONCE (irq->new_tag); -if (irq->tag == tag) +if (irq->tag != tag && + !pcie_tph_set_st_entry (bp->pdev, irq->msix_nr, tag)) + new_tag = true;
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_tph_update(struct bnxt *bp) · line 14695
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-4+if (rxr->page_pool->p.nid !=bnxt_cp_num_to_node (bp, i)) + new_node = true; +if (!new_tag && !new_node)continue ; -if (pcie_tph_set_st_entry (bp->pdev, irq->msix_nr, tag)) -continue ; - - err =netdev_rx_queue_restart (dev, irq->ring_nr); + err =netdev_rx_queue_restart (dev, i);
queue restart already has the code to do HWRM_RING_FREE of the CP ring to program the new TPH tag. We can add the missing logic to re-allocate the CP ring pages from the proper NUMA. Since we are paying the heavy price for a ring restart, should we include the CP ring to make it more complete?
[email protected]
AI reviewRe: [PATCH net-next 1/6] eth: bnxt_en: order event data before setting the sp_event bit
In reply to Jakub KicinskiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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] The patch fixes only some of the producers that publish data and then raise an sp_event bit.
--
eth: bnxt_en: order event data before setting the sp_event bit
This commit adds smp_mb__before_atomic() in bnxt_queue_sp_work() before the set_bit() on bp->sp_event. Data that callers store for bnxt_sp_task() then becomes visible before the event bit. The barrier pairs with the fully ordered test_and_clear_bit() in bnxt_sp_task().
Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void __bnxt_queue_sp_work(struct bnxt *bp) · line 403
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-0@@ -394,6 +394,10 @@ static void __bnxt_queue_sp_work(struct bnxt *bp)static void bnxt_queue_sp_work (struct bnxt *bp,unsigned int event) { +/* Make the data the event carries visible before the event bit, +* pairs with test_and_clear_bit() in bnxt_sp_task(). +*/ +smp_mb__before_atomic ();set_bit (event, &bp->sp_event);__bnxt_queue_sp_work (bp); }
[Severity: Medium]
Should the same ordering also cover the producers that set sp_event bits directly and then call __bnxt_queue_sp_work()?
The new comment reads like an ordering contract for sp_event in general. Several paths in bnxt.c do not go through bnxt_queue_sp_work(), so they never reach the new barrier. Each of them stores the event data, does a plain set_bit() on bp->sp_event, and then calls __bnxt_queue_sp_work(), which has no barrier.
In bnxt_async_event_process(), the echo request case does this:
if (fw_health) {
fw_health->echo_req_data1 = data1;
fw_health->echo_req_data2 = data2;
set_bit(BNXT_FW_ECHO_REQUEST_SP_EVENT, &bp->sp_event);
break;
}
...
__bnxt_queue_sp_work(bp);Could bnxt_fw_echo_reply() then copy stale echo_req_data1/2 into HWRM_FUNC_ECHO_RESPONSE?
In the RESET_NOTIFY case, the code writes fw_reset_timestamp, fw_reset_min_dsecs, fw_reset_max_dsecs and the BNXT_STATE_FW_FATAL_COND or BNXT_STATE_FW_NON_FATAL_COND bit in bp->state, and then does:
set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event);
The state bits are also set with a relaxed set_bit(), on a different word, so nothing orders them against the sp_event bit. bnxt_sp_task() then checks them:
if (test_and_clear_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event)) {
if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state) ||
test_bit(BNXT_STATE_FW_NON_FATAL_COND, &bp->state))
bnxt_devlink_health_fw_report(bp);
else
bnxt_fw_reset(bp);
}Can this take bnxt_fw_reset() instead of bnxt_devlink_health_fw_report(), or start the reset with stale wait limits?
bnxt_event_error_report() does the same with bp->thermal_threshold_type:
bp->thermal_threshold_type = type; set_bit(BNXT_THERMAL_THRESHOLD_SP_EVENT, &bp->sp_event);
and bnxt_hwmon_notify_event() switches on that value.
bnxt_sched_reset_rxr() follows the same pattern:
rxr->bnapi->in_reset = true; if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); else set_bit(BNXT_RST_RING_SP_EVENT, &bp->sp_event); __bnxt_queue_sp_work(bp);
If bnxt_rx_ring_reset() sees a stale in_reset == false, it skips the ring:
if (!rxr->bnapi->in_reset) continue;
in_reset then stays true, so bnxt_sched_reset_rxr() never schedules that ring reset again. Would that ring stay stuck until a full reset?
These paths are still unchanged at the end of the series, as of the "restart Rx queues when their IRQ moves to another NUMA node" patch.
Moving the barrier into __bnxt_queue_sp_work() would not cover these paths, because the open-coded set_bit() calls run before it. Could smp_mb__before_atomic() go before each open-coded set_bit() instead, or could these producers use an ordered helper?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118023905.3050661-1-kuba%40kernel.org
[email protected]
AI reviewRe: [PATCH net-next 2/6] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
In reply to Jakub KicinskiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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.
Quoted 23 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +15
-0@@ -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); +} +
[ ... ]
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-2@@ -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);
[ ... ]
Quoted 12 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8
-0@@ -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); +
[ ... ]
drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_request_irq(struct bnxt *bp) · line 12104
Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-0@@ -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.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118023905.3050661-1-kuba%40kernel.org
[email protected]
AI reviewRe: [PATCH net-next 6/6] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
In reply to Jakub KicinskiThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 · 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).
- [High] The new error handling in bnxt_irq_affinity_update() cannot work, and the path it targets oopses.
- [High] bnxt_irq_affinity_update() takes only the netdev instance lock, via bnxt_lock_sp() (not bnxt_rtnl_lock_sp()), before calling…
- [Medium] The code restarts more queues than the commit message and the new function comment describe ('Restart the Rx queues whose IRQ…
--
eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
This patch schedules the IRQ affinity update work on every device that supports the queue API, instead of only when the TPH Steering Tag changes. The work restarts an Rx queue when its page pool's nid differs from the node of the CPU servicing the IRQ. After a failed restart it checks that the device is still open.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0
[ ... ]
Quoted 12 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-1@@ -14663,7 +14662,10 @@ static void bnxt_rtnl_unlock_sp(struct bnxt *bp)rtnl_unlock (); } -static void bnxt_tph_update (struct bnxt *bp) +/* Restart the Rx queues whose IRQ moved, if the move changed the TPH +* Steering Tag or the node the queue memory should be allocated on. +*/ +static void bnxt_irq_affinity_update (struct bnxt *bp) {struct net_device *dev = bp->dev;int i;
[ ... ]
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_tph_update(struct bnxt *bp) · line 14691
Quoted 13 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5
-4@@ -14680,20 +14684,26 @@ static void bnxt_tph_update(struct bnxt *bp) map_idx =bnxt_cp_num_to_irq_num (bp, i); irq = &bp->irq_tbl[map_idx]; tag =READ_ONCE (irq->new_tag); -if (irq->tag == tag) -continue ; - -if (pcie_tph_set_st_entry (bp->pdev, irq->msix_nr, tag)) +if (irq->tag != tag && + !pcie_tph_set_st_entry (bp->pdev, irq->msix_nr, tag)) + new_tag = true; +if (rxr->page_pool->p.nid !=bnxt_cp_num_to_node (bp, i)) + new_node = true;
[Severity: Medium]
The new function comment says only "Rx queues whose IRQ moved" are restarted. Is that what this loop does?
An affinity notification for any one Rx IRQ queues BNXT_IRQ_AFFINITY_SP_EVENT. This loop then compares every ring's page_pool nid against bnxt_cp_num_to_node(bp, i), whether or not that ring's IRQ moved.
For rings whose affinity was never set, bnxt_request_irq() leaves ring_nid[i] as NUMA_NO_NODE. bnxt_cp_num_to_node() then falls back to:
cpu = cpumask_local_spread(n, dev_to_node(&bp->pdev->dev)); return cpu_to_node(cpu);
That result depends on cpu_online_mask at the time of the call.
After CPU hotplug (for example SMT disable or offlining CPUs), can this fallback pick a different node from the one used at open? If so, moving one unrelated IRQ would restart these other queues and move their memory to the new default-spread node.
The comment in bnxt_request_irq() says this placement is "just a hint", so the new node may not match where the IRQ actually runs.
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_tph_update(struct bnxt *bp) · line 14701
Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5
-1+if (!new_tag && !new_node)continue ; - err =netdev_rx_queue_restart (dev, irq->ring_nr); + err =netdev_rx_queue_restart (dev, i);if (err) {netdev_err (dev,"RX queue restart failed: err=%d\n" , err); +/* Failing to start a new queue may close the device */ +if (!test_bit (BNXT_STATE_OPEN , &bp->state)) +break ;
[Severity: High]
If the restart fails because the device was closed, can this check ever be reached? Here is the sequence I'm looking at:
bnxt_irq_affinity_update()
netdev_rx_queue_restart(dev, i)
netdev_rx_queue_reconfig()
ndo_queue_stop(old_mem) /* succeeds */
bnxt_queue_start(new_mem)
/* clone page_pool, rings and rx_tpa moved into bp->rx_ring[idx] */
bnxt_hwrm_rx_ring_alloc() fails -> err_reset
netif_close(dev)
bnxt_close()->bnxt_close_nic()->__bnxt_close_nic()
bnxt_free_mem(bp, true)
kfree(bp->rx_ring);
bp->rx_ring = NULL;
err_start_queue:
bnxt_queue_start(old_mem)
rxr = &bp->rx_ring[idx];
rxr->rx_prod = clone->rx_prod; /* bp->rx_ring is NULL */Wouldn't this hit a NULL pointer dereference in the sp workqueue while netdev_lock is held, before control returns to this check?
If that step were survived, err_free_new_queue_mem would call ndo_queue_mem_free(dev, new_mem). That runs page_pool_destroy() and bnxt_free_ring() a second time on resources bnxt_free_mem() already released.
The commit message says "check that the device is still up after errors", which relies on this path returning normally.
Before this patch the path ran only on TPH Steering Tag changes. bnxt_irq_affinity_notify() now queues the work on every queue-API PF, and any cross-node Rx IRQ move restarts a queue. irqbalance or a write to /proc/irq/N/smp_affinity is enough to trigger it. An HWRM failure during queue start is the only other precondition.
[Severity: High]bnxt_irq_affinity_update() starts with bnxt_lock_sp(bp). That only takes netdev_lock(bp->dev), not RTNL.
The new comment expects this restart to close the device. The close happens via bnxt_queue_start() err_reset -> netif_close(dev) -> netif_close_many() -> __dev_close_many(), which begins with:
ASSERT_RTNL(); might_sleep();
It then calls the NETDEV_GOING_DOWN notifiers, dev_deactivate_many(), rtmsg_ifinfo() and the NETDEV_DOWN notifiers.
Doesn't all of that run without RTNL here? That would trigger the assertion and race with other RTNL holders.
Would bnxt_rtnl_lock_sp()/bnxt_rtnl_unlock_sp() be more appropriate, as bnxt_reset() uses?
The old bnxt_tph_update() used the same helper, but it only ran on TPH tag changes. With this patch the path runs for any cross-node IRQ move on a queue-API PF. In the same failure, the core rollback then hits the NULL bp->rx_ring dereference described above.
Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2
-1continue ; } - irq->tag = tag; +if (new_tag) + irq->tag = tag; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118023905.3050661-1-kuba%40kernel.org
Jakub Kicinski
maintainerRe: [PATCH net-next 6/6] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
In reply to Michael ChanQuoted 5 lines · On Wed, 18 Nov 2026 17:24:12 -0800 Michael Chan wrote:
queue restart already has the code to do
HWRM_RING_FREEof the CP ring to program the new TPH tag. We can add the missing logic to re-allocate the CP ring pages from the proper NUMA. Since we are paying the heavy price for a ring restart, should we include the CP ring to make it more complete?
I coded this up. AI review thing popped up the problem that re-allocating CP rings causes loss of IRQ moderation settings. This seems net-worthy to me :S Attaching a memory provider on a machine with TPH will lead to loss of coalescing settings. Quite unpleasant for the -irq settings in particular.
Can I send out the coal fixes for net and this series without the CP realloc? I'd follow up with the CP realloc after the net->net-next merge which we just missed :(
Michael Chan
maintainerRe: [PATCH net-next 6/6] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
Quoted 9 lines · Jakub Kicinski
I coded this up. AI review thing popped up the problem that re-allocating CP rings causes loss of IRQ moderation settings. This seems net-worthy to me :S Attaching a memory provider on a machine with TPH will lead to loss of coalescing settings. Quite unpleasant for the -irq settings in particular.
Can I send out the coal fixes for net and this series without the CP realloc? I'd follow up with the CP realloc after the net->net-next merge which we just missed :(
Sure, no objections from me.