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 4/6] tcp_metrics: annotate data-races around tm->tcpm_vals[]
Date: Wed, 2 Aug 2023 10:37:52 -0700 [thread overview]
Message-ID: <20230802173752.52164-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230802131500.1478140-5-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Wed, 2 Aug 2023 13:14:58 +0000
> tm->tcpm_vals[] values can be read or written locklessly.
>
> Add needed READ_ONCE()/WRITE_ONCE() to document this,
> and force use of tcp_metric_get() and tcp_metric_set()
>
> 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 | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
> index 131fa300496914f78c682182f0db480ceb71b6a0..fd4ab7a51cef210005146dfbc3235a2db717a44f 100644
> --- a/net/ipv4/tcp_metrics.c
> +++ b/net/ipv4/tcp_metrics.c
> @@ -63,17 +63,19 @@ static bool tcp_metric_locked(struct tcp_metrics_block *tm,
> return READ_ONCE(tm->tcpm_lock) & (1 << idx);
> }
>
> -static u32 tcp_metric_get(struct tcp_metrics_block *tm,
> +static u32 tcp_metric_get(const struct tcp_metrics_block *tm,
> enum tcp_metric_index idx)
> {
> - return tm->tcpm_vals[idx];
> + /* Paired with WRITE_ONCE() in tcp_metric_set() */
> + return READ_ONCE(tm->tcpm_vals[idx]);
> }
>
> static void tcp_metric_set(struct tcp_metrics_block *tm,
> enum tcp_metric_index idx,
> u32 val)
> {
> - tm->tcpm_vals[idx] = val;
> + /* Paired with READ_ONCE() in tcp_metric_get() */
> + WRITE_ONCE(tm->tcpm_vals[idx], val);
> }
>
> static bool addr_same(const struct inetpeer_addr *a,
> @@ -115,13 +117,16 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm,
> WRITE_ONCE(tm->tcpm_lock, val);
>
> msval = dst_metric_raw(dst, RTAX_RTT);
> - tm->tcpm_vals[TCP_METRIC_RTT] = msval * USEC_PER_MSEC;
> + tcp_metric_set(tm, TCP_METRIC_RTT, msval * USEC_PER_MSEC);
>
> msval = dst_metric_raw(dst, RTAX_RTTVAR);
> - tm->tcpm_vals[TCP_METRIC_RTTVAR] = msval * USEC_PER_MSEC;
> - tm->tcpm_vals[TCP_METRIC_SSTHRESH] = dst_metric_raw(dst, RTAX_SSTHRESH);
> - tm->tcpm_vals[TCP_METRIC_CWND] = dst_metric_raw(dst, RTAX_CWND);
> - tm->tcpm_vals[TCP_METRIC_REORDERING] = dst_metric_raw(dst, RTAX_REORDERING);
> + tcp_metric_set(tm, TCP_METRIC_RTTVAR, msval * USEC_PER_MSEC);
> + tcp_metric_set(tm, TCP_METRIC_SSTHRESH,
> + dst_metric_raw(dst, RTAX_SSTHRESH));
> + tcp_metric_set(tm, TCP_METRIC_CWND,
> + dst_metric_raw(dst, RTAX_CWND));
> + tcp_metric_set(tm, TCP_METRIC_REORDERING,
> + dst_metric_raw(dst, RTAX_REORDERING));
> if (fastopen_clear) {
> tm->tcpm_fastopen.mss = 0;
> tm->tcpm_fastopen.syn_loss = 0;
> @@ -667,7 +672,7 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
> if (!nest)
> goto nla_put_failure;
> for (i = 0; i < TCP_METRIC_MAX_KERNEL + 1; i++) {
> - u32 val = tm->tcpm_vals[i];
> + u32 val = tcp_metric_get(tm, i);
>
> if (!val)
> continue;
> --
> 2.41.0.640.ga95def55d0-goog
next prev parent reply other threads:[~2023-08-02 17:38 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 [this message]
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=20230802173752.52164-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 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).