* [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings
@ 2023-03-24 10:02 Nuno Gonçalves
2023-03-24 12:19 ` Maciej Fijalkowski
2023-03-26 4:11 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Nuno Gonçalves @ 2023-03-24 10:02 UTC (permalink / raw)
To: Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
Jonathan Lemon, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Christian Brauner, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend
Cc: Nuno Gonçalves, netdev, bpf, linux-kernel
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(-)
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings
2023-03-24 10:02 [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings Nuno Gonçalves
@ 2023-03-24 12:19 ` Maciej Fijalkowski
2023-03-24 13:30 ` Magnus Karlsson
2023-03-26 4:11 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 4+ messages in thread
From: Maciej Fijalkowski @ 2023-03-24 12:19 UTC (permalink / raw)
To: Nuno Gonçalves
Cc: Björn Töpel, Magnus Karlsson, Jonathan Lemon,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Christian Brauner, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, netdev, bpf, linux-kernel
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings
2023-03-24 12:19 ` Maciej Fijalkowski
@ 2023-03-24 13:30 ` Magnus Karlsson
0 siblings, 0 replies; 4+ messages in thread
From: Magnus Karlsson @ 2023-03-24 13:30 UTC (permalink / raw)
To: Maciej Fijalkowski
Cc: Nuno Gonçalves, Björn Töpel, Magnus Karlsson,
Jonathan Lemon, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Christian Brauner, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
bpf, linux-kernel
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
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings
2023-03-24 10:02 [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings Nuno Gonçalves
2023-03-24 12:19 ` Maciej Fijalkowski
@ 2023-03-26 4:11 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-26 4:11 UTC (permalink / raw)
To: =?utf-8?q?Nuno_Gon=C3=A7alves_=3Cnunog=40fr24=2Ecom=3E?=
Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon, davem,
edumazet, kuba, pabeni, brauner, ast, daniel, hawk,
john.fastabend, netdev, bpf, linux-kernel
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-26 4:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-24 10:02 [PATCH bpf-next V4] xsk: allow remap of fill and/or completion rings Nuno Gonçalves
2023-03-24 12:19 ` Maciej Fijalkowski
2023-03-24 13:30 ` Magnus Karlsson
2023-03-26 4:11 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).