netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] xsk: correct tx_ring_empty_descs count statistics
@ 2025-03-29  6:15 Wang Liang
  2025-03-31 15:22 ` Stanislav Fomichev
  0 siblings, 1 reply; 11+ messages in thread
From: Wang Liang @ 2025-03-29  6:15 UTC (permalink / raw)
  To: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon, davem,
	edumazet, kuba, pabeni, horms, ast, daniel, hawk, john.fastabend
  Cc: yuehaibing, zhangchangzhong, wangliang74, netdev, bpf,
	linux-kernel

The tx_ring_empty_descs count may be incorrect, when set the XDP_TX_RING
option but do not reserve tx ring. Because xsk_poll() try to wakeup the
driver by calling xsk_generic_xmit() for non-zero-copy mode. So the
tx_ring_empty_descs count increases once the xsk_poll()is called:

  xsk_poll
    xsk_generic_xmit
      __xsk_generic_xmit
        xskq_cons_peek_desc
          xskq_cons_read_desc
            q->queue_empty_descs++;

To avoid this count error, add check for tx descs before send msg in poll.

Fixes: df551058f7a3 ("xsk: Fix crash in poll when device does not support ndo_xsk_wakeup")
Signed-off-by: Wang Liang <wangliang74@huawei.com>
---
 net/xdp/xsk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 89d2bef96469..fb01e6736677 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -989,7 +989,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
 	if (pool->cached_need_wakeup) {
 		if (xs->zc)
 			xsk_wakeup(xs, pool->cached_need_wakeup);
-		else if (xs->tx)
+		else if (xs->tx && xskq_has_descs(xs->tx))
 			/* Poll needs to drive Tx also in copy mode */
 			xsk_generic_xmit(sk);
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-04-02  2:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-29  6:15 [PATCH net] xsk: correct tx_ring_empty_descs count statistics Wang Liang
2025-03-31 15:22 ` Stanislav Fomichev
2025-03-31 22:03   ` Stanislav Fomichev
2025-04-01  2:35     ` Wang Liang
2025-04-01  6:57       ` Magnus Karlsson
2025-04-01  7:39         ` Wang Liang
2025-04-01  7:43         ` Wang Liang
2025-04-01  8:12           ` Magnus Karlsson
2025-04-01  9:33             ` Wang Liang
2025-04-01 11:00               ` Magnus Karlsson
2025-04-02  2:38                 ` Wang Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).