Patch "selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0" has been added to the 5.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0

to the 5.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     selftests-xsk-destroy-bpf-resources-only-when-ctx-re.patch
and it can be found in the queue-5.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 705ffe964984e70683c9ba857412435592e3a930
Author: Maciej Fijalkowski <maciej.fijalkowski@xxxxxxxxx>
Date:   Wed Jun 29 16:34:58 2022 +0200

    selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0
    
    [ Upstream commit 39e940d4abfabb08b6937a315546b24d10be67e3 ]
    
    Currently, xsk_socket__delete frees BPF resources regardless of ctx
    refcount. Xdpxceiver has a test to verify whether underlying BPF
    resources would not be wiped out after closing XSK socket that was
    bound to interface with other active sockets. From library's xsk part
    perspective it also means that the internal xsk context is shared and
    its refcount is bumped accordingly.
    
    After a switch to loading XDP prog based on previously opened XSK
    socket, mentioned xdpxceiver test fails with:
    
      not ok 16 [xdpxceiver.c:swap_xsk_resources:1334]: ERROR: 9/"Bad file descriptor
    
    which means that in swap_xsk_resources(), xsk_socket__delete() released
    xskmap which in turn caused a failure of xsk_socket__update_xskmap().
    
    To fix this, when deleting socket, decrement ctx refcount before
    releasing BPF resources and do so only when refcount dropped to 0 which
    means there are no more active sockets for this ctx so BPF resources can
    be freed safely.
    
    Fixes: 2f6324a3937f ("libbpf: Support shared umems between queues and devices")
    Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@xxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Acked-by: Magnus Karlsson <magnus.karlsson@xxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20220629143458.934337-5-maciej.fijalkowski@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index af136f73b09d..67dc010e9fe3 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -1147,8 +1147,6 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
 		goto out_mmap_tx;
 	}
 
-	ctx->prog_fd = -1;
-
 	if (!(xsk->config.libbpf_flags & XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD)) {
 		err = __xsk_setup_xdp_prog(xsk, NULL);
 		if (err)
@@ -1229,7 +1227,10 @@ void xsk_socket__delete(struct xsk_socket *xsk)
 
 	ctx = xsk->ctx;
 	umem = ctx->umem;
-	if (ctx->prog_fd != -1) {
+
+	xsk_put_ctx(ctx, true);
+
+	if (!ctx->refcount) {
 		xsk_delete_bpf_maps(xsk);
 		close(ctx->prog_fd);
 		if (ctx->has_bpf_link)
@@ -1248,8 +1249,6 @@ void xsk_socket__delete(struct xsk_socket *xsk)
 		}
 	}
 
-	xsk_put_ctx(ctx, true);
-
 	umem->refcount--;
 	/* Do not close an fd that also has an associated umem connected
 	 * to it.



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux