libbpf: Only create rx and tx XDP rings when necessary
authorCiara Loftus <ciara.loftus@intel.com>
Wed, 31 Mar 2021 06:12:18 +0000 (06:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Apr 2021 06:42:01 +0000 (08:42 +0200)
commitcaef7806141a66f7d4224d2e478ccd8a48044a55
tree95fd8f9a96ffe82be0fa242350e15d438c0cf577
parent4cc9177b099e251bd1f7713a0517d622b1b442b1
libbpf: Only create rx and tx XDP rings when necessary

commit ca7a83e2487ad0bc9a3e0e7a8645354aa1782f13 upstream.

Prior to this commit xsk_socket__create(_shared) always attempted to create
the rx and tx rings for the socket. However this causes an issue when the
socket being setup is that which shares the fd with the UMEM. If a
previous call to this function failed with this socket after the rings were
set up, a subsequent call would always fail because the rings are not torn
down after the first call and when we try to set them up again we encounter
an error because they already exist. Solve this by remembering whether the
rings were set up by introducing new bools to struct xsk_umem which
represent the ring setup status and using them to determine whether or
not to set up the rings.

Fixes: 1cad07884239 ("libbpf: add support for using AF_XDP sockets")
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210331061218.1647-4-ciara.loftus@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/lib/bpf/xsk.c