From: Stefano Brivio <sbrivio@redhat.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Eric Dumazet <edumazet@google.com>,
netdev@vger.kernel.org, Kuniyuki Iwashima <kuniyu@amazon.com>,
Mike Manning <mvrmanning@gmail.com>,
David Gibson <david@gibson.dropbear.id.au>,
Paul Holzinger <pholzing@redhat.com>,
Philo Lu <lulie@linux.alibaba.com>,
Cambda Zhu <cambda@linux.alibaba.com>,
Fred Chen <fred.cc@alibaba-inc.com>,
Yubing Qiu <yubing.qiuyubing@alibaba-inc.com>
Subject: Re: [PATCH net-next 2/2] datagram, udp: Set local address and rehash socket atomically against lookup
Date: Thu, 5 Dec 2024 16:58:30 +0100 [thread overview]
Message-ID: <20241205165830.64da6fd7@elisabeth> (raw)
In-Reply-To: <fa941e0d-2359-4d06-8e61-de40b3d570cb@redhat.com>
On Thu, 5 Dec 2024 10:30:14 +0100
Paolo Abeni <pabeni@redhat.com> wrote:
> On 12/4/24 23:12, Stefano Brivio wrote:
>
> > [...]
> >
> > To fix this, replace the rehash operation by a set_rcv_saddr()
> > callback holding the spinlock on the primary hash chain, just like
> > the rehash operation used to do, but also setting the address (via
> > inet_update_saddr(), moved to headers) while holding the spinlock.
> >
> > To make this atomic against the lookup operation, also acquire the
> > spinlock on the primary chain there.
>
> I'm sorry for the late feedback.
>
> I'm concerned by the unconditional spinlock in __udp4_lib_lookup(). I
> fear it could cause performance regressions in different workloads:
> heavy UDP unicast flow, or even TCP over UDP tunnel when the NIC
> supports RX offload for the relevant UDP tunnel protocol.
>
> In the first case there will be an additional atomic operation per packet.
So, I've been looking into this a bit, and request-response rates with
neper's udp_rr (https://github.com/google/neper/blob/master/udp_rr.c)
for a client/server pair via loopback interface are the same before and
after this patch.
The reason is, I suppose, that the only contention on that spinlock is
the "intended" one, that is, between connect() and lookup.
Then I moved on to bulk flows, with socat or iperf3. But there (and
that's the whole point of this fix) we have connected sockets, and once
they are connected, we switch to early demux, which is not affected by
this patch.
In the end, I don't think this will affect "regular", bulk unicast
flows, because applications using them will typically connect sockets,
and we'll switch to early demux right away.
This lookup is not exactly "slow path", but it's not fast path either.
> In the latter the spin_lock will be contended with multiple concurrent
> TCP over UDP tunnel flows: the NIC with UDP tunnel offload can use the
> inner header to compute the RX hash, and use different rx queues for
> such flows.
>
> The GRO stage will perform UDP tunnel socket lookup and will contend the
> bucket lock.
In this case (I couldn't find out yet), aren't sockets connected? I
would expect that we switch to the early demux path relatively soon for
anything that needs to have somehow high throughput.
And if we don't, probably the more reasonable alternative would be to
"fix" that, rather than keeping this relatively common case broken.
Do you have a benchmark or something I can run?
> > This results in some awkwardness at a caller site, specifically
> > sock_bindtoindex_locked(), where we really just need to rehash the
> > socket without changing its address. With the new operation, we now
> > need to forcibly set the current address again.
> >
> > On the other hand, this appears more elegant than alternatives such
> > as fetching the spinlock reference in ip4_datagram_connect() and
> > ip6_datagram_conect(), and keeping the rehash operation around for
> > a single user also seems a tad overkill.
>
> Would such option require the same additional lock at lookup time?
Yes, it's conceptually the same, we would pretty much just move code
around.
I've been thinking about possible alternatives but they all involve a
much bigger rework. One idea could be that we RCU-connect() sockets,
instead of just having the hash table insertion under RCU. That is, as
long as we're in the grace period, the lookup would still see the old
receive address.
But, especially now that we have *three* hash tables, this is extremely
involved, and perhaps would warrant a rewrite of the whole thing. Given
that we're currently breaking users, I'd rather fix this first.
Sure, things have been broken for 19 years so I guess it's okay to defer
this fix to net-next (see discussion around the RFC), but I'd still
suggest that we fix this as a first step, because the breakage is
embarrassingly obvious (see reproducers).
--
Stefano
next prev parent reply other threads:[~2024-12-05 15:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 22:12 [PATCH net-next 0/2] Fix race between datagram socket address change and rehash Stefano Brivio
2024-12-04 22:12 ` [PATCH net-next 1/2] datagram: Rehash sockets only if local address changed for their family Stefano Brivio
2024-12-04 22:12 ` [PATCH net-next 2/2] datagram, udp: Set local address and rehash socket atomically against lookup Stefano Brivio
2024-12-05 9:30 ` Paolo Abeni
2024-12-05 15:58 ` Stefano Brivio [this message]
2024-12-05 16:53 ` Paolo Abeni
2024-12-06 10:50 ` Stefano Brivio
2024-12-06 12:36 ` Paolo Abeni
2024-12-06 13:35 ` Stefano Brivio
2024-12-06 15:10 ` Paolo Abeni
2024-12-18 16:21 ` Stefano Brivio
2024-12-05 16:35 ` Eric Dumazet
2024-12-05 22:32 ` David Gibson
2024-12-05 22:52 ` Eric Dumazet
2024-12-06 2:16 ` David Gibson
2024-12-06 9:04 ` Eric Dumazet
2024-12-09 2:20 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241205165830.64da6fd7@elisabeth \
--to=sbrivio@redhat.com \
--cc=cambda@linux.alibaba.com \
--cc=david@gibson.dropbear.id.au \
--cc=edumazet@google.com \
--cc=fred.cc@alibaba-inc.com \
--cc=kuniyu@amazon.com \
--cc=lulie@linux.alibaba.com \
--cc=mvrmanning@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pholzing@redhat.com \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yubing.qiuyubing@alibaba-inc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).