Skip to content

Commit 8a1eca8

Browse files
edumazetgregkh
authored andcommitted
net_sched: sch_sfq: annotate data-races around q->perturb_period
commit a17ef9e upstream. sfq_perturbation() reads q->perturb_period locklessly. Add annotations to fix potential issues. Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 98236b2 commit 8a1eca8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/sched/sch_sfq.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ static void sfq_perturbation(struct timer_list *t)
611611
struct Qdisc *sch = q->sch;
612612
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
613613
siphash_key_t nkey;
614+
int period;
614615

615616
get_random_bytes(&nkey, sizeof(nkey));
616617
spin_lock(root_lock);
@@ -619,8 +620,12 @@ static void sfq_perturbation(struct timer_list *t)
619620
sfq_rehash(sch);
620621
spin_unlock(root_lock);
621622

622-
if (q->perturb_period)
623-
mod_timer(&q->perturb_timer, jiffies + q->perturb_period);
623+
/* q->perturb_period can change under us from
624+
* sfq_change() and sfq_destroy().
625+
*/
626+
period = READ_ONCE(q->perturb_period);
627+
if (period)
628+
mod_timer(&q->perturb_timer, jiffies + period);
624629
}
625630

626631
static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
@@ -662,7 +667,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
662667
q->quantum = ctl->quantum;
663668
q->scaled_quantum = SFQ_ALLOT_SIZE(q->quantum);
664669
}
665-
q->perturb_period = ctl->perturb_period * HZ;
670+
WRITE_ONCE(q->perturb_period, ctl->perturb_period * HZ);
666671
if (ctl->flows)
667672
q->maxflows = min_t(u32, ctl->flows, SFQ_MAX_FLOWS);
668673
if (ctl->divisor) {
@@ -724,7 +729,7 @@ static void sfq_destroy(struct Qdisc *sch)
724729
struct sfq_sched_data *q = qdisc_priv(sch);
725730

726731
tcf_block_put(q->block);
727-
q->perturb_period = 0;
732+
WRITE_ONCE(q->perturb_period, 0);
728733
del_timer_sync(&q->perturb_timer);
729734
sfq_free(q->ht);
730735
sfq_free(q->slots);

0 commit comments

Comments
 (0)