diff mbox series

[net-next] xsk: Bring back busy polling support in XDP_COPY

Message ID 20250325044358.2675384-1-skhawaja@google.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] xsk: Bring back busy polling support in XDP_COPY | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -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 fail 1 blamed authors not CCed: sdf@fomichev.me; 11 maintainers not CCed: jonathan.lemon@gmail.com sdf@fomichev.me maciej.fijalkowski@intel.com ast@kernel.org daniel@iogearbox.net hawk@kernel.org magnus.karlsson@intel.com horms@kernel.org bpf@vger.kernel.org john.fastabend@gmail.com bjorn@kernel.org
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 warning WARNING: line length of 85 exceeds 80 columns
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-26--00-00 (tests: 896)

Commit Message

Samiullah Khawaja March 25, 2025, 4:43 a.m. UTC
Commit 5ef44b3cb43b ("xsk: Bring back busy polling support") fixed the
busy polling support in xsk for XDP_ZEROCOPY after it was broken in
commit 86e25f40aa1e ("net: napi: Add napi_config"). The busy polling
support with XDP_COPY remained broken since the napi_id setup in
xsk_rcv_check was removed.

Bring back the setup of napi_id for XDP_COPY so socket level SO_BUSYPOLL
can be used to poll the underlying napi.

Tested using AF_XDP support in virtio-net by running the xsk_rr AF_XDP
benchmarking tool shared here:
https://lore.kernel.org/all/20250320163523.3501305-1-skhawaja@google.com/T/

Enabled socket busy polling using following commands in qemu,

```
sudo ethtool -L eth0 combined 1
sudo ethtool -G eth0 rx 1024
echo 400 | sudo tee /proc/sys/net/core/busy_read
echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs
echo 15000   | sudo tee /sys/class/net/eth0/gro_flush_timeout
```

Fixes: 5ef44b3cb43b ("xsk: Bring back busy polling support")
Fixes: 86e25f40aa1e ("net: napi: Add napi_config")
Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
---
 net/xdp/xsk.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

Comments

Samiullah Khawaja March 25, 2025, 4:24 p.m. UTC | #1
On Mon, Mar 24, 2025 at 9:43 PM Samiullah Khawaja <skhawaja@google.com> wrote:
>
> Commit 5ef44b3cb43b ("xsk: Bring back busy polling support") fixed the
> busy polling support in xsk for XDP_ZEROCOPY after it was broken in
> commit 86e25f40aa1e ("net: napi: Add napi_config"). The busy polling
> support with XDP_COPY remained broken since the napi_id setup in
> xsk_rcv_check was removed.
>
> Bring back the setup of napi_id for XDP_COPY so socket level SO_BUSYPOLL
> can be used to poll the underlying napi.
>
> Tested using AF_XDP support in virtio-net by running the xsk_rr AF_XDP
> benchmarking tool shared here:
> https://lore.kernel.org/all/20250320163523.3501305-1-skhawaja@google.com/T/
>
> Enabled socket busy polling using following commands in qemu,
>
> ```
> sudo ethtool -L eth0 combined 1
> sudo ethtool -G eth0 rx 1024
> echo 400 | sudo tee /proc/sys/net/core/busy_read
> echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs
> echo 15000   | sudo tee /sys/class/net/eth0/gro_flush_timeout
> ```
>
> Fixes: 5ef44b3cb43b ("xsk: Bring back busy polling support")
> Fixes: 86e25f40aa1e ("net: napi: Add napi_config")
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---
>  net/xdp/xsk.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index e5d104ce7b82..de8bf97b2cb9 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -310,6 +310,18 @@ static bool xsk_is_bound(struct xdp_sock *xs)
>         return false;
>  }
>
> +static void __xsk_mark_napi_id_once(struct sock *sk, struct net_device *dev, u32 qid)
> +{
> +       struct netdev_rx_queue *rxq;
> +
> +       if (qid >= dev->real_num_rx_queues)
> +               return;
> +
> +       rxq = __netif_get_rx_queue(dev, qid);
> +       if (rxq->napi)
> +               __sk_mark_napi_id_once(sk, rxq->napi->napi_id);
> +}
> +
>  static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  {
>         if (!xsk_is_bound(xs))
> @@ -323,6 +335,7 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>                 return -ENOSPC;
>         }
>
> +       __xsk_mark_napi_id_once(&xs->sk, xs->dev, xs->queue_id);
>         return 0;
>  }
>
> @@ -1300,13 +1313,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
>         xs->queue_id = qid;
>         xp_add_xsk(xs->pool, xs);
>
> -       if (xs->zc && qid < dev->real_num_rx_queues) {
> -               struct netdev_rx_queue *rxq;
> -
> -               rxq = __netif_get_rx_queue(dev, qid);
> -               if (rxq->napi)
> -                       __sk_mark_napi_id_once(sk, rxq->napi->napi_id);
> -       }
> +       if (xs->zc)
> +               __xsk_mark_napi_id_once(sk, dev, qid);
>
>  out_unlock:
>         if (err) {
> --
> 2.49.0.395.g12beb8f557-goog
>

The original commit 5ef44b3cb43b ("xsk: Bring back busy polling
support") has landed in 6.13 so I will revise this and resend it to
the net. Thanks
Stanislav Fomichev March 25, 2025, 4:37 p.m. UTC | #2
On 03/25, Samiullah Khawaja wrote:
> Commit 5ef44b3cb43b ("xsk: Bring back busy polling support") fixed the
> busy polling support in xsk for XDP_ZEROCOPY after it was broken in
> commit 86e25f40aa1e ("net: napi: Add napi_config"). The busy polling
> support with XDP_COPY remained broken since the napi_id setup in
> xsk_rcv_check was removed.
> 
> Bring back the setup of napi_id for XDP_COPY so socket level SO_BUSYPOLL
> can be used to poll the underlying napi.
> 
> Tested using AF_XDP support in virtio-net by running the xsk_rr AF_XDP
> benchmarking tool shared here:
> https://lore.kernel.org/all/20250320163523.3501305-1-skhawaja@google.com/T/
> 
> Enabled socket busy polling using following commands in qemu,
> 
> ```
> sudo ethtool -L eth0 combined 1
> sudo ethtool -G eth0 rx 1024
> echo 400 | sudo tee /proc/sys/net/core/busy_read
> echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs
> echo 15000   | sudo tee /sys/class/net/eth0/gro_flush_timeout
> ```
> 
> Fixes: 5ef44b3cb43b ("xsk: Bring back busy polling support")
> Fixes: 86e25f40aa1e ("net: napi: Add napi_config")
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---
>  net/xdp/xsk.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index e5d104ce7b82..de8bf97b2cb9 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -310,6 +310,18 @@ static bool xsk_is_bound(struct xdp_sock *xs)
>  	return false;
>  }
>  
> +static void __xsk_mark_napi_id_once(struct sock *sk, struct net_device *dev, u32 qid)
> +{
> +	struct netdev_rx_queue *rxq;
> +
> +	if (qid >= dev->real_num_rx_queues)
> +		return;
> +
> +	rxq = __netif_get_rx_queue(dev, qid);
> +	if (rxq->napi)
> +		__sk_mark_napi_id_once(sk, rxq->napi->napi_id);
> +}
> +
>  static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  {
>  	if (!xsk_is_bound(xs))
> @@ -323,6 +335,7 @@ static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  		return -ENOSPC;
>  	}

[..]

> +	__xsk_mark_napi_id_once(&xs->sk, xs->dev, xs->queue_id);
>  	return 0;
>  }

Can we move this part to a different place? __xsk_rcv maybe? So it
doesn't trigger for the zc case where napi is resolved at bind time.
diff mbox series

Patch

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index e5d104ce7b82..de8bf97b2cb9 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -310,6 +310,18 @@  static bool xsk_is_bound(struct xdp_sock *xs)
 	return false;
 }
 
+static void __xsk_mark_napi_id_once(struct sock *sk, struct net_device *dev, u32 qid)
+{
+	struct netdev_rx_queue *rxq;
+
+	if (qid >= dev->real_num_rx_queues)
+		return;
+
+	rxq = __netif_get_rx_queue(dev, qid);
+	if (rxq->napi)
+		__sk_mark_napi_id_once(sk, rxq->napi->napi_id);
+}
+
 static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
 {
 	if (!xsk_is_bound(xs))
@@ -323,6 +335,7 @@  static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
 		return -ENOSPC;
 	}
 
+	__xsk_mark_napi_id_once(&xs->sk, xs->dev, xs->queue_id);
 	return 0;
 }
 
@@ -1300,13 +1313,8 @@  static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 	xs->queue_id = qid;
 	xp_add_xsk(xs->pool, xs);
 
-	if (xs->zc && qid < dev->real_num_rx_queues) {
-		struct netdev_rx_queue *rxq;
-
-		rxq = __netif_get_rx_queue(dev, qid);
-		if (rxq->napi)
-			__sk_mark_napi_id_once(sk, rxq->napi->napi_id);
-	}
+	if (xs->zc)
+		__xsk_mark_napi_id_once(sk, dev, qid);
 
 out_unlock:
 	if (err) {