From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jack Wang <163wangjack@gmail.com>,
vinicius.gomes@intel.com, jhs@mojatatu.com,
xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, victor@mojatatu.com, mhm.dawod@gmail.com,
esalomatkina@ispras.ru, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v5 1/2] net/sched: cbs: use signed 64-bit math for BYTES_PER_KBIT conversions
Date: Sun, 6 Dec 2026 13:28:07 +0000 [thread overview]
Message-ID: <20261206132807.550de376@pumpkin> (raw)
In-Reply-To: <axPzNaExgBV3dIQl@ashevche-desk.local>
On Sat, 5 Dec 2026 13:19:17 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 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)?
Widening the constant might make it less likely that the compiler actually
widens the variable before the multiply (instead of doing a 32x32 multiple
that has a 64bit result).
I hate these silly constants.
If I want to know what the code it actually doing I need to look up
whether BYTES_PER_KBIT is 1000/8 or 1024/8 (or even something else).
In any case it ought to be KBITS_TO_BYTES(x).
David
>
> ...
>
> > - 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.
>
next prev parent reply other threads:[~2026-12-06 13:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 14:00 ` Jack Wang
2026-12-06 13:28 ` David Laight [this message]
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-06 13:33 ` David Laight
2026-12-05 7:38 ` [PATCH net v5 0/2] net/sched: cbs: fix 32-bit rate conversions and slope tearing netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206132807.550de376@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=163wangjack@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=esalomatkina@ispras.ru \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhm.dawod@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=victor@mojatatu.com \
--cc=vinicius.gomes@intel.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®