Skip to content

Commit e2ce367

Browse files
Björn Töpelborkmann
authored andcommitted
xsk: simplify AF_XDP socket teardown
Prior this commit, when the struct socket object was being released, the UMEM did not have its reference count decreased. Instead, this was done in the struct sock sk_destruct function. There is no reason to keep the UMEM reference around when the socket is being orphaned, so in this patch the xdp_put_mem is called in the xsk_release function. This results in that the xsk_destruct function can be removed! Note that, it still holds that a struct xsk_sock reference might still linger in the XSKMAP after the UMEM is released, e.g. if a user does not clear the XSKMAP prior to closing the process. This sock will be in a "released" zombie like state, until the XSKMAP is removed. Signed-off-by: Björn Töpel <bjorn.topel@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 76c43ae commit e2ce367

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

net/xdp/xsk.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ static int xsk_release(struct socket *sock)
366366

367367
xskq_destroy(xs->rx);
368368
xskq_destroy(xs->tx);
369+
xdp_put_umem(xs->umem);
369370

370371
sock_orphan(sk);
371372
sock->sk = NULL;
@@ -713,18 +714,6 @@ static const struct proto_ops xsk_proto_ops = {
713714
.sendpage = sock_no_sendpage,
714715
};
715716

716-
static void xsk_destruct(struct sock *sk)
717-
{
718-
struct xdp_sock *xs = xdp_sk(sk);
719-
720-
if (!sock_flag(sk, SOCK_DEAD))
721-
return;
722-
723-
xdp_put_umem(xs->umem);
724-
725-
sk_refcnt_debug_dec(sk);
726-
}
727-
728717
static int xsk_create(struct net *net, struct socket *sock, int protocol,
729718
int kern)
730719
{
@@ -751,9 +740,6 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol,
751740

752741
sk->sk_family = PF_XDP;
753742

754-
sk->sk_destruct = xsk_destruct;
755-
sk_refcnt_debug_inc(sk);
756-
757743
sock_set_flag(sk, SOCK_RCU_FREE);
758744

759745
xs = xdp_sk(sk);

0 commit comments

Comments
 (0)