Skip to content

Commit 25c7a6d

Browse files
edumazetdavem330
authored andcommitted
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: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3828a93 commit 25c7a6d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

include/net/arp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key)
5757
unsigned long now = jiffies;
5858

5959
/* avoid dirtying neighbour */
60-
if (n->confirmed != now)
61-
n->confirmed = now;
60+
if (READ_ONCE(n->confirmed) != now)
61+
WRITE_ONCE(n->confirmed, now);
6262
}
6363
rcu_read_unlock_bh();
6464
}

include/net/ndisc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ static inline void __ipv6_confirm_neigh(struct net_device *dev,
414414
unsigned long now = jiffies;
415415

416416
/* avoid dirtying neighbour */
417-
if (n->confirmed != now)
418-
n->confirmed = now;
417+
if (READ_ONCE(n->confirmed) != now)
418+
WRITE_ONCE(n->confirmed, now);
419419
}
420420
rcu_read_unlock_bh();
421421
}
@@ -431,8 +431,8 @@ static inline void __ipv6_confirm_neigh_stub(struct net_device *dev,
431431
unsigned long now = jiffies;
432432

433433
/* avoid dirtying neighbour */
434-
if (n->confirmed != now)
435-
n->confirmed = now;
434+
if (READ_ONCE(n->confirmed) != now)
435+
WRITE_ONCE(n->confirmed, now);
436436
}
437437
rcu_read_unlock_bh();
438438
}

include/net/sock.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,8 +1939,8 @@ struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie);
19391939

19401940
static inline void sk_dst_confirm(struct sock *sk)
19411941
{
1942-
if (!sk->sk_dst_pending_confirm)
1943-
sk->sk_dst_pending_confirm = 1;
1942+
if (!READ_ONCE(sk->sk_dst_pending_confirm))
1943+
WRITE_ONCE(sk->sk_dst_pending_confirm, 1);
19441944
}
19451945

19461946
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)
19501950
unsigned long now = jiffies;
19511951

19521952
/* avoid dirtying neighbour */
1953-
if (n->confirmed != now)
1954-
n->confirmed = now;
1955-
if (sk && sk->sk_dst_pending_confirm)
1956-
sk->sk_dst_pending_confirm = 0;
1953+
if (READ_ONCE(n->confirmed) != now)
1954+
WRITE_ONCE(n->confirmed, now);
1955+
if (sk && READ_ONCE(sk->sk_dst_pending_confirm))
1956+
WRITE_ONCE(sk->sk_dst_pending_confirm, 0);
19571957
}
19581958
}
19591959

0 commit comments

Comments
 (0)