All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: prevent load/store tearing on sk->sk_stamp
@ 2019-11-05  5:38 Eric Dumazet
  2019-11-05 16:25 ` Deepa Dinamani
  2019-11-06  2:23 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-11-05  5:38 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet, Deepa Dinamani

Add a couple of READ_ONCE() and WRITE_ONCE() to prevent
load-tearing and store-tearing in sock_read_timestamp()
and sock_write_timestamp()

This might prevent another KCSAN report.

Fixes: 3a0ed3e96197 ("sock: Make sock->sk_stamp thread-safe")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Deepa Dinamani <deepa.kernel@gmail.com>
---
 include/net/sock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 8f9adcfac41bea7e46062851a25c042261323679..718e62fbe869db3ee7e8994bd1bfd559ab9c61c7 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2342,7 +2342,7 @@ static inline ktime_t sock_read_timestamp(struct sock *sk)
 
 	return kt;
 #else
-	return sk->sk_stamp;
+	return READ_ONCE(sk->sk_stamp);
 #endif
 }
 
@@ -2353,7 +2353,7 @@ static inline void sock_write_timestamp(struct sock *sk, ktime_t kt)
 	sk->sk_stamp = kt;
 	write_sequnlock(&sk->sk_stamp_seq);
 #else
-	sk->sk_stamp = kt;
+	WRITE_ONCE(sk->sk_stamp, kt);
 #endif
 }
 
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: prevent load/store tearing on sk->sk_stamp
  2019-11-05  5:38 [PATCH net] net: prevent load/store tearing on sk->sk_stamp Eric Dumazet
@ 2019-11-05 16:25 ` Deepa Dinamani
  2019-11-05 16:50   ` Eric Dumazet
  2019-11-06  2:23 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Deepa Dinamani @ 2019-11-05 16:25 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David S . Miller, netdev, Eric Dumazet, Arnd Bergmann

On Mon, Nov 4, 2019 at 9:38 PM Eric Dumazet <edumazet@google.com> wrote:
>
> Add a couple of READ_ONCE() and WRITE_ONCE() to prevent
> load-tearing and store-tearing in sock_read_timestamp()
> and sock_write_timestamp()
>
> This might prevent another KCSAN report.
>
> Fixes: 3a0ed3e96197 ("sock: Make sock->sk_stamp thread-safe")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Deepa Dinamani <deepa.kernel@gmail.com>
> ---
>  include/net/sock.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 8f9adcfac41bea7e46062851a25c042261323679..718e62fbe869db3ee7e8994bd1bfd559ab9c61c7 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -2342,7 +2342,7 @@ static inline ktime_t sock_read_timestamp(struct sock *sk)
>
>         return kt;
>  #else
> -       return sk->sk_stamp;
> +       return READ_ONCE(sk->sk_stamp);
>  #endif
>  }
>
> @@ -2353,7 +2353,7 @@ static inline void sock_write_timestamp(struct sock *sk, ktime_t kt)
>         sk->sk_stamp = kt;
>         write_sequnlock(&sk->sk_stamp_seq);
>  #else
> -       sk->sk_stamp = kt;
> +       WRITE_ONCE(sk->sk_stamp, kt);
>  #endif
>  }
>
> --
> 2.24.0.rc1.363.gb1bccd3e3d-goog

I do not see any harm with this. Does it cause performance degradation?

Acked-by: Deepa Dinamani <deepa.kernel@gmail.com>

-Deepa

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: prevent load/store tearing on sk->sk_stamp
  2019-11-05 16:25 ` Deepa Dinamani
@ 2019-11-05 16:50   ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-11-05 16:50 UTC (permalink / raw)
  To: Deepa Dinamani; +Cc: David S . Miller, netdev, Eric Dumazet, Arnd Bergmann

On Tue, Nov 5, 2019 at 8:25 AM Deepa Dinamani <deepa.kernel@gmail.com> wrote:

> I do not see any harm with this. Does it cause performance degradation?
>

It does not change compiler output, at least for common GCC versions.

It would change things if a hypothetical caller would do for example :

ktime_t res;

res = sock_read_timestamp(sk);
res = sock_read_timestamp(sk);

Since without  the READ_ONCE(), compiler could remove the first instance.

> Acked-by: Deepa Dinamani <deepa.kernel@gmail.com>
>
> -Deepa

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: prevent load/store tearing on sk->sk_stamp
  2019-11-05  5:38 [PATCH net] net: prevent load/store tearing on sk->sk_stamp Eric Dumazet
  2019-11-05 16:25 ` Deepa Dinamani
@ 2019-11-06  2:23 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-11-06  2:23 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, eric.dumazet, deepa.kernel

From: Eric Dumazet <edumazet@google.com>
Date: Mon,  4 Nov 2019 21:38:43 -0800

> Add a couple of READ_ONCE() and WRITE_ONCE() to prevent
> load-tearing and store-tearing in sock_read_timestamp()
> and sock_write_timestamp()
> 
> This might prevent another KCSAN report.
> 
> Fixes: 3a0ed3e96197 ("sock: Make sock->sk_stamp thread-safe")
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-06  2:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  5:38 [PATCH net] net: prevent load/store tearing on sk->sk_stamp Eric Dumazet
2019-11-05 16:25 ` Deepa Dinamani
2019-11-05 16:50   ` Eric Dumazet
2019-11-06  2:23 ` David Miller

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.