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>
Subject: Re: [PATCH net 2/6] tcp_metrics: annotate data-races around tm->tcpm_stamp
Date: Wed, 2 Aug 2023 10:30:58 -0700 [thread overview]
Message-ID: <20230802173058.50855-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230802131500.1478140-3-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Wed, 2 Aug 2023 13:14:56 +0000
> tm->tcpm_stamp can be read or written locklessly.
>
> Add needed READ_ONCE()/WRITE_ONCE() to document this.
>
> Also constify tcpm_check_stamp() dst argument.
>
> Fixes: 51c5d0c4b169 ("tcp: Maintain dynamic metrics in local cache.")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> net/ipv4/tcp_metrics.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
> index c4daf0aa2d4d9695e128b67df571d91d647a254d..83861658879638149d2746290a285a4f75fc3117 100644
> --- a/net/ipv4/tcp_metrics.c
> +++ b/net/ipv4/tcp_metrics.c
> @@ -97,7 +97,7 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
> u32 msval;
> u32 val;
>
> - tm->tcpm_stamp = jiffies;
> + WRITE_ONCE(tm->tcpm_stamp, jiffies);
>
> val = 0;
> if (dst_metric_locked(dst, RTAX_RTT))
> @@ -131,9 +131,15 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
>
> #define TCP_METRICS_TIMEOUT (60 * 60 * HZ)
>
> -static void tcpm_check_stamp(struct tcp_metrics_block *tm, struct dst_entry *dst)
> +static void tcpm_check_stamp(struct tcp_metrics_block *tm,
> + const struct dst_entry *dst)
> {
> - if (tm && unlikely(time_after(jiffies, tm->tcpm_stamp + TCP_METRICS_TIMEOUT)))
> + unsigned long limit;
> +
> + if (!tm)
> + return;
> + limit = READ_ONCE(tm->tcpm_stamp) + TCP_METRICS_TIMEOUT;
> + if (unlikely(time_after(jiffies, limit)))
> tcpm_suck_dst(tm, dst, false);
> }
>
> @@ -174,7 +180,8 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
> oldest = deref_locked(tcp_metrics_hash[hash].chain);
> for (tm = deref_locked(oldest->tcpm_next); tm;
> tm = deref_locked(tm->tcpm_next)) {
> - if (time_before(tm->tcpm_stamp, oldest->tcpm_stamp))
> + if (time_before(READ_ONCE(tm->tcpm_stamp),
> + READ_ONCE(oldest->tcpm_stamp)))
> oldest = tm;
> }
> tm = oldest;
> @@ -434,7 +441,7 @@ void tcp_update_metrics(struct sock *sk)
> tp->reordering);
> }
> }
> - tm->tcpm_stamp = jiffies;
> + WRITE_ONCE(tm->tcpm_stamp, jiffies);
> out_unlock:
> rcu_read_unlock();
> }
> @@ -647,7 +654,7 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
> }
>
> if (nla_put_msecs(msg, TCP_METRICS_ATTR_AGE,
> - jiffies - tm->tcpm_stamp,
> + jiffies - READ_ONCE(tm->tcpm_stamp),
> TCP_METRICS_ATTR_PAD) < 0)
> goto nla_put_failure;
>
> --
> 2.41.0.640.ga95def55d0-goog
next prev parent reply other threads:[~2023-08-02 17:33 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 [this message]
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
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=20230802173058.50855-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 \
/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.