q->idleslope and q->sendslope are s64 written locklessly in cbs_change() and read concurrently in cbs_dequeue_soft() and cbs_dump(). On 32-bit kernels, plain 64-bit accesses can tear, especially for negative sendslope values. Convert both fields to atomic64_t, matching q->port_rate. Fixes: 8eb54a421a62 ("net_sched: sch_cbs: implement lockless cbs_dump()") Signed-off-by: Jack Wang <163w…@gmail.com> --- net/sched/sch_cbs.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c index cb14500a1f7c..27d08ce07ecf 100644 --- a/net/sched/sch_cbs.c +++ b/net/sched/sch_cbs.c @@ -75,8 +75,8 @@ struct cbs_sched_data { s64 credits; /* in bytes */ s32 locredit; /* in bytes */ s32 hicredit; /* in bytes */ - s64 sendslope; /* in bytes/s */ - s64 idleslope; /* in bytes/s */ + atomic64_t sendslope; /* in bytes/s */ + atomic64_t idleslope; /* in bytes/s */ struct qdisc_watchdog watchdog; int (*enqueue)(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free); @@ -188,7 +188,9 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch) return NULL; } if (q->credits < 0) { - credits = timediff_to_credits(now - q->last, q->idleslope); + s64 idleslope = atomic64_read(&q->idleslope); + + credits = timediff_to_credits(now - q->last, idleslope); credits = q->credits + credits; q->credits = min_t(s64, credits, q->hicredit); @@ -196,7 +198,7 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch) if (q->credits < 0) { s64 delay; - delay = delay_from_credits(q->credits, q->idleslope); + delay = delay_from_credits(q->credits, idleslope); qdisc_watchdog_schedule_ns(&q->watchdog, now + delay); q->last = now; @@ -213,7 +215,7 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch) /* As sendslope is a negative number, this will decrease the * amount of q->credits. */ - credits = credits_from_len(len, q->sendslope, + credits = credits_from_len(len, atomic64_read(&q->sendslope), atomic64_read(&q->port_rate)); credits += q->credits; @@ -405,8 +407,8 @@ static int cbs_change(struct Qdisc *sch, struct nlattr *opt, /* Everything went OK, save the parameters used. */ WRITE_ONCE(q->hicredit, qopt->hicredit); WRITE_ONCE(q->locredit, qopt->locredit); - WRITE_ONCE(q->idleslope, qopt->idleslope * (s64)BYTES_PER_KBIT); - WRITE_ONCE(q->sendslope, qopt->sendslope * (s64)BYTES_PER_KBIT); + atomic64_set(&q->idleslope, qopt->idleslope * (s64)BYTES_PER_KBIT); + atomic64_set(&q->sendslope, qopt->sendslope * (s64)BYTES_PER_KBIT); WRITE_ONCE(q->offload, qopt->offload); return 0; @@ -475,8 +477,8 @@ static int cbs_dump(struct Qdisc *sch, struct sk_buff *skb) opt.hicredit = READ_ONCE(q->hicredit); opt.locredit = READ_ONCE(q->locredit); - opt.sendslope = div64_s64(READ_ONCE(q->sendslope), (s64)BYTES_PER_KBIT); - opt.idleslope = div64_s64(READ_ONCE(q->idleslope), (s64)BYTES_PER_KBIT); + opt.sendslope = div64_s64(atomic64_read(&q->sendslope), (s64)BYTES_PER_KBIT); + opt.idleslope = div64_s64(atomic64_read(&q->idleslope), (s64)BYTES_PER_KBIT); opt.offload = READ_ONCE(q->offload); if (nla_put(skb, TCA_CBS_PARMS, sizeof(opt), &opt))
-- 2.53.0