All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] xsk: Enable shared umem support.
@ 2019-11-05 23:35 William Tu
  2019-11-06 16:53 ` Magnus Karlsson
  0 siblings, 1 reply; 3+ messages in thread
From: William Tu @ 2019-11-05 23:35 UTC (permalink / raw)
  To: netdev; +Cc: dev, i.maximets, echaudro, bjorn.topel, magnus.karlsson

Currently the shared umem feature is not supported in libbpf.
The patch removes the refcount check in libbpf to enable use of
shared umem.  Also, a umem can be shared by multiple netdevs,
so remove the checking at xsk_bind.

Tested using OVS at:
https://mail.openvswitch.org/pipermail/ovs-dev/2019-November/364392.html

Signed-off-by: William Tu <u9012063@gmail.com>
---
 net/xdp/xsk.c       |  5 -----
 tools/lib/bpf/xsk.c | 10 +++++-----
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 6040bc2b0088..0f2b16e275e3 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -697,11 +697,6 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 			sockfd_put(sock);
 			goto out_unlock;
 		}
-		if (umem_xs->dev != dev || umem_xs->queue_id != qid) {
-			err = -EINVAL;
-			sockfd_put(sock);
-			goto out_unlock;
-		}
 
 		xdp_get_umem(umem_xs->umem);
 		WRITE_ONCE(xs->umem, umem_xs->umem);
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 74d84f36a5b2..e6c4eb077dcd 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -579,16 +579,13 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
 	struct sockaddr_xdp sxdp = {};
 	struct xdp_mmap_offsets off;
 	struct xsk_socket *xsk;
+	bool shared;
 	int err;
 
 	if (!umem || !xsk_ptr || !rx || !tx)
 		return -EFAULT;
 
-	if (umem->refcount) {
-		pr_warn("Error: shared umems not supported by libbpf.\n");
-		return -EBUSY;
-	}
-
+	shared = !!(usr_config->bind_flags & XDP_SHARED_UMEM);
 	xsk = calloc(1, sizeof(*xsk));
 	if (!xsk)
 		return -ENOMEM;
@@ -687,6 +684,9 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
 	sxdp.sxdp_queue_id = xsk->queue_id;
 	sxdp.sxdp_flags = xsk->config.bind_flags;
 
+	if (shared)
+		sxdp.sxdp_shared_umem_fd = umem->fd;
+
 	err = bind(xsk->fd, (struct sockaddr *)&sxdp, sizeof(sxdp));
 	if (err) {
 		err = -errno;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] xsk: Enable shared umem support.
  2019-11-05 23:35 [PATCH net-next] xsk: Enable shared umem support William Tu
@ 2019-11-06 16:53 ` Magnus Karlsson
  2019-11-06 17:38   ` William Tu
  0 siblings, 1 reply; 3+ messages in thread
From: Magnus Karlsson @ 2019-11-06 16:53 UTC (permalink / raw)
  To: William Tu
  Cc: Network Development, dev, i.maximets, Eelco Chaudron,
	Björn Töpel, Karlsson, Magnus

On Wed, Nov 6, 2019 at 12:41 AM William Tu <u9012063@gmail.com> wrote:
>
> Currently the shared umem feature is not supported in libbpf.
> The patch removes the refcount check in libbpf to enable use of
> shared umem.  Also, a umem can be shared by multiple netdevs,
> so remove the checking at xsk_bind.

Hi William,

I do have a five part patch set sitting on the shelf that implements
this as well as a sample, added documentation and support for Rx-only
and Tx-only sockets. Let me just rebase it, retest it then submit it
to the list and you can see what you think of it. It is along the
lines of what you are suggesting here. I am travelling at the moment,
so this might not happen until tomorrow.

Structure of the patch set that I will submit:

Patch 1: Adds shared umem support to libbpf
Patch 2: Shared umem support and example XPD program added to xdpsock sample
Patch 3: Adds Rx-only and Tx-only support to libbpf
Patch 4: Uses Rx-only sockets for rxdrop and Tx-only sockets for txpush in
         the xdpsock sample
Patch 5: Add documentation entries for these two features

> Tested using OVS at:
> https://mail.openvswitch.org/pipermail/ovs-dev/2019-November/364392.html
>
> Signed-off-by: William Tu <u9012063@gmail.com>
> ---
>  net/xdp/xsk.c       |  5 -----
>  tools/lib/bpf/xsk.c | 10 +++++-----
>  2 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 6040bc2b0088..0f2b16e275e3 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -697,11 +697,6 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
>                         sockfd_put(sock);
>                         goto out_unlock;
>                 }
> -               if (umem_xs->dev != dev || umem_xs->queue_id != qid) {
> -                       err = -EINVAL;
> -                       sockfd_put(sock);
> -                       goto out_unlock;
> -               }
>
>                 xdp_get_umem(umem_xs->umem);
>                 WRITE_ONCE(xs->umem, umem_xs->umem);
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index 74d84f36a5b2..e6c4eb077dcd 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -579,16 +579,13 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
>         struct sockaddr_xdp sxdp = {};
>         struct xdp_mmap_offsets off;
>         struct xsk_socket *xsk;
> +       bool shared;
>         int err;
>
>         if (!umem || !xsk_ptr || !rx || !tx)
>                 return -EFAULT;
>
> -       if (umem->refcount) {
> -               pr_warn("Error: shared umems not supported by libbpf.\n");
> -               return -EBUSY;
> -       }
> -
> +       shared = !!(usr_config->bind_flags & XDP_SHARED_UMEM);
>         xsk = calloc(1, sizeof(*xsk));
>         if (!xsk)
>                 return -ENOMEM;
> @@ -687,6 +684,9 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
>         sxdp.sxdp_queue_id = xsk->queue_id;
>         sxdp.sxdp_flags = xsk->config.bind_flags;
>
> +       if (shared)
> +               sxdp.sxdp_shared_umem_fd = umem->fd;
> +
>         err = bind(xsk->fd, (struct sockaddr *)&sxdp, sizeof(sxdp));
>         if (err) {
>                 err = -errno;
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] xsk: Enable shared umem support.
  2019-11-06 16:53 ` Magnus Karlsson
@ 2019-11-06 17:38   ` William Tu
  0 siblings, 0 replies; 3+ messages in thread
From: William Tu @ 2019-11-06 17:38 UTC (permalink / raw)
  To: Magnus Karlsson
  Cc: Network Development, dev, i.maximets, Eelco Chaudron,
	Björn Töpel, Karlsson, Magnus

On Wed, Nov 06, 2019 at 05:53:09PM +0100, Magnus Karlsson wrote:
> On Wed, Nov 6, 2019 at 12:41 AM William Tu <u9012063@gmail.com> wrote:
> >
> > Currently the shared umem feature is not supported in libbpf.
> > The patch removes the refcount check in libbpf to enable use of
> > shared umem.  Also, a umem can be shared by multiple netdevs,
> > so remove the checking at xsk_bind.
> 
> Hi William,
> 
> I do have a five part patch set sitting on the shelf that implements
> this as well as a sample, added documentation and support for Rx-only
> and Tx-only sockets. Let me just rebase it, retest it then submit it
> to the list and you can see what you think of it. It is along the
> lines of what you are suggesting here. I am travelling at the moment,
> so this might not happen until tomorrow.
> 
> Structure of the patch set that I will submit:
> 
> Patch 1: Adds shared umem support to libbpf
> Patch 2: Shared umem support and example XPD program added to xdpsock sample
> Patch 3: Adds Rx-only and Tx-only support to libbpf
> Patch 4: Uses Rx-only sockets for rxdrop and Tx-only sockets for txpush in
>          the xdpsock sample
> Patch 5: Add documentation entries for these two features
> 
Hi Magnus,

Thank you. I will wait for your patch set.

William


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-06 17:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05 23:35 [PATCH net-next] xsk: Enable shared umem support William Tu
2019-11-06 16:53 ` Magnus Karlsson
2019-11-06 17:38   ` William Tu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.