From: Paolo Abeni <pabeni@redhat.com>
To: Jack Wang <163wangjack@gmail.com>, netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
Elena Salomatkina <esalomatkina@ispras.ru>
Subject: Re: [PATCH net v3] net/sched: cbs: perform rate conversions in signed 64-bit arithmetic
Date: Tue, 18 Aug 2026 11:41:31 +0200 [thread overview]
Message-ID: <83a768c4-1200-4baa-bdc2-9d20960dc6d1@redhat.com> (raw)
In-Reply-To: <20260813060256.28748-1-163wangjack@gmail.com>
On 8/13/26 8:02 AM, Jack Wang wrote:
> cbs_set_port_rate() and cbs_change() multiply link rates and slope values
> by BYTES_PER_KBIT, an unsigned long constant. On 32-bit architectures,
> the multiplications therefore take place in 32-bit unsigned arithmetic
> before the results are assigned to s64 fields.
>
> For port rates above approximately 34.36 Gbit/s this wraps port_rate.
> The same conversion turns a negative sendslope into a large positive
> value, reversing the CBS credit adjustment. This affects software CBS;
> port_rate is also refreshed on NETDEV_UP and NETDEV_CHANGE notifications.
>
> Cast the first operand of each multiplication to s64 so all intermediate
> operations use signed 64-bit arithmetic and preserve the value's sign on
> every architecture
>
> Also reject a negative idleslope. A negative idleslope can arm the
> watchdog in the past and busy-loop.
>
> Fixes: 585d763af09c ("net/sched: Introduce Credit Based Shaper (CBS) qdisc")
> Fixes: 397006ba5d918 ("net/sched: cbs: Fix integer overflow in cbs_set_port_rate()")
>
> Signed-off-by: Jack Wang <163wangjack@gmail.com>
No empty lines in the tag area.
> ---
> v3:
> - Reject only negative idleslope values.
> - Keep idleslope 0 accepted for compatibility with existing tc-testing
> defaults, fixing test 1820 regression reported by Victor.
> - Keep the timediff_to_credits() overflow out of this series as a separate
> follow-up.
>
> v2:
> - Reject non-positive idleslope values to prevent scheduling the watchdog
> in the past.
>
> v1: https://lore.kernel.org/netdev/20260806155253.50252-1-163wangjack@gmail.com/
>
> net/sched/sch_cbs.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c
> index 1c93469c56e3..8db98d7c98a8 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 * BYTES_PER_KBIT;
>
> atomic64_set(&q->port_rate, port_rate);
> netdev_dbg(dev, "cbs: set %s's port_rate to: %lld, linkspeed: %d\n",
> @@ -392,6 +392,10 @@ static int cbs_change(struct Qdisc *sch, struct nlattr *opt,
> }
>
> qopt = nla_data(tb[TCA_CBS_PARMS]);
> + if (qopt->idleslope < 0) {
> + NL_SET_ERR_MSG(extack, "Idleslope must not be negative");
Sashiko noted this isn't enough to avoid the busy loop timer:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260813060256.28748-1-163wangjack%40gmail.com
I understand that a 0 value must be accepted, but I think we need either
a better solution or drop entirely this check that does not provide much
value per se. I think the first option would be better.
Also please note saskiko has more comments.
/P
prev parent reply other threads:[~2026-08-18 9:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 6:02 [PATCH net v3] net/sched: cbs: perform rate conversions in signed 64-bit arithmetic Jack Wang
2026-08-18 9:41 ` Paolo Abeni [this message]
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=83a768c4-1200-4baa-bdc2-9d20960dc6d1@redhat.com \
--to=pabeni@redhat.com \
--cc=163wangjack@gmail.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=netdev@vger.kernel.org \
--cc=vinicius.gomes@intel.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