Commit 4ffdd22e authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

tun: remove possible false sharing in tun_flow_update()

As mentioned in https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE#it-may-improve-performance
a C compiler can legally transform

if (e->queue_index != queue_index)
	e->queue_index = queue_index;

to :

	e->queue_index = queue_index;

Note that the code using jiffies has no issue, since jiffies
has volatile attribute.

if (e->updated != jiffies)
    e->updated = jiffies;

Fixes: 83b1bc12 ("tun: align write-heavy flow entry members to a cache line")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Zhang Yu <zhangyu31@baidu.com>
Cc: Wang Li <wangli39@baidu.com>
Cc: Li RongQing <lirongqing@baidu.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
parent e37542ba
...@@ -526,8 +526,8 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash, ...@@ -526,8 +526,8 @@ static void tun_flow_update(struct tun_struct *tun, u32 rxhash,
e = tun_flow_find(head, rxhash); e = tun_flow_find(head, rxhash);
if (likely(e)) { if (likely(e)) {
/* TODO: keep queueing to old queue until it's empty? */ /* TODO: keep queueing to old queue until it's empty? */
if (e->queue_index != queue_index) if (READ_ONCE(e->queue_index) != queue_index)
e->queue_index = queue_index; WRITE_ONCE(e->queue_index, queue_index);
if (e->updated != jiffies) if (e->updated != jiffies)
e->updated = jiffies; e->updated = jiffies;
sock_rps_record_flow_hash(e->rps_rxhash); sock_rps_record_flow_hash(e->rps_rxhash);
......
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