diff mbox series

[net] xsk: correct tx_ring_empty_descs count statistics

Message ID 20250329061548.1357925-1-wangliang74@huawei.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net] xsk: correct tx_ring_empty_descs count statistics | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 14 of 14 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-03-31--03-00 (tests: 891)

Commit Message

Wang Liang March 29, 2025, 6:15 a.m. UTC
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(-)

Comments

Stanislav Fomichev March 31, 2025, 3:22 p.m. UTC | #1
On 03/29, Wang Liang wrote:
> 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>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
diff mbox series

Patch

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);
 	}