netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] libbpf: fix compatibility problem in xsk_socket__create
@ 2020-10-07 11:42 Magnus Karlsson
  2020-10-07 20:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Magnus Karlsson @ 2020-10-07 11:42 UTC (permalink / raw)
  To: magnus.karlsson, bjorn.topel, ast, daniel, netdev, jonathan.lemon
  Cc: bpf, ciara.loftus

From: Magnus Karlsson <magnus.karlsson@intel.com>

Fix a compatibility problem when the old XDP_SHARED_UMEM mode is used
together with the xsk_socket__create() call. In the old XDP_SHARED_UMEM
mode, only sharing of the same device and queue id was allowed, and in
this mode, the fill ring and completion ring were shared between the
AF_XDP sockets. Therefore, it was perfectly fine to call the
xsk_socket__create() API for each socket and not use the new
xsk_socket__create_shared() API. This behavior was ruined by the
commit introducing XDP_SHARED_UMEM support between different devices
and/or queue ids. This patch restores the ability to use
xsk_socket__create in these circumstances so that backward
compatibility is not broken.

Fixes: 2f6324a3937f ("libbpf: Support shared umems between queues and devices")
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
v1->v2:
* Removed the check for different fill or completion rings entered in
  xsk_umem__create and xsk_socket__create_shared. The current
  behavior, that the ones entered in xsk_socket__create_shared
  supersedes the ones in xsk_umem__create, should be kept. Will
  document this in a separate patch and show how it can make the
  application code path easier.
---
 tools/lib/bpf/xsk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 30b4ca5..e3c98c0 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -705,7 +705,7 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
 	struct xsk_ctx *ctx;
 	int err, ifindex;
 
-	if (!umem || !xsk_ptr || !(rx || tx) || !fill || !comp)
+	if (!umem || !xsk_ptr || !(rx || tx))
 		return -EFAULT;
 
 	xsk = calloc(1, sizeof(*xsk));
@@ -735,6 +735,11 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
 
 	ctx = xsk_get_ctx(umem, ifindex, queue_id);
 	if (!ctx) {
+		if (!fill || !comp) {
+			err = -EFAULT;
+			goto out_socket;
+		}
+
 		ctx = xsk_create_ctx(xsk, umem, ifindex, ifname, queue_id,
 				     fill, comp);
 		if (!ctx) {
-- 
2.7.4


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

* Re: [PATCH bpf-next v2] libbpf: fix compatibility problem in xsk_socket__create
  2020-10-07 11:42 [PATCH bpf-next v2] libbpf: fix compatibility problem in xsk_socket__create Magnus Karlsson
@ 2020-10-07 20:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2020-10-07 20:40 UTC (permalink / raw)
  To: Magnus Karlsson
  Cc: magnus.karlsson, bjorn.topel, ast, daniel, netdev, jonathan.lemon,
	bpf, ciara.loftus

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

On Wed,  7 Oct 2020 13:42:26 +0200 you wrote:
> From: Magnus Karlsson <magnus.karlsson@intel.com>
> 
> Fix a compatibility problem when the old XDP_SHARED_UMEM mode is used
> together with the xsk_socket__create() call. In the old XDP_SHARED_UMEM
> mode, only sharing of the same device and queue id was allowed, and in
> this mode, the fill ring and completion ring were shared between the
> AF_XDP sockets. Therefore, it was perfectly fine to call the
> xsk_socket__create() API for each socket and not use the new
> xsk_socket__create_shared() API. This behavior was ruined by the
> commit introducing XDP_SHARED_UMEM support between different devices
> and/or queue ids. This patch restores the ability to use
> xsk_socket__create in these circumstances so that backward
> compatibility is not broken.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] libbpf: fix compatibility problem in xsk_socket__create
    https://git.kernel.org/bpf/bpf-next/c/80348d8867c6

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] 2+ messages in thread

end of thread, other threads:[~2020-10-07 20:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-07 11:42 [PATCH bpf-next v2] libbpf: fix compatibility problem in xsk_socket__create Magnus Karlsson
2020-10-07 20:40 ` 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).