netfilter: flowtable: avoid possible false sharing
authorPablo Neira Ayuso <pablo@netfilter.org>
Sat, 17 Jul 2021 08:10:29 +0000 (10:10 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 23 Jul 2021 12:18:01 +0000 (14:18 +0200)
The flowtable follows the same timeout approach as conntrack, use the
same idiom as in cc16921351d8 ("netfilter: conntrack: avoid same-timeout
update") but also include the fix provided by e37542ba111f ("netfilter:
conntrack: avoid possible false sharing").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_flow_table_core.c

index 1e50908b1b7e1d97a3fa1accd5043446fdaa7514..551976e4284cad8f373c9c23236a7096375974aa 100644 (file)
@@ -331,7 +331,11 @@ EXPORT_SYMBOL_GPL(flow_offload_add);
 void flow_offload_refresh(struct nf_flowtable *flow_table,
                          struct flow_offload *flow)
 {
-       flow->timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow);
+       u32 timeout;
+
+       timeout = nf_flowtable_time_stamp + flow_offload_get_timeout(flow);
+       if (READ_ONCE(flow->timeout) != timeout)
+               WRITE_ONCE(flow->timeout, timeout);
 
        if (likely(!nf_flowtable_hw_offload(flow_table)))
                return;