Skip to contentSkip to conversation

bug in AF_XDP socket cleanup?

DISCUSSION William Tu 2 participants 2 messages Sep 26, 2019 – Sep 27, 2019 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

William Tu

author
#1 lore raw
Quoted 19 lines · Július Milan

Hi folks

I am stuck with proper cleanup of AF_XDP socket. Not sure if I am doing something wrong or is it a bug.

I create xdp socket, then I remove it and then I am trying to create it again and got EBUSY from bind syscall

of xsk_socket__create.

My cleanup looks like this:

xsk_socket__delete();

xsk_umem__delete();

Quoted 7 lines

bpf_set_link_xdp_fd(ifindex, -1, opt_xdp_flags);

Attaching simple test case. It’s just reduced and modified xdpsock_user.c form kernel samples.

Tested on kernel v5.3 4d856f72c10ecb060868ed10ff1b1453943fc6c8 and related libbpf.

There are a couple of fixes related to cleanup.
Can you make sure your kernel has these patches

commit 0402acd683c678874df6bdbc23530ca07ea19353

Author: Björn Töpel <[email protected]>
Date:   Thu Aug 15 11:30:13 2019 +0200

xsk: remove AF_XDP socket from map when the socket is released

And libbpf has
commit 5750902a6e9bc6adb77da8257c0e34db2bfdebb2

Author: Björn Töpel <[email protected]>
Date:   Tue Apr 30 14:45:36 2019 +0200

libbpf: proper XSKMAP cleanup

commit 0e6741f092979535d159d5a851f12c88bfb7cb9a

Author: Björn Töpel <[email protected]>
Date:   Tue Apr 30 14:45:35 2019 +0200

libbpf: fix invalid munmap call

Thanks
William

#2 lore raw
In reply to a message not in the archive

Hi Július,

The ring clean up routines in i40e and ixgbe are asynchronous, so they will likely not be ready when you return from the xsk_socket__delete() call. What happens if you add a sleep(1) before you create it a second time?

/Magnus

Quoted 32 lines · Július Milan

Hi folks

I am stuck with proper cleanup of AF_XDP socket. Not sure if I am doing something wrong or is it a bug.

I create xdp socket, then I remove it and then I am trying to create it again and got EBUSY from bind syscall

of xsk_socket__create.

My cleanup looks like this:

xsk_socket__delete();

xsk_umem__delete();

bpf_set_link_xdp_fd(ifindex, -1, opt_xdp_flags);

Attaching simple test case. It’s just reduced and modified xdpsock_user.c form kernel samples.

Tested on kernel v5.3 4d856f72c10ecb060868ed10ff1b1453943fc6c8 and related libbpf.

Thanks a lot

Julius