From: netdev-bot+sashiko@kernel.org
To: jhs@mojatatu.com
Cc: netdev@vger.kernel.org, jiri@resnulli.us, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
willemb@google.com, horms@kernel.org,
alexei.starovoitov@gmail.com, victor@mojatatu.com,
Po.Liu@nxp.com, stable@vger.kernel.org,
syzbot+0054fed3dc9085390f51@syzkaller.appspotmail.com,
shawnq1@163.com
Subject: Re: [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic
Date: Wed, 25 Nov 2026 14:15:10 +0000 [thread overview]
Message-ID: <179561611071.3135.17430122131465607714@kernel.org> (raw)
In-Reply-To: <ACT-WEXM.v4.r0.20261124074514-1@mojatatu.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The v3 -> v4 changelog says v4 bounds base_time and cycle_time
"at KTIME_MAX rather than S64_MAX" and gives as a reason that "the v3…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
gate_timer_func() (net/sched/act_gate.c:119), which this patch…
--
net/sched: act_gate: bound the cycle time and start time arithmetic
The netlink policy now limits TCA_GATE_BASE_TIME and TCA_GATE_CYCLE_TIME
to the range [0, KTIME_MAX]. gate_get_start_time() now works out the part
of the cycle still ahead of now and adds it with ktime_add_safe(), so the
result saturates instead of wrapping. gate_timer_func() reuses that helper
when it falls behind and restarts the walk at the first entry.
Link: https://lore.kernel.org/netdev/20261022144732.61188-1-shawnq1@163.com/
Link: https://lore.kernel.org/netdev/20260827191547.4004973-2-kuba@kernel.org/
Link: https://lore.kernel.org/netdev/20260827121751.33dac8aa@kernel.org/
Link: https://lore.kernel.org/netdev/DN37NBGPJJG9.2DSVDCKS3UYTV@gmail.com/
> diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
> index 711cf24435409..4835f65439011 100644
> --- a/net/sched/act_gate.c
> +++ b/net/sched/act_gate.c
[ ... ]
> @@ -108,13 +108,10 @@ static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)
> now = gate_get_time(gact);
>
> if (ktime_after(now, close_time)) {
> - ktime_t cycle, base;
> - u64 n;
> -
> - cycle = p->tcfg_cycletime;
> - base = ns_to_ktime(p->tcfg_basetime);
> - n = div64_u64(ktime_sub_ns(now, base), cycle);
> - close_time = ktime_add_ns(base, (n + 1) * cycle);
> + gate_get_start_time(gact, p, &close_time);
> + gact->current_close_time = close_time;
> + next = list_first_entry(&p->entries,
> + struct tcfg_gate_entry, list);
> }
>
> gact->next_entry = next;
[Severity: High]
This isn't a bug introduced by this patch, but since gate_timer_func() is
being reworked here: can the callback rewrite the expiry of a timer that
has already been queued again underneath it?
Take an RTM_NEWACTION replace that keeps basetime, clockid and tk_offset
the same. need_cancel is then false in tcf_gate_init(), so
hrtimer_cancel() is skipped:
need_cancel = ret != ACT_P_CREATED &&
gate_timer_needs_cancel(basetime, old_basetime,
tko, old_tk_offset,
timer_clockid, old_clockid);
...
spin_lock_bh(&gact->tcf_lock);
...
gate_start_timer(gact, start);
spin_unlock_bh(&gact->tcf_lock);
If the timer is expiring on another CPU at that moment, the sequence
looks like this:
CPU1 (soft hrtimer softirq)
__run_hrtimer()
dequeues the timer, drops cpu_base->lock
gate_timer_func()
spin_lock(&gact->tcf_lock) <- spins
CPU2
tcf_gate_init()
spin_lock_bh(&gact->tcf_lock)
gate_start_timer()
hrtimer_start() <- timer queued again on CPU1's base,
expiry = min(start, old expiry)
spin_unlock_bh(&gact->tcf_lock)
CPU1
hrtimer_set_expires(&gact->hitimer, close_time);
return HRTIMER_RESTART;
if (restart == HRTIMER_RESTART && !timer->is_queued) <- skipped
At that point hrtimer_set_expires() writes node.expires and _softexpires
on a node that is already linked into the timerqueue rbtree. It does this
without cpu_base->lock, and the node is never re-sorted.
Would that leave the gate timer in the leftmost position with a future
key? If so, __hrtimer_run_queues() would stop at it, and other soft
hrtimers on the same clock base and CPU would wait until the gate's new
expiry.
This patch accepts cycle_time values up to KTIME_MAX on replace, so
close_time can saturate near KTIME_SEC_MAX. Could those other timers then
be held off indefinitely? hrtimer_forward() has WARN_ON(timer->is_queued)
to enforce this same rule.
Would either of these avoid it:
- cancel the timer on every replace, outside tcf_lock, or
- have the callback skip its re-arm when the timer was queued again
under it?
> @@ -173,13 +170,20 @@ static const struct nla_policy entry_policy[TCA_GATE_ENTRY_MAX + 1] = {
> [TCA_GATE_ENTRY_MAX_OCTETS] = { .type = NLA_S32 },
> };
>
> +static const struct netlink_range_validation gate_time_range = {
> + .min = 0,
> + .max = KTIME_MAX,
> +};
[Severity: Low]
This isn't a bug, but the v3 -> v4 notes say:
- Bound base_time as well as cycle_time, and bound both at KTIME_MAX
rather than S64_MAX: bounding one attribute's value does not bound the
start time the timer is armed with, and the v3 range still computes a
negative ktime_t for some accepted pairs.
Is the "KTIME_MAX rather than S64_MAX" part accurate? In
include/linux/time64.h:
#define KTIME_MAX ((s64)~((u64)1 << 63))
That is 0x7fffffffffffffff, which is the same value as S64_MAX. So
switching the constant does not change gate_time_range.max.
What actually prevents negative or wrapped start times in v4 seems to be
two other changes: the new base_time bound, and the ktime_add_safe()
computation in gate_get_start_time(). The selftests patch later in this
series also names its tests "above S64_MAX" while testing the KTIME_MAX
bound.
Could the notes describe those changes instead?
> static const struct nla_policy gate_policy[TCA_GATE_MAX + 1] = {
> [TCA_GATE_PARMS] =
> NLA_POLICY_EXACT_LEN(sizeof(struct tc_gate)),
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/ACT-WEXM.v4.r0.20261124074514%40mojatatu.com
next prev parent reply other threads:[~2026-11-25 14:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 14:12 [PATCH net v4 0/3] net/sched: act_gate: bound the cycle time and refuse schedule entries shorter than 10 us Jamal Hadi Salim
2026-11-24 14:12 ` [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic Jamal Hadi Salim
2026-11-24 19:56 ` Alexei Starovoitov
2026-11-24 23:31 ` Jamal Hadi Salim
2026-11-24 23:38 ` Alexei Starovoitov
2026-11-25 14:15 ` netdev-bot+sashiko [this message]
2026-11-24 14:12 ` [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us Jamal Hadi Salim
2026-11-24 16:12 ` Sebastian Andrzej Siewior
2026-11-24 16:58 ` Jamal Hadi Salim
2026-11-24 17:11 ` Jamal Hadi Salim
2026-11-25 14:15 ` netdev-bot+sashiko
2026-11-24 14:12 ` [PATCH net v4 3/3] selftests: tc-testing: act_gate: cover the new cycle time and interval limits Jamal Hadi Salim
2026-11-25 14:15 ` netdev-bot+sashiko
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=179561611071.3135.17430122131465607714@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=Po.Liu@nxp.com \
--cc=alexei.starovoitov@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shawnq1@163.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+0054fed3dc9085390f51@syzkaller.appspotmail.com \
--cc=victor@mojatatu.com \
--cc=willemb@google.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