Skip to content

Commit d2fa700

Browse files
magnus-karlssonkernel-patches-bot
authored andcommitted
libbpf: fix compatibility problem in xsk_socket__create
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. Therfore, 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 behaviour 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. We also make sure that a user that uses the xsk_socket__create_shared() api for the first socket in the old XDP_SHARED_UMEM mode above, gets and error message if the user tries to feed a fill ring or a completion ring that is not the same as the ones used for the umem registration. Previously, libbpf would just have silently ignored the supplied fill and completion rings and just taken them from the umem. Better to provide an error to the user. Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Fixes: 2f6324a ("libbpf: Support shared umems between queues and devices")
1 parent db2d8af commit d2fa700

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/lib/bpf/xsk.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
705705
struct xsk_ctx *ctx;
706706
int err, ifindex;
707707

708-
if (!umem || !xsk_ptr || !(rx || tx) || !fill || !comp)
708+
if (!umem || !xsk_ptr || !(rx || tx))
709709
return -EFAULT;
710710

711711
xsk = calloc(1, sizeof(*xsk));
@@ -735,12 +735,24 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
735735

736736
ctx = xsk_get_ctx(umem, ifindex, queue_id);
737737
if (!ctx) {
738+
if (!fill || !comp) {
739+
err = -EFAULT;
740+
goto out_socket;
741+
}
742+
738743
ctx = xsk_create_ctx(xsk, umem, ifindex, ifname, queue_id,
739744
fill, comp);
740745
if (!ctx) {
741746
err = -ENOMEM;
742747
goto out_socket;
743748
}
749+
} else if ((fill && ctx->fill != fill) || (comp && ctx->comp != comp)) {
750+
/* If the xsk_socket__create_shared() api is used for the first socket
751+
* registration, then make sure the fill and completion rings supplied
752+
* are the same as the ones used to register the umem. If not, bail out.
753+
*/
754+
err = -EINVAL;
755+
goto out_socket;
744756
}
745757
xsk->ctx = ctx;
746758

0 commit comments

Comments
 (0)