diff mbox series

[bpf-next,V4] xsk: allow remap of fill and/or completion rings

Message ID 20230324100222.13434-1-nunog@fr24.com (mailing list archive)
State Accepted
Commit 5f5a7d8d8bd461f515543040ad7d107cc405d30c
Delegated to: BPF
Headers show
Series [bpf-next,V4] xsk: allow remap of fill and/or completion rings | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-36 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for test_verifier on x86_64 with llvm-16
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
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: 20 this patch: 20
netdev/cc_maintainers success CCed 15 of 15 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 20 this patch: 20
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 fail Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16

Commit Message

Nuno Gonçalves March 24, 2023, 10:02 a.m. UTC
The remap of fill and completion rings was frowned upon as they
control the usage of UMEM which does not support concurrent use.
At the same time this would disallow the remap of these rings
into another process.

A possible use case is that the user wants to transfer the socket/
UMEM ownership to another process (via SYS_pidfd_getfd) and so
would need to also remap these rings.

This will have no impact on current usages and just relaxes the
remap limitation.

Signed-off-by: Nuno Gonçalves <nunog@fr24.com>
---
V3 -> V4: Remove undesired format changes
V2 -> V3: Call READ_ONCE for each variable and not for the ternary operator
V1 -> V2: Format and comment changes

 net/xdp/xsk.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--
2.40.0

Comments

Maciej Fijalkowski March 24, 2023, 12:19 p.m. UTC | #1
On Fri, Mar 24, 2023 at 10:02:22AM +0000, Nuno Gonçalves wrote:
> The remap of fill and completion rings was frowned upon as they
> control the usage of UMEM which does not support concurrent use.
> At the same time this would disallow the remap of these rings
> into another process.
> 
> A possible use case is that the user wants to transfer the socket/
> UMEM ownership to another process (via SYS_pidfd_getfd) and so
> would need to also remap these rings.
> 
> This will have no impact on current usages and just relaxes the
> remap limitation.
> 
> Signed-off-by: Nuno Gonçalves <nunog@fr24.com>
> ---
> V3 -> V4: Remove undesired format changes
> V2 -> V3: Call READ_ONCE for each variable and not for the ternary operator
> V1 -> V2: Format and comment changes

thanks, it now looks good to me, i applied this locally and it builds, so:
Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

but i am giving a last call to Magnus since he was acking this before.

> 
>  net/xdp/xsk.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 2ac58b282b5eb..cc1e7f15fa731 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -1301,9 +1301,10 @@ static int xsk_mmap(struct file *file, struct socket *sock,
>  	loff_t offset = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
>  	unsigned long size = vma->vm_end - vma->vm_start;
>  	struct xdp_sock *xs = xdp_sk(sock->sk);
> +	int state = READ_ONCE(xs->state);
>  	struct xsk_queue *q = NULL;
> 
> -	if (READ_ONCE(xs->state) != XSK_READY)
> +	if (state != XSK_READY && state != XSK_BOUND)
>  		return -EBUSY;
> 
>  	if (offset == XDP_PGOFF_RX_RING) {
> @@ -1314,9 +1315,11 @@ static int xsk_mmap(struct file *file, struct socket *sock,
>  		/* Matches the smp_wmb() in XDP_UMEM_REG */
>  		smp_rmb();
>  		if (offset == XDP_UMEM_PGOFF_FILL_RING)
> -			q = READ_ONCE(xs->fq_tmp);
> +			q = state == XSK_READY ? READ_ONCE(xs->fq_tmp) :
> +						 READ_ONCE(xs->pool->fq);
>  		else if (offset == XDP_UMEM_PGOFF_COMPLETION_RING)
> -			q = READ_ONCE(xs->cq_tmp);
> +			q = state == XSK_READY ? READ_ONCE(xs->cq_tmp) :
> +						 READ_ONCE(xs->pool->cq);
>  	}
> 
>  	if (!q)
> --
> 2.40.0
>
Magnus Karlsson March 24, 2023, 1:30 p.m. UTC | #2
On Fri, 24 Mar 2023 at 13:22, Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> On Fri, Mar 24, 2023 at 10:02:22AM +0000, Nuno Gonçalves wrote:
> > The remap of fill and completion rings was frowned upon as they
> > control the usage of UMEM which does not support concurrent use.
> > At the same time this would disallow the remap of these rings
> > into another process.
> >
> > A possible use case is that the user wants to transfer the socket/
> > UMEM ownership to another process (via SYS_pidfd_getfd) and so
> > would need to also remap these rings.
> >
> > This will have no impact on current usages and just relaxes the
> > remap limitation.
> >
> > Signed-off-by: Nuno Gonçalves <nunog@fr24.com>
> > ---
> > V3 -> V4: Remove undesired format changes
> > V2 -> V3: Call READ_ONCE for each variable and not for the ternary operator
> > V1 -> V2: Format and comment changes
>
> thanks, it now looks good to me, i applied this locally and it builds, so:
> Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
>
> but i am giving a last call to Magnus since he was acking this before.

I have already acked it, but I can do it twice.
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>

> >
> >  net/xdp/xsk.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> > index 2ac58b282b5eb..cc1e7f15fa731 100644
> > --- a/net/xdp/xsk.c
> > +++ b/net/xdp/xsk.c
> > @@ -1301,9 +1301,10 @@ static int xsk_mmap(struct file *file, struct socket *sock,
> >       loff_t offset = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
> >       unsigned long size = vma->vm_end - vma->vm_start;
> >       struct xdp_sock *xs = xdp_sk(sock->sk);
> > +     int state = READ_ONCE(xs->state);
> >       struct xsk_queue *q = NULL;
> >
> > -     if (READ_ONCE(xs->state) != XSK_READY)
> > +     if (state != XSK_READY && state != XSK_BOUND)
> >               return -EBUSY;
> >
> >       if (offset == XDP_PGOFF_RX_RING) {
> > @@ -1314,9 +1315,11 @@ static int xsk_mmap(struct file *file, struct socket *sock,
> >               /* Matches the smp_wmb() in XDP_UMEM_REG */
> >               smp_rmb();
> >               if (offset == XDP_UMEM_PGOFF_FILL_RING)
> > -                     q = READ_ONCE(xs->fq_tmp);
> > +                     q = state == XSK_READY ? READ_ONCE(xs->fq_tmp) :
> > +                                              READ_ONCE(xs->pool->fq);
> >               else if (offset == XDP_UMEM_PGOFF_COMPLETION_RING)
> > -                     q = READ_ONCE(xs->cq_tmp);
> > +                     q = state == XSK_READY ? READ_ONCE(xs->cq_tmp) :
> > +                                              READ_ONCE(xs->pool->cq);
> >       }
> >
> >       if (!q)
> > --
> > 2.40.0
> >
patchwork-bot+netdevbpf@kernel.org March 26, 2023, 4:11 a.m. UTC | #3
Hello:

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

On Fri, 24 Mar 2023 10:02:22 +0000 you wrote:
> The remap of fill and completion rings was frowned upon as they
> control the usage of UMEM which does not support concurrent use.
> At the same time this would disallow the remap of these rings
> into another process.
> 
> A possible use case is that the user wants to transfer the socket/
> UMEM ownership to another process (via SYS_pidfd_getfd) and so
> would need to also remap these rings.
> 
> [...]

Here is the summary with links:
  - [bpf-next,V4] xsk: allow remap of fill and/or completion rings
    https://git.kernel.org/bpf/bpf-next/c/5f5a7d8d8bd4

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 2ac58b282b5eb..cc1e7f15fa731 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -1301,9 +1301,10 @@  static int xsk_mmap(struct file *file, struct socket *sock,
 	loff_t offset = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
 	unsigned long size = vma->vm_end - vma->vm_start;
 	struct xdp_sock *xs = xdp_sk(sock->sk);
+	int state = READ_ONCE(xs->state);
 	struct xsk_queue *q = NULL;

-	if (READ_ONCE(xs->state) != XSK_READY)
+	if (state != XSK_READY && state != XSK_BOUND)
 		return -EBUSY;

 	if (offset == XDP_PGOFF_RX_RING) {
@@ -1314,9 +1315,11 @@  static int xsk_mmap(struct file *file, struct socket *sock,
 		/* Matches the smp_wmb() in XDP_UMEM_REG */
 		smp_rmb();
 		if (offset == XDP_UMEM_PGOFF_FILL_RING)
-			q = READ_ONCE(xs->fq_tmp);
+			q = state == XSK_READY ? READ_ONCE(xs->fq_tmp) :
+						 READ_ONCE(xs->pool->fq);
 		else if (offset == XDP_UMEM_PGOFF_COMPLETION_RING)
-			q = READ_ONCE(xs->cq_tmp);
+			q = state == XSK_READY ? READ_ONCE(xs->cq_tmp) :
+						 READ_ONCE(xs->pool->cq);
 	}

 	if (!q)