diff mbox series

[v2,bpf-next] xsk: mark napi_id on sendmsg()

Message ID 20220707130842.49408-1-maciej.fijalkowski@intel.com (mailing list archive)
State Accepted
Commit ca2e1a627035002cd33d9667431e80bad90c25fa
Delegated to: BPF
Headers show
Series [v2,bpf-next] xsk: mark napi_id on sendmsg() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/cc_maintainers warning 10 maintainers not CCed: edumazet@google.com songliubraving@fb.com hawk@kernel.org pabeni@redhat.com jonathan.lemon@gmail.com yhs@fb.com davem@davemloft.net john.fastabend@gmail.com kafai@fb.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/checkpatch warning WARNING: line length of 83 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15

Commit Message

Maciej Fijalkowski July 7, 2022, 1:08 p.m. UTC
When application runs in busy poll mode and does not receive a single
packet but only sends them, it is currently
impossible to get into napi_busy_loop() as napi_id is only marked on Rx
side in xsk_rcv_check(). In there, napi_id is being taken from
xdp_rxq_info carried by xdp_buff. From Tx perspective, we do not have
access to it. What we have handy is the xsk pool.

Xsk pool works on a pool of internal xdp_buff wrappers called
xdp_buff_xsk. AF_XDP ZC enabled drivers call xp_set_rxq_info() so each
of xdp_buff_xsk has a valid pointer to xdp_rxq_info of underlying queue.
Therefore, on Tx side, napi_id can be pulled from
xs->pool->heads[0].xdp.rxq->napi_id. Hide this pointer chase under
helper function, xsk_pool_get_napi_id().

Do this only for sockets working in ZC mode as otherwise rxq pointers
would not be initialized.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---

v2:
* target bpf-next instead of bpf and don't treat it as fix (Bjorn)
* hide pointer chasing under helper function (Bjorn)

 include/net/xdp_sock_drv.h | 14 ++++++++++++++
 net/xdp/xsk.c              |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Magnus Karlsson July 14, 2022, 12:39 p.m. UTC | #1
On Thu, Jul 7, 2022 at 3:20 PM Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> When application runs in busy poll mode and does not receive a single
> packet but only sends them, it is currently
> impossible to get into napi_busy_loop() as napi_id is only marked on Rx
> side in xsk_rcv_check(). In there, napi_id is being taken from
> xdp_rxq_info carried by xdp_buff. From Tx perspective, we do not have
> access to it. What we have handy is the xsk pool.
>
> Xsk pool works on a pool of internal xdp_buff wrappers called
> xdp_buff_xsk. AF_XDP ZC enabled drivers call xp_set_rxq_info() so each
> of xdp_buff_xsk has a valid pointer to xdp_rxq_info of underlying queue.
> Therefore, on Tx side, napi_id can be pulled from
> xs->pool->heads[0].xdp.rxq->napi_id. Hide this pointer chase under
> helper function, xsk_pool_get_napi_id().
>
> Do this only for sockets working in ZC mode as otherwise rxq pointers
> would not be initialized.

Thanks Maciej.

Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> ---
>
> v2:
> * target bpf-next instead of bpf and don't treat it as fix (Bjorn)
> * hide pointer chasing under helper function (Bjorn)
>
>  include/net/xdp_sock_drv.h | 14 ++++++++++++++
>  net/xdp/xsk.c              |  5 ++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index 4aa031849668..4277b0dcee05 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h
> @@ -44,6 +44,15 @@ static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
>         xp_set_rxq_info(pool, rxq);
>  }
>
> +static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
> +{
> +#ifdef CONFIG_NET_RX_BUSY_POLL
> +       return pool->heads[0].xdp.rxq->napi_id;
> +#else
> +       return 0;
> +#endif
> +}
> +
>  static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
>                                       unsigned long attrs)
>  {
> @@ -198,6 +207,11 @@ static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
>  {
>  }
>
> +static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
> +{
> +       return 0;
> +}
> +
>  static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
>                                       unsigned long attrs)
>  {
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 19ac872a6624..86a97da7e50b 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -637,8 +637,11 @@ static int __xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len
>         if (unlikely(need_wait))
>                 return -EOPNOTSUPP;
>
> -       if (sk_can_busy_loop(sk))
> +       if (sk_can_busy_loop(sk)) {
> +               if (xs->zc)
> +                       __sk_mark_napi_id_once(sk, xsk_pool_get_napi_id(xs->pool));
>                 sk_busy_loop(sk, 1); /* only support non-blocking sockets */
> +       }
>
>         if (xs->zc && xsk_no_wakeup(sk))
>                 return 0;
> --
> 2.27.0
>
patchwork-bot+netdevbpf@kernel.org July 14, 2022, 8:50 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Thu,  7 Jul 2022 15:08:42 +0200 you wrote:
> When application runs in busy poll mode and does not receive a single
> packet but only sends them, it is currently
> impossible to get into napi_busy_loop() as napi_id is only marked on Rx
> side in xsk_rcv_check(). In there, napi_id is being taken from
> xdp_rxq_info carried by xdp_buff. From Tx perspective, we do not have
> access to it. What we have handy is the xsk pool.
> 
> [...]

Here is the summary with links:
  - [v2,bpf-next] xsk: mark napi_id on sendmsg()
    https://git.kernel.org/bpf/bpf-next/c/ca2e1a627035

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
index 4aa031849668..4277b0dcee05 100644
--- a/include/net/xdp_sock_drv.h
+++ b/include/net/xdp_sock_drv.h
@@ -44,6 +44,15 @@  static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
 	xp_set_rxq_info(pool, rxq);
 }
 
+static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
+{
+#ifdef CONFIG_NET_RX_BUSY_POLL
+	return pool->heads[0].xdp.rxq->napi_id;
+#else
+	return 0;
+#endif
+}
+
 static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
 				      unsigned long attrs)
 {
@@ -198,6 +207,11 @@  static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
 {
 }
 
+static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
+{
+	return 0;
+}
+
 static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
 				      unsigned long attrs)
 {
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 19ac872a6624..86a97da7e50b 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -637,8 +637,11 @@  static int __xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len
 	if (unlikely(need_wait))
 		return -EOPNOTSUPP;
 
-	if (sk_can_busy_loop(sk))
+	if (sk_can_busy_loop(sk)) {
+		if (xs->zc)
+			__sk_mark_napi_id_once(sk, xsk_pool_get_napi_id(xs->pool));
 		sk_busy_loop(sk, 1); /* only support non-blocking sockets */
+	}
 
 	if (xs->zc && xsk_no_wakeup(sk))
 		return 0;