diff options
author | Magnus Karlsson <magnus.karlsson@intel.com> | 2020-12-18 14:45:24 +0100 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-12-18 16:10:21 +0100 |
commit | f09ced4053bc0a2094a12b60b646114c966ef4c6 (patch) | |
tree | da2345ffe99bd31cf1db279a97bbdfe4bac268f8 /include/net/xdp_sock.h | |
parent | xsk: Fix memory leak for failed bind (diff) | |
download | linux-f09ced4053bc0a2094a12b60b646114c966ef4c6.tar.xz linux-f09ced4053bc0a2094a12b60b646114c966ef4c6.zip |
xsk: Fix race in SKB mode transmit with shared cq
Fix a race when multiple sockets are simultaneously calling sendto()
when the completion ring is shared in the SKB case. This is the case
when you share the same netdev and queue id through the
XDP_SHARED_UMEM bind flag. The problem is that multiple processes can
be in xsk_generic_xmit() and call the backpressure mechanism in
xskq_prod_reserve(xs->pool->cq). As this is a shared resource in this
specific scenario, a race might occur since the rings are
single-producer single-consumer.
Fix this by moving the tx_completion_lock from the socket to the pool
as the pool is shared between the sockets that share the completion
ring. (The pool is not shared when this is not the case.) And then
protect the accesses to xskq_prod_reserve() with this lock. The
tx_completion_lock is renamed cq_lock to better reflect that it
protects accesses to the potentially shared completion ring.
Fixes: 35fcde7f8deb ("xsk: support for Tx")
Reported-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Link: https://lore.kernel.org/bpf/20201218134525.13119-2-magnus.karlsson@gmail.com
Diffstat (limited to 'include/net/xdp_sock.h')
-rw-r--r-- | include/net/xdp_sock.h | 4 |
1 files changed, 0 insertions, 4 deletions
diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index 4f4e93bf814c..cc17bc957548 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -58,10 +58,6 @@ struct xdp_sock { struct xsk_queue *tx ____cacheline_aligned_in_smp; struct list_head tx_list; - /* Mutual exclusion of NAPI TX thread and sendmsg error paths - * in the SKB destructor callback. - */ - spinlock_t tx_completion_lock; /* Protects generic receive. */ spinlock_t rx_lock; |