Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/sched: cbs: fix 32-bit overflow in transmission time estimate
@ 2026-11-19  5:33 Mohamed Dawod
  2026-11-20  0:17 ` Vinicius Costa Gomes
  0 siblings, 1 reply; 2+ messages in thread
From: Mohamed Dawod @ 2026-11-19  5:33 UTC (permalink / raw)
  To: netdev
  Cc: vinicius.gomes, jhs, jiri, davem, edumazet, kuba, pabeni, horms,
	ye.zh-yuan, linux-kernel, Mohamed Dawod

cbs_dequeue_soft() estimates when the transmission of a packet completes:

	q->last = now + div64_s64(len * NSEC_PER_SEC, port_rate);

len is an int and NSEC_PER_SEC is 1000000000L. On 32-bit architectures
long is 32 bits wide, so the product is computed in 32 bits and wraps
before it is widened for div64_s64(). For a 1242 byte frame the product
is 1242000000000 mod 2^32 = 754451456, which gives a transmission time
of about 60 ns at 100 Mbit/s instead of about 99 us.

As a result q->last stays almost equal to now and the packet sending
time is ignored again, which is the problem 'commit 961d0e5b3294
("net: cbs: Fix software cbs to consider packet sending time")'
set out to fix. The throughput becomes

	idleslope * port_rate / |sendslope|

instead of idleslope.

Measured on a BeagleBone Black (32-bit ARM, CPSW, 100 Mbit/s full
duplex) with software CBS (offload 0), one UDP flow with a 1200 byte
payload (1242 byte frames), sendslope = idleslope - 100000. The rate
was read from the qdisc byte counters:

	idleslope [kbit/s]   before [Mbit/s]   after [Mbit/s]
	10000                11.1              10
	20000                25.0              20
	30000                42.9              30

Cast len to s64 so the multiplication is done in 64 bits on all
architectures.

Fixes: 961d0e5b3294 ("net: cbs: Fix software cbs to consider packet sending time")
Signed-off-by: Mohamed Dawod <mhm.dawod@gmail.com>
---
 net/sched/sch_cbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/sched/sch_cbs.c
+++ b/net/sched/sch_cbs.c
@@ cbs_dequeue_soft()
 	if (unlikely(atomic64_read(&q->port_rate) == 0))
 		q->last = now;
 	else
-		q->last = now + div64_s64(len * NSEC_PER_SEC,
+		q->last = now + div64_s64((s64)len * NSEC_PER_SEC,
 					  atomic64_read(&q->port_rate));
---
 net/sched/sch_cbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c
index 1c93469c56e3..107c2b6e9da3 100644
--- a/net/sched/sch_cbs.c
+++ b/net/sched/sch_cbs.c
@@ -222,7 +222,7 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch)
 	if (unlikely(atomic64_read(&q->port_rate) == 0))
 		q->last = now;
 	else
-		q->last = now + div64_s64(len * NSEC_PER_SEC,
+		q->last = now + div64_s64((s64)len * NSEC_PER_SEC,
 					  atomic64_read(&q->port_rate));
 
 	return skb;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net/sched: cbs: fix 32-bit overflow in transmission time estimate
  2026-11-19  5:33 [PATCH net] net/sched: cbs: fix 32-bit overflow in transmission time estimate Mohamed Dawod
@ 2026-11-20  0:17 ` Vinicius Costa Gomes
  0 siblings, 0 replies; 2+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-20  0:17 UTC (permalink / raw)
  To: Mohamed Dawod, netdev
  Cc: jhs, jiri, davem, edumazet, kuba, pabeni, horms, ye.zh-yuan,
	linux-kernel, Mohamed Dawod

Mohamed Dawod <mhm.dawod@gmail.com> writes:

> cbs_dequeue_soft() estimates when the transmission of a packet completes:
>
> 	q->last = now + div64_s64(len * NSEC_PER_SEC, port_rate);
>
> len is an int and NSEC_PER_SEC is 1000000000L. On 32-bit architectures
> long is 32 bits wide, so the product is computed in 32 bits and wraps
> before it is widened for div64_s64(). For a 1242 byte frame the product
> is 1242000000000 mod 2^32 = 754451456, which gives a transmission time
> of about 60 ns at 100 Mbit/s instead of about 99 us.
>
> As a result q->last stays almost equal to now and the packet sending
> time is ignored again, which is the problem 'commit 961d0e5b3294
> ("net: cbs: Fix software cbs to consider packet sending time")'
> set out to fix. The throughput becomes
>
> 	idleslope * port_rate / |sendslope|
>
> instead of idleslope.
>
> Measured on a BeagleBone Black (32-bit ARM, CPSW, 100 Mbit/s full
> duplex) with software CBS (offload 0), one UDP flow with a 1200 byte
> payload (1242 byte frames), sendslope = idleslope - 100000. The rate
> was read from the qdisc byte counters:
>
> 	idleslope [kbit/s]   before [Mbit/s]   after [Mbit/s]
> 	10000                11.1              10
> 	20000                25.0              20
> 	30000                42.9              30
>
> Cast len to s64 so the multiplication is done in 64 bits on all
> architectures.
>
> Fixes: 961d0e5b3294 ("net: cbs: Fix software cbs to consider packet sending time")
> Signed-off-by: Mohamed Dawod <mhm.dawod@gmail.com>

It seems that you had tool issues and the diff ended up being
duplicated. With that mechanical/process issue fixed:

Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

It seems that it would also save CPU time, less 'qdisc_watchdog' being
scheduled without being able to make any progress.


Cheers,
-- 
Vinicius

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20  0:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  5:33 [PATCH net] net/sched: cbs: fix 32-bit overflow in transmission time estimate Mohamed Dawod
2026-11-20  0:17 ` Vinicius Costa Gomes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox