]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net_sched: act_ctinfo: use atomic64_t for three counters
authorEric Dumazet <edumazet@google.com>
Wed, 9 Jul 2025 09:01:57 +0000 (09:01 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 11 Jul 2025 23:01:16 +0000 (16:01 -0700)
Commit 21c167aa0ba9 ("net/sched: act_ctinfo: use percpu stats")
missed that stats_dscp_set, stats_dscp_error and stats_cpmark_set
might be written (and read) locklessly.

Use atomic64_t for these three fields, I doubt act_ctinfo is used
heavily on big SMP hosts anyway.

Fixes: 24ec483cec98 ("net: sched: Introduce act_ctinfo action")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Pedro Tammela <pctammela@mojatatu.com>
Link: https://patch.msgid.link/20250709090204.797558-6-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/tc_act/tc_ctinfo.h
net/sched/act_ctinfo.c

index f071c1d70a25e14a7a68c6294563a08851fbc738..a04bcac7adf4b61b73181d5dbd2ff9eee3cf5e97 100644 (file)
@@ -18,9 +18,9 @@ struct tcf_ctinfo_params {
 struct tcf_ctinfo {
        struct tc_action common;
        struct tcf_ctinfo_params __rcu *params;
-       u64 stats_dscp_set;
-       u64 stats_dscp_error;
-       u64 stats_cpmark_set;
+       atomic64_t stats_dscp_set;
+       atomic64_t stats_dscp_error;
+       atomic64_t stats_cpmark_set;
 };
 
 enum {
index 5b1241ddc75851998d93cd533acd74d7688410ac..93ab3bcd6d3106a1561f043e078d0be5997ea277 100644 (file)
@@ -44,9 +44,9 @@ static void tcf_ctinfo_dscp_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
                                ipv4_change_dsfield(ip_hdr(skb),
                                                    INET_ECN_MASK,
                                                    newdscp);
-                               ca->stats_dscp_set++;
+                               atomic64_inc(&ca->stats_dscp_set);
                        } else {
-                               ca->stats_dscp_error++;
+                               atomic64_inc(&ca->stats_dscp_error);
                        }
                }
                break;
@@ -57,9 +57,9 @@ static void tcf_ctinfo_dscp_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
                                ipv6_change_dsfield(ipv6_hdr(skb),
                                                    INET_ECN_MASK,
                                                    newdscp);
-                               ca->stats_dscp_set++;
+                               atomic64_inc(&ca->stats_dscp_set);
                        } else {
-                               ca->stats_dscp_error++;
+                               atomic64_inc(&ca->stats_dscp_error);
                        }
                }
                break;
@@ -72,7 +72,7 @@ static void tcf_ctinfo_cpmark_set(struct nf_conn *ct, struct tcf_ctinfo *ca,
                                  struct tcf_ctinfo_params *cp,
                                  struct sk_buff *skb)
 {
-       ca->stats_cpmark_set++;
+       atomic64_inc(&ca->stats_cpmark_set);
        skb->mark = READ_ONCE(ct->mark) & cp->cpmarkmask;
 }
 
@@ -323,15 +323,18 @@ static int tcf_ctinfo_dump(struct sk_buff *skb, struct tc_action *a,
        }
 
        if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_DSCP_SET,
-                             ci->stats_dscp_set, TCA_CTINFO_PAD))
+                             atomic64_read(&ci->stats_dscp_set),
+                             TCA_CTINFO_PAD))
                goto nla_put_failure;
 
        if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_DSCP_ERROR,
-                             ci->stats_dscp_error, TCA_CTINFO_PAD))
+                             atomic64_read(&ci->stats_dscp_error),
+                             TCA_CTINFO_PAD))
                goto nla_put_failure;
 
        if (nla_put_u64_64bit(skb, TCA_CTINFO_STATS_CPMARK_SET,
-                             ci->stats_cpmark_set, TCA_CTINFO_PAD))
+                             atomic64_read(&ci->stats_cpmark_set),
+                             TCA_CTINFO_PAD))
                goto nla_put_failure;
 
        spin_unlock_bh(&ci->tcf_lock);