Skip to content

Commit

Permalink
xsk: simplify AF_XDP socket teardown
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Björn Töpel authored and Daniel Borkmann committed Dec 19, 2018
1 parent 76c43ae commit e2ce367
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions net/xdp/xsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ static int xsk_release(struct socket *sock)

xskq_destroy(xs->rx);
xskq_destroy(xs->tx);
xdp_put_umem(xs->umem);

sock_orphan(sk);
sock->sk = NULL;
Expand Down Expand Up @@ -713,18 +714,6 @@ static const struct proto_ops xsk_proto_ops = {
.sendpage = sock_no_sendpage,
};

static void xsk_destruct(struct sock *sk)
{
struct xdp_sock *xs = xdp_sk(sk);

if (!sock_flag(sk, SOCK_DEAD))
return;

xdp_put_umem(xs->umem);

sk_refcnt_debug_dec(sk);
}

static int xsk_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
Expand All @@ -751,9 +740,6 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol,

sk->sk_family = PF_XDP;

sk->sk_destruct = xsk_destruct;
sk_refcnt_debug_inc(sk);

sock_set_flag(sk, SOCK_RCU_FREE);

xs = xdp_sk(sk);
Expand Down

0 comments on commit e2ce367

Please sign in to comment.