[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f9d3e1dd-133a-45de-827e-c2f152b619b8@kernel.org>
Date: Wed, 6 Dec 2023 09:39:06 -0700
From: David Ahern <dsahern@...nel.org>
To: David Laight <David.Laight@...LAB.COM>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Cc: Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
"David S. Miller" <davem@...emloft.net>,
Stephen Hemminger <stephen@...workplumber.org>,
"jakub@...udflare.com" <jakub@...udflare.com>,
Eric Dumazet <edumazet@...gle.com>, 'Mat Martineau' <martineau@...nel.org>
Subject: Re: [PATCH net-next v2] Use READ/WRITE_ONCE() for IP
local_port_range.
On 12/6/23 6:44 AM, David Laight wrote:
> 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@...lab.com>
> ---
> Changes for v2:
> - minor layout changes.
> - remove unlikely() from comparisons when per-socket range set.
> - avoid shifts of signed values that generate unsigned 32bit results.
> I fiddled with the code that validates the argument to IP_LOCAL_PORT_RANGE
> then decided to leave it (mostly) unchanged because it is also moved.
> (There is a 'u16 x = int_val >> 16' which is required to move bit 31 to
> bit 15 and is probably undefined behaviour - but will be ok on all sane cpu.)
>
> include/net/inet_sock.h | 5 +----
> include/net/ip.h | 8 +++++++-
> include/net/netns/ipv4.h | 3 +--
> net/ipv4/af_inet.c | 4 +---
> net/ipv4/inet_connection_sock.c | 29 ++++++++++-------------------
> net/ipv4/ip_sockglue.c | 33 ++++++++++++++++-----------------
> net/ipv4/sysctl_net_ipv4.c | 18 +++++++-----------
> 7 files changed, 43 insertions(+), 57 deletions(-)
>
Reviewed-by: David Ahern <dsahern@...nel.org>
Powered by blists - more mailing lists