* [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing
@ 2026-12-05 7:33 Jack Wang
2026-12-05 7:33 ` [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Jack Wang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Jack Wang @ 2026-12-05 7:33 UTC (permalink / raw)
To: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni
Cc: horms, victor, mhm.dawod, esalomatkina, andriy.shevchenko, netdev,
linux-kernel
This series fixes two 32-bit issues in sch_cbs:
1. Perform BYTES_PER_KBIT rate/slope conversions in signed 64-bit
arithmetic to restore software CBS shaping on ILP32 kernels.
2. Convert q->idleslope and q->sendslope to atomic64_t to prevent
64-bit tearing on 32-bit kernels.
The separate 32-bit overflow in len * NSEC_PER_SEC in cbs_dequeue_soft()
is being addressed independently by Mohamed Dawod, and the pre-existing
watchdog busy-loop and timediff_to_credits() overflow will be handled in
a separate follow-up patch.
v5:
- Restore the problem description and user-visible regression details
in patch 1, and scope its title to BYTES_PER_KBIT conversions.
- Split the atomic64_t conversion into patch 2 with its own Fixes: tag.
v4: https://lore.kernel.org/netdev/20261201085406.228-1-163wangjack@gmail.com/
- Drop the partial idleslope < 0 check (watchdog busy-loop will be
fixed separately).
- Cast BYTES_PER_KBIT to s64 for signed 64-bit math on ILP32 and LP64.
- Convert idleslope/sendslope to atomic64_t to prevent 32-bit tearing.
- Update Fixes: tags, remove the blank line in the tag block, and drop
v1 Acked-by due to the atomic64_t change.
v3: https://lore.kernel.org/netdev/20260813060256.28748-1-163wangjack@gmail.com/
- Reject only negative idleslope (keep 0 for tdc test 1820).
- Defer timediff_to_credits() overflow to a separate follow-up.
v2: https://lore.kernel.org/netdev/20260812080204.32373-1-163wangjack@gmail.com/
- Reject non-positive idleslope values.
v1: https://lore.kernel.org/netdev/20260806155253.50252-1-163wangjack@gmail.com/
Jack Wang (2):
net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions
net/sched: cbs: use atomic64_t for idleslope and sendslope
net/sched/sch_cbs.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
base-commit: 7b53449540502cb21b32bca62a6258e22cd97bbe
--
2.53.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions
2026-12-05 7:33 [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing Jack Wang
@ 2026-12-05 7:33 ` Jack Wang
2026-12-05 11:19 ` Andy Shevchenko
2026-12-05 7:33 ` [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope Jack Wang
2026-12-05 7:38 ` [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing netdev-bot+sinfo
2 siblings, 1 reply; 7+ messages in thread
From: Jack Wang @ 2026-12-05 7:33 UTC (permalink / raw)
To: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni
Cc: horms, victor, mhm.dawod, esalomatkina, andriy.shevchenko, netdev,
linux-kernel
BYTES_PER_KBIT is unsigned long, so ILP32 uses 32-bit unsigned math.
Since v6.8, negative sendslope turns positive, breaking software CBS
and cbs_dump() while high idleslope/port_rate overflow.
Cast BYTES_PER_KBIT and speed in cbs_set_port_rate() to s64 to ensure
signed 64-bit arithmetic on all architectures.
Fixes: 000db9e9ad42 ("net/sched: cbs: Use units.h instead of the copy of a definition")
Fixes: 397006ba5d91 ("net/sched: cbs: Fix integer overflow in cbs_set_port_rate()")
Signed-off-by: Jack Wang <163wangjack@gmail.com>
---
net/sched/sch_cbs.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c
index 1c93469c56e3..cb14500a1f7c 100644
--- a/net/sched/sch_cbs.c
+++ b/net/sched/sch_cbs.c
@@ -335,7 +335,7 @@ static void cbs_set_port_rate(struct net_device *dev, struct cbs_sched_data *q)
speed = ecmd.base.speed;
skip:
- port_rate = speed * 1000 * BYTES_PER_KBIT;
+ port_rate = (s64)speed * 1000 * (s64)BYTES_PER_KBIT;
atomic64_set(&q->port_rate, port_rate);
netdev_dbg(dev, "cbs: set %s's port_rate to: %lld, linkspeed: %d\n",
@@ -405,8 +405,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 * BYTES_PER_KBIT);
- WRITE_ONCE(q->sendslope, qopt->sendslope * BYTES_PER_KBIT);
+ WRITE_ONCE(q->idleslope, qopt->idleslope * (s64)BYTES_PER_KBIT);
+ WRITE_ONCE(q->sendslope, qopt->sendslope * (s64)BYTES_PER_KBIT);
WRITE_ONCE(q->offload, qopt->offload);
return 0;
@@ -475,8 +475,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), BYTES_PER_KBIT);
- opt.idleslope = div64_s64(READ_ONCE(q->idleslope), BYTES_PER_KBIT);
+ 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.offload = READ_ONCE(q->offload);
if (nla_put(skb, TCA_CBS_PARMS, sizeof(opt), &opt))
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope
2026-12-05 7:33 [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing Jack Wang
2026-12-05 7:33 ` [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Jack Wang
@ 2026-12-05 7:33 ` Jack Wang
2026-12-05 11:22 ` Andy Shevchenko
2026-12-05 7:38 ` [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing netdev-bot+sinfo
2 siblings, 1 reply; 7+ messages in thread
From: Jack Wang @ 2026-12-05 7:33 UTC (permalink / raw)
To: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni
Cc: horms, victor, mhm.dawod, esalomatkina, andriy.shevchenko, netdev,
linux-kernel
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 <163wangjack@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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing
2026-12-05 7:33 [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing Jack Wang
2026-12-05 7:33 ` [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Jack Wang
2026-12-05 7:33 ` [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope Jack Wang
@ 2026-12-05 7:38 ` netdev-bot+sinfo
2 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-12-05 7:38 UTC (permalink / raw)
To: Jack Wang
Cc: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni, horms, victor, mhm.dawod, esalomatkina, andriy.shevchenko,
netdev, linux-kernel
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions
2026-12-05 7:33 ` [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Jack Wang
@ 2026-12-05 11:19 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-12-05 11:19 UTC (permalink / raw)
To: Jack Wang
Cc: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni, horms, victor, mhm.dawod, esalomatkina, netdev,
linux-kernel
On Sat, Dec 05, 2026 at 03:33:03PM +0800, Jack Wang wrote:
> BYTES_PER_KBIT is unsigned long, so ILP32 uses 32-bit unsigned math.
> Since v6.8, negative sendslope turns positive, breaking software CBS
> and cbs_dump() while high idleslope/port_rate overflow.
>
> Cast BYTES_PER_KBIT and speed in cbs_set_port_rate() to s64 to ensure
> signed 64-bit arithmetic on all architectures.
...
> skip:
> - port_rate = speed * 1000 * BYTES_PER_KBIT;
> + port_rate = (s64)speed * 1000 * (s64)BYTES_PER_KBIT;
The second casting is redundant. Actually how do you expect port_rate be
negative?
...
> - WRITE_ONCE(q->idleslope, qopt->idleslope * BYTES_PER_KBIT);
> - WRITE_ONCE(q->sendslope, qopt->sendslope * BYTES_PER_KBIT);
> + WRITE_ONCE(q->idleslope, qopt->idleslope * (s64)BYTES_PER_KBIT);
> + WRITE_ONCE(q->sendslope, qopt->sendslope * (s64)BYTES_PER_KBIT);
Taking into account the above, why this casting near to the constant and not to
the variable(s)?
...
> - opt.sendslope = div64_s64(READ_ONCE(q->sendslope), BYTES_PER_KBIT);
> - opt.idleslope = div64_s64(READ_ONCE(q->idleslope), BYTES_PER_KBIT);
> + opt.sendslope = div64_s64(READ_ONCE(q->sendslope), (s64)BYTES_PER_KBIT);
> + opt.idleslope = div64_s64(READ_ONCE(q->idleslope), (s64)BYTES_PER_KBIT);
Why? What makes the difference here? The parameter of the function is already
s64.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope
2026-12-05 7:33 ` [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope Jack Wang
@ 2026-12-05 11:22 ` Andy Shevchenko
2026-12-05 13:08 ` Jack Wang
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2026-12-05 11:22 UTC (permalink / raw)
To: Jack Wang
Cc: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni, horms, victor, mhm.dawod, esalomatkina, netdev,
linux-kernel
On Sat, Dec 05, 2026 at 03:33:04PM +0800, Jack Wang wrote:
> 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.
...
> 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;
So, what's wrong with combining these two now?
credits = q->credits + timediff_to_credits(now - q->last, idleslope);
...
> - credits = credits_from_len(len, q->sendslope,
> + credits = credits_from_len(len, atomic64_read(&q->sendslope),
> atomic64_read(&q->port_rate));
And how does this help? Any value read by atomic APIs immediately becomes
outdated (yes, by luck if not synchronised, it may keep the same value
for a while).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope
2026-12-05 11:22 ` Andy Shevchenko
@ 2026-12-05 13:08 ` Jack Wang
0 siblings, 0 replies; 7+ messages in thread
From: Jack Wang @ 2026-12-05 13:08 UTC (permalink / raw)
To: andriy.shevchenko
Cc: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni, horms, victor, mhm.dawod, esalomatkina, netdev,
linux-kernel
On Sat, 5 Dec 2026 13:22:22 +0200, Andy Shevchenko wrote:
> So, what's wrong with combining these two now?
>
> credits = q->credits + timediff_to_credits(now - q->last, idleslope);
>
> ...
Agree with that.
>
>> - credits = credits_from_len(len, q->sendslope,
>> + credits = credits_from_len(len, atomic64_read(&q->sendslope),
>> atomic64_read(&q->port_rate));
>
> And how does this help? Any value read by atomic APIs immediately becomes
> outdated (yes, by luck if not synchronised, it may keep the same value
> for a while).
This change is not meant for synchronization. The intent is to
prevent 64-bit load/store tearing on 32-bit architectures during
concurrent updates from cbs_change().
Thanks,
JW
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-05 13:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 7:33 [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing Jack Wang
2026-12-05 7:33 ` [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions Jack Wang
2026-12-05 11:19 ` Andy Shevchenko
2026-12-05 7:33 ` [PATCH net v5 2/2] net/sched: cbs: use atomic64_t for idleslope and sendslope Jack Wang
2026-12-05 11:22 ` Andy Shevchenko
2026-12-05 13:08 ` Jack Wang
2026-12-05 7:38 ` [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox