eth: bnxt_en: allocate memory on the right NUMA node
Jakub Kicinski
maintainerv2 cover 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")
I held off reallocating the Rx completion ring on queue restart, we need to fix the IRQ coalescing there first:
https://lore.kernel.org/all/[email protected]/
v2:
- convert the sp_event producers which set the bit directly (Björn)
- correct the comment on ring_nid, it's not only written by the notifier
- allocate ring_nid with kmalloc_objs()
- add a prep patch with a local bp variable in the IRQ affinity notifier
- split the TPH condition in the IRQ affinity notifier (Joe)
- only compare the node of queues with explicitly set IRQ affinity
v1: https://lore.kernel.org/[email protected]
Jakub Kicinski (7):
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: add a local bp variable in the IRQ affinity notifier
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 | 250 ++++++++++++++-------- 2 files changed, 169 insertions(+), 88 deletions(-)
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH v2 1/7 eth: bnxt_en: order event data before setting the sp_event bit
Producers of sp_events may store data for bnxt_sp_task() right before raising the event, e.g. the IRQ affinity notifier publishes the new TPH Steering Tag, the async event handler records the FW echo request data or the FW reset wait limits. 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 a helper which issues smp_mb__before_atomic() before setting the bit, it pairs with the fully ordered test_and_clear_bit() in bnxt_sp_task(). Use it for all events, including those which carry no data, so that new producers don't have to think about it.
Reported by an LLM reviewer while working on subsequent patches. Very unlikely to matter in practice.
---
v2:
- convert the producers which set the bit directly (Björn)
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +21 -12
@@ -392,9 +392,18 @@ static void __bnxt_queue_sp_work(struct bnxt *bp)schedule_work (&bp->sp_task); } +static void bnxt_set_sp_event (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); +} +static void bnxt_queue_sp_work (struct bnxt *bp,unsigned int event) { -set_bit (event, &bp->sp_event); +bnxt_set_sp_event (bp, event);__bnxt_queue_sp_work (bp); }
@@ -403,9 +412,9 @@ static void bnxt_sched_reset_rxr(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)if (!rxr->bnapi->in_reset) { rxr->bnapi->in_reset = true;if (bp->flags &BNXT_FLAG_CHIP_P5_PLUS ) -set_bit (BNXT_RESET_TASK_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_RESET_TASK_SP_EVENT );else -set_bit (BNXT_RST_RING_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_RST_RING_SP_EVENT );__bnxt_queue_sp_work (bp); } rxr->rx_next_cons =0xffff ;
@@ -2751,7 +2760,7 @@ static bool bnxt_event_error_report(struct bnxt *bp, u32 data1, u32 data2) BNXT_EVENT_THERMAL_THRESHOLD_TEMP(data2));if (notify) { bp->thermal_threshold_type = type; -set_bit (BNXT_THERMAL_THRESHOLD_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_THERMAL_THRESHOLD_SP_EVENT );return true; }return false;
@@ -2817,18 +2826,18 @@ static int bnxt_async_event_process(struct bnxt *bp,netdev_warn (bp->dev,"Link speed %d no longer supported\n" , speed); } -set_bit (BNXT_LINK_SPEED_CHNG_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_LINK_SPEED_CHNG_SP_EVENT ); } fallthrough;case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE :case ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE : -set_bit (BNXT_LINK_CFG_CHANGE_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_LINK_CFG_CHANGE_SP_EVENT ); fallthrough;case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE : -set_bit (BNXT_LINK_CHNG_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_LINK_CHNG_SP_EVENT );break ;case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD : -set_bit (BNXT_HWRM_PF_UNLOAD_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_HWRM_PF_UNLOAD_SP_EVENT );break ;case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED : {u16 port_id =BNXT_GET_EVENT_PORT (data1);
@@ -2839,13 +2848,13 @@ static int bnxt_async_event_process(struct bnxt *bp,if (bp->pf.port_id != port_id)break ; -set_bit (BNXT_HWRM_PORT_MODULE_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_HWRM_PORT_MODULE_SP_EVENT );break ; }case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE :if (BNXT_PF (bp)) goto async_event_process_exit; -set_bit (BNXT_RESET_TASK_SILENT_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_RESET_TASK_SILENT_SP_EVENT );break ;case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY : {char *type_str ="Solicited" ;
@@ -2877,7 +2886,7 @@ static int bnxt_async_event_process(struct bnxt *bp, type_str, data1, data2, bp->fw_reset_min_dsecs *100 , bp->fw_reset_max_dsecs * 100); -set_bit (BNXT_FW_RESET_NOTIFY_SP_EVENT , &bp->sp_event); +bnxt_set_sp_event (bp,BNXT_FW_RESET_NOTIFY_SP_EVENT );break ; }case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY : {
@@ -2955,7 +2964,7 @@ static int bnxt_async_event_process(struct bnxt *bp,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); +bnxt_set_sp_event (bp,BNXT_FW_ECHO_REQUEST_SP_EVENT );break ; } goto async_event_process_exit;
Signature · 1 line
2.56.1
Re: [PATCH net-next v2 1/7] eth: bnxt_en: order event data before setting the sp_event bit
Quoted 14 lines · Jakub Kicinski
Producers of
sp_eventsmay store data forbnxt_sp_task()right before raising the event, e.g. the IRQ affinity notifier publishes the new TPH Steering Tag, the async event handler records the FW echo request data or the FW reset wait limits.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 a helper which issues
smp_mb__before_atomic()before setting the bit, it pairs with the fully orderedtest_and_clear_bit()inbnxt_sp_task(). Use it for all events, including those which carry no data, so that new producers don't have to think about it.
Quoted 7 lines
Reported by an LLM reviewer while working on subsequent patches. Very unlikely to matter in practice.
Signed-off-by Jakub Kicinski <[email protected]>---
v2:
- convert the producers which set the bit directly (Björn)
Jakub Kicinski
maintainerPATCH v2 2/7 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.
---
v2:
- correct the comment on ring_nid, it's not only written by the notifier
- allocate ring_nid with kmalloc_objs()
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 5 +++ drivers/net/ethernet/broadcom/bnxt/bnxt.c | 46 +++++++++++++++++++---- 2 files changed, 44 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; +/* NUMA node of the first online CPU in the affinity mask if it was +* configured explicitly by the user, otherwise NUMA_NO_NODE. +* Written by the IRQ affinity notifier, readers must use READ_ONCE(). +*/ +int *ring_nid;int max_irqs;int total_irqs;int ulp_num_msix_want;
drivers/net/ethernet/broadcom/bnxt/bnxt.c +39 -7
108 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH net-next v2 2/7] eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
Thank 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 (1)
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 page pool's NUMA node is chosen from a cached bp->ring_nid[] entry before the driver checks whether that entry has…
Pre-existing issues:
- [Low] Two different CPUs can be taken from the same affinity mask.
--
eth: bnxt_en: follow explicitly set IRQ affinity when placing page pool
This patch makes the NUMA node of the Rx page pool follow IRQ affinity that the user set explicitly. The affinity notifier computes the node of the first online CPU in the mask and publishes it in a new bp->ring_nid[] array. bnxt_alloc_rx_rings() and bnxt_queue_mem_alloc() look the node up through a new helper, bnxt_cp_num_to_node(), which falls back to cpumask_local_spread() when no affinity was set.
Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0@@ -3823,6 +3823,20 @@ static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)return 0 ; }
drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem) · line 3835
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10
-0+/* Node of the CPU expected to service cp ring @n. If user did not configure +* the affinity explicitly, use the default spread (historic behavior). +*/ +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;
[Severity: Medium]
Can this return a stale node when the recorded mask no longer has any online CPU?
The only place that resets ring_nid[i] to NUMA_NO_NODE for a stale mask is bnxt_request_irq(). In __bnxt_open_nic(), memory is allocated before the IRQs are requested:
__bnxt_open_nic() {
...
rc = bnxt_alloc_mem(bp, irq_re_init);
...
if (irq_re_init) {
bnxt_init_napi(bp);
rc = bnxt_request_irq(bp);
...
}This means bnxt_alloc_mem()->bnxt_alloc_rx_rings()->bnxt_cp_num_to_node() reads ring_nid[i] before this check runs:
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);Here is one sequence. The user pins ring i through /proc/irq/N/smp_affinity, the device is closed, and then every CPU in that mask goes offline. The notifier was released with the IRQs, and hotplug IRQ migration does not call it.
On the next open, the page pool and ring memory are allocated on the old node. bnxt_request_irq() then moves the IRQ to cpumask_local_spread(i, numa_node), which may be on a different node. Before this patch, both used cpumask_local_spread() and ended up on the same node.
bnxt_half_open_nic() calls bnxt_alloc_mem() but never calls bnxt_request_irq(), so on that path the stale value is never corrected.
The later patch in the series ("restart Rx queues when their IRQ moves to another NUMA node") does not seem to fix this either. Its bnxt_irq_affinity_update() only acts when nid != NUMA_NO_NODE, and bnxt_request_irq() has just reset ring_nid to NUMA_NO_NODE. The mismatch would last until the next affinity change or close/open.
At that point the comment on ring_nid in bnxt.h ("NUMA node of the first online CPU in the affinity mask") also does not hold.
Would it work to check cpumask_intersects() in bnxt_cp_num_to_node(), or to invalidate stale entries before bnxt_alloc_mem() runs?
Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3
-0+ cpu =cpumask_local_spread (n,dev_to_node (&bp->pdev->dev)); +return cpu_to_node (cpu); +}
[ ... ]
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify, · line 11905
Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +7
-0@@ -11882,6 +11896,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); +/* Readers can't access ring_cpu_mask atomically, so pre-compute +* the info they care about (NUMA node, TPH tag) and store it +* with WRITE_ONCE(). +*/ + 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);
[Severity: Low]
This is a pre-existing issue and was not introduced by this patch. The TPH steering tag later in this same notifier is still computed from cpumask_first(mask):
if (pcie_tph_get_cpu_st(irq->bp->pdev, TPH_MEM_TYPE_VM, cpumask_first(mask), &tag)) return;
The ST table init in bnxt_request_irq() also uses cpumask_first(cpu_mask). A user-written mask only has to overlap the online mask, so its lowest CPU can be offline.
With such a mask, the steering tag targets one CPU, while bnxt_queue_mem_alloc()->bnxt_cp_num_to_node() places the page pool on the node of a different CPU.
Before this patch the page pool node ignored the mask entirely, so this patch narrows the mismatch rather than causing it. Could the node and the tag both use the first online CPU in the mask, so that they stay consistent?
Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0#ifdef CONFIG_RFS_ACCEL if (irq->bp->dev->rx_cpu_rmap && irq->ring_nr < irq->bp->rx_nr_rings) {int err;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120035214.369158-1-kuba%40kernel.org
Jakub Kicinski
maintainerPATCH v2 3/7 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.
---
v2: no change
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 ++++++++++++++--------- 1 file changed, 52 insertions(+), 35 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +52 -35
@@ -3770,7 +3770,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 ;
@@ -3815,8 +3816,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 ; }
@@ -3866,25 +3868,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 ;
@@ -3911,8 +3915,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; }
@@ -4024,13 +4030,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 ;
@@ -4074,19 +4081,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; }
@@ -4111,9 +4118,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 ;
@@ -4187,11 +4194,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;
@@ -4217,7 +4226,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; }
@@ -4244,12 +4253,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 ;
@@ -4276,11 +4288,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; }
@@ -4325,13 +4338,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 ;
@@ -4343,7 +4356,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);
@@ -4364,7 +4377,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)
@@ -4374,7 +4387,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;
@@ -4396,14 +4409,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;
@@ -5415,8 +5430,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 ;
@@ -9242,7 +9259,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,
@@ -16546,23 +16563,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 v2 4/7 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.
---
v2: no change
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -1
@@ -3784,6 +3784,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 );
@@ -9259,7 +9260,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 v2 5/7 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.
---
v2: no change
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +12 -12
@@ -3795,10 +3795,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 ;
@@ -3817,7 +3817,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))
@@ -4212,10 +4211,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 ;
@@ -4357,7 +4357,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);
@@ -4388,7 +4388,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;
@@ -4410,7 +4411,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 v2 6/7 eth: bnxt_en: add a local bp variable in the IRQ affinity notifier
In reply to Jakub Kicinskibnxt_irq_affinity_notify() refers to irq->bp in almost every statement. Add a local variable to shorten the lines, the next patch will make the conditions at the end of the function more complex. No functional change.
---
v2: new patch
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +12 -11
@@ -11949,13 +11949,15 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify, {struct bnxt_irq *irq;unsigned int cpu; +struct bnxt *bp;int nid;u16 tag; irq = container_of(notify, struct bnxt_irq, affinity_notify); + bp = irq->bp; -cpumask_copy (irq->bp->ring_cpu_mask[irq->ring_nr], mask); -set_bit (irq->ring_nr, irq->bp->ring_affinity_set); +cpumask_copy (bp->ring_cpu_mask[irq->ring_nr], mask); +set_bit (irq->ring_nr, bp->ring_affinity_set);/* Readers can't access ring_cpu_mask atomically, so pre-compute * the info they care about (NUMA node, TPH tag) and store it
@@ -11963,32 +11965,31 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify,*/ 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); +WRITE_ONCE (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) { +if (bp->dev->rx_cpu_rmap && irq->ring_nr < bp->rx_nr_rings) {int err; - err =cpu_rmap_update (irq->bp->dev->rx_cpu_rmap, irq->ring_nr, - mask); + err =cpu_rmap_update (bp->dev->rx_cpu_rmap, irq->ring_nr, mask);if (err) -netdev_warn (irq->bp->dev, +netdev_warn (bp->dev,"aRFS rmap update failed: %d\n" , err); }#endif -if (!irq->bp->tph_mode) +if (!bp->tph_mode)return ; -if (irq->ring_nr >= irq->bp->rx_nr_rings) +if (irq->ring_nr >= bp->rx_nr_rings)return ; -if (pcie_tph_get_cpu_st (irq->bp->pdev,TPH_MEM_TYPE_VM , +if (pcie_tph_get_cpu_st (bp->pdev,TPH_MEM_TYPE_VM ,cpumask_first (mask), &tag))return ;WRITE_ONCE (irq->new_tag, tag); -bnxt_queue_sp_work (irq->bp,BNXT_TPH_UPDATE_SP_EVENT ); +bnxt_queue_sp_work (bp,BNXT_TPH_UPDATE_SP_EVENT ); }static void bnxt_irq_affinity_release (struct kref *ref)
Signature · 1 line
2.56.1
Jakub Kicinski
maintainerPATCH v2 7/7 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. Only consider queues whose IRQ affinity was set from the outside, so that moving one IRQ doesn't restart other queues just because CPU hotplug shifted our default spread.
Since we need queue state of the currently allocated queue to compare nid - check that the device is still up after errors.
---
v2:
- split the TPH condition in the notifier (Joe)
- only compare the node of queues with IRQ affinity set from the outside
v1: https://lore.kernel.org/[email protected]
--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 53 +++++++++++++++-------- 2 files changed, 35 insertions(+), 20 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 +34 -19
94 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH net-next v2 7/7] eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
Quoted 14 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. Only consider queues whose IRQ affinity was set from the outside, so that moving one IRQ doesn't restart other queues just because CPU hotplug shifted our default spread.
Quoted 6 lines
Since we need queue state of the currently allocated queue to compare nid - check that the device is still up after errors.
Reviewed-by Björn Töpel <[email protected]>Reviewed-by Joe Damato <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Just one minor comment below.
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify, · line 11981
Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-1@@ -11978,18 +11978,17 @@ static void bnxt_irq_affinity_notify(struct irq_affinity_notify *notify, }#endif -if (!bp->tph_mode) +/* Only Rx queues can be restarted to follow the IRQ */
This comment is not quite precise. If it is a combined channel, the queue restart also restarts the TX ring for TPH. Just like my earlier comment about including the RX CP ring, we can also include the TX and TX CP ring.
Anyway, no need to respin just to change the comment. Thanks.
[email protected]
AI reviewRe: [PATCH net-next v2 7/7] 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: 3 · Medium: 0 · 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 close-on-error handling in bnxt_irq_affinity_update() cannot work.
- [High] bnxt_irq_affinity_update() takes only the netdev instance lock through bnxt_lock_sp() (bnxt.c:14636-14646: clear_bit(IN_SP_TASK);…
- [High] With this patch, PFs that support the queue API but run without TPH restart their Rx queues when the IRQ moves to another NUMA node.
--
eth: bnxt_en: restart Rx queues when their IRQ moves to another NUMA node
This patch schedules the IRQ affinity sp work on every device that supports the queue API, not only in TPH mode. bnxt_irq_affinity_update() then restarts an Rx queue if the TPH Steering Tag changed or if the page pool's nid no longer matches the IRQ's node. It also stops the loop when a failed restart has closed the device.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0
[ ... ]
Quoted 16 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4
-2@@ -14677,27 +14679,40 @@ 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; +int map_idx, err, nid;struct bnxt_irq *irq; -int map_idx, err;u16 tag; 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)
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_tph_update(struct bnxt *bp) · line 14699
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +7
-2-continue ; +if (irq->tag != tag) { +if (!pcie_tph_set_st_entry (bp->pdev, irq->msix_nr, tag)) + new_tag = true; + } -if (pcie_tph_set_st_entry (bp->pdev, irq->msix_nr, tag)) + nid =READ_ONCE (bp->ring_nid[i]); +if (nid !=NUMA_NO_NODE && rxr->page_pool->p.nid != nid) + new_node = true;
[Severity: High]
When bp->tph_mode is off, this new_node check alone now restarts the queue. Does the restart quiesce the XDP TX ring that shares this Rx queue's NAPI?
XDP requires combined rings. The XDP TX ring is attached to the Rx bnapi, and its tx_int is bnxt_tx_int_xdp(). bnxt_queue_stop() calls bnxt_tx_queue_stop(), which skips freeing and draining the TX ring when TPH is off:
bnxt_tx_queue_stop() {
...
if (!bp->tph_mode)
continue;
bnxt_hwrm_tx_ring_free(bp, txr, true);
bnxt_hwrm_cp_ring_free(bp, txr->tx_cpr);
bnxt_free_one_tx_ring_skbs(bp, txr, txr->txq_index);
...
}That leaves XDP_TX descriptors already posted to hardware in flight while bnxt_queue_start() installs the clone's pools:
rxr->page_pool = clone->page_pool; rxr->head_pool = clone->head_pool;
Those completions are processed later in bnxt_tx_int_xdp():
page_pool_recycle_direct(rxr->page_pool, tx_buf->page);
Wouldn't that recycle old-pool pages into the new pool? The same path also rings the Rx doorbell with a tx_buf->rx_prod from the old ring.
Meanwhile, bnxt_queue_mem_free(old_mem) frees the old rx_buf_ring pages, including XDP_TX head pages that hardware may still be reading. It then calls page_pool_destroy() on the old pool, which DMA-unmaps the pages that pool still tracks. Some of those pages may already have been reposted to hardware Rx through the new pool.
Before this patch, bnxt only called netdev_rx_queue_restart() in TPH mode, where the TX rings are freed during stop. Is it safe to reach this restart on non-TPH devices that have XDP attached?
drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_tph_update(struct bnxt *bp) · line 14752
Quoted 12 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]
Can netdev_rx_queue_restart() return here safely once the device has been closed?
If bnxt_queue_start() for new_mem hits an HWRM failure, it jumps to err_reset and calls netif_close(dev), which leads to:
netif_close()
__dev_close_many()
bnxt_close()
bnxt_close_nic()
__bnxt_close_nic()
bnxt_free_mem(bp, true)
bnxt_free_rx_rings() <- destroys rxr->page_pool (new pool)
kfree(bp->rx_ring); bp->rx_ring = NULL;Next, netdev_rx_queue_reconfig() takes its err_start_queue path. It does not check whether the device is still running:
if (qops->ndo_queue_start(dev, qcfg_old, old_mem, rxq_idx)) {
...
}err_free_new_queue_mem:
qops->ndo_queue_mem_free(dev, new_mem);
bnxt_queue_start(old_mem) then runs:
rxr = &bp->rx_ring[idx]; clone = qmem; rxr->rx_prod = clone->rx_prod;
with bp->rx_ring set to NULL. Wouldn't this oops? Even if it didn't, bnxt_queue_mem_free(new_mem) would call page_pool_destroy() a second time on the new pool, which bnxt_free_rx_rings() has already destroyed.
The reverse order has the same problem. Suppose the new queue fails in the MRU path without closing, and the rollback start for old_mem then reaches err_reset. The close destroys the old pool, and ndo_queue_mem_free(old_mem) destroys it again.
So whenever the device closes inside the restart, the new BNXT_STATE_OPEN check doesn't seem to be reached safely.
This restart can now be triggered by any cross-node affinity change on a queue-API PF, for example from irqbalance or a write to /proc/irq/*/smp_affinity, not only by TPH Steering Tag changes.
[Severity: High]
Related to the above: which locks are held when this close happens?
bnxt_irq_affinity_update() takes only the netdev instance lock, through bnxt_lock_sp():
bnxt_lock_sp() {
clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
netdev_lock(bp->dev);
}Unlike bnxt_rtnl_lock_sp(), it does not take RTNL. The err_reset path in bnxt_queue_start() calls netif_close(dev), and __dev_close_many() begins with:
ASSERT_RTNL();
might_sleep();
list_for_each_entry(dev, head, close_list) {
netpoll_poll_disable(dev);
call_netdevice_notifiers(NETDEV_GOING_DOWN, dev);Wouldn't this trigger the RTNL assertion?
The NETDEV_GOING_DOWN and NETDEV_DOWN notifiers and rtmsg_ifinfo() would also run without RTNL. That lets them race with other RTNL holders that don't take this device's instance lock.
The new comment "Failing to start a new queue may close the device" expects this close path. With this patch, it can be reached on every BNXT_SUPPORTS_QUEUE_API PF, not only in TPH mode.
Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0continue ; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120035214.369158-1-kuba%40kernel.org
Quoted 3 lines · Jakub Kicinski
Teach bnxt to allocate the memory touched by the fast path on the NUMA node where NAPI is being serviced.
For the series,