From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <lmb@isovalent.com>
Cc: <andrii@kernel.org>, <ast@kernel.org>, <bpf@vger.kernel.org>,
<daniel@iogearbox.net>, <davem@davemloft.net>,
<dsahern@kernel.org>, <edumazet@google.com>, <haoluo@google.com>,
<hemanthmalla@gmail.com>, <joe@wand.net.nz>,
<john.fastabend@gmail.com>, <jolsa@kernel.org>,
<kpsingh@kernel.org>, <kuba@kernel.org>, <kuniyu@amazon.com>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
<martin.lau@linux.dev>, <mykolal@fb.com>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>, <sdf@google.com>,
<shuah@kernel.org>, <song@kernel.org>,
<willemdebruijn.kernel@gmail.com>, <yhs@fb.com>
Subject: Re: [PATCH bpf-next v3 1/7] udp: re-score reuseport groups when connected sockets are present
Date: Mon, 26 Jun 2023 10:25:37 -0700 [thread overview]
Message-ID: <20230626172537.57064-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230613-so-reuseport-v3-1-907b4cbb7b99@isovalent.com>
From: Lorenz Bauer <lmb@isovalent.com>
Date: Mon, 26 Jun 2023 16:08:58 +0100
> Contrary to TCP, UDP reuseport groups can contain TCP_ESTABLISHED
> sockets. To support these properly we remember whether a group has
> a connected socket and skip the fast reuseport early-return. In
> effect we continue scoring all reuseport sockets and then choose the
> one with the highest score.
>
> The current code fails to re-calculate the score for the result of
> lookup_reuseport. According to Kuniyuki Iwashima:
>
> 1) SO_INCOMING_CPU is set
> -> selected sk might have +1 score
>
> 2) BPF prog returns ESTABLISHED and/or SO_INCOMING_CPU sk
> -> selected sk will have more than 8
>
> Using the old score could trigger more lookups depending on the
> order that sockets are created.
>
> sk -> sk (SO_INCOMING_CPU) -> sk (ESTABLISHED)
> | |
> `-> select the next SO_INCOMING_CPU sk
> |
> `-> select itself (We should save this lookup)
>
> Fixes: efc6b6f6c311 ("udp: Improve load balancing for SO_REUSEPORT.")
> Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
1 minor nit below.
> ---
> net/ipv4/udp.c | 20 +++++++++++++++-----
> net/ipv6/udp.c | 19 ++++++++++++++-----
> 2 files changed, 29 insertions(+), 10 deletions(-)
>
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index fd3dae081f3a..5ef478d2c408 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -450,14 +450,24 @@ static struct sock *udp4_lib_lookup2(struct net *net,
> score = compute_score(sk, net, saddr, sport,
> daddr, hnum, dif, sdif);
> if (score > badness) {
> - result = lookup_reuseport(net, sk, skb,
> - saddr, sport, daddr, hnum);
> + badness = score;
> + result = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
> + if (!result) {
> + result = sk;
> + continue;
> + }
> +
> /* Fall back to scoring if group has connections */
> - if (result && !reuseport_has_conns(sk))
> + if (!reuseport_has_conns(sk))
> return result;
>
> - result = result ? : sk;
> - badness = score;
> + /* Reuseport logic returned an error, keep original score. */
> + if (IS_ERR(result))
> + continue;
> +
> + badness = compute_score(result, net, saddr, sport,
> + daddr, hnum, dif, sdif);
> +
Unnecessary blank line here.
> }
> }
> return result;
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index e5a337e6b970..8b3cb1d7da7c 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -193,14 +193,23 @@ static struct sock *udp6_lib_lookup2(struct net *net,
> score = compute_score(sk, net, saddr, sport,
> daddr, hnum, dif, sdif);
> if (score > badness) {
> - result = lookup_reuseport(net, sk, skb,
> - saddr, sport, daddr, hnum);
> + badness = score;
> + result = lookup_reuseport(net, sk, skb, saddr, sport, daddr, hnum);
> + if (!result) {
> + result = sk;
> + continue;
> + }
> +
> /* Fall back to scoring if group has connections */
> - if (result && !reuseport_has_conns(sk))
> + if (!reuseport_has_conns(sk))
> return result;
>
> - result = result ? : sk;
> - badness = score;
> + /* Reuseport logic returned an error, keep original score. */
> + if (IS_ERR(result))
> + continue;
> +
> + badness = compute_score(sk, net, saddr, sport,
> + daddr, hnum, dif, sdif);
> }
> }
> return result;
>
> --
> 2.40.1
next prev parent reply other threads:[~2023-06-26 17:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 15:08 [PATCH bpf-next v3 0/7] Add SO_REUSEPORT support for TC bpf_sk_assign Lorenz Bauer
2023-06-26 15:08 ` [PATCH bpf-next v3 1/7] udp: re-score reuseport groups when connected sockets are present Lorenz Bauer
2023-06-26 17:25 ` Kuniyuki Iwashima [this message]
2023-06-26 15:08 ` [PATCH bpf-next v3 2/7] net: export inet_lookup_reuseport and inet6_lookup_reuseport Lorenz Bauer
2023-06-26 17:32 ` Kuniyuki Iwashima
2023-06-27 8:56 ` Lorenz Bauer
2023-06-27 10:19 ` Daniel Borkmann
2023-06-26 15:09 ` [PATCH bpf-next v3 3/7] net: document inet[6]_lookup_reuseport sk_state requirements Lorenz Bauer
2023-06-26 17:57 ` Kuniyuki Iwashima
2023-06-26 15:09 ` [PATCH bpf-next v3 4/7] net: remove duplicate reuseport_lookup functions Lorenz Bauer
2023-06-26 18:11 ` Kuniyuki Iwashima
2023-06-26 15:09 ` [PATCH bpf-next v3 5/7] net: remove duplicate sk_lookup helpers Lorenz Bauer
2023-06-26 20:02 ` Kuniyuki Iwashima
2023-06-26 15:09 ` [PATCH bpf-next v3 6/7] bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign Lorenz Bauer
2023-06-26 21:08 ` Kuniyuki Iwashima
2023-06-26 21:23 ` Kuniyuki Iwashima
2023-06-26 15:09 ` [PATCH bpf-next v3 7/7] selftests/bpf: Test that SO_REUSEPORT can be used with sk_assign helper Lorenz Bauer
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=20230626172537.57064-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=hemanthmalla@gmail.com \
--cc=joe@wand.net.nz \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lmb@isovalent.com \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yhs@fb.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).