]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Wed, 29 Jun 2022 14:34:58 +0000 (16:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:26 +0000 (14:23 +0200)
commitd53bb6e7ec2a8c807357f536cc3cc67780282852
tree128d3162894179c9b7376567bea7368152a5e9b4
parent52f6e1db2b6da7d46b6ffdcf31283a5020556330
selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0

[ Upstream commit d25a98e65441c767de780f9e4c850e46257f6cb7 ]

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: 3c545a59a8a2 ("libbpf: Support shared umems between queues and devices")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20220629143458.934337-5-maciej.fijalkowski@intel.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/xsk.c