net: atlantic: convert RX path to page_pool
Subsystems (5)
cover net: atlantic: convert RX path to page_pool
On systems where the NIC sits behind an IOMMU, the atlantic RX path cannot reach line rate: every RX buffer is allocated with dev_alloc_pages() and mapped with dma_map_page(), then unmapped and freed once the stack has consumed the packet. Every map/unmap is an IOTLB/pagetable operation, and at 10G rates this dominates the RX path. On an AMD Strix Halo system with a Thunderbolt-attached QNAP QNA-T310G1S (MTU 1500, TCP over IPv6, iperf3 -R), RX tops out at about 2.2 Gbit/s.
An earlier patch [1] worked around this by making the RX page order tunable via a module parameter, amortizing one map/unmap over eight pages worth of frames. The review feedback was to convert the driver to the page_pool API instead of adding a knob. This series does that conversion.
Patch 1 fixes a long-standing teardown leak first: TX buffers beyond the budgeted single aq_ring_tx_clean() pass, or still posted past the frozen hw_head, are stranded when the interface goes down. Today that is a silent leak; after the conversion a stranded XDP_TX frame would hold a page_pool fragment reference and turn every such ifdown into a permanently stalled pool shutdown, so it needs fixing before the conversion lands.
Patch 2 converts the RX path to page_pool with the fragment API. Pages are DMA-mapped once when they enter the per-ring pool (PP_FLAG_DMA_MAP) and stay mapped while they recycle between the driver and the stack, so steady-state RX performs no IOMMU work. page_pool_dev_alloc_frag() takes over the sub-page splitting the driver's hand-rolled "page flip" scheme did based on page_ref_count(), buffer ownership becomes transfer-based, and the XDP memory model switches to MEM_TYPE_PAGE_POOL.
Performance, QNA-T310G1S (AQC100) behind Thunderbolt/IOMMU, MTU 1500, TCP over IPv6, iperf3 -R:
before: 2.24 Gbit/s
after: 9.14 Gbit/s
matching what previously required the rxpageorder=3 workaround, but with order-0 pages and no tunable.
Tested on the same setup: line rate with plain RX and with XDP_PASS; XDP_TX with a MAC-swap reflector under sustained traffic; repeated ifdown/ifup and module unload cycles under both plain RX and XDP_TX load complete without "stalled pool shutdown" warnings or other splats.
[1] https://lore.kernel.org/lkml/[email protected]/
Yangyu Chen (2):
net: atlantic: free stranded TX buffers on ring deinit
net: atlantic: convert RX path to page_pool
drivers/net/ethernet/aquantia/Kconfig | 1 + .../ethernet/aquantia/atlantic/aq_ethtool.c | 3 - .../net/ethernet/aquantia/atlantic/aq_ptp.c | 20 +- .../net/ethernet/aquantia/atlantic/aq_ring.c | 268 +++++++++--------- .../net/ethernet/aquantia/atlantic/aq_ring.h | 7 +- .../net/ethernet/aquantia/atlantic/aq_vec.c | 17 +- 6 files changed, 172 insertions(+), 144 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/2 net: atlantic: free stranded TX buffers on ring deinit
aq_vec_deinit() drains the TX rings with a single aq_ring_tx_clean() call, which frees at most AQ_CFG_TX_CLEAN_BUDGET (256) descriptors and stops at hw_head, which no longer moves once aq_vec_stop() has stopped the hardware and NAPI. Completed descriptors beyond the budget and everything still posted in [hw_head, sw_tail) keep their skb or xdp_frame when the interface goes down: aq_vec_ring_free() then frees the buffer ring and the references are lost for good.
Today this is a silent memory leak on every interface down under TX/XDP_TX load. With the following conversion of the RX path to page_pool it becomes much more visible: XDP_TX frames carry fragment references on the RX ring's page_pool, so a single stranded frame keeps the pool's inflight count above zero forever. page_pool_destroy() then never completes, the pool is leaked together with its pages, and "page_pool_release_retry() stalled pool shutdown" is warned every 60 seconds from that point on, on every ifdown, XDP detach or ring resize under XDP_TX load.
Bring back aq_ring_tx_deinit() as it was before the removal and use it for teardown again, with one extension: TX rings can hold xdp_frames nowadays, so release those too. They are returned with xdp_return_frame() since this runs in process context.
---
Notes:
Without this fix, converting the RX path to page_pool (next patch) turns the stranded XDP_TX frames into leaked page_pool fragments, so page_pool_destroy() can never drain and the shutdown stalls forever.
Reproduced on an AQC100 with this patch dropped from the series (i.e. page_pool applied without the tx-deinit fix):
# reflect received frames back out through XDP_TX
xdp-bench tx enp99s0 # or any trivial XDP_TX prog
# from a peer on the same link, flood RX so frames are in flight, then ip link set enp99s0 down
The pool is destroyed with frames still stranded on the TX ring, and page_pool_release_retry() warns every 60s with the same id and inflight count and a growing age, indefinitely:
[161110.753385] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 60 sec [161171.170756] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 120 sec [161231.588685] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 181 sec [161292.005886] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 241 sec
With this patch the stranded buffers are freed at deinit, inflight drops to zero and the pool drains cleanly.
.../net/ethernet/aquantia/atlantic/aq_ring.c | 30 +++++++++++++++++++ .../net/ethernet/aquantia/atlantic/aq_ring.h | 1 + .../net/ethernet/aquantia/atlantic/aq_vec.c | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-)
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +30 -0
@@ -360,6 +360,36 @@ bool aq_ring_tx_clean(struct aq_ring_s *self)return !!budget; } +void aq_ring_tx_deinit (struct aq_ring_s *self) +{ +if (!self) + goto err_exit; + +for (; self->sw_head != self->sw_tail; + self->sw_head =aq_ring_next_dx (self, self->sw_head)) { +struct aq_ring_buff_s *buff = &self->buff_ring[self->sw_head]; +struct device *ndev =aq_nic_get_dev (self->aq_nic); + +if (likely (buff->is_mapped)) { +if (unlikely (buff->is_sop)) { +dma_unmap_single (ndev, buff->pa, buff->len, +DMA_TO_DEVICE ); + }else { +dma_unmap_page (ndev, buff->pa, buff->len, +DMA_TO_DEVICE ); + } + } + +if (unlikely (buff->is_eop)) { +if (buff->skb) +dev_kfree_skb_any (buff->skb); +else if (buff->xdpf) +xdp_return_frame (buff->xdpf); + } + } +err_exit:; +} +static void aq_rx_checksum (struct aq_ring_s *self,struct aq_ring_buff_s *buff,struct sk_buff *skb)
drivers/net/ethernet/aquantia/atlantic/aq_ring.h +1 -0
@@ -202,6 +202,7 @@ void aq_ring_update_queue_state(struct aq_ring_s *ring);void aq_ring_queue_wake (struct aq_ring_s *ring);void aq_ring_queue_stop (struct aq_ring_s *ring);bool aq_ring_tx_clean (struct aq_ring_s *self); +void aq_ring_tx_deinit (struct aq_ring_s *self);int aq_xdp_xmit (struct net_device *dev,int num_frames,struct xdp_frame **frames,u32 flags); int aq_ring_rx_clean(struct aq_ring_s *self,
drivers/net/ethernet/aquantia/atlantic/aq_vec.c +1 -1
@@ -275,7 +275,7 @@ void aq_vec_deinit(struct aq_vec_s *self)for (i =0U ; self->tx_rings > i; ++i) { ring = self->ring[i]; -aq_ring_tx_clean (&ring[AQ_VEC_TX_ID ]); +aq_ring_tx_deinit (&ring[AQ_VEC_TX_ID ]);aq_ring_rx_deinit (&ring[AQ_VEC_RX_ID ]); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next 1/2] net: atlantic: free stranded TX buffers on ring deinit
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:
Pre-existing issues:
- [High] The patch fixes a resource leak of stranded TX buffers on interface teardown by replacing aq_ring_tx_clean() with the restored aq_ring_tx_deinit() in aq_vec_deinit(), but misses the identical leak pattern in aq_ptp_ring_deinit(). --
--- Patch [1]: [PATCH net-next 1/2] net: atlantic: free stranded TX buffers on ring deinit --- commit 0bceee292a00058408f6f3baf2ae8103a4e90f9c
Author: Yangyu Chen <[email protected]>
net: atlantic: free stranded TX buffers on ring deinit
This commit brings back aq_ring_tx_deinit() to properly drain TX rings during teardown. This prevents silent memory leaks of stranded buffers and stalls during page pool destruction when the interface goes down under TX or XDP_TX load.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_vec.c +0
-0
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_vec.c void aq_vec_deinit(struct aq_vec_s *self) · line 278
Quoted 6 lines
drivers/net/ethernet/aquantia/atlantic/aq_vec.c +1
-1@@ -275,7 +275,7 @@ void aq_vec_deinit(struct aq_vec_s *self)for (i =0U ; self->tx_rings > i; ++i) { ring = self->ring[i]; -aq_ring_tx_clean (&ring[AQ_VEC_TX_ID ]); +aq_ring_tx_deinit (&ring[AQ_VEC_TX_ID ]);
[Severity: High]
This is a pre-existing issue, but should aq_ptp_ring_deinit() also be updated to use aq_ring_tx_deinit() instead of aq_ring_tx_clean()?
In drivers/net/ethernet/aquantia/atlantic/aq_ptp.c:aq_ptp_ring_deinit():
aq_ring_tx_clean(&aq_ptp->ptp_tx); aq_ring_rx_deinit(&aq_ptp->ptp_rx);
Since aq_ring_tx_clean() stops at hw_head and applies a budget, any in-flight SKBs and their DMA mappings on the PTP TX ring might still be permanently leaked when the hardware is stopped and the interface is brought down.
Does the PTP ring teardown need the same fix applied here?
Quoted 3 lines
drivers/net/ethernet/aquantia/atlantic/aq_vec.c +0
-0aq_ring_rx_deinit (&ring[AQ_VEC_RX_ID ]); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH net-next 1/2] net: atlantic: free stranded TX buffers on ring deinit
In reply to Yangyu ChenQuoted 19 lines · Yangyu Chen
aq_vec_deinit()drains the TX rings with a singleaq_ring_tx_clean()call, which frees at mostAQ_CFG_TX_CLEAN_BUDGET(256) descriptors and stops athw_head, which no longer moves onceaq_vec_stop()has stopped the hardware and NAPI. Completed descriptors beyond the budget and everything still posted in [hw_head,sw_tail) keep their skb orxdp_framewhen the interface goes down:aq_vec_ring_free()then frees the buffer ring and the references are lost for good.Today this is a silent memory leak on every interface down under TX/XDP_TX load. With the following conversion of the RX path to
page_poolit becomes much more visible:XDP_TXframes carry fragment references on the RX ring'spage_pool, so a single stranded frame keeps the pool's inflight count above zero forever.page_pool_destroy()then never completes, the pool is leaked together with its pages, and "page_pool_release_retry()stalled pool shutdown" is warned every 60 seconds from that point on, on every ifdown, XDP detach or ring resize underXDP_TXload.
Quoted 8 lines
Bring back
aq_ring_tx_deinit()as it was before the removal and use it for teardown again, with one extension: TX rings can holdxdp_framesnowadays, so release those too. They are returned withxdp_return_frame()since this runs in process context.Fixes eb36bedf28be ("net: aquantia: remove function aq_ring_tx_deinit")Assisted-by Claude:claude-fable-5Signed-off-by Yangyu Chen <[email protected]>
Looks fine as far as I can tell, but don't you want this sent to net as a fix?
Quoted 37 lines
---
Notes:
Without this fix, converting the RX path topage_pool(next patch) turns the strandedXDP_TXframes into leakedpage_poolfragments, sopage_pool_destroy()can never drain and the shutdown stalls forever.Reproduced on an AQC100 with this patch dropped from the series (i.e.
page_poolapplied without the tx-deinit fix):# reflect received frames back out through
XDP_TX
xdp-bench tx enp99s0 # or any trivialXDP_TXprog
# from a peer on the same link, flood RX so frames are in flight, then ip link set enp99s0 downThe pool is destroyed with frames still stranded on the TX ring, and
page_pool_release_retry()warns every 60s with the same id and inflight count and a growing age, indefinitely:[161110.753385]
page_pool_release_retry()stalled pool shutdown: id 361, 12 inflight 60 sec [161171.170756]page_pool_release_retry()stalled pool shutdown: id 361, 12 inflight 120 sec [161231.588685]page_pool_release_retry()stalled pool shutdown: id 361, 12 inflight 181 sec [161292.005886]page_pool_release_retry()stalled pool shutdown: id 361, 12 inflight 241 secWith this patch the stranded buffers are freed at deinit, inflight drops to zero and the pool drains cleanly.
.../net/ethernet/aquantia/atlantic/aq_ring.c | 30 +++++++++++++++++++ .../net/ethernet/aquantia/atlantic/aq_ring.h | 1 + .../net/ethernet/aquantia/atlantic/aq_vec.c | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-)drivers/net/ethernet/aquantia/atlantic/aq_ring.c +0
-0
drivers/net/ethernet/aquantia/atlantic/aq_ring.c bool aq_ring_tx_clean(struct aq_ring_s *self) · line 366
Quoted 7 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +4
-0@@ -360,6 +360,36 @@ bool aq_ring_tx_clean(struct aq_ring_s *self)return !!budget; } +void aq_ring_tx_deinit (struct aq_ring_s *self) +{ +if (!self) + goto err_exit;
return; here and delete label?
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +4
-0+ +for (; self->sw_head != self->sw_tail; + self->sw_head =aq_ring_next_dx (self, self->sw_head)) { +struct aq_ring_buff_s *buff = &self->buff_ring[self->sw_head];
drivers/net/ethernet/aquantia/atlantic/aq_ring.c bool aq_ring_tx_clean(struct aq_ring_s *self) · line 380
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +10
-0+struct device *ndev =aq_nic_get_dev (self->aq_nic); + +if (likely (buff->is_mapped)) { +if (unlikely (buff->is_sop)) { +dma_unmap_single (ndev, buff->pa, buff->len, +DMA_TO_DEVICE ); + }else { +dma_unmap_page (ndev, buff->pa, buff->len, +DMA_TO_DEVICE ); + }
I would remove the unlikelys that seem unnecassry to me. This is a reconfig path and the unlikely is probably not improving perf.
Quoted 44 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +12
-0+ } + +if (unlikely (buff->is_eop)) { +if (buff->skb) +dev_kfree_skb_any (buff->skb); +else if (buff->xdpf) +xdp_return_frame (buff->xdpf); + } + } +err_exit:; +} +static void aq_rx_checksum (struct aq_ring_s *self,struct aq_ring_buff_s *buff,struct sk_buff *skb)drivers/net/ethernet/aquantia/atlantic/aq_ring.h +1
-0@@ -202,6 +202,7 @@ void aq_ring_update_queue_state(struct aq_ring_s *ring);void aq_ring_queue_wake (struct aq_ring_s *ring);void aq_ring_queue_stop (struct aq_ring_s *ring);bool aq_ring_tx_clean (struct aq_ring_s *self); +void aq_ring_tx_deinit (struct aq_ring_s *self);int aq_xdp_xmit (struct net_device *dev,int num_frames,struct xdp_frame **frames,u32 flags); int aq_ring_rx_clean(struct aq_ring_s *self,drivers/net/ethernet/aquantia/atlantic/aq_vec.c +1
-2@@ -275,7 +275,7 @@ void aq_vec_deinit(struct aq_vec_s *self)for (i =0U ; self->tx_rings > i; ++i) { ring = self->ring[i]; -aq_ring_tx_clean (&ring[AQ_VEC_TX_ID ]); +aq_ring_tx_deinit (&ring[AQ_VEC_TX_ID ]);aq_ring_rx_deinit (&ring[AQ_VEC_RX_ID ]); } --2.47.3
Signature · 2 lines
Thanks, Mina
Re: [PATCH net-next 1/2] net: atlantic: free stranded TX buffers on ring deinit
Quoted 75 lines · Mina Almasry
Quoted 19 lines · Yangyu Chen
aq_vec_deinit()drains the TX rings with a singleaq_ring_tx_clean()call, which frees at mostAQ_CFG_TX_CLEAN_BUDGET(256) descriptors and stops athw_head, which no longer moves onceaq_vec_stop()has stopped the hardware and NAPI. Completed descriptors beyond the budget and everything still posted in [hw_head,sw_tail) keep their skb orxdp_framewhen the interface goes down:aq_vec_ring_free()then frees the buffer ring and the references are lost for good.Today this is a silent memory leak on every interface down under TX/XDP_TX load. With the following conversion of the RX path to
page_poolit becomes much more visible:XDP_TXframes carry fragment references on the RX ring'spage_pool, so a single stranded frame keeps the pool's inflight count above zero forever.page_pool_destroy()then never completes, the pool is leaked together with its pages, and "page_pool_release_retry()stalled pool shutdown" is warned every 60 seconds from that point on, on every ifdown, XDP detach or ring resize underXDP_TXload.Quoted 8 lines
Bring back
aq_ring_tx_deinit()as it was before the removal and use it for teardown again, with one extension: TX rings can holdxdp_framesnowadays, so release those too. They are returned withxdp_return_frame()since this runs in process context.Fixes eb36bedf28be ("net: aquantia: remove function aq_ring_tx_deinit")Assisted-by Claude:claude-fable-5Signed-off-by Yangyu Chen <[email protected]>Looks fine as far as I can tell, but don't you want this sent to net as a fix?
Quoted 40 lines
---
Notes:
Without this fix, converting the RX path topage_pool(next patch) turns the strandedXDP_TXframes into leakedpage_poolfragments, sopage_pool_destroy()can never drain and the shutdown stalls forever.Reproduced on an AQC100 with this patch dropped from the series (i.e.
page_poolapplied without the tx-deinit fix):# reflect received frames back out through XDP_TX xdp-bench tx enp99s0 # or any trivial XDP_TX prog # from a peer on the same link, flood RX so frames are in flight, then ip link set enp99s0 downThe pool is destroyed with frames still stranded on the TX ring, and
page_pool_release_retry()warns every 60s with the same id and inflight count and a growing age, indefinitely:[161110.753385] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 60 sec [161171.170756] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 120 sec [161231.588685] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 181 sec [161292.005886] page_pool_release_retry() stalled pool shutdown: id 361, 12 inflight 241 secWith this patch the stranded buffers are freed at deinit, inflight drops to zero and the pool drains cleanly.
.../net/ethernet/aquantia/atlantic/aq_ring.c | 30 +++++++++++++++++++ .../net/ethernet/aquantia/atlantic/aq_ring.h | 1 + .../net/ethernet/aquantia/atlantic/aq_vec.c | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-)drivers/net/ethernet/aquantia/atlantic/aq_ring.c +0
-0@@ -360,6 +360,36 @@ bool aq_ring_tx_clean(struct aq_ring_s *self)return !!budget; }
Quoted 6 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c bool aq_ring_tx_clean(struct aq_ring_s *self) · line 366
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +4
-0+void aq_ring_tx_deinit (struct aq_ring_s *self) +{ +if (!self) + goto err_exit;return; here and delete label?
Maybe I can change it in the next revision.I would this fixes to be more like a revert of commit eb36bedf28be ("net: aquantia: remove function aq_ring_tx_deinit"), so I would
like to keep that.
Maybe I can change it in the next revision.
Thanks,
Yangyu Chen
Quoted 68 lines
Quoted 5 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +4
-0+ +for (; self->sw_head != self->sw_tail; + self->sw_head =aq_ring_next_dx (self, self->sw_head)) { +struct aq_ring_buff_s *buff = &self->buff_ring[self->sw_head];drivers/net/ethernet/aquantia/atlantic/aq_ring.c bool aq_ring_tx_clean(struct aq_ring_s *self) · line 380
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +10
-0+struct device *ndev =aq_nic_get_dev (self->aq_nic); + +if (likely (buff->is_mapped)) { +if (unlikely (buff->is_sop)) { +dma_unmap_single (ndev, buff->pa, buff->len, +DMA_TO_DEVICE ); + }else { +dma_unmap_page (ndev, buff->pa, buff->len, +DMA_TO_DEVICE ); + }I would remove the unlikelys that seem unnecassry to me. This is a reconfig path and the unlikely is probably not improving perf.
Quoted 44 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +12
-0+ } + +if (unlikely (buff->is_eop)) { +if (buff->skb) +dev_kfree_skb_any (buff->skb); +else if (buff->xdpf) +xdp_return_frame (buff->xdpf); + } + } +err_exit:; +} +static void aq_rx_checksum (struct aq_ring_s *self,struct aq_ring_buff_s *buff,struct sk_buff *skb)drivers/net/ethernet/aquantia/atlantic/aq_ring.h +1
-0@@ -202,6 +202,7 @@ void aq_ring_update_queue_state(struct aq_ring_s *ring);void aq_ring_queue_wake (struct aq_ring_s *ring);void aq_ring_queue_stop (struct aq_ring_s *ring);bool aq_ring_tx_clean (struct aq_ring_s *self); +void aq_ring_tx_deinit (struct aq_ring_s *self);int aq_xdp_xmit (struct net_device *dev,int num_frames,struct xdp_frame **frames,u32 flags); int aq_ring_rx_clean(struct aq_ring_s *self,drivers/net/ethernet/aquantia/atlantic/aq_vec.c +1
-2@@ -275,7 +275,7 @@ void aq_vec_deinit(struct aq_vec_s *self)for (i =0U ; self->tx_rings > i; ++i) { ring = self->ring[i]; -aq_ring_tx_clean (&ring[AQ_VEC_TX_ID ]); +aq_ring_tx_deinit (&ring[AQ_VEC_TX_ID ]);aq_ring_rx_deinit (&ring[AQ_VEC_RX_ID ]); } --2.47.3
Signature · 2 lines
Thanks, Mina
PATCH 2/2 net: atlantic: convert RX path to page_pool
In reply to Yangyu ChenThe driver currently allocates RX buffers with dev_alloc_pages(), maps them with dma_map_page(), and uses a hand-rolled page-flip scheme to subdivide high-order pages. Behind an IOMMU, the map/unmap churn is a major RX cost: on a Thunderbolt-attached QNAP QNA-T310G1S, iperf3 -R over IPv6 tops out at about 2.2 Gbit/s over MTU 1500.
Convert RX buffers to page_pool fragments. Pages are DMA-mapped once when entering the pool and recycled through the stack or XDP via the MEM_TYPE_PAGE_POOL memory model. This removes the custom page-flip accounting, lets page_pool handle fragment reuse, and ensures every RX path either keeps the ring's fragment reference for reposting or hands it to the skb/xdp_buff for later recycling.
Register the PTP RX ring's xdp_rxq as well, since it shares the RX clean paths. Walk the full RX ring during deinit so consumed but not yet refilled slots cannot leak page-pool references. Drop the ethtool PageFlips/PageReuses/PageFrees counters which only described the old scheme.
On the QNA-T310G1S, MTU 1500, TCP over IPv6, iperf3 -R improves from 2.24 Gbit/s to 9.14 Gbit/s. The module was also smoke-tested with native XDP PASS, DROP, and ABORTED actions; carrier recovered after each attach/detach cycle and dmesg showed no page_pool/DMA warnings.
--- drivers/net/ethernet/aquantia/Kconfig | 1 + .../ethernet/aquantia/atlantic/aq_ethtool.c | 3 - .../net/ethernet/aquantia/atlantic/aq_ptp.c | 20 +- .../net/ethernet/aquantia/atlantic/aq_ring.c | 238 ++++++++---------- .../net/ethernet/aquantia/atlantic/aq_ring.h | 6 +- .../net/ethernet/aquantia/atlantic/aq_vec.c | 15 +- 6 files changed, 140 insertions(+), 143 deletions(-)
drivers/net/ethernet/aquantia/Kconfig +1 -0
@@ -20,6 +20,7 @@ config AQTION tristate "aQuantia AQtion(tm) Support" depends on PCI depends on MACSEC || MACSEC=n + select PAGE_POOL help This enables the support for the aQuantia AQtion(tm) Ethernet card.
drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c +0 -3
@@ -100,9 +100,6 @@ static const char * const aq_ethtool_queue_rx_stat_names[] = {"%sQueue[%d] AllocFails" ,"%sQueue[%d] SkbAllocFails" ,"%sQueue[%d] Polls" , -"%sQueue[%d] PageFlips" , -"%sQueue[%d] PageReuses" , -"%sQueue[%d] PageFrees" ,"%sQueue[%d] XdpAbort" ,"%sQueue[%d] XdpDrop" , "%sQueue[%d] XdpPass",
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +19 -1
@@ -13,6 +13,7 @@#include <linux/ptp_classify.h> #include <linux/interrupt.h> #include <linux/clocksource.h> +#include <net/xdp.h> #include "aq_nic.h" #include "aq_ptp.h"
@@ -1192,12 +1193,25 @@ int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic)if (err) goto err_exit_ptp_tx; + err =xdp_rxq_info_reg (&aq_ptp->ptp_rx.xdp_rxq, aq_nic->ndev, + rx_ring_idx, aq_ptp->napi.napi_id); +if (err <0 ) + goto err_exit_ptp_rx; + + err =xdp_rxq_info_reg_mem_model (&aq_ptp->ptp_rx.xdp_rxq, +MEM_TYPE_PAGE_POOL , + aq_ptp->ptp_rx.pg_pool); +if (err <0 ) { +xdp_rxq_info_unreg (&aq_ptp->ptp_rx.xdp_rxq); + goto err_exit_ptp_rx; + } +if (aq_ptp->a1_ptp) { err =aq_ring_hwts_rx_alloc (&aq_ptp->hwts_rx, aq_nic,PTP_HWST_RING_IDX , aq_nic->aq_nic_cfg.rxds, aq_nic->aq_nic_cfg.aq_hw_caps->rxd_size);if (err) - goto err_exit_ptp_rx; + goto err_exit_xdp_rxq; } err =aq_ptp_skb_ring_init (&aq_ptp->skb_ring, aq_nic->aq_nic_cfg.rxds);
@@ -1217,6 +1231,8 @@ int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic) err_exit_hwts_rx:if (aq_ptp->a1_ptp)aq_ring_hwts_rx_free (&aq_ptp->hwts_rx); +err_exit_xdp_rxq: +xdp_rxq_info_unreg (&aq_ptp->ptp_rx.xdp_rxq); err_exit_ptp_rx:aq_ring_free (&aq_ptp->ptp_rx); err_exit_ptp_tx:
@@ -1233,6 +1249,8 @@ void aq_ptp_ring_free(struct aq_nic_s *aq_nic)return ;aq_ring_free (&aq_ptp->ptp_tx); +if (xdp_rxq_info_is_reg (&aq_ptp->ptp_rx.xdp_rxq)) +xdp_rxq_info_unreg (&aq_ptp->ptp_rx.xdp_rxq);aq_ring_free (&aq_ptp->ptp_rx);if (aq_ptp->a1_ptp)aq_ring_hwts_rx_free (&aq_ptp->hwts_rx);
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +110 -128
387 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_ring.h +2 -4
@@ -17,12 +17,12 @@#define AQ_XDP_TAILROOM SKB_DATA_ALIGN(sizeof(struct skb_shared_info))struct page ; +struct page_pool ;struct aq_nic_cfg_s ;struct aq_rxpage {struct page *page;dma_addr_t daddr; -unsigned int order;unsigned int pg_off; };
@@ -105,9 +105,6 @@ struct aq_ring_stats_rx_s {u64 alloc_fails;u64 skb_alloc_fails;u64 polls; -u64 pg_losts; -u64 pg_flips; -u64 pg_reuses;u64 xdp_aborted;u64 xdp_drop;u64 xdp_pass;
@@ -151,6 +148,7 @@ struct aq_ring_s {u16 tail_size;union aq_ring_stats_s stats;dma_addr_t dx_ring_pa; +struct page_pool *pg_pool;struct bpf_prog *xdp_prog;enum atl_ring_type ring_type;struct xdp_rxq_info xdp_rxq;
drivers/net/ethernet/aquantia/atlantic/aq_vec.c +8 -7
@@ -146,25 +146,26 @@ int aq_vec_ring_alloc(struct aq_vec_s *self, struct aq_nic_s *aq_nic,aq_nic_set_tx_ring (aq_nic, idx_ring, ring); ring = &self->ring[i][AQ_VEC_RX_ID ]; + err =aq_ring_rx_alloc (ring, aq_nic, idx_ring, aq_nic_cfg); +if (err) + goto err_exit; +if (xdp_rxq_info_reg (&ring->xdp_rxq, aq_nic->ndev, idx, self->napi.napi_id) <0 ) { +aq_ring_free (ring); err = -ENOMEM ; goto err_exit; }if (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, -MEM_TYPE_PAGE_SHARED ,NULL ) <0 ) { +MEM_TYPE_PAGE_POOL , + ring->pg_pool) <0 ) {xdp_rxq_info_unreg (&ring->xdp_rxq); +aq_ring_free (ring); err = -ENOMEM ; goto err_exit; } - err =aq_ring_rx_alloc (ring, aq_nic, idx_ring, aq_nic_cfg); -if (err) { -xdp_rxq_info_unreg (&ring->xdp_rxq); - goto err_exit; - } - ++self->rx_rings; }
Signature · 1 line
2.47.3
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [Critical] Uninitialized physical addresses cause severe DMA memory corruption during RX buffer refill.
Pre-existing issues:
- [High] The ndo_xdp_xmit callback violates API contract by not repacking arrays on failure, causing UAF and memory leaks.
- [High] Malformed RX packets exceeding MAX_SKB_FRAGS cause a permanent infinite NAPI polling loop.
- [High] Aborting XDP assembly on oversized packets leaves trailing fragments uncleaned, leading to packet injection.
- [High] Updating u64_stats without disabling preemption causes a system livelock on 32-bit architectures. --
--- Patch [2]: [PATCH net-next 2/2] net: atlantic: convert RX path to page_pool --- commit d3fa6dc4118e01fdb55de72ea89c2b574594ac08
Author: Yangyu Chen <[email protected]>
net: atlantic: convert RX path to page_pool
This commit converts the atlantic driver's RX path to use page_pool for fragment management to reduce DMA map/unmap overhead. It also registers the PTP RX ring's xdp_rxq and cleans up deprecated ethtool counters.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +0
-0
[ ... ]
Quoted 104 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +9
-91-static int aq_get_rxpages (struct aq_ring_s *self,struct aq_ring_buff_s *rxbuf) +static int aq_get_rxpages (struct aq_ring_s *self,struct aq_ring_buff_s *rxbuf) { -unsigned int order = self->page_order; -u16 page_offset = self->page_offset; -u16 frame_max = self->frame_max; -u16 tail_size = self->tail_size; -int ret; - -if (rxbuf->rxdata.page) { -/* One means ring is the only user and can reuse */ -if (page_ref_count (rxbuf->rxdata.page) >1 ) { -/* Try reuse buffer */ - rxbuf->rxdata.pg_off += frame_max + page_offset + - tail_size; -if (rxbuf->rxdata.pg_off + frame_max + tail_size <= - (PAGE_SIZE << order)) { -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_flips++; -u64_stats_update_end (&self->stats.rx.syncp); - - }else { -/* Buffer exhausted. We have other users and -* should release this page and realloc -*/ -aq_free_rxpage (&rxbuf->rxdata, -aq_nic_get_dev (self->aq_nic)); -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_losts++; -u64_stats_update_end (&self->stats.rx.syncp); - } - }else { - rxbuf->rxdata.pg_off = page_offset; -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_reuses++; -u64_stats_update_end (&self->stats.rx.syncp); - } +unsigned int size = self->page_offset + self->frame_max + + self->tail_size; +unsigned int pg_off;struct page *page; -int ret = -ENOMEM ; -dma_addr_t daddr; - - page =dev_alloc_pages (order); -if (unlikely (!page)) - goto err_exit; - daddr =dma_map_page (dev, page,0 ,PAGE_SIZE << order, -DMA_FROM_DEVICE ); +/* Buffers whose page was not passed up the stack are reposted +* with the data they already carry discarded. +*/ +if (rxbuf->rxdata.page) +return 0 ; -if (unlikely (dma_mapping_error (dev, daddr))) - goto free_page; - - rxpage->page = page; - rxpage->daddr = daddr; - rxpage->order = order; - rxpage->pg_off = rx_ring->page_offset; - -return 0 ; - -free_page: -__free_pages (page, order); - -err_exit: -return ret; -} - -static int aq_get_rxpages (struct aq_ring_s *self,struct aq_ring_buff_s *rxbuf) -{ -unsigned int order = self->page_order; -u16 page_offset = self->page_offset; -u16 frame_max = self->frame_max; -u16 tail_size = self->tail_size; -int ret; - -if (rxbuf->rxdata.page) { -/* One means ring is the only user and can reuse */ -if (page_ref_count (rxbuf->rxdata.page) >1 ) { -/* Try reuse buffer */ - rxbuf->rxdata.pg_off += frame_max + page_offset + - tail_size; -if (rxbuf->rxdata.pg_off + frame_max + tail_size <= - (PAGE_SIZE << order)) { -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_flips++; -u64_stats_update_end (&self->stats.rx.syncp); - - }else { -/* Buffer exhausted. We have other users and -* should release this page and realloc -*/ -aq_free_rxpage (&rxbuf->rxdata, -aq_nic_get_dev (self->aq_nic)); -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_losts++; -u64_stats_update_end (&self->stats.rx.syncp); - } - }else {
drivers/net/ethernet/aquantia/atlantic/aq_ring.c
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +5
-5- rxbuf->rxdata.pg_off = page_offset; -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_reuses++; -u64_stats_update_end (&self->stats.rx.syncp); - } + page =page_pool_dev_alloc_frag (self->pg_pool, &pg_off, size); +if (unlikely (!page)) { +u64_stats_update_begin (&self->stats.rx.syncp); + self->stats.rx.alloc_fails++; +u64_stats_update_end (&self->stats.rx.syncp);
[Severity: High]
This is a pre-existing issue, but can this cause a system livelock on 32-bit architectures?
The u64_stats_update_begin() function is called here in process context (e.g., during aq_ring_rx_fill() via aq_vec_start()) without disabling preemption.
If a writer is preempted by a reader (such as ndo_get_stats64() invoked from a different CPU), the reader will spin forever in the u64_stats_fetch_retry() loop on 32-bit systems because the sequence counter will never become even.
Quoted 5 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +2
-2+return -ENOMEM ; + } -if (!rxbuf->rxdata.page) { - ret =aq_alloc_rxpages (&rxbuf->rxdata, self);
drivers/net/ethernet/aquantia/atlantic/aq_ring.c line 47
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +3
-7-if (ret) { -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.alloc_fails++; -u64_stats_update_end (&self->stats.rx.syncp); - } -return ret; - } + rxbuf->rxdata.page = page; + rxbuf->rxdata.daddr =page_pool_get_dma_addr (page); + rxbuf->rxdata.pg_off = pg_off + self->page_offset;
[Severity: Critical]
Can this cause severe DMA memory corruption during RX buffer refill?
The initialization of buff->pa appears to be missing or was removed here, but the hardware callback still executes immediately after and unconditionally overwrites the descriptor's physical address:
hw_atl_b0_hw_ring_rx_fill() {
...
rxd->buf_addr = buff->pa;
rxd->hdr_addr = 0U;
...
}Because buff->pa is no longer initialized for RX, it contains garbage from the previous packet (specifically rss_hash and next, due to the union in the aq_ring_buff_s struct).
This programs the NIC with arbitrary physical addresses, causing it to DMA incoming network packets into random physical memory.
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_ring.c int aq_xdp_xmit(struct net_device *dev, int num_frames, · line 380
Quoted 2 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +0
-0@@ -438,22 +380,15 @@ int aq_xdp_xmit(struct net_device *dev, int num_frames, }
[Severity: High]
This is a pre-existing issue, but does the error handling in aq_xdp_xmit() violate the ndo_xdp_xmit API contract?
When transmitting a batch of XDP frames, if a frame in the middle fails (returning NETDEV_TX_BUSY), the function increments a drop counter and returns num_frames - drop:
aq_xdp_xmit() {
...
if (aq_nic_xmit_xdpf(aq_nic, ring, xdpf) == NETDEV_TX_BUSY)
drop++;
...
return num_frames - drop;
}The loop drops frames but does not repack the frames array. The network stack (e.g., devmap) assumes that a partial success count N means the first N frames succeeded and the rest failed.
It will free the frames at the end of the array, some of which were actually successfully queued for transmission by the driver. This leads to freeing memory that the NIC is actively trying to DMA, while leaking the memory of the frame that actually failed.
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_ring.c static bool aq_add_rx_fragment(struct device *dev, · line 496
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +3
-1@@ -547,8 +490,11 @@ static bool aq_add_rx_fragment(struct device *dev, do { skb_frag_t *frag; - if (unlikely(sinfo->nr_frags >= MAX_SKB_FRAGS)) + if (unlikely(sinfo->nr_frags >= MAX_SKB_FRAGS)) { + /* Attached frags must reach xdp_return_buff() */ + xdp_buff_set_frags_flag(xdp); return true;
[Severity: High]
This is a pre-existing issue, but does aborting XDP assembly on oversized packets leave trailing fragments uncleaned?
When an RX packet exceeds MAX_SKB_FRAGS during XDP processing, this early return aborts but fails to set buff_->is_cleaned = 1 for the remaining descriptors of the malformed packet.
The outer loop in __aq_ring_xdp_clean() handles the abort by advancing sw_head by 1. Because the trailing fragments were never marked as cleaned, subsequent iterations of the loop will encounter them and incorrectly parse them as the Start-Of-Packet (SOP) for new frames.
This forces the driver to interpret raw middle-of-packet payload data as Ethernet/IP headers, leading to arbitrary packet injection.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +1
-0+ } frag = &sinfo->frags[sinfo->nr_frags++]; buff_ = &ring->buff_ring[buff_->next];
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_ring.c static int __aq_ring_rx_clean(struct aq_ring_s *self, struct napi_struct *napi, · line 629
Quoted 5 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +1
-0@@ -675,6 +626,7 @@ static int __aq_ring_rx_clean(struct aq_ring_s *self, struct napi_struct *napi, err = -ENOMEM ; goto err_exit; } +skb_mark_for_recycle (skb);
[Severity: High]
This is a pre-existing issue, but does the bailout logic in __aq_ring_rx_clean() create an unrecoverable infinite loop?
If a remote attacker sends a highly fragmented or malformed packet that spans more than MAX_SKB_FRAGS descriptors, the driver detects this and jumps to err_exit:
__aq_ring_rx_clean() {
...
if (unlikely(!is_rsc_completed) || frag_cnt > MAX_SKB_FRAGS) {
err = 0;
goto err_exit;
}
...
}Because it bails out without advancing the sw_head ring pointer or dropping the packet, the driver will process the exact same malformed packet on the next NAPI poll, hit the exact same condition, and bail out again.
This creates a permanent infinite loop in softirq context, leading to a complete denial of service for the CPU core processing RX queues.
Quoted 3 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +0
-0if (is_ptp_ring) buff->len -= aq_ptp_extract_ts(self->aq_nic, skb_hwtstamps(skb),
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Paolo Abeni
maintainerQuoted 23 lines · On 7/10/26 7:38 PM, [email protected] wrote:
Quoted 5 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +2
-2+return -ENOMEM ; + } -if (!rxbuf->rxdata.page) { - ret =aq_alloc_rxpages (&rxbuf->rxdata, self);drivers/net/ethernet/aquantia/atlantic/aq_ring.c line 47
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +3
-7-if (ret) { -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.alloc_fails++; -u64_stats_update_end (&self->stats.rx.syncp); - } -return ret; - } + rxbuf->rxdata.page = page; + rxbuf->rxdata.daddr =page_pool_get_dma_addr (page); + rxbuf->rxdata.pg_off = pg_off + self->page_offset;[Severity: Critical]
Can this cause severe DMA memory corruption during RX buffer refill?The initialization of
buff->paappears to be missing or was removed here, but the hardware callback still executes immediately after and unconditionally overwrites the descriptor's physical address:
Quoted 6 lines
hw_atl_b0_hw_ring_rx_fill() {
...
rxd->buf_addr = buff->pa;
rxd->hdr_addr = 0U;
...
}FTR, AFAICS the above is AI sloop (and quite an unexpected one!) as buff->pa is actually always initialized by:
buff->pa = aq_buf_daddr(&buff->rxdata);
that comes after the aq_get_rxpages() call. All other issues are pre-existing ones.
/P
Quoted 79 lines · Yangyu Chen
The driver currently allocates RX buffers with
dev_alloc_pages(), maps them withdma_map_page(), and uses a hand-rolled page-flip scheme to subdivide high-order pages. Behind an IOMMU, the map/unmap churn is a major RX cost: on a Thunderbolt-attached QNAP QNA-T310G1S, iperf3 -R over IPv6 tops out at about 2.2 Gbit/s over MTU 1500.Convert RX buffers to
page_poolfragments. Pages are DMA-mapped once when entering the pool and recycled through the stack or XDP via theMEM_TYPE_PAGE_POOLmemory model. This removes the custom page-flip accounting, letspage_poolhandle fragment reuse, and ensures every RX path either keeps the ring's fragment reference for reposting or hands it to the skb/xdp_buff for later recycling.Register the PTP RX ring's
xdp_rxqas well, since it shares the RX clean paths. Walk the full RX ring during deinit so consumed but not yet refilled slots cannot leak page-pool references. Drop the ethtool PageFlips/PageReuses/PageFrees counters which only described the old scheme.On the QNA-T310G1S, MTU 1500, TCP over IPv6, iperf3 -R improves from 2.24 Gbit/s to 9.14 Gbit/s. The module was also smoke-tested with native XDP PASS, DROP, and ABORTED actions; carrier recovered after each attach/detach cycle and dmesg showed no page_pool/DMA warnings.
Assisted-by Claude:claude-fable-5Signed-off-by Yangyu Chen <[email protected]>--- drivers/net/ethernet/aquantia/Kconfig | 1 + .../ethernet/aquantia/atlantic/aq_ethtool.c | 3 - .../net/ethernet/aquantia/atlantic/aq_ptp.c | 20 +- .../net/ethernet/aquantia/atlantic/aq_ring.c | 238 ++++++++---------- .../net/ethernet/aquantia/atlantic/aq_ring.h | 6 +- .../net/ethernet/aquantia/atlantic/aq_vec.c | 15 +- 6 files changed, 140 insertions(+), 143 deletions(-)drivers/net/ethernet/aquantia/Kconfig +1
-0@@ -20,6 +20,7 @@ config AQTION tristate "aQuantia AQtion(tm) Support" depends on PCI depends on MACSEC || MACSEC=n + select PAGE_POOL help This enables the support for the aQuantia AQtion(tm) Ethernet card.drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c +0
-3@@ -100,9 +100,6 @@ static const char * const aq_ethtool_queue_rx_stat_names[] = {"%sQueue[%d] AllocFails" ,"%sQueue[%d] SkbAllocFails" ,"%sQueue[%d] Polls" , -"%sQueue[%d] PageFlips" , -"%sQueue[%d] PageReuses" , -"%sQueue[%d] PageFrees" ,"%sQueue[%d] XdpAbort" ,"%sQueue[%d] XdpDrop" , "%sQueue[%d] XdpPass",drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +2
-0@@ -13,6 +13,7 @@#include <linux/ptp_classify.h> #include <linux/interrupt.h> #include <linux/clocksource.h> +#include <net/xdp.h> #include "aq_nic.h" #include "aq_ptp.h" @@ -1192,12 +1193,25 @@ int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic)if (err) goto err_exit_ptp_tx; + err = xdp_rxq_info_reg(&aq_ptp->ptp_rx.xdp_rxq, aq_nic->ndev,
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic) · line 1206
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +10
-0+ rx_ring_idx, aq_ptp->napi.napi_id); +if (err <0 ) + goto err_exit_ptp_rx; + + err =xdp_rxq_info_reg_mem_model (&aq_ptp->ptp_rx.xdp_rxq, +MEM_TYPE_PAGE_POOL , + aq_ptp->ptp_rx.pg_pool); +if (err <0 ) { +xdp_rxq_info_unreg (&aq_ptp->ptp_rx.xdp_rxq); + goto err_exit_ptp_rx;
Why do it like this? Why not goto err_exit_xdp_rxq; which will do the same thing?
Quoted 164 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +7
-1+ } +if (aq_ptp->a1_ptp) { err =aq_ring_hwts_rx_alloc (&aq_ptp->hwts_rx, aq_nic,PTP_HWST_RING_IDX , aq_nic->aq_nic_cfg.rxds, aq_nic->aq_nic_cfg.aq_hw_caps->rxd_size);if (err) - goto err_exit_ptp_rx; + goto err_exit_xdp_rxq; } err =aq_ptp_skb_ring_init (&aq_ptp->skb_ring, aq_nic->aq_nic_cfg.rxds);@@ -1217,6 +1231,8 @@ int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic) err_exit_hwts_rx:if (aq_ptp->a1_ptp)aq_ring_hwts_rx_free (&aq_ptp->hwts_rx); +err_exit_xdp_rxq: +xdp_rxq_info_unreg (&aq_ptp->ptp_rx.xdp_rxq); err_exit_ptp_rx:aq_ring_free (&aq_ptp->ptp_rx); err_exit_ptp_tx:@@ -1233,6 +1249,8 @@ void aq_ptp_ring_free(struct aq_nic_s *aq_nic)return ;aq_ring_free (&aq_ptp->ptp_tx); +if (xdp_rxq_info_is_reg (&aq_ptp->ptp_rx.xdp_rxq)) +xdp_rxq_info_unreg (&aq_ptp->ptp_rx.xdp_rxq);aq_ring_free (&aq_ptp->ptp_rx);if (aq_ptp->a1_ptp)aq_ring_hwts_rx_free (&aq_ptp->hwts_rx);drivers/net/ethernet/aquantia/atlantic/aq_ring.c +16
-98@@ -14,120 +14,37 @@#include "aq_vec.h" #include "aq_main.h" +#include <net/page_pool/helpers.h> #include <net/xdp.h> #include <linux/filter.h> #include <linux/bpf_trace.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> -static void aq_get_rxpages_xdp (struct aq_ring_buff_s *buff, -struct xdp_buff *xdp) -{ -struct skb_shared_info *sinfo; -int i; - -if (xdp_buff_has_frags (xdp)) { - sinfo =xdp_get_shared_info_from_buff (xdp); - -for (i =0 ; i < sinfo->nr_frags; i++) { -skb_frag_t *frag = &sinfo->frags[i]; - -page_ref_inc (skb_frag_page (frag)); - } - } -page_ref_inc (buff->rxdata.page); -} - -static inline void aq_free_rxpage (struct aq_rxpage *rxpage,struct device *dev) -{ -unsigned int len =PAGE_SIZE << rxpage->order; - -dma_unmap_page (dev, rxpage->daddr, len,DMA_FROM_DEVICE ); - -/* Drop the ref for being in the ring. */ -__free_pages (rxpage->page, rxpage->order); - rxpage->page =NULL ; -} - -static int aq_alloc_rxpages (struct aq_rxpage *rxpage,struct aq_ring_s *rx_ring) +static int aq_get_rxpages (struct aq_ring_s *self,struct aq_ring_buff_s *rxbuf) { -struct device *dev =aq_nic_get_dev (rx_ring->aq_nic); -unsigned int order = rx_ring->page_order; +unsigned int size = self->page_offset + self->frame_max + + self->tail_size; +unsigned int pg_off;struct page *page; -int ret = -ENOMEM ; -dma_addr_t daddr; - - page =dev_alloc_pages (order); -if (unlikely (!page)) - goto err_exit; - daddr =dma_map_page (dev, page,0 ,PAGE_SIZE << order, -DMA_FROM_DEVICE ); +/* Buffers whose page was not passed up the stack are reposted +* with the data they already carry discarded. +*/ +if (rxbuf->rxdata.page) +return 0 ; -if (unlikely (dma_mapping_error (dev, daddr))) - goto free_page; - - rxpage->page = page; - rxpage->daddr = daddr; - rxpage->order = order; - rxpage->pg_off = rx_ring->page_offset; - -return 0 ; - -free_page: -__free_pages (page, order); - -err_exit: -return ret; -} - -static int aq_get_rxpages (struct aq_ring_s *self,struct aq_ring_buff_s *rxbuf) -{ -unsigned int order = self->page_order; -u16 page_offset = self->page_offset; -u16 frame_max = self->frame_max; -u16 tail_size = self->tail_size; -int ret; - -if (rxbuf->rxdata.page) { -/* One means ring is the only user and can reuse */ -if (page_ref_count (rxbuf->rxdata.page) >1 ) { -/* Try reuse buffer */ - rxbuf->rxdata.pg_off += frame_max + page_offset + - tail_size; -if (rxbuf->rxdata.pg_off + frame_max + tail_size <= - (PAGE_SIZE << order)) { -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_flips++; -u64_stats_update_end (&self->stats.rx.syncp); - - }else { -/* Buffer exhausted. We have other users and -* should release this page and realloc -*/ -aq_free_rxpage (&rxbuf->rxdata, -aq_nic_get_dev (self->aq_nic)); -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_losts++; -u64_stats_update_end (&self->stats.rx.syncp); - } - }else { - rxbuf->rxdata.pg_off = page_offset; -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.pg_reuses++; -u64_stats_update_end (&self->stats.rx.syncp); - } + page =page_pool_dev_alloc_frag (self->pg_pool, &pg_off, size); +if (unlikely (!page)) { +u64_stats_update_begin (&self->stats.rx.syncp); + self->stats.rx.alloc_fails++; +u64_stats_update_end (&self->stats.rx.syncp); +return -ENOMEM ; } -if (!rxbuf->rxdata.page) { - ret =aq_alloc_rxpages (&rxbuf->rxdata, self); -if (ret) { -u64_stats_update_begin (&self->stats.rx.syncp); - self->stats.rx.alloc_fails++;
drivers/net/ethernet/aquantia/atlantic/aq_ring.c line 50
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +3
-4-u64_stats_update_end (&self->stats.rx.syncp); - } -return ret; - } + rxbuf->rxdata.page = page; + rxbuf->rxdata.daddr =page_pool_get_dma_addr (page); + rxbuf->rxdata.pg_off = pg_off + self->page_offset;return 0 ; }
The LLM thinks this code is perfect :-), but any chance you can pretty up the diff above a bit so it's more easily human reviewable? Maybe keep the function names the same or factor the renames into another patch or something? Right now it looks like completely deleted code and new added.
Signature · 2 lines
Thanks, Mina
Jakub Kicinski
maintainerQuoted 1 line · On Fri, 10 Jul 2026 01:36:44 +0800 Yangyu Chen wrote:
Subject: [PATCH net-next 0/2] net: atlantic: convert RX path to
page_pool
Sukhdeep, please review.
Sukhdeep Soni [C]
maintainerQuoted 2 lines · Jakub Kicinski
Subject: [PATCH net-next 0/2] net: atlantic: convert RX path to
page_poolSukhdeep, please review.
Sorry for the delay, I was caught up with other work. I'll review the patches and reply shortly.