Commit 25c7a6d1 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: avoid potential false sharing in neighbor related code

There are common instances of the following construct :

	if (n->confirmed != now)
		n->confirmed = now;

A C compiler could legally remove the conditional.

Use READ_ONCE()/WRITE_ONCE() to avoid this problem.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3828a93f
...@@ -57,8 +57,8 @@ static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key) ...@@ -57,8 +57,8 @@ static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key)
unsigned long now = jiffies; unsigned long now = jiffies;
/* avoid dirtying neighbour */ /* avoid dirtying neighbour */
if (n->confirmed != now) if (READ_ONCE(n->confirmed) != now)
n->confirmed = now; WRITE_ONCE(n->confirmed, now);
} }
rcu_read_unlock_bh(); rcu_read_unlock_bh();
} }
......
...@@ -414,8 +414,8 @@ static inline void __ipv6_confirm_neigh(struct net_device *dev, ...@@ -414,8 +414,8 @@ static inline void __ipv6_confirm_neigh(struct net_device *dev,
unsigned long now = jiffies; unsigned long now = jiffies;
/* avoid dirtying neighbour */ /* avoid dirtying neighbour */
if (n->confirmed != now) if (READ_ONCE(n->confirmed) != now)
n->confirmed = now; WRITE_ONCE(n->confirmed, now);
} }
rcu_read_unlock_bh(); rcu_read_unlock_bh();
} }
...@@ -431,8 +431,8 @@ static inline void __ipv6_confirm_neigh_stub(struct net_device *dev, ...@@ -431,8 +431,8 @@ static inline void __ipv6_confirm_neigh_stub(struct net_device *dev,
unsigned long now = jiffies; unsigned long now = jiffies;
/* avoid dirtying neighbour */ /* avoid dirtying neighbour */
if (n->confirmed != now) if (READ_ONCE(n->confirmed) != now)
n->confirmed = now; WRITE_ONCE(n->confirmed, now);
} }
rcu_read_unlock_bh(); rcu_read_unlock_bh();
} }
......
...@@ -1939,8 +1939,8 @@ struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie); ...@@ -1939,8 +1939,8 @@ struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie);
static inline void sk_dst_confirm(struct sock *sk) static inline void sk_dst_confirm(struct sock *sk)
{ {
if (!sk->sk_dst_pending_confirm) if (!READ_ONCE(sk->sk_dst_pending_confirm))
sk->sk_dst_pending_confirm = 1; WRITE_ONCE(sk->sk_dst_pending_confirm, 1);
} }
static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n) static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n)
...@@ -1950,10 +1950,10 @@ static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n) ...@@ -1950,10 +1950,10 @@ static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n)
unsigned long now = jiffies; unsigned long now = jiffies;
/* avoid dirtying neighbour */ /* avoid dirtying neighbour */
if (n->confirmed != now) if (READ_ONCE(n->confirmed) != now)
n->confirmed = now; WRITE_ONCE(n->confirmed, now);
if (sk && sk->sk_dst_pending_confirm) if (sk && READ_ONCE(sk->sk_dst_pending_confirm))
sk->sk_dst_pending_confirm = 0; WRITE_ONCE(sk->sk_dst_pending_confirm, 0);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment