diff --git a/include/net/sock.h b/include/net/sock.h index a5d112270206873439821e3fb90b923aefada248..ba48b3cdfb6434ce4acf9467fcd20d83425eb8c3 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -963,8 +963,8 @@ static inline void sk_incoming_cpu_update(struct sock *sk) { int cpu = raw_smp_processor_id(); - if (unlikely(sk->sk_incoming_cpu != cpu)) - sk->sk_incoming_cpu = cpu; + if (unlikely(READ_ONCE(sk->sk_incoming_cpu) != cpu)) + WRITE_ONCE(sk->sk_incoming_cpu, cpu); } static inline void sock_rps_record_flow_hash(__u32 hash) diff --git a/net/core/sock.c b/net/core/sock.c index 6bb92f94f1dcde99007fc929bf956059d7a22f5a..55298b8f5c4bd1f43d6c7b4807fb206c2e9f2dff 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1027,7 +1027,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname, break; case SO_INCOMING_CPU: - sk->sk_incoming_cpu = val; + WRITE_ONCE(sk->sk_incoming_cpu, val); break; case SO_CNX_ADVICE: @@ -1363,7 +1363,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, break; case SO_INCOMING_CPU: - v.val = sk->sk_incoming_cpu; + v.val = READ_ONCE(sk->sk_incoming_cpu); break; case SO_MEMINFO: diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 2ec684057ebdc03ae7105bc3277d203810945df5..cf18cd2292b9f953c5e02fe9073a019b7118d6b2 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -252,7 +252,7 @@ static inline int compute_score(struct sock *sk, struct net *net, return -1; score += 4; - if (sk->sk_incoming_cpu == raw_smp_processor_id()) + if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id()) score++; } return score; diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 6a4b3962060d17fe4983bdbdff01c74d6849b4c5..c2ca87bafc5649256e81db7bb7a50073a847cfe6 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -405,7 +405,7 @@ static int compute_score(struct sock *sk, struct net *net, return -1; score += 4; - if (sk->sk_incoming_cpu == raw_smp_processor_id()) + if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id()) score++; return score; } diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index 5eeeba7181a1b3b314c23b8d752b08d38d6eddef..62b09714f2f62c8dc55778b02b904f53dc9a3da1 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -116,7 +116,7 @@ static inline int compute_score(struct sock *sk, struct net *net, return -1; score++; - if (sk->sk_incoming_cpu == raw_smp_processor_id()) + if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id()) score++; } return score; diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 4ce786e2a76082eeaa3d8a0e9e79321b59f7eac2..9d8a2814d681f1197705f574a75465e12e2c69a5 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -150,7 +150,7 @@ static int compute_score(struct sock *sk, struct net *net, return -1; score++; - if (sk->sk_incoming_cpu == raw_smp_processor_id()) + if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id()) score++; return score;