net, xsk: Avoid taking multiple skbuff references
Commit642e450b6b
("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:642e450b6b
("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
This commit is contained in:

committed by
Daniel Borkmann

parent
178648916e
commit
36ccdf8582
@@ -4180,7 +4180,7 @@ int dev_queue_xmit_accel(struct sk_buff *skb, struct net_device *sb_dev)
|
||||
}
|
||||
EXPORT_SYMBOL(dev_queue_xmit_accel);
|
||||
|
||||
int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
|
||||
int __dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
|
||||
{
|
||||
struct net_device *dev = skb->dev;
|
||||
struct sk_buff *orig_skb = skb;
|
||||
@@ -4210,17 +4210,13 @@ int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
|
||||
dev_xmit_recursion_dec();
|
||||
|
||||
local_bh_enable();
|
||||
|
||||
if (!dev_xmit_complete(ret))
|
||||
kfree_skb(skb);
|
||||
|
||||
return ret;
|
||||
drop:
|
||||
atomic_long_inc(&dev->tx_dropped);
|
||||
kfree_skb_list(skb);
|
||||
return NET_XMIT_DROP;
|
||||
}
|
||||
EXPORT_SYMBOL(dev_direct_xmit);
|
||||
EXPORT_SYMBOL(__dev_direct_xmit);
|
||||
|
||||
/*************************************************************************
|
||||
* Receiver routines
|
||||
|
Reference in New Issue
Block a user