]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net_sched: sch_sfq: annotate data-races around q->perturb_period
authorEric Dumazet <edumazet@google.com>
Tue, 30 Apr 2024 18:00:15 +0000 (18:00 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 3 May 2024 02:01:35 +0000 (19:01 -0700)
sfq_perturbation() reads q->perturb_period locklessly.
Add annotations to fix potential issues.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240430180015.3111398-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sched/sch_sfq.c

index e66f4afb920d28b2fcca1e15634b61ca41ee1bcc..3b9245a3c767a6feed5e06f90459ae896b217c23 100644 (file)
@@ -608,6 +608,7 @@ static void sfq_perturbation(struct timer_list *t)
        struct Qdisc *sch = q->sch;
        spinlock_t *root_lock;
        siphash_key_t nkey;
+       int period;
 
        get_random_bytes(&nkey, sizeof(nkey));
        rcu_read_lock();
@@ -618,8 +619,12 @@ static void sfq_perturbation(struct timer_list *t)
                sfq_rehash(sch);
        spin_unlock(root_lock);
 
-       if (q->perturb_period)
-               mod_timer(&q->perturb_timer, jiffies + q->perturb_period);
+       /* q->perturb_period can change under us from
+        * sfq_change() and sfq_destroy().
+        */
+       period = READ_ONCE(q->perturb_period);
+       if (period)
+               mod_timer(&q->perturb_timer, jiffies + period);
        rcu_read_unlock();
 }
 
@@ -662,7 +667,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
                q->quantum = ctl->quantum;
                q->scaled_quantum = SFQ_ALLOT_SIZE(q->quantum);
        }
-       q->perturb_period = ctl->perturb_period * HZ;
+       WRITE_ONCE(q->perturb_period, ctl->perturb_period * HZ);
        if (ctl->flows)
                q->maxflows = min_t(u32, ctl->flows, SFQ_MAX_FLOWS);
        if (ctl->divisor) {
@@ -724,7 +729,7 @@ static void sfq_destroy(struct Qdisc *sch)
        struct sfq_sched_data *q = qdisc_priv(sch);
 
        tcf_block_put(q->block);
-       q->perturb_period = 0;
+       WRITE_ONCE(q->perturb_period, 0);
        del_timer_sync(&q->perturb_timer);
        sfq_free(q->ht);
        sfq_free(q->slots);