Use READ/WRITE_ONCE() for IP local_port_range.
authorDavid Laight <David.Laight@ACULAB.COM>
Wed, 6 Dec 2023 13:44:20 +0000 (13:44 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 8 Dec 2023 18:44:42 +0000 (10:44 -0800)
commitd9f28735af8781d9c8c6c406c2a102090644133d
treeaff37910520f90b4c192c41a00fbde053c2d01e8
parent36b0bdb6d330fe0546fc7f97d93e8cfa57421ad9
Use READ/WRITE_ONCE() for IP local_port_range.

Commit 227b60f5102cd added a seqlock to ensure that the low and high
port numbers were always updated together.
This is overkill because the two 16bit port numbers can be held in
a u32 and read/written in a single instruction.

More recently 91d0b78c5177f added support for finer per-socket limits.
The user-supplied value is 'high << 16 | low' but they are held
separately and the socket options protected by the socket lock.

Use a u32 containing 'high << 16 | low' for both the 'net' and 'sk'
fields and use READ_ONCE()/WRITE_ONCE() to ensure both values are
always updated together.

Change (the now trival) inet_get_local_port_range() to a static inline
to optimise the calling code.
(In particular avoiding returning integers by reference.)

Signed-off-by: David Laight <david.laight@aculab.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Acked-by: Mat Martineau <martineau@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/4e505d4198e946a8be03fb1b4c3072b0@AcuMS.aculab.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/inet_sock.h
include/net/ip.h
include/net/netns/ipv4.h
net/ipv4/af_inet.c
net/ipv4/inet_connection_sock.c
net/ipv4/ip_sockglue.c
net/ipv4/sysctl_net_ipv4.c