OSDN Git Service

net, xsk: Avoid taking multiple skbuff references
authorBjörn Töpel <bjorn.topel@intel.com>
Mon, 23 Nov 2020 17:56:00 +0000 (18:56 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 24 Nov 2020 21:39:56 +0000 (22:39 +0100)
commit36ccdf85829a7dd6936dba5d02fa50138471f0d3
tree9f0318f3a13070a94243d1058f6e2f32d9e29912
parent178648916e73e00de83150eb0c90c0d3a977a46a
net, xsk: Avoid taking multiple skbuff references

Commit 642e450b6b59 ("xsk: Do not discard packet when NETDEV_TX_BUSY")
addressed the problem that packets were discarded from the Tx AF_XDP
ring, when the driver returned NETDEV_TX_BUSY. Part of the fix was
bumping the skbuff reference count, so that the buffer would not be
freed by dev_direct_xmit(). A reference count larger than one means
that the skbuff is "shared", which is not the case.

If the "shared" skbuff is sent to the generic XDP receive path,
netif_receive_generic_xdp(), and pskb_expand_head() is entered the
BUG_ON(skb_shared(skb)) will trigger.

This patch adds a variant to dev_direct_xmit(), __dev_direct_xmit(),
where a user can select the skbuff free policy. This allows AF_XDP to
avoid bumping the reference count, but still keep the NETDEV_TX_BUSY
behavior.

Fixes: 642e450b6b59 ("xsk: Do not discard packet when NETDEV_TX_BUSY")
Reported-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20201123175600.146255-1-bjorn.topel@gmail.com
include/linux/netdevice.h
net/core/dev.c
net/xdp/xsk.c