From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <edumazet@google.com>
Cc: <davem@davemloft.net>, <dsahern@kernel.org>,
<eric.dumazet@gmail.com>, <kuba@kernel.org>, <kuniyu@amazon.com>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>,
<ycheng@google.com>
Subject: Re: [PATCH net 6/6] tcp_metrics: fix data-race in tcpm_suck_dst() vs fastopen
Date: Wed, 2 Aug 2023 10:47:51 -0700 [thread overview]
Message-ID: <20230802174751.54502-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230802131500.1478140-7-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Wed, 2 Aug 2023 13:15:00 +0000
> Whenever tcpm_new() reclaims an old entry, tcpm_suck_dst()
> would overwrite data that could be read from tcp_fastopen_cache_get()
> or tcp_metrics_fill_info().
>
> We need to acquire fastopen_seqlock to maintain consistency.
>
> For newly allocated objects, tcpm_new() can switch to kzalloc()
> to avoid an extra fastopen_seqlock acquisition.
>
> Fixes: 1fe4c481ba63 ("net-tcp: Fast Open client - cookie cache")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Yuchung Cheng <ycheng@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> net/ipv4/tcp_metrics.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
> index 4fd274836a48f73d0b1206adfa14c17c3b28bc30..99ac5efe244d3c654deaa8f8c0fffeeb5d5597b1 100644
> --- a/net/ipv4/tcp_metrics.c
> +++ b/net/ipv4/tcp_metrics.c
> @@ -93,6 +93,7 @@ static struct tcpm_hash_bucket *tcp_metrics_hash __read_mostly;
> static unsigned int tcp_metrics_hash_log __read_mostly;
>
> static DEFINE_SPINLOCK(tcp_metrics_lock);
> +static DEFINE_SEQLOCK(fastopen_seqlock);
>
> static void tcpm_suck_dst(struct tcp_metrics_block *tm,
> const struct dst_entry *dst,
> @@ -129,11 +130,13 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
> tcp_metric_set(tm, TCP_METRIC_REORDERING,
> dst_metric_raw(dst, RTAX_REORDERING));
> if (fastopen_clear) {
> + write_seqlock(&fastopen_seqlock);
> tm->tcpm_fastopen.mss = 0;
> tm->tcpm_fastopen.syn_loss = 0;
> tm->tcpm_fastopen.try_exp = 0;
> tm->tcpm_fastopen.cookie.exp = false;
> tm->tcpm_fastopen.cookie.len = 0;
> + write_sequnlock(&fastopen_seqlock);
> }
> }
>
> @@ -194,7 +197,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
> }
> tm = oldest;
> } else {
> - tm = kmalloc(sizeof(*tm), GFP_ATOMIC);
> + tm = kzalloc(sizeof(*tm), GFP_ATOMIC);
> if (!tm)
> goto out_unlock;
> }
> @@ -204,7 +207,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
> tm->tcpm_saddr = *saddr;
> tm->tcpm_daddr = *daddr;
>
> - tcpm_suck_dst(tm, dst, true);
> + tcpm_suck_dst(tm, dst, reclaim);
>
> if (likely(!reclaim)) {
> tm->tcpm_next = tcp_metrics_hash[hash].chain;
> @@ -556,8 +559,6 @@ bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst)
> return ret;
> }
>
> -static DEFINE_SEQLOCK(fastopen_seqlock);
> -
> void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
> struct tcp_fastopen_cookie *cookie)
> {
> --
> 2.41.0.640.ga95def55d0-goog
next prev parent reply other threads:[~2023-08-02 17:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 13:14 [PATCH net 0/6] tcp_metrics: series of fixes Eric Dumazet
2023-08-02 13:14 ` [PATCH net 1/6] tcp_metrics: fix addr_same() helper Eric Dumazet
2023-08-02 15:04 ` David Ahern
2023-08-02 17:26 ` Kuniyuki Iwashima
2023-08-02 13:14 ` [PATCH net 2/6] tcp_metrics: annotate data-races around tm->tcpm_stamp Eric Dumazet
2023-08-02 15:06 ` David Ahern
2023-08-02 17:30 ` Kuniyuki Iwashima
2023-08-02 13:14 ` [PATCH net 3/6] tcp_metrics: annotate data-races around tm->tcpm_lock Eric Dumazet
2023-08-02 15:07 ` David Ahern
2023-08-02 17:35 ` Kuniyuki Iwashima
2023-08-02 13:14 ` [PATCH net 4/6] tcp_metrics: annotate data-races around tm->tcpm_vals[] Eric Dumazet
2023-08-02 15:09 ` David Ahern
2023-08-02 17:37 ` Kuniyuki Iwashima
2023-08-02 13:14 ` [PATCH net 5/6] tcp_metrics: annotate data-races around tm->tcpm_net Eric Dumazet
2023-08-02 15:12 ` David Ahern
2023-08-02 17:42 ` Kuniyuki Iwashima
2023-08-02 13:15 ` [PATCH net 6/6] tcp_metrics: fix data-race in tcpm_suck_dst() vs fastopen Eric Dumazet
2023-08-02 17:47 ` Kuniyuki Iwashima [this message]
2023-08-03 18:10 ` [PATCH net 0/6] tcp_metrics: series of fixes patchwork-bot+netdevbpf
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=20230802174751.54502-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ycheng@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.