xdp: fix race on generic receive path
authorIlya Maximets <i.maximets@samsung.com>
Wed, 3 Jul 2019 12:09:16 +0000 (15:09 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Jul 2019 07:12:51 +0000 (09:12 +0200)
commitfd7c22ba7a0ad898b9ecf77dd53f5ccc48492e35
treedc67885cf28cf5a9c0d8101e12e44acad5518bfc
parent29af1ae8002585a40ddd9e670ba8d383c5696fdc
xdp: fix race on generic receive path

[ Upstream commit bf0bdd1343efbbf65b4d53aef1fce14acbd79d50 ]

Unlike driver mode, generic xdp receive could be triggered
by different threads on different CPU cores at the same time
leading to the fill and rx queue breakage. For example, this
could happen while sending packets from two processes to the
first interface of veth pair while the second part of it is
open with AF_XDP socket.

Need to take a lock for each generic receive to avoid race.

Fixes: c497176cb2e4 ("xsk: add Rx receive functions and poll support")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Tested-by: William Tu <u9012063@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/xdp_sock.h
net/xdp/xsk.c