diff mbox series

[bpf-next] xsk: add multi-buffer support for sockets sharing umem

Message ID 20230907035032.2627879-1-tirthendu.sarkar@intel.com (mailing list archive)
State Accepted
Commit d609f3d228a8efe991f44f11f24146e2a5209755
Delegated to: BPF
Headers show
Series [bpf-next] xsk: add multi-buffer support for sockets sharing umem | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next, async
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: 1358 this patch: 1358
netdev/cc_maintainers warning 3 maintainers not CCed: edumazet@google.com hawk@kernel.org john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
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: 1381 this patch: 1381
netdev/checkpatch warning CHECK: Prefer using the BIT macro
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-0 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on s390x with gcc

Commit Message

Tirthendu Sarkar Sept. 7, 2023, 3:50 a.m. UTC
Userspace applications indicate their multi-buffer capability to xsk
using XSK_USE_SG socket bind flag. For sockets using shared umem the
bind flag may contain XSK_USE_SG only for the first socket. For any
subsequent socket the only option supported is XDP_SHARED_UMEM.

Add option XDP_UMEM_SG_FLAG in umem config flags to store the
multi-buffer handling capability when indicated by XSK_USE_SG option in
bing flag by the first socket. Use this to derive multi-buffer capability
for subsequent sockets in xsk core.

Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com>
Fixes: 81470b5c3c66 ("xsk: introduce XSK_USE_SG bind flag for xsk socket")
---
 include/net/xdp_sock.h  | 2 ++
 net/xdp/xsk.c           | 2 +-
 net/xdp/xsk_buff_pool.c | 3 +++
 3 files changed, 6 insertions(+), 1 deletion(-)

Comments

Fijalkowski, Maciej Sept. 7, 2023, 8:12 a.m. UTC | #1
On Thu, Sep 07, 2023 at 09:20:32AM +0530, Tirthendu Sarkar wrote:
> Userspace applications indicate their multi-buffer capability to xsk
> using XSK_USE_SG socket bind flag. For sockets using shared umem the
> bind flag may contain XSK_USE_SG only for the first socket. For any
> subsequent socket the only option supported is XDP_SHARED_UMEM.
> 
> Add option XDP_UMEM_SG_FLAG in umem config flags to store the
> multi-buffer handling capability when indicated by XSK_USE_SG option in
> bing flag by the first socket. Use this to derive multi-buffer capability
> for subsequent sockets in xsk core.
> 
> Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com>
> Fixes: 81470b5c3c66 ("xsk: introduce XSK_USE_SG bind flag for xsk socket")

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

> ---
>  include/net/xdp_sock.h  | 2 ++
>  net/xdp/xsk.c           | 2 +-
>  net/xdp/xsk_buff_pool.c | 3 +++
>  3 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
> index 1617af380162..69b472604b86 100644
> --- a/include/net/xdp_sock.h
> +++ b/include/net/xdp_sock.h
> @@ -14,6 +14,8 @@
>  #include <linux/mm.h>
>  #include <net/sock.h>
>  
> +#define XDP_UMEM_SG_FLAG (1 << 1)
> +
>  struct net_device;
>  struct xsk_queue;
>  struct xdp_buff;
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 55f8b9b0e06d..7482d0aca504 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -1228,7 +1228,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
>  
>  	xs->dev = dev;
>  	xs->zc = xs->umem->zc;
> -	xs->sg = !!(flags & XDP_USE_SG);
> +	xs->sg = !!(xs->umem->flags & XDP_UMEM_SG_FLAG);
>  	xs->queue_id = qid;
>  	xp_add_xsk(xs->pool, xs);
>  
> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index b3f7b310811e..49cb9f9a09be 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c
> @@ -170,6 +170,9 @@ int xp_assign_dev(struct xsk_buff_pool *pool,
>  	if (err)
>  		return err;
>  
> +	if (flags & XDP_USE_SG)
> +		pool->umem->flags |= XDP_UMEM_SG_FLAG;
> +
>  	if (flags & XDP_USE_NEED_WAKEUP)
>  		pool->uses_need_wakeup = true;
>  	/* Tx needs to be explicitly woken up the first time.  Also
> -- 
> 2.34.1
>
Simon Horman Sept. 7, 2023, 3:12 p.m. UTC | #2
On Thu, Sep 07, 2023 at 09:20:32AM +0530, Tirthendu Sarkar wrote:
> Userspace applications indicate their multi-buffer capability to xsk
> using XSK_USE_SG socket bind flag. For sockets using shared umem the
> bind flag may contain XSK_USE_SG only for the first socket. For any
> subsequent socket the only option supported is XDP_SHARED_UMEM.
> 
> Add option XDP_UMEM_SG_FLAG in umem config flags to store the
> multi-buffer handling capability when indicated by XSK_USE_SG option in
> bing flag by the first socket. Use this to derive multi-buffer capability
> for subsequent sockets in xsk core.
> 
> Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com>
> Fixes: 81470b5c3c66 ("xsk: introduce XSK_USE_SG bind flag for xsk socket")
> ---
>  include/net/xdp_sock.h  | 2 ++
>  net/xdp/xsk.c           | 2 +-
>  net/xdp/xsk_buff_pool.c | 3 +++
>  3 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
> index 1617af380162..69b472604b86 100644
> --- a/include/net/xdp_sock.h
> +++ b/include/net/xdp_sock.h
> @@ -14,6 +14,8 @@
>  #include <linux/mm.h>
>  #include <net/sock.h>
>  
> +#define XDP_UMEM_SG_FLAG (1 << 1)

nit: This could be BIT(1)
Tirthendu Sarkar Sept. 11, 2023, 8:50 a.m. UTC | #3
> -----Original Message-----
> From: Simon Horman <horms@kernel.org>
> Subject: Re: [PATCH bpf-next] xsk: add multi-buffer support for sockets
> sharing umem
> 
> On Thu, Sep 07, 2023 at 09:20:32AM +0530, Tirthendu Sarkar wrote:
> > Userspace applications indicate their multi-buffer capability to xsk
> > using XSK_USE_SG socket bind flag. For sockets using shared umem the
> > bind flag may contain XSK_USE_SG only for the first socket. For any
> > subsequent socket the only option supported is XDP_SHARED_UMEM.
> >
> > Add option XDP_UMEM_SG_FLAG in umem config flags to store the
> > multi-buffer handling capability when indicated by XSK_USE_SG option in
> > bing flag by the first socket. Use this to derive multi-buffer capability
> > for subsequent sockets in xsk core.
> >
> > Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com>
> > Fixes: 81470b5c3c66 ("xsk: introduce XSK_USE_SG bind flag for xsk socket")
> > ---
> >  include/net/xdp_sock.h  | 2 ++
> >  net/xdp/xsk.c           | 2 +-
> >  net/xdp/xsk_buff_pool.c | 3 +++
> >  3 files changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
> > index 1617af380162..69b472604b86 100644
> > --- a/include/net/xdp_sock.h
> > +++ b/include/net/xdp_sock.h
> > @@ -14,6 +14,8 @@
> >  #include <linux/mm.h>
> >  #include <net/sock.h>
> >
> > +#define XDP_UMEM_SG_FLAG (1 << 1)
> 
> nit: This could be BIT(1)

Thanks. We could have a follow up patch with such changes across xsk core.
patchwork-bot+netdevbpf@kernel.org Sept. 15, 2023, 6:10 p.m. UTC | #4
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu,  7 Sep 2023 09:20:32 +0530 you wrote:
> Userspace applications indicate their multi-buffer capability to xsk
> using XSK_USE_SG socket bind flag. For sockets using shared umem the
> bind flag may contain XSK_USE_SG only for the first socket. For any
> subsequent socket the only option supported is XDP_SHARED_UMEM.
> 
> Add option XDP_UMEM_SG_FLAG in umem config flags to store the
> multi-buffer handling capability when indicated by XSK_USE_SG option in
> bing flag by the first socket. Use this to derive multi-buffer capability
> for subsequent sockets in xsk core.
> 
> [...]

Here is the summary with links:
  - [bpf-next] xsk: add multi-buffer support for sockets sharing umem
    https://git.kernel.org/bpf/bpf-next/c/d609f3d228a8

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
index 1617af380162..69b472604b86 100644
--- a/include/net/xdp_sock.h
+++ b/include/net/xdp_sock.h
@@ -14,6 +14,8 @@ 
 #include <linux/mm.h>
 #include <net/sock.h>
 
+#define XDP_UMEM_SG_FLAG (1 << 1)
+
 struct net_device;
 struct xsk_queue;
 struct xdp_buff;
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 55f8b9b0e06d..7482d0aca504 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -1228,7 +1228,7 @@  static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 
 	xs->dev = dev;
 	xs->zc = xs->umem->zc;
-	xs->sg = !!(flags & XDP_USE_SG);
+	xs->sg = !!(xs->umem->flags & XDP_UMEM_SG_FLAG);
 	xs->queue_id = qid;
 	xp_add_xsk(xs->pool, xs);
 
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index b3f7b310811e..49cb9f9a09be 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -170,6 +170,9 @@  int xp_assign_dev(struct xsk_buff_pool *pool,
 	if (err)
 		return err;
 
+	if (flags & XDP_USE_SG)
+		pool->umem->flags |= XDP_UMEM_SG_FLAG;
+
 	if (flags & XDP_USE_NEED_WAKEUP)
 		pool->uses_need_wakeup = true;
 	/* Tx needs to be explicitly woken up the first time.  Also