Skip to content

Commit 5c3b74a

Browse files
edumazetdavem330
authored andcommitted
rfs: annotate lockless accesses to RFS sock flow table
Add READ_ONCE()/WRITE_ONCE() on accesses to the sock flow table. This also prevents a (smart ?) compiler to remove the condition in: if (table->ents[index] != newval) table->ents[index] = newval; We need the condition to avoid dirtying a shared cache line. Fixes: fec5e65 ("rfs: Receive Flow Steering") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1e5c647 commit 5c3b74a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/linux/netdevice.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,11 @@ static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
768768
/* We only give a hint, preemption can change CPU under us */
769769
val |= raw_smp_processor_id();
770770

771-
if (table->ents[index] != val)
772-
table->ents[index] = val;
771+
/* The following WRITE_ONCE() is paired with the READ_ONCE()
772+
* here, and another one in get_rps_cpu().
773+
*/
774+
if (READ_ONCE(table->ents[index]) != val)
775+
WRITE_ONCE(table->ents[index], val);
773776
}
774777
}
775778

net/core/dev.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4471,8 +4471,10 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
44714471
u32 next_cpu;
44724472
u32 ident;
44734473

4474-
/* First check into global flow table if there is a match */
4475-
ident = sock_flow_table->ents[hash & sock_flow_table->mask];
4474+
/* First check into global flow table if there is a match.
4475+
* This READ_ONCE() pairs with WRITE_ONCE() from rps_record_sock_flow().
4476+
*/
4477+
ident = READ_ONCE(sock_flow_table->ents[hash & sock_flow_table->mask]);
44764478
if ((ident ^ hash) & ~rps_cpu_mask)
44774479
goto try_rps;
44784480

0 commit comments

Comments
 (0)