[PATCH v1 net 0/3] soreuseport: Fix issues related to the faster selection algorithm.

From: Kuniyuki Iwashima
Date: Mon Oct 10 2022 - 13:44:40 EST


setsockopt(SO_INCOMING_CPU) for UDP/TCP is broken since 4.5/4.6 due to
these commits:

* e32ea7e74727 ("soreuseport: fast reuseport UDP socket selection")
* c125e80b8868 ("soreuseport: fast reuseport TCP socket selection")

These commits introduced the O(1) socket selection algorithm and removed
O(n) iteration over the list, but it ignores the score calculated by
compute_score(). As a result, it caused two misbehaviours:

* Unconnected sockets receive packets sent to connected sockets
* SO_INCOMING_CPU does not work

The former is fixed by commit acdcecc61285 ("udp: correct reuseport
selection with connected sockets"), but it introduced a rare race,
which the first patch fixes. The second patch fixes the latter, and
the third adds a test for SO_INCOMING_CPU.


Kuniyuki Iwashima (3):
udp: Update reuse->has_conns under reuseport_lock.
soreuseport: Fix socket selection for SO_INCOMING_CPU.
selftest: Add test for SO_INCOMING_CPU.

include/net/sock_reuseport.h | 25 ++-
net/core/sock.c | 5 +-
net/core/sock_reuseport.c | 88 ++++++++++-
net/ipv4/datagram.c | 2 +-
net/ipv4/udp.c | 2 +-
net/ipv6/datagram.c | 2 +-
net/ipv6/udp.c | 2 +-
tools/testing/selftests/net/.gitignore | 1 +
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/so_incoming_cpu.c | 148 ++++++++++++++++++
10 files changed, 260 insertions(+), 16 deletions(-)
create mode 100644 tools/testing/selftests/net/so_incoming_cpu.c

--
2.30.2