* [PATCH net v8 1/4] net: stmmac: honor allocation flags when initializing RX buffers
2026-11-19 14:08 [PATCH net v8 0/4] net: stmmac: fix RX descriptors and XSK TX on resume Ding Hui
@ 2026-11-19 14:08 ` Ding Hui
2026-11-19 14:08 ` [PATCH net v8 2/4] net: stmmac: track unfilled XSK RX descriptors explicitly Ding Hui
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Ding Hui @ 2026-11-19 14:08 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
open list:STMMAC ETHERNET DRIVER,
moderated list:ARM/STM32 ARCHITECTURE,
moderated list:ARM/STM32 ARCHITECTURE, open list
Cc: dinghui, xiasanbo, yangchen11, liuxuanjun, fujiahui, zhoujing3
From: Ding Hui <dinghui@lixiang.com>
stmmac_init_rx_buffers() accepts allocation flags but stopped using them
when RX buffers were converted to page_pool. As a result, callers passing
GFP_KERNEL still allocate with GFP_ATOMIC | __GFP_NOWARN and cannot use
reclaim to satisfy an allocation.
Use the supplied flags while retaining GFP_DMA32 for hardware without
64-bit DMA addressing. This also allows the resume path to allocate
missing RX pages with GFP_KERNEL.
Fixes: 2af6106ae949 ("net: stmmac: Introducing support for Page Pool")
Signed-off-by: Ding Hui <dinghui@lixiang.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 25894771e9e9..8bd244046195 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1689,7 +1689,7 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv,
{
struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
- gfp_t gfp = (GFP_ATOMIC | __GFP_NOWARN);
+ gfp_t gfp = flags;
if (priv->dma_cap.host_dma_width <= 32)
gfp |= GFP_DMA32;
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH net v8 2/4] net: stmmac: track unfilled XSK RX descriptors explicitly
2026-11-19 14:08 [PATCH net v8 0/4] net: stmmac: fix RX descriptors and XSK TX on resume Ding Hui
2026-11-19 14:08 ` [PATCH net v8 1/4] net: stmmac: honor allocation flags when initializing RX buffers Ding Hui
@ 2026-11-19 14:08 ` Ding Hui
2026-11-23 14:39 ` netdev-bot+sashiko
2026-11-19 14:08 ` [PATCH net v8 3/4] net: stmmac: restore RX descriptor buffer addresses on resume Ding Hui
2026-11-19 14:09 ` [PATCH net v8 4/4] net: stmmac: restore the XSK TX pool " Ding Hui
3 siblings, 1 reply; 8+ messages in thread
From: Ding Hui @ 2026-11-19 14:08 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
open list:STMMAC ETHERNET DRIVER,
moderated list:ARM/STM32 ARCHITECTURE,
moderated list:ARM/STM32 ARCHITECTURE, open list
Cc: dinghui, xiasanbo, yangchen11, liuxuanjun, fujiahui, zhoujing3
From: Ding Hui <dinghui@lixiang.com>
An XSK fill ring may supply fewer buffers than the RX ring needs. Those
unfilled descriptors must remain CPU-owned, including on legacy cores
whose clear callback only clears the buffer address. Add an ownership
operation that preserves descriptor size and ring/chain control fields.
Track the number of descriptors awaiting refill independently of the
ring indices, so an entirely empty ring can be distinguished from one
with no pending refills. Initialize the pending region after the allocated
prefix and stop consumption before entering it. Retry pending refills
on each poll, including userspace wakeups with fewer than a batch of
buffers, and retain batching during packet processing.
Update the tail after successful refills and kick legacy RX DMA. Use the
end-of-ring tail address for a refill ending at index zero, including a
completely empty ring populated before DMA has advanced from the base.
Select the receive buffer size from the XSK pool even if no buffers were
available at initialization.
Define the RX OWN masks as u32 before complementing them, following the
existing TX OWN mask convention. This avoids sparse truncation warnings
in the ownership-clearing callbacks on 64-bit builds.
Fixes: bba2556efad6 ("net: stmmac: Enable RX via AF_XDP zero-copy")
Signed-off-by: Ding Hui <dinghui@lixiang.com>
---
drivers/net/ethernet/stmicro/stmmac/descs.h | 4 +-
.../ethernet/stmicro/stmmac/dwmac4_descs.c | 6 +++
.../ethernet/stmicro/stmmac/dwmac4_descs.h | 2 +-
.../net/ethernet/stmicro/stmmac/dwxgmac2.h | 2 +-
.../ethernet/stmicro/stmmac/dwxgmac2_descs.c | 6 +++
.../net/ethernet/stmicro/stmmac/enh_desc.c | 6 +++
drivers/net/ethernet/stmicro/stmmac/hwif.h | 3 ++
.../net/ethernet/stmicro/stmmac/norm_desc.c | 6 +++
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 49 +++++++++++++------
10 files changed, 67 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs.h b/drivers/net/ethernet/stmicro/stmmac/descs.h
index 0af819a98fda..3053b915f804 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs.h
@@ -33,8 +33,8 @@
#define RDES0_ERROR_SUMMARY BIT(15)
#define RDES0_FRAME_LEN_MASK GENMASK(29, 16)
#define RDES0_DA_FILTER_FAIL BIT(30)
-#define RDES0_OWN BIT(31)
- /* RDES1 */
+#define RDES0_OWN ((u32)BIT(31)) /* silence sparse */
+/* RDES1 */
#define RDES1_BUFFER1_SIZE_MASK GENMASK(10, 0)
#define RDES1_BUFFER2_SIZE_MASK GENMASK(21, 11)
#define RDES1_SECOND_ADDRESS_CHAINED BIT(24)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index c6a8f8d73501..307bbd63dbcb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -176,6 +176,11 @@ static void dwmac4_set_tx_owner(struct dma_desc *p)
p->des3 |= cpu_to_le32(TDES3_OWN);
}
+static void dwmac4_clear_rx_owner(struct dma_desc *p)
+{
+ p->des3 &= cpu_to_le32(~RDES3_OWN);
+}
+
static void dwmac4_set_rx_owner(struct dma_desc *p, int disable_rx_ic)
{
u32 flags = (RDES3_OWN | RDES3_BUFFER1_VALID_ADDR);
@@ -539,6 +544,7 @@ const struct stmmac_desc_ops dwmac4_desc_ops = {
.rx_status = dwmac4_wrback_get_rx_status,
.set_tx_owner = dwmac4_set_tx_owner,
.set_rx_owner = dwmac4_set_rx_owner,
+ .clear_rx_owner = dwmac4_clear_rx_owner,
.get_rx_vlan_tci = dwmac4_wrback_get_rx_vlan_tci,
.get_rx_vlan_valid = dwmac4_wrback_get_rx_vlan_valid,
.get_rx_frame_len = dwmac4_wrback_get_rx_frame_len,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
index fb1fea5b0e6e..c69f95268cd0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
@@ -134,7 +134,7 @@
#define RDES3_INT_ON_COMPLETION_EN BIT(30)
/* TDS3 use for both format (read and write back) */
-#define RDES3_OWN BIT(31)
+#define RDES3_OWN ((u32)BIT(31)) /* silence sparse */
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
extern const struct stmmac_desc_ops dwmac4_desc_ops;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f8ab347f7b5b..50f9d1dfc92d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -434,7 +434,7 @@
#define XGMAC_RDES2_L4FM BIT(28)
#define XGMAC_RDES2_L3FM BIT(27)
#define XGMAC_RDES2_HL GENMASK(9, 0)
-#define XGMAC_RDES3_OWN BIT(31)
+#define XGMAC_RDES3_OWN ((u32)BIT(31)) /* silence sparse */
#define XGMAC_RDES3_CTXT BIT(30)
#define XGMAC_RDES3_IOC BIT(30)
#define XGMAC_RDES3_LD BIT(28)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
index 6719ac6e395b..ad377c76ed4e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
@@ -51,6 +51,11 @@ static void dwxgmac2_set_tx_owner(struct dma_desc *p)
p->des3 |= cpu_to_le32(XGMAC_TDES3_OWN);
}
+static void dwxgmac2_clear_rx_owner(struct dma_desc *p)
+{
+ p->des3 &= cpu_to_le32(~XGMAC_RDES3_OWN);
+}
+
static void dwxgmac2_set_rx_owner(struct dma_desc *p, int disable_rx_ic)
{
u32 flags = XGMAC_RDES3_OWN;
@@ -350,6 +355,7 @@ const struct stmmac_desc_ops dwxgmac210_desc_ops = {
.rx_status = dwxgmac2_get_rx_status,
.set_tx_owner = dwxgmac2_set_tx_owner,
.set_rx_owner = dwxgmac2_set_rx_owner,
+ .clear_rx_owner = dwxgmac2_clear_rx_owner,
.get_rx_vlan_tci = dwxgmac2_wrback_get_rx_vlan_tci,
.get_rx_vlan_valid = dwxgmac2_wrback_get_rx_vlan_valid,
.get_rx_frame_len = dwxgmac2_get_rx_frame_len,
diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
index 7ece8d4157a8..57909a9ba70d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
@@ -299,6 +299,11 @@ static void enh_desc_set_tx_owner(struct dma_desc *p)
p->des0 |= cpu_to_le32(ETDES0_OWN);
}
+static void enh_desc_clear_rx_owner(struct dma_desc *p)
+{
+ p->des0 &= cpu_to_le32(~RDES0_OWN);
+}
+
static void enh_desc_set_rx_owner(struct dma_desc *p, int disable_rx_ic)
{
p->des0 |= cpu_to_le32(RDES0_OWN);
@@ -460,6 +465,7 @@ const struct stmmac_desc_ops enh_desc_ops = {
.set_tx_ic = enh_desc_set_tx_ic,
.set_tx_owner = enh_desc_set_tx_owner,
.set_rx_owner = enh_desc_set_rx_owner,
+ .clear_rx_owner = enh_desc_clear_rx_owner,
.get_rx_frame_len = enh_desc_get_rx_frame_len,
.rx_extended_status = enh_desc_get_ext_status,
.enable_tx_timestamp = enh_desc_enable_tx_timestamp,
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 8ae95e91a36a..05edec258a8b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -65,6 +65,7 @@ struct stmmac_desc_ops {
struct dma_desc *p, void __iomem *ioaddr);
/* Handle extra events on specific interrupts hw dependent */
void (*set_rx_owner)(struct dma_desc *p, int disable_rx_ic);
+ void (*clear_rx_owner)(struct dma_desc *p);
/* Get the receive frame size */
int (*get_rx_frame_len)(struct dma_desc *p, int rx_coe_type);
/* Return the reception status looking at the RDES1 */
@@ -121,6 +122,8 @@ struct stmmac_desc_ops {
stmmac_do_callback(__priv, desc, get_rx_vlan_valid, __args)
#define stmmac_tx_status(__priv, __args...) \
stmmac_do_callback(__priv, desc, tx_status, __args)
+#define stmmac_clear_rx_owner(__priv, __args...) \
+ stmmac_do_void_callback(__priv, desc, clear_rx_owner, __args)
#define stmmac_set_rx_owner(__priv, __args...) \
stmmac_do_void_callback(__priv, desc, set_rx_owner, __args)
#define stmmac_get_rx_frame_len(__priv, __args...) \
diff --git a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
index d19bf7ca4db3..473d53c31072 100644
--- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
@@ -141,6 +141,11 @@ static void ndesc_set_tx_owner(struct dma_desc *p)
p->des0 |= cpu_to_le32(TDES0_OWN);
}
+static void ndesc_clear_rx_owner(struct dma_desc *p)
+{
+ p->des0 &= cpu_to_le32(~RDES0_OWN);
+}
+
static void ndesc_set_rx_owner(struct dma_desc *p, int disable_rx_ic)
{
p->des0 |= cpu_to_le32(RDES0_OWN);
@@ -284,6 +289,7 @@ const struct stmmac_desc_ops ndesc_ops = {
.set_tx_ic = ndesc_set_tx_ic,
.set_tx_owner = ndesc_set_tx_owner,
.set_rx_owner = ndesc_set_rx_owner,
+ .clear_rx_owner = ndesc_clear_rx_owner,
.get_rx_frame_len = ndesc_get_rx_frame_len,
.enable_tx_timestamp = ndesc_enable_tx_timestamp,
.get_tx_timestamp_status = ndesc_get_tx_timestamp_status,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index b76acfe0d958..b81695453cc6 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -128,6 +128,8 @@ struct stmmac_rx_queue {
unsigned int cur_rx;
unsigned int dirty_rx;
unsigned int buf_alloc_num;
+ /* XSK descriptors waiting for refill, including a completely empty ring. */
+ unsigned int xsk_rx_pending;
unsigned int napi_skb_frag_size;
dma_addr_t dma_rx_phy;
unsigned int state_saved;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8bd244046195..f9ac82d2e726 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -436,7 +436,7 @@ static void stmmac_set_queue_rx_buf_size(struct stmmac_priv *priv,
{
u32 buf_size;
- if (rx_q->xsk_pool && rx_q->buf_alloc_num)
+ if (rx_q->xsk_pool)
buf_size = xsk_pool_get_rx_frame_size(rx_q->xsk_pool);
else
buf_size = priv->dma_conf.dma_buf_sz;
@@ -453,6 +453,9 @@ static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv, u32 queue)
{
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
+ if (rx_q->xsk_pool)
+ return rx_q->xsk_rx_pending;
+
return CIRC_CNT(rx_q->cur_rx, rx_q->dirty_rx,
priv->dma_conf.dma_rx_size);
}
@@ -1610,6 +1613,9 @@ static void stmmac_clear_rx_descriptors(struct stmmac_priv *priv,
priv->descriptor_mode,
(i == dma_conf->dma_rx_size - 1),
dma_conf->dma_buf_sz);
+ /* Only the allocated prefix may be handed to RX DMA. */
+ if (rx_q->xsk_pool && i >= rx_q->buf_alloc_num)
+ stmmac_clear_rx_owner(priv, desc);
}
}
@@ -5601,7 +5607,7 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
budget = min(budget, stmmac_rx_dirty(priv, queue));
- while (budget-- > 0 && entry != rx_q->cur_rx) {
+ while (budget-- > 0) {
struct stmmac_rx_buffer *buf = &rx_q->buf_pool[entry];
dma_addr_t dma_addr;
bool use_rx_wd;
@@ -5626,12 +5632,18 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
dma_wmb();
stmmac_set_rx_owner(priv, rx_desc, use_rx_wd);
+ rx_q->xsk_rx_pending--;
entry = STMMAC_NEXT_ENTRY(entry, priv->dma_conf.dma_rx_size);
}
if (rx_desc) {
rx_q->dirty_rx = entry;
- stmmac_set_queue_rx_tail_ptr(priv, rx_q, queue, rx_q->dirty_rx);
+ /* Use the end-of-ring address when filling an initially empty
+ * ring completely, so the tail differs from its initial base.
+ */
+ stmmac_set_queue_rx_tail_ptr(priv, rx_q, queue,
+ entry ?: priv->dma_conf.dma_rx_size);
+ stmmac_enable_dma_reception(priv, priv->ioaddr, queue);
}
return ret;
@@ -5652,7 +5664,6 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[queue];
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
unsigned int count = 0, error = 0, len = 0;
- int dirty = stmmac_rx_dirty(priv, queue);
unsigned int next_entry = rx_q->cur_rx;
bool in_progress = rx_q->state_saved;
u32 rx_errors = 0, rx_dropped = 0;
@@ -5661,6 +5672,9 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
bool failure = false;
int xdp_status = 0;
+ if (rx_q->xsk_rx_pending)
+ failure = !stmmac_rx_refill_zc(priv, queue, rx_q->xsk_rx_pending);
+
if (netif_msg_rx_status(priv)) {
void *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);
@@ -5697,11 +5711,13 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
entry = next_entry;
buf = &rx_q->buf_pool[entry];
- if (dirty >= STMMAC_RX_FILL_BATCH) {
- failure = failure ||
- !stmmac_rx_refill_zc(priv, queue, dirty);
- dirty = 0;
- }
+ if (!failure && rx_q->xsk_rx_pending >= STMMAC_RX_FILL_BATCH)
+ failure = !stmmac_rx_refill_zc(priv, queue,
+ rx_q->xsk_rx_pending);
+
+ /* A CPU-owned slot in the refill region is not a packet. */
+ if (rx_q->xsk_rx_pending == priv->dma_conf.dma_rx_size)
+ break;
p = stmmac_get_rx_desc(priv, rx_q, entry);
@@ -5714,10 +5730,8 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
/* Prefetch the next RX descriptor */
next_entry = STMMAC_NEXT_ENTRY(rx_q->cur_rx,
priv->dma_conf.dma_rx_size);
- if (unlikely(next_entry == rx_q->dirty_rx))
- break;
-
rx_q->cur_rx = next_entry;
+ rx_q->xsk_rx_pending++;
np = stmmac_get_rx_desc(priv, rx_q, next_entry);
@@ -5746,7 +5760,6 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
if (unlikely(error)) {
xsk_buff_free(buf->xdp);
buf->xdp = NULL;
- dirty++;
if (status & rx_not_ls)
goto read_again;
@@ -5761,7 +5774,6 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
buf->xdp = NULL;
rx_dropped++;
error = 1;
- dirty++;
goto read_again;
}
@@ -5805,7 +5817,6 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
}
buf->xdp = NULL;
- dirty++;
count++;
}
@@ -5817,6 +5828,9 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
stmmac_finalize_xdp_rx(priv, xdp_status);
+ if (!failure && rx_q->xsk_rx_pending)
+ failure = !stmmac_rx_refill_zc(priv, queue, rx_q->xsk_rx_pending);
+
u64_stats_update_begin(&rxq_stats->napi_syncp);
u64_stats_add(&rxq_stats->napi.rx_pkt_n, count);
u64_stats_update_end(&rxq_stats->napi_syncp);
@@ -8460,6 +8474,11 @@ static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue)
rx_q->state_saved = false;
rx_q->cur_rx = 0;
rx_q->dirty_rx = 0;
+ if (rx_q->xsk_pool) {
+ rx_q->dirty_rx = rx_q->buf_alloc_num % priv->dma_conf.dma_rx_size;
+ rx_q->xsk_rx_pending = priv->dma_conf.dma_rx_size -
+ rx_q->buf_alloc_num;
+ }
}
static void stmmac_reset_tx_queue(struct stmmac_priv *priv, u32 queue)
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH net v8 2/4] net: stmmac: track unfilled XSK RX descriptors explicitly
2026-11-19 14:08 ` [PATCH net v8 2/4] net: stmmac: track unfilled XSK RX descriptors explicitly Ding Hui
@ 2026-11-23 14:39 ` netdev-bot+sashiko
0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 14:39 UTC (permalink / raw)
To: dinghui1111
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, dinghui, xiasanbo, yangchen11,
liuxuanjun, fujiahui, zhoujing3
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 0 · Low: 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).
- [High] Permanent RX stall on dwmac4/dwxgmac2 XSK queues after a full-
ring refill that ends at a non-zero index.
- [High] net: stmmac: pre-loop refill failure in stmmac_rx_zc() skips
later refills
- [Low] The comment added in stmmac_rx_refill_zc() describes a narrower
condition than the code under it.
--
net: stmmac: track unfilled XSK RX descriptors explicitly
This commit adds an xsk_rx_pending counter that tracks XSK RX descriptors
waiting for refill. It also adds a clear_rx_owner descriptor op so unfilled
descriptors stay CPU-owned. stmmac_rx_zc() and stmmac_rx_refill_zc() now
retry refills on every poll and write an end-of-ring tail address when a
refill ends at index zero.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 8bd2440461959..f9ac82d2e7266 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -5626,12 +5632,18 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
> dma_wmb();
> stmmac_set_rx_owner(priv, rx_desc, use_rx_wd);
>
> + rx_q->xsk_rx_pending--;
> entry = STMMAC_NEXT_ENTRY(entry, priv->dma_conf.dma_rx_size);
> }
>
> if (rx_desc) {
> rx_q->dirty_rx = entry;
> - stmmac_set_queue_rx_tail_ptr(priv, rx_q, queue, rx_q->dirty_rx);
> + /* Use the end-of-ring address when filling an initially empty
> + * ring completely, so the tail differs from its initial base.
> + */
[Severity: Low]
This isn't a bug, but the comment covers less than the code below it does.
The entry ?: dma_rx_size expression applies to every refill whose last
entry wraps to 0. That includes ordinary wrap-around on every lap of the
ring, not only a complete fill of an initially empty ring.
The commit message calls this "a refill ending at index zero", which
matches the code. Could the comment say the same?
It might also help to say why this differs from stmmac_rx_refill(), which
writes the base address for index 0:
stmmac_set_queue_rx_tail_ptr(priv, rx_q, queue, rx_q->dirty_rx);
The later patches in the series leave this comment unchanged.
> + stmmac_set_queue_rx_tail_ptr(priv, rx_q, queue,
> + entry ?: priv->dma_conf.dma_rx_size);
> + stmmac_enable_dma_reception(priv, priv->ioaddr, queue);
> }
[Severity: High]
Can RX DMA stay stalled after a full-ring refill that ends at a non-zero
index?
This patch removes the one-slot gap that stmmac_rx_zc() used to keep:
- if (unlikely(next_entry == rx_q->dirty_rx))
- break;
The consume loop now stops only on dma_own or on this check:
if (rx_q->xsk_rx_pending == priv->dma_conf.dma_rx_size)
break;
Suppose the XSK fill ring runs dry under traffic. The CPU can then consume
every descriptor, and the ring becomes completely empty with
cur_rx == dirty_rx == k for any k. The last successful refill wrote the
tail as base + k * desc, and DMA has stopped with its current pointer at k.
Now suppose userspace supplies at least dma_rx_size buffers before the next
poll. The refill at the top of stmmac_rx_zc() runs:
if (rx_q->xsk_rx_pending)
failure = !stmmac_rx_refill_zc(priv, queue, rx_q->xsk_rx_pending);
It fills all N slots and entry wraps back to k. The tail is then written as
entry ?: dma_rx_size, which is base + k * desc again. That equals both the
stalled DMA current pointer and the previous tail value. The ?: special
case only covers k == 0.
The comment above depends on a tail equal to the DMA position not
restarting DMA ("so the tail differs from its initial base"). Doesn't the
same reasoning apply when k != 0?
After this refill xsk_rx_pending is 0, so no later poll writes the tail
again. Every later poll finds descriptor cur_rx DMA-owned and breaks out.
stmmac_enable_dma_reception() seems to be implemented only for dwmac1000.
On dwmac4 the RBU interrupt only increments rx_buf_unav_irq, and on xgmac
it only schedules NAPI. On dwmac4 and dwxgmac2, would the queue stay dead
until it is reinitialized?
The later patches in the series don't seem to change this logic.
[ ... ]
> @@ -5661,6 +5672,9 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
> bool failure = false;
> int xdp_status = 0;
>
> + if (rx_q->xsk_rx_pending)
> + failure = !stmmac_rx_refill_zc(priv, queue, rx_q->xsk_rx_pending);
> +
> if (netif_msg_rx_status(priv)) {
> void *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);
>
[Severity: High]
Can a refill failure at the top of stmmac_rx_zc() stop buffers that
are freed later in the same poll from being reposted?
The pre-loop call asks stmmac_rx_refill_zc() for all of
xsk_rx_pending. Whenever the pool holds fewer free buffers than that,
xsk_buff_alloc() returns NULL partway through and failure is latched
to true before the receive loop starts. A partially filled fill ring
is exactly the case this patch is meant to support.
Both the batch refill inside the loop and the new refill after
stmmac_finalize_xdp_rx() are gated on !failure. Neither one runs for
the rest of the poll.
Meanwhile several paths call xsk_buff_free() on the buffer:
- XDP_PASS
- STMMAC_XDP_CONSUMED (XDP_DROP, XDP_ABORTED, failed redirect)
- the discard_frame and rx_not_ls error paths
- XDP_TX, via xdp_convert_buff_to_frame()
Each of these puts the buffer back on the pool free_list, where
xsk_buff_alloc() could hand it straight back out. The old code started
every poll with failure set to false. It would have reposted those
buffers once dirty reached STMMAC_RX_FILL_BATCH.
With XDP_USE_NEED_WAKEUP, suppose those paths consume every descriptor
that was posted. The poll then ends with xsk_rx_pending equal to
dma_rx_size and no DMA-owned descriptor left in the ring.
stmmac_rx_zc() returns count < limit and NAPI completes, so no further
RX interrupt can arrive. None of these frames reach the XSK RX ring.
Doesn't recovery then depend entirely on userspace issuing a wakeup
without having received anything?
Without need_wakeup the problem goes the other way. Suppose the pool
has fewer than dma_rx_size buffers in total, for example a TX-only
socket that never populates the fill ring. Then xsk_rx_pending never
reaches zero and the pre-loop refill fails on every poll, so
stmmac_rx_zc() returns limit every time. Wouldn't NAPI then never
complete, even on an idle link? Before this patch the same setup left
failure false and returned count.
Should the later refills still be attempted after an earlier failure,
for example by OR-ing the result into failure instead of skipping the
call? And is busy polling intended when the fill ring is simply
smaller than the RX ring?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795096430.git.dinghui%40lixiang.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net v8 3/4] net: stmmac: restore RX descriptor buffer addresses on resume
2026-11-19 14:08 [PATCH net v8 0/4] net: stmmac: fix RX descriptors and XSK TX on resume Ding Hui
2026-11-19 14:08 ` [PATCH net v8 1/4] net: stmmac: honor allocation flags when initializing RX buffers Ding Hui
2026-11-19 14:08 ` [PATCH net v8 2/4] net: stmmac: track unfilled XSK RX descriptors explicitly Ding Hui
@ 2026-11-19 14:08 ` Ding Hui
2026-11-23 14:39 ` netdev-bot+sashiko
2026-11-19 14:09 ` [PATCH net v8 4/4] net: stmmac: restore the XSK TX pool " Ding Hui
3 siblings, 1 reply; 8+ messages in thread
From: Ding Hui @ 2026-11-19 14:08 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
open list:STMMAC ETHERNET DRIVER,
moderated list:ARM/STM32 ARCHITECTURE,
moderated list:ARM/STM32 ARCHITECTURE, open list
Cc: dinghui, xiasanbo, yangchen11, liuxuanjun, fujiahui, zhoujing3
From: Ding Hui <dinghui@lixiang.com>
Suspend disables NAPI before stopping RX DMA. Hardware can complete RX
descriptors in between, overwriting GMAC4/XGMAC buffer addresses with
writeback status. Resume currently rearms those descriptors without
restoring their addresses, leading to a fatal bus error.
Share buffer preparation with the refill paths and restore addresses
from attached buffers. Allocate missing primary and secondary pages
independently with GFP_KERNEL. If allocation fails, return the error
without restarting DMA and leave the device detached.
For XSK queues, restore a contiguous populated prefix and leave the rest
CPU-owned in the pending refill region. Preserve attached buffers beyond
the prefix for later refill. Recompute the initial tail and pending count
rather than retaining the allocation count from open.
Rebuild chain pointers and use stmmac_reset_rx_queue() to discard partial
receive state from before the DMA reset. Initialize RX descriptors after
restoring their addresses,
using the existing per-queue initializer to preserve the watchdog policy
and legacy control fields. Keep the unpopulated XSK suffix CPU-owned when
DMA restarts. This replaces the separate final ownership-setting loop.
Collect the resume work in stmmac_resume_descriptors(), with one loop over
TX queues and one over RX queues. Free outstanding TX buffers before
initializing each TX ring, and remove the now-unused all-queue TX wrapper.
The RX rings no longer undergo initialization before address restoration.
Unlike the reverted commit 9c63faaa931e ("net: stmmac: re-init rx buffers
when mac resume back"), retain attached buffers and their DMA mappings.
Fixes: f748be531d70 ("stmmac: support new GMAC4")
Signed-off-by: Ding Hui <dinghui@lixiang.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 221 +++++++++++++-----
1 file changed, 158 insertions(+), 63 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f9ac82d2e726..1508cf08f03b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1677,6 +1677,40 @@ static bool stmmac_rx_check_buf2_cap(struct stmmac_priv *priv)
return priv->hw->desc && priv->hw->desc->set_sec_addr;
}
+static int stmmac_prepare_rx_buffer(struct stmmac_priv *priv,
+ struct stmmac_rx_queue *rx_q,
+ struct stmmac_rx_buffer *buf,
+ struct dma_desc *p, gfp_t flags)
+{
+ gfp_t gfp = flags;
+
+ if (priv->dma_cap.host_dma_width <= 32)
+ gfp |= GFP_DMA32;
+
+ if (!buf->page) {
+ buf->page = page_pool_alloc_pages(rx_q->page_pool, gfp);
+ if (!buf->page)
+ return -ENOMEM;
+ buf->page_offset = stmmac_rx_offset(priv);
+ }
+
+ if (stmmac_rx_check_buf2_cap(priv) && !buf->sec_page) {
+ buf->sec_page = page_pool_alloc_pages(rx_q->page_pool, gfp);
+ if (!buf->sec_page)
+ return -ENOMEM;
+
+ buf->sec_addr = page_pool_get_dma_addr(buf->sec_page);
+ }
+
+ buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
+
+ stmmac_set_desc_addr(priv, p, buf->addr);
+ stmmac_set_desc_sec_addr(priv, p, buf->sec_addr,
+ stmmac_rx_check_buf2_cap(priv));
+
+ return 0;
+}
+
/**
* stmmac_init_rx_buffers - init the RX descriptor buffer.
* @priv: driver private structure
@@ -1695,32 +1729,100 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv,
{
struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
- gfp_t gfp = flags;
+ int ret;
- if (priv->dma_cap.host_dma_width <= 32)
- gfp |= GFP_DMA32;
+ ret = stmmac_prepare_rx_buffer(priv, rx_q, buf, p, flags);
+ if (ret)
+ return ret;
- if (!buf->page) {
- buf->page = page_pool_alloc_pages(rx_q->page_pool, gfp);
- if (!buf->page)
+ if (dma_conf->dma_buf_sz == BUF_SIZE_16KiB)
+ stmmac_init_desc3(priv, p);
+
+ return 0;
+}
+
+static int stmmac_prepare_rx_buffer_zc(struct stmmac_priv *priv,
+ struct stmmac_rx_queue *rx_q,
+ struct stmmac_rx_buffer *buf,
+ struct dma_desc *p)
+{
+ if (!buf->xdp) {
+ buf->xdp = xsk_buff_alloc(rx_q->xsk_pool);
+ if (!buf->xdp)
return -ENOMEM;
- buf->page_offset = stmmac_rx_offset(priv);
}
- if (stmmac_rx_check_buf2_cap(priv) && !buf->sec_page) {
- buf->sec_page = page_pool_alloc_pages(rx_q->page_pool, gfp);
- if (!buf->sec_page)
- return -ENOMEM;
+ stmmac_set_desc_addr(priv, p, xsk_buff_xdp_get_dma(buf->xdp));
+ stmmac_set_desc_sec_addr(priv, p, 0, false);
- buf->sec_addr = page_pool_get_dma_addr(buf->sec_page);
- stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, true);
+ return 0;
+}
+
+/**
+ * stmmac_reinit_rx_descriptors - restore RX descriptors before restarting DMA
+ * @priv: driver private structure
+ * @dma_conf: DMA configuration
+ * @queue: RX queue index
+ *
+ * Restore addresses overwritten by hardware writeback, retaining attached
+ * buffers and allocating missing page_pool buffers with GFP_KERNEL. Keep
+ * descriptors CPU-owned until addresses and chain pointers are restored.
+ *
+ * For XSK, publish only the contiguous populated prefix. The remainder is
+ * left in the refill region, including any buffers already attached there,
+ * and can be populated by NAPI when userspace supplies more fill buffers.
+ *
+ * Return: 0 on success, or -ENOMEM if a required page cannot be allocated.
+ */
+static int stmmac_reinit_rx_descriptors(struct stmmac_priv *priv,
+ struct stmmac_dma_conf *dma_conf,
+ u32 queue)
+{
+ struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
+ struct dma_desc *p;
+ int i, ret;
+
+ for (i = 0; i < dma_conf->dma_rx_size; i++) {
+ p = stmmac_get_rx_desc(priv, rx_q, i);
+ stmmac_clear_rx_owner(priv, p);
}
- buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
+ rx_q->buf_alloc_num = 0;
+ for (i = 0; i < dma_conf->dma_rx_size; i++) {
+ struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
- stmmac_set_desc_addr(priv, p, buf->addr);
- if (dma_conf->dma_buf_sz == BUF_SIZE_16KiB)
- stmmac_init_desc3(priv, p);
+ p = stmmac_get_rx_desc(priv, rx_q, i);
+ if (rx_q->xsk_pool) {
+ ret = stmmac_prepare_rx_buffer_zc(priv, rx_q, buf, p);
+ if (ret)
+ break;
+ } else {
+ ret = stmmac_init_rx_buffers(priv, dma_conf, p, i,
+ GFP_KERNEL, queue);
+ if (ret)
+ return ret;
+ }
+ rx_q->buf_alloc_num++;
+ }
+
+ /* Hardware timestamp writeback may have overwritten chain pointers. */
+ if (priv->descriptor_mode == STMMAC_CHAIN_MODE) {
+ void *des = priv->extend_desc ? (void *)rx_q->dma_erx :
+ (void *)rx_q->dma_rx;
+
+ stmmac_mode_init(priv, des, rx_q->dma_rx_phy,
+ dma_conf->dma_rx_size, priv->extend_desc);
+ }
+
+ rx_q->rx_count_frames = 0;
+ stmmac_reset_rx_queue(priv, queue);
+
+ /* Initialize control fields and publish ownership only after restoring
+ * addresses and chain pointers. DMA is stopped; initialization also
+ * clears OWN again for the unpopulated XSK suffix before DMA restarts.
+ */
+ dma_wmb();
+ stmmac_clear_rx_descriptors(priv, dma_conf, queue);
return 0;
}
@@ -2157,16 +2259,37 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv,
}
/**
- * stmmac_free_tx_skbufs - free TX skb buffers
- * @priv: private structure
+ * stmmac_resume_descriptors - prepare TX and RX rings before restarting DMA
+ * @priv: driver private structure
+ *
+ * Release outstanding TX buffers before initializing each TX ring. Restore
+ * RX buffer addresses before initializing RX descriptors and their ownership.
+ * All DMA channels must be stopped throughout this operation.
+ *
+ * Return: 0 on success, or a negative errno if RX restoration fails.
*/
-static void stmmac_free_tx_skbufs(struct stmmac_priv *priv)
+static int stmmac_resume_descriptors(struct stmmac_priv *priv)
{
- u8 tx_queue_cnt = priv->plat->tx_queues_to_use;
- u8 queue;
+ struct stmmac_dma_conf *dma_conf = &priv->dma_conf;
+ u32 queue;
+ int ret;
- for (queue = 0; queue < tx_queue_cnt; queue++)
- dma_free_tx_skbufs(priv, &priv->dma_conf, queue);
+ for (queue = 0; queue < priv->plat->tx_queues_to_use; queue++) {
+ stmmac_reset_tx_queue(priv, queue);
+ dma_free_tx_skbufs(priv, dma_conf, queue);
+ stmmac_clear_tx_descriptors(priv, dma_conf, queue);
+ }
+
+ for (queue = 0; queue < priv->plat->rx_queues_to_use; queue++) {
+ ret = stmmac_reinit_rx_descriptors(priv, dma_conf, queue);
+ if (ret) {
+ netdev_err(priv->dev, "Failed to restore RX queue %u: %d\n",
+ queue, ret);
+ return ret;
+ }
+ }
+
+ return 0;
}
/**
@@ -5172,10 +5295,6 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
int dirty = stmmac_rx_dirty(priv, queue);
unsigned int entry = rx_q->dirty_rx;
- gfp_t gfp = (GFP_ATOMIC | __GFP_NOWARN);
-
- if (priv->dma_cap.host_dma_width <= 32)
- gfp |= GFP_DMA32;
while (dirty-- > 0) {
struct stmmac_rx_buffer *buf = &rx_q->buf_pool[entry];
@@ -5184,25 +5303,9 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
p = stmmac_get_rx_desc(priv, rx_q, entry);
- if (!buf->page) {
- buf->page = page_pool_alloc_pages(rx_q->page_pool, gfp);
- if (!buf->page)
- break;
- }
-
- if (stmmac_rx_check_buf2_cap(priv) && !buf->sec_page) {
- buf->sec_page = page_pool_alloc_pages(rx_q->page_pool, gfp);
- if (!buf->sec_page)
- break;
-
- buf->sec_addr = page_pool_get_dma_addr(buf->sec_page);
- }
-
- buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
-
- stmmac_set_desc_addr(priv, p, buf->addr);
- stmmac_set_desc_sec_addr(priv, p, buf->sec_addr,
- stmmac_rx_check_buf2_cap(priv));
+ if (stmmac_prepare_rx_buffer(priv, rx_q, buf, p,
+ GFP_ATOMIC | __GFP_NOWARN))
+ break;
stmmac_refill_desc3(priv, rx_q, p);
use_rx_wd = !stmmac_rx_need_ic(priv, rx_q, queue);
@@ -5609,22 +5712,15 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
while (budget-- > 0) {
struct stmmac_rx_buffer *buf = &rx_q->buf_pool[entry];
- dma_addr_t dma_addr;
+ struct dma_desc *p = stmmac_get_rx_desc(priv, rx_q, entry);
bool use_rx_wd;
- if (!buf->xdp) {
- buf->xdp = xsk_buff_alloc(rx_q->xsk_pool);
- if (!buf->xdp) {
- ret = false;
- break;
- }
+ if (stmmac_prepare_rx_buffer_zc(priv, rx_q, buf, p)) {
+ ret = false;
+ break;
}
- rx_desc = stmmac_get_rx_desc(priv, rx_q, entry);
-
- dma_addr = xsk_buff_xdp_get_dma(buf->xdp);
- stmmac_set_desc_addr(priv, rx_desc, dma_addr);
- stmmac_set_desc_sec_addr(priv, rx_desc, 0, false);
+ rx_desc = p;
stmmac_refill_desc3(priv, rx_q, rx_desc);
use_rx_wd = !stmmac_rx_need_ic(priv, rx_q, queue);
@@ -8563,10 +8659,9 @@ int stmmac_resume(struct device *dev)
mutex_lock(&priv->lock);
- stmmac_reset_queues_param(priv);
-
- stmmac_free_tx_skbufs(priv);
- stmmac_clear_descriptors(priv, &priv->dma_conf);
+ ret = stmmac_resume_descriptors(priv);
+ if (ret)
+ goto error_unlock;
ret = stmmac_hw_setup(ndev);
if (ret < 0) {
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH net v8 3/4] net: stmmac: restore RX descriptor buffer addresses on resume
2026-11-19 14:08 ` [PATCH net v8 3/4] net: stmmac: restore RX descriptor buffer addresses on resume Ding Hui
@ 2026-11-23 14:39 ` netdev-bot+sashiko
0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 14:39 UTC (permalink / raw)
To: dinghui1111
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, dinghui, xiasanbo, yangchen11,
liuxuanjun, fujiahui, zhoujing3
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 2
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] This patch adds a failure point to stmmac_resume(): `ret =
stmmac_resume_descriptors(priv); if (ret) goto error_unlock;`.
- [Medium] The new early failure in stmmac_resume()
(stmmac_resume_descriptors() returning -ENOMEM) jumps to error_unlock.
- [Low] Part of the commit message describes code that is not in the
tree.
- [Low] The commit message frames the bug only as GMAC4/XGMAC writeback
overwriting buffer addresses, which leads to a 'fatal bus error'.
--
net: stmmac: restore RX descriptor buffer addresses on resume
The patch restores RX descriptor buffer addresses on resume. On GMAC4 and
XGMAC, hardware writeback during suspend can overwrite them. Buffer
preparation is factored into stmmac_prepare_rx_buffer() and
stmmac_prepare_rx_buffer_zc(). A new stmmac_reinit_rx_descriptors()
allocates any missing pages with GFP_KERNEL, and the per-ring resume work
is gathered in stmmac_resume_descriptors().
> Rebuild chain pointers and use stmmac_reset_rx_queue() to discard partial
> receive state from before the DMA reset. Initialize RX descriptors after
> restoring their addresses,
> using the existing per-queue initializer to preserve the watchdog policy
> and legacy control fields. Keep the unpopulated XSK suffix CPU-owned when
> DMA restarts. This replaces the separate final ownership-setting loop.
[ ... ]
> The RX rings no longer undergo initialization before address restoration.
[Severity: Low]
Which ownership-setting loop does this replace? Before this patch,
stmmac_resume() only called stmmac_reset_queues_param(),
stmmac_free_tx_skbufs() and stmmac_clear_descriptors().
stmmac_set_rx_owner() is only used in stmmac_rx_refill() and
stmmac_rx_refill_zc().
The second sentence has the same problem. The old resume path never
restored RX addresses, so nothing was ever initialized "before address
restoration".
Both sentences read like notes against an earlier, unposted version. Could
they be reworded to describe what changes relative to the current tree?
> Share buffer preparation with the refill paths and restore addresses
> from attached buffers. Allocate missing primary and secondary pages
> independently with GFP_KERNEL. If allocation fails, return the error
> without restarting DMA and leave the device detached.
[Severity: Low]
The commit message doesn't say why pages can be missing at resume time.
stmmac_rx() hands buf->page to the stack or page_pool and sets
buf->page = NULL. If the GFP_ATOMIC refill in stmmac_rx_refill() then
fails, that entry is left with no page attached.
The old resume path set OWN on every RX descriptor through
stmmac_clear_descriptors() whether a page was attached or not. On cores
whose writeback leaves the address word intact, the re-armed descriptor
still pointed at a page the driver no longer owned. DMA could then write
into recycled memory.
The new stmmac_reinit_rx_descriptors() fixes this too. Could the commit
message describe this case, so stable backporters know the patch also
fixes it?
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index f9ac82d2e7266..1508cf08f03b0 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
[ ... ]
> @@ -8563,10 +8659,9 @@ int stmmac_resume(struct device *dev)
>
> mutex_lock(&priv->lock);
>
> - stmmac_reset_queues_param(priv);
> -
> - stmmac_free_tx_skbufs(priv);
> - stmmac_clear_descriptors(priv, &priv->dma_conf);
> + ret = stmmac_resume_descriptors(priv);
> + if (ret)
> + goto error_unlock;
[Severity: High]
If stmmac_resume_descriptors() fails here, does NAPI stay disabled while
netif_running() is still true?
stmmac_suspend() already called stmmac_disable_all_queues(), and
error_unlock skips stmmac_enable_all_queues(). Any later stmmac_suspend()
or stmmac_release() would then call napi_disable() a second time on the
same instances:
stmmac_release()
__stmmac_release()
stmmac_disable_all_queues()
__stmmac_disable_all_queues()
napi_disable(&ch->rx_napi)
napi_disable_locked()
net/core/dev.c:napi_disable_locked() {
...
while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
usleep_range(20, 200);
val = READ_ONCE(n->state);
}
...
}
SCHED is still set from the first disable. Wouldn't this loop spin forever?
In the close path (ip link set down, MTU change, XDP setup, ring resize) it
would hold rtnl_lock. On the next system suspend it would hold priv->lock.
The -ENOMEM comes from the GFP_KERNEL page_pool allocations in
stmmac_reinit_rx_descriptors() -> stmmac_init_rx_buffers(). These run
during resume with the PM gfp restriction in place, so failure looks
reachable under memory pressure.
The commit message says "If allocation fails, return the error without
restarting DMA and leave the device detached". Is that detached state safe
to leave the device in? The stmmac_hw_setup() failure path already behaves
this way, but this patch adds a new way to reach it.
[Severity: Medium]
On the same failure path, is the MAC receiver left enabled?
error_unlock only powers down the legacy SerDes and drops the locks. Only
error_stop_dma calls stmmac_mac_set(priv, priv->ioaddr, false). With
Wake-on-LAN enabled, stmmac_suspend() never disables the MAC:
if (priv->wolopts) {
stmmac_pmt(priv, priv->hw, priv->wolopts);
priv->irq_wake = 1;
} else {
stmmac_mac_set(priv, priv->ioaddr, false);
dwmac4_pmt() sets GMAC_CONFIG_RE when it arms wake-up. The
stmmac_pmt(priv, priv->hw, 0) call earlier in stmmac_resume() only writes
PMT=0 and leaves RE set. Because stmmac_hw_setup() is skipped, no DMA soft
reset clears the configuration either.
After the failure, the MAC keeps receiving with the link still up, while
RX DMA is stopped. The failing queue's descriptors have already been made
CPU-owned by the OWN-clearing loop at the top of
stmmac_reinit_rx_descriptors(). Incoming frames fill the MTL FIFO with
nothing to drain it. STMMAC_DOWN is not set, so the pre-suspend interrupt
enables can still reach stmmac_interrupt().
Should this path disable the MAC (and the DMA interrupts) before
returning? Otherwise the device is neither armed for wake-up nor quiesced.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795096430.git.dinghui%40lixiang.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net v8 4/4] net: stmmac: restore the XSK TX pool on resume
2026-11-19 14:08 [PATCH net v8 0/4] net: stmmac: fix RX descriptors and XSK TX on resume Ding Hui
` (2 preceding siblings ...)
2026-11-19 14:08 ` [PATCH net v8 3/4] net: stmmac: restore RX descriptor buffer addresses on resume Ding Hui
@ 2026-11-19 14:09 ` Ding Hui
2026-11-23 14:39 ` netdev-bot+sashiko
3 siblings, 1 reply; 8+ messages in thread
From: Ding Hui @ 2026-11-19 14:09 UTC (permalink / raw)
To: Maxime Chevallier, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
open list:STMMAC ETHERNET DRIVER,
moderated list:ARM/STM32 ARCHITECTURE,
moderated list:ARM/STM32 ARCHITECTURE, open list
Cc: dinghui, xiasanbo, yangchen11, liuxuanjun, fujiahui, zhoujing3
From: Ding Hui <dinghui@lixiang.com>
When suspend interrupts AF_XDP zero-copy transmission, resume releases
outstanding TX buffers through dma_free_tx_skbufs(). If it completes XSK
frames, that helper also clears tx_q->xsk_pool even though the socket
remains bound to the queue.
The resume path does not run the TX ring allocation routine that normally
sets this pointer. Consequently, stmmac_tx_clean() skips XSK transmission
and a running TX-only socket can stop sending after resume, despite the
link coming back up.
Restore the TX pool from the queue's existing XSK binding after releasing
TX buffers and before restarting DMA and NAPI. Keep the buffer cleanup
helper's behavior for teardown unchanged.
Fixes: 132c32ee5bc0 ("net: stmmac: Add TX via XDP zero-copy socket")
Signed-off-by: Ding Hui <dinghui@lixiang.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 1508cf08f03b..550a0bd647e1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2277,6 +2277,9 @@ static int stmmac_resume_descriptors(struct stmmac_priv *priv)
for (queue = 0; queue < priv->plat->tx_queues_to_use; queue++) {
stmmac_reset_tx_queue(priv, queue);
dma_free_tx_skbufs(priv, dma_conf, queue);
+ /* Buffer cleanup may clear the pool; the socket remains bound. */
+ dma_conf->tx_queue[queue].xsk_pool =
+ stmmac_get_xsk_pool(priv, queue);
stmmac_clear_tx_descriptors(priv, dma_conf, queue);
}
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH net v8 4/4] net: stmmac: restore the XSK TX pool on resume
2026-11-19 14:09 ` [PATCH net v8 4/4] net: stmmac: restore the XSK TX pool " Ding Hui
@ 2026-11-23 14:39 ` netdev-bot+sashiko
0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 14:39 UTC (permalink / raw)
To: dinghui1111
Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, dinghui, xiasanbo, yangchen11,
liuxuanjun, fujiahui, zhoujing3
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · 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 fix is incomplete because it is applied to one caller
instead of the shared helper.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the same
resume path leaves corrupted TX next-descriptor pointers in chain mode.
--
net: stmmac: restore the XSK TX pool on resume
When dma_free_tx_skbufs() completes outstanding XSK TX frames, it also
clears tx_q->xsk_pool. This commit restores that pointer in
stmmac_resume_descriptors() after the call. Without the restore,
stmmac_tx_clean() skips zero-copy transmission after resume, even though
the AF_XDP socket is still bound.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 1508cf08f03b0..550a0bd647e13 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -2277,6 +2277,9 @@ static int stmmac_resume_descriptors(struct stmmac_priv *priv)
> for (queue = 0; queue < priv->plat->tx_queues_to_use; queue++) {
> stmmac_reset_tx_queue(priv, queue);
> dma_free_tx_skbufs(priv, dma_conf, queue);
> + /* Buffer cleanup may clear the pool; the socket remains bound. */
> + dma_conf->tx_queue[queue].xsk_pool =
> + stmmac_get_xsk_pool(priv, queue);
[Severity: High]
Does stmmac_tx_err() run into the same problem? It is not a teardown
path, but it also calls dma_free_tx_skbufs() and then restarts the queue:
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_tx_err() {
...
stmmac_stop_tx_dma(priv, chan);
dma_free_tx_skbufs(priv, &priv->dma_conf, chan);
stmmac_clear_tx_descriptors(priv, &priv->dma_conf, chan);
stmmac_reset_tx_queue(priv, chan);
stmmac_init_tx_chan(priv, priv->ioaddr, priv->plat->dma_cfg,
tx_q->dma_tx_phy, chan);
stmmac_start_tx_dma(priv, chan);
...
}
stmmac_dma_interrupt() and stmmac_msi_intr_tx() call it on a TX hard
error. If xsk_frames_done is non-zero, dma_free_tx_skbufs() does:
if (tx_q->xsk_pool && tx_q->xsk_frames_done) {
xsk_tx_completed(tx_q->xsk_pool, tx_q->xsk_frames_done);
tx_q->xsk_frames_done = 0;
tx_q->xsk_pool = NULL;
}
Nothing in stmmac_tx_err() sets the pointer again, even though
af_xdp_zc_qps still has the bit set for this queue.
After that, stmmac_tx_clean() skips its if (tx_q->xsk_pool) block, so
stmmac_xdp_xmit_zc() never runs. stmmac_napi_check() also starts sending
TX interrupts to ch->tx_napi:
tx_napi = tx_q->xsk_pool ? &ch->rxtx_napi : &ch->tx_napi;
For ZC queues, stmmac_enable_all_queues() enabled rxtx_napi, not tx_napi.
Wouldn't this stall zero-copy TX in the same way as the resume case?
The commit message says:
Keep the buffer cleanup helper's behavior for teardown unchanged.
This suggests the other callers of dma_free_tx_skbufs() are all teardown
paths, but stmmac_tx_err() is not one of them.
Would it be better to fix this in the shared helper instead? For example,
xsk_pool could be cleared only in __free_dma_tx_desc_resources(), or
dma_free_tx_skbufs() could stop clearing it altogether. Either would
cover both paths and remove the need for a restore in each caller.
> stmmac_clear_tx_descriptors(priv, dma_conf, queue);
> }
[Severity: High]
This isn't a bug introduced by this patch, but does the TX loop here
need the same chain-pointer rebuild as the RX loop?
In chain mode with non-extended descriptors and hwts_tx_en set, the MAC
writes the timestamp seconds into des3 of the last-segment descriptor.
In chain mode, des3 also holds the address of the next descriptor.
clean_desc3() in chain_mode.c repairs this:
if (tx_q->tx_skbuff_dma[entry].last_segment && !priv->extend_desc &&
priv->hwts_tx_en)
/* NOTE: Device will overwrite des3 with timestamp value if
* 1588-2002 time stamping is enabled, hence reinitialize it
* to keep explicit chaining in the descriptor.
*/
However, clean_desc3() only runs from stmmac_tx_clean(). stmmac_suspend()
disables NAPI before it stops DMA. A frame that completes in between is
never cleaned, so its des3 still holds the timestamp.
On resume, stmmac_clear_tx_descriptors()->ndesc_init_tx_desc() only
clears TDES0_OWN and sets the chain bit. It does not touch des3, and
nothing on this path calls stmmac_mode_init() for TX again.
The RX side of this function already handles the same hazard in
stmmac_reinit_rx_descriptors():
/* Hardware timestamp writeback may have overwritten chain pointers. */
if (priv->descriptor_mode == STMMAC_CHAIN_MODE) {
...
stmmac_mode_init(priv, des, rx_q->dma_rx_phy,
dma_conf->dma_rx_size, priv->extend_desc);
}
Could TX DMA then fetch its next descriptor from an address equal to the
PTP seconds value? stmmac_tx_err() seems to have the same gap.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795096430.git.dinghui%40lixiang.com
^ permalink raw reply [flat|nested] 8+ messages in thread