* [PATCH net v4 0/3] net/sched: act_gate: bound the cycle time and refuse schedule entries shorter than 10 us
@ 2026-11-24 14:12 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
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 14:12 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Alexei Starovoitov, linux-rt-devel, Victor Nogueira,
Edward Adam Davis, Po Liu, Shuah Khan, linux-kselftest, stable,
syzbot+0054fed3dc9085390f51, shaos, sashiko-bot
An act_gate schedule is armed from TCA_GATE_BASE_TIME and
TCA_GATE_CYCLE_TIME, both unchecked u64 attributes that are read into a
signed ktime_t. A cycle time above S64_MAX turns negative on that read
and the cycle arithmetic that follows wraps.
That arms the timer in the past. Every expiry then recomputes the same
past time, so the timer softirq never finishes and the task that
installed the action spins until the watchdog reports a soft lockup.
A schedule entry of a few nanoseconds reaches the same state from the
other direction: the entry interval is the period the hrtimer runs at, so
the handler is always behind its own next expiry and the action holds a
core for as long as it exists.
1/3 cap base_time and cycle_time at KTIME_MAX, and make every
start-time computation saturate instead of wrapping.
2/3 require at least 10 us per schedule entry.
3/3 cover the refusals, the largest accepted base time and cycle time,
and both sides of the interval boundary in the tdc action tests.
Edward Adam Davis posted a v3 that capped cycle_time at S64_MAX and moved
the attribute to NLA_S64. That refuses the reported value but leaves the
invariant to the wrap: base_time is read the same way into the same
arithmetic and stays unbounded, so an accepted pair can still compute a
start the timer was never meant to take. The type change is also
unnecessary; S64_MAX is a fine range for NLA_U64.
Alexei Starovoitov traced the stall to this action on the syzbot thread
and sketched the saturating arithmetic used here:
https://lore.kernel.org/netdev/DN37NBGPJJG9.2DSVDCKS3UYTV@gmail.com/
This series keeps NLA_U64 for both attributes and bounds the computed
start time rather than one input's value. cycle_time = 0 stays accepted:
it means "derive the cycle from the entry intervals".
The 10 us entry floor comes from the measured cost of one expiry rather
than a device's frame time, and 2/3 states the margin it leaves. The
100 us floor proposed for taprio was withdrawn for narrowing working uAPI
and for a margin it never explained; this floor answers both.
Changes in v4:
- Reworked as a three-patch series on the current net tree.
- Bound base_time and cycle_time at KTIME_MAX, keeping NLA_U64.
- Saturating start-time arithmetic, shared with the catch-up path.
- Minimum entry interval, with its measured cost and its tdc coverage.
v1 -> v2: reject an out-of-range cycletime instead of clamping it.
v2 -> v3: move the range check into the netlink policy.
Jamal Hadi Salim (3):
net/sched: act_gate: bound the cycle time and start time arithmetic
net/sched: act_gate: refuse schedule entries shorter than 10 us
selftests: tc-testing: act_gate: cover the new cycle time and interval
limits
net/sched/act_gate.c | 45 +++--
.../tc-testing/tc-tests/actions/gate.json | 189 ++++++++++++++++++
2 files changed, 217 insertions(+), 17 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic
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 ` Jamal Hadi Salim
2026-11-24 19:56 ` Alexei Starovoitov
2026-11-25 14:15 ` netdev-bot+sashiko
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 14:12 ` [PATCH net v4 3/3] selftests: tc-testing: act_gate: cover the new cycle time and interval limits Jamal Hadi Salim
2 siblings, 2 replies; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 14:12 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Alexei Starovoitov, Victor Nogueira, Po Liu, stable,
syzbot+0054fed3dc9085390f51, shaos
The issue:
TCA_GATE_BASE_TIME and TCA_GATE_CYCLE_TIME are u64 attributes read into
a signed ktime_t, so a value above S64_MAX turns negative and the cycle
arithmetic that follows wraps instead of saturating.
With base_time = 1 and cycle_time = 0xffffffffffffffff the computed start
time comes out as 0 instead of the next cycle boundary, so the timer is
armed in the past. Every expiry recomputes that same past time, so the
softirq never finishes and the installing task spins inside
_raw_spin_unlock_bh() until the watchdog reports a soft lockup.
Reported by syzbot and independently by shaos; the request below
reproduces the stall in our test environment.
The Fix:
Cap base_time and cycle_time at KTIME_MAX in the policy. Both keep
NLA_U64 and 0 stays accepted, because a 0 cycle time means "derive it
from the entry intervals"; TCA_GATE_CYCLE_TIME_EXT does not drive the
timer and is deliberately left unbounded.
Work out the part of the cycle still ahead of now and add it with
ktime_add_safe(), so an unrepresentable expiry saturates in the far
future instead of wrapping into the past. gate_timer_func() reuses that
helper, stores the boundary it computes, and restarts the walk at the
first entry: the next expiry measures from the boundary that was armed.
Conditions to recreate the bug:
CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace:
tc_ctl_action() tests netlink_capable(), which checks init_user_ns, so a
user namespace of its own does not help. iproute2 parses cycle-time as
__s64 then through strtod(), silently rewriting 0xffffffffffffffff to
0x8000000000000000, so tc cannot produce the input. Build the action as
a raw RTM_NEWACTION message instead: index 1, TCA_GATE_BASE_TIME = 1,
TCA_GATE_CYCLE_TIME = 0xffffffffffffffff, and one schedule entry of
1000000 ns.
The send never returns and the CPU stays in the timer softirq. With
softlockup_panic=1 and watchdog_thresh=5 the kernel reports
watchdog: BUG: soft lockup - CPU#0 stuck for 13s! [poc:832]
with tcf_gate_init() and _raw_spin_unlock_bh() on the stack, then
reboots. The same message now fails with -ERANGE.
Fixes: a51c328df310 ("net: qos: introduce a gate control flow action")
Reported-by: syzbot+0054fed3dc9085390f51@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0054fed3dc9085390f51
Reported-by: shaos <shawnq1@163.com>
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/
Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
v3 -> v4:
- 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.
(Sashiko review of v3, forwarded by Jakub Kicinski)
- Keep NLA_U64 for both attributes and carry the range in the policy,
instead of changing the type to NLA_S64, and drop the unrelated
blank-line hunk.
(Jakub Kicinski)
- Saturate the start-time computation, use the same helper from
gate_timer_func(), store the boundary it computes and restart the walk
at the first entry. Bounding the inputs alone does not stop the old
expression from wrapping, and a boundary recomputed from a later now is
not the boundary the armed timer was measured from. The shape is the one
Alexei Starovoitov sketched on the syzbot stall thread.
- Add a 10 us floor on the schedule entry interval, derived from the
measured cost of one expiry. The tdc coverage pins both sides of that
boundary, the refusals, and the largest accepted base time and cycle
time.
v2 -> v3: reject an out-of-range cycletime through the netlink policy
instead of a runtime -EINVAL test.
v1 -> v2: reject an out-of-range cycletime with -EINVAL instead of
clamping it.
---
net/sched/act_gate.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
index 711cf2443540..4835f6543901 100644
--- a/net/sched/act_gate.c
+++ b/net/sched/act_gate.c
@@ -45,8 +45,8 @@ static void gate_get_start_time(struct tcf_gate *gact,
const struct tcf_gate_params *param,
ktime_t *start)
{
- ktime_t now, base, cycle;
- u64 n;
+ ktime_t now, base;
+ u64 cycle, rem;
base = ns_to_ktime(param->tcfg_basetime);
now = gate_get_time(gact);
@@ -58,8 +58,8 @@ static void gate_get_start_time(struct tcf_gate *gact,
cycle = param->tcfg_cycletime;
- n = div64_u64(ktime_sub_ns(now, base), cycle);
- *start = ktime_add_ns(base, (n + 1) * cycle);
+ div64_u64_rem(ktime_sub_ns(now, base), cycle, &rem);
+ *start = ktime_add_safe(now, ns_to_ktime(cycle - rem));
}
static void gate_start_timer(struct tcf_gate *gact, ktime_t start)
@@ -94,8 +94,8 @@ static enum hrtimer_restart gate_timer_func(struct hrtimer *timer)
gact->current_entry_octets = 0;
gact->current_max_octets = next->maxoctets;
- gact->current_close_time = ktime_add_ns(gact->current_close_time,
- next->interval);
+ gact->current_close_time = ktime_add_safe(gact->current_close_time,
+ next->interval);
close_time = gact->current_close_time;
@@ -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;
@@ -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,
+};
+
static const struct nla_policy gate_policy[TCA_GATE_MAX + 1] = {
[TCA_GATE_PARMS] =
NLA_POLICY_EXACT_LEN(sizeof(struct tc_gate)),
[TCA_GATE_PRIORITY] = { .type = NLA_S32 },
[TCA_GATE_ENTRY_LIST] = { .type = NLA_NESTED },
- [TCA_GATE_BASE_TIME] = { .type = NLA_U64 },
- [TCA_GATE_CYCLE_TIME] = { .type = NLA_U64 },
+ [TCA_GATE_BASE_TIME] =
+ NLA_POLICY_FULL_RANGE(NLA_U64, &gate_time_range),
+ [TCA_GATE_CYCLE_TIME] =
+ NLA_POLICY_FULL_RANGE(NLA_U64, &gate_time_range),
[TCA_GATE_CYCLE_TIME_EXT] = { .type = NLA_U64 },
[TCA_GATE_FLAGS] = { .type = NLA_U32 },
[TCA_GATE_CLOCKID] = { .type = NLA_S32 },
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us
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 14:12 ` Jamal Hadi Salim
2026-11-24 16:12 ` Sebastian Andrzej Siewior
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
2 siblings, 2 replies; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 14:12 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
linux-rt-devel, Victor Nogueira, Po Liu, stable, sashiko-bot
This is a followup of commit a51c328df310 ("net: qos: introduce a gate
control flow action") as reported by Sashiko.
The issue:
fill_gate_entry() only rejects an interval of zero, but that interval is
the period gate_timer_func() re-arms the hrtimer at, and a few
nanoseconds is below the cost of servicing one expiry: the next is due
before the current one finishes, so the action holds a CPU in the timer
softirq for as long as it exists.
On a 2-vCPU guest, entries of 1 us and below hold 86% to 90% of a core,
2 us holds 61%, and 3 us holds 22%; from 3.5 us on the cost falls to a
few percent and it reaches zero by 100 us.
The Fix:
Require at least 10 us per entry. An act_gate schedule is not tied to a
device, so unlike taprio there is no frame time to derive a bound from;
the bound has to come from the cost of servicing one expiry, with room
for a kernel that services it slower.
On a 2-vCPU guest one expiry costs a few hundred nanoseconds, so 10 us
sits 25 to 50 times above it, and that margin is also what holds on a
debug or PREEMPT_RT kernel where the cost is a few microseconds and a
floor at the 3.5 us knee would slip back in.
That is what the withdrawn 100 us taprio floor got wrong. It refused
schedules that cost a fraction of their own interval, a 250 us cycle
split into four windows among them, on a margin over the measured cost it
never explained. This floor admits those windows and states its margin.
The interval == 0 test is subsumed. A change cannot bypass the floor: a
change carrying a list re-validates every entry, and one without a list
copies entries the running kernel has already accepted.
Some context:
The request that reproduces the cycle-time stall also carries a 1 ns
entry interval. With the cycle time derived from the entries, that alone
sets a 1 ns timer period: the report covers both defects.
Conditions to recreate the bug:
CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace
(netlink_capable() checks init_user_ns, so a user namespace of its own
does not help), in a new network namespace:
tc actions add action gate index 1 sched-entry close 1
The action is accepted and the CPU running the timer softirq stays busy
for as long as the action exists. An entry of 10 us or more still
installs.
Fixes: a51c328df310 ("net: qos: introduce a gate control flow action")
Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/tencent_4ED9536B0375C96183B2244CF7709768C605@qq.com
Cc: stable@vger.kernel.org
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
net/sched/act_gate.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
index 4835f6543901..797562dbde69 100644
--- a/net/sched/act_gate.c
+++ b/net/sched/act_gate.c
@@ -25,6 +25,11 @@ static struct tc_action_ops act_gate_ops;
*/
#define GATE_ENTRIES_MAX 1024U
+/* An entry shorter than this lets the next expiry land before the softirq
+ * servicing the current one can finish, so the timer stays permanently behind.
+ */
+#define GATE_MIN_INTERVAL_NSEC 10000U
+
static ktime_t gate_get_time(struct tcf_gate *gact)
{
ktime_t mono = ktime_get();
@@ -199,8 +204,10 @@ static int fill_gate_entry(struct nlattr **tb, struct tcfg_gate_entry *entry,
if (tb[TCA_GATE_ENTRY_INTERVAL])
interval = nla_get_u32(tb[TCA_GATE_ENTRY_INTERVAL]);
- if (interval == 0) {
- NL_SET_ERR_MSG(extack, "Invalid interval for schedule entry");
+ if (interval < GATE_MIN_INTERVAL_NSEC) {
+ NL_SET_ERR_MSG_FMT(extack,
+ "Entry interval must be at least %u ns",
+ GATE_MIN_INTERVAL_NSEC);
return -EINVAL;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH net v4 3/3] selftests: tc-testing: act_gate: cover the new cycle time and interval limits
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 14:12 ` [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us Jamal Hadi Salim
@ 2026-11-24 14:12 ` Jamal Hadi Salim
2026-11-25 14:15 ` netdev-bot+sashiko
2 siblings, 1 reply; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 14:12 UTC (permalink / raw)
To: netdev
Cc: Jamal Hadi Salim, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Shuah Khan, Victor Nogueira, linux-kselftest, Po Liu
The tests:
The gate action now bounds the base time and the cycle time at KTIME_MAX
and refuses a schedule entry shorter than 10 us. Cover the four
refusals, both ends of the cycle time range and both sides of the
interval boundary.
The refusals:
A base time or a cycle time of 2^63 is above KTIME_MAX, so it is refused
as out of range; a base time of -1 reaches the kernel as the largest u64
and is refused the same way. An entry interval of 9999 ns is below the
floor and is refused as an invalid argument.
The accepted values:
An entry interval of exactly 10000 ns installs and reads back with the
interval it was given, and so do a base time and a cycle time of exactly
KTIME_MAX.
Context note:
tc does not pass the action path's extended acknowledgment back to the
caller, so the negative cases re-run the failing command and match the
kernel's own error text instead of relying on the exit code alone.
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
---
.../tc-testing/tc-tests/actions/gate.json | 189 ++++++++++++++++++
1 file changed, 189 insertions(+)
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json b/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json
index db645c22ad7b..1c910e07c41c 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json
@@ -347,5 +347,194 @@
"teardown": [
"$TC action flush action gate"
]
+ },
+ {
+ "id": "c873",
+ "name": "Add gate action with the minimum schedule entry interval",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate sched-entry close 10000ns index 100",
+ "expExitCode": "0",
+ "verifyCmd": "$TC action get action gate index 100",
+ "matchPattern": "interval 10us",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
+ },
+ {
+ "id": "2c35",
+ "name": "Reject gate action with a schedule entry below the minimum interval",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate sched-entry close 9999ns index 100",
+ "expExitCode": "255",
+ "verifyCmd": "$TC action add action gate sched-entry close 9999ns index 100 2>&1",
+ "matchPattern": "RTNETLINK answers: Invalid argument",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
+ },
+ {
+ "id": "92b8",
+ "name": "Reject gate action with a base time above S64_MAX",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate base-time 9223372036854775808 sched-entry close 10000ns index 200",
+ "expExitCode": "255",
+ "verifyCmd": "$TC action add action gate base-time 9223372036854775808 sched-entry close 10000ns index 200 2>&1",
+ "matchPattern": "RTNETLINK answers: Numerical result out of range",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
+ },
+ {
+ "id": "8265",
+ "name": "Reject gate action with a cycle time above S64_MAX",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate cycle-time 9223372036854775808 sched-entry close 10000ns index 300",
+ "expExitCode": "255",
+ "verifyCmd": "$TC action add action gate cycle-time 9223372036854775808 sched-entry close 10000ns index 300 2>&1",
+ "matchPattern": "RTNETLINK answers: Numerical result out of range",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
+ },
+ {
+ "id": "7d1f",
+ "name": "Add gate action with the maximum base time",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate base-time 9223372036854775807 sched-entry close 10000ns index 201",
+ "expExitCode": "0",
+ "verifyCmd": "$TC action get action gate index 201",
+ "matchPattern": "index 201",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
+ },
+ {
+ "id": "9f10",
+ "name": "Add gate action with the maximum cycle time",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate cycle-time 9223372036854775807 sched-entry close 10000ns index 301",
+ "expExitCode": "0",
+ "verifyCmd": "$TC action get action gate index 301",
+ "matchPattern": "index 301",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
+ },
+ {
+ "id": "5c47",
+ "name": "Reject gate action with a negative base time",
+ "category": [
+ "actions",
+ "gate"
+ ],
+ "plugins": {
+ "requires": "nsPlugin"
+ },
+ "setup": [
+ [
+ "$TC actions flush action gate",
+ 0,
+ 1,
+ 255
+ ]
+ ],
+ "cmdUnderTest": "$TC action add action gate base-time -1 sched-entry close 10000ns index 401",
+ "expExitCode": "255",
+ "verifyCmd": "$TC action add action gate base-time -1 sched-entry close 10000ns index 401 2>&1",
+ "matchPattern": "RTNETLINK answers: Numerical result out of range",
+ "matchCount": "1",
+ "teardown": [
+ "$TC actions flush action gate"
+ ]
}
]
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us
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-25 14:15 ` netdev-bot+sashiko
1 sibling, 1 reply; 13+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-11-24 16:12 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Clark Williams, Steven Rostedt, linux-rt-devel, Victor Nogueira,
Po Liu, stable, sashiko-bot
On 2026-11-24 09:12:09 [-0500], Jamal Hadi Salim wrote:
> This is a followup of commit a51c328df310 ("net: qos: introduce a gate
> control flow action") as reported by Sashiko.
>
> The issue:
> fill_gate_entry() only rejects an interval of zero, but that interval is
> the period gate_timer_func() re-arms the hrtimer at, and a few
> nanoseconds is below the cost of servicing one expiry: the next is due
> before the current one finishes, so the action holds a CPU in the timer
> softirq for as long as it exists.
The timer is programmed in the past, fires immediately and hogs the
CPU.
> On a 2-vCPU guest, entries of 1 us and below hold 86% to 90% of a core,
> 2 us holds 61%, and 3 us holds 22%; from 3.5 us on the cost falls to a
> few percent and it reaches zero by 100 us.
>
> The Fix:
> Require at least 10 us per entry. An act_gate schedule is not tied to a
> device, so unlike taprio there is no frame time to derive a bound from;
> the bound has to come from the cost of servicing one expiry, with room
> for a kernel that services it slower.
The 10us sound sane. With enough debug (say kasan, lockdep, …) this
might become tight again.
…
>
> Fixes: a51c328df310 ("net: qos: introduce a gate control flow action")
> Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
There is no syzbot report for this?
> Closes: https://sashiko.dev/#/patchset/tencent_4ED9536B0375C96183B2244CF7709768C605@qq.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> --- a/net/sched/act_gate.c
> +++ b/net/sched/act_gate.c
> @@ -25,6 +25,11 @@ static struct tc_action_ops act_gate_ops;
> */
> #define GATE_ENTRIES_MAX 1024U
>
> +/* An entry shorter than this lets the next expiry land before the softirq
> + * servicing the current one can finish, so the timer stays permanently behind.
> + */
No strong opinion. I leave this here.
| With a too small interval the next timer will be programmed in the past
| and will fire immediately.
> +#define GATE_MIN_INTERVAL_NSEC 10000U
> +
> static ktime_t gate_get_time(struct tcf_gate *gact)
> {
> ktime_t mono = ktime_get();
Sebastian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us
2026-11-24 16:12 ` Sebastian Andrzej Siewior
@ 2026-11-24 16:58 ` Jamal Hadi Salim
2026-11-24 17:11 ` Jamal Hadi Salim
0 siblings, 1 reply; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 16:58 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: netdev, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Clark Williams, Steven Rostedt, linux-rt-devel, Victor Nogueira,
Po Liu, stable, sashiko-bot
On Tue, Nov 24, 2026 at 11:13 AM Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
>
> On 2026-11-24 09:12:09 [-0500], Jamal Hadi Salim wrote:
> > This is a followup of commit a51c328df310 ("net: qos: introduce a gate
> > control flow action") as reported by Sashiko.
> >
> > The issue:
> > fill_gate_entry() only rejects an interval of zero, but that interval is
> > the period gate_timer_func() re-arms the hrtimer at, and a few
> > nanoseconds is below the cost of servicing one expiry: the next is due
> > before the current one finishes, so the action holds a CPU in the timer
> > softirq for as long as it exists.
>
> The timer is programmed in the past, fires immediately and hogs the
> CPU.
>
> > On a 2-vCPU guest, entries of 1 us and below hold 86% to 90% of a core,
> > 2 us holds 61%, and 3 us holds 22%; from 3.5 us on the cost falls to a
> > few percent and it reaches zero by 100 us.
> >
> > The Fix:
> > Require at least 10 us per entry. An act_gate schedule is not tied to a
> > device, so unlike taprio there is no frame time to derive a bound from;
> > the bound has to come from the cost of servicing one expiry, with room
> > for a kernel that services it slower.
>
> The 10us sound sane. With enough debug (say kasan, lockdep, …) this
> might become tight again.
>
Agreed. Unfortunately, there is no way to derive a "good value" here
(it depends on workload, machine, utilization, etc, etc).
poor choice of wording on my part - should probably have said all of
what i said above for precisiness...
Cant wait to see the pedantic nitpicks the sashikos will get about
this. Regardless if this is all they came up with I am not resending.
> …
> >
> > Fixes: a51c328df310 ("net: qos: introduce a gate control flow action")
> > Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
>
> There is no syzbot report for this?
>
It's in 1/3
> > Closes: https://sashiko.dev/#/patchset/tencent_4ED9536B0375C96183B2244CF7709768C605@qq.com
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
>
> Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>
> > --- a/net/sched/act_gate.c
> > +++ b/net/sched/act_gate.c
> > @@ -25,6 +25,11 @@ static struct tc_action_ops act_gate_ops;
> > */
> > #define GATE_ENTRIES_MAX 1024U
> >
> > +/* An entry shorter than this lets the next expiry land before the softirq
> > + * servicing the current one can finish, so the timer stays permanently behind.
> > + */
>
> No strong opinion. I leave this here.
>
> | With a too small interval the next timer will be programmed in the past
> | and will fire immediately.
>
see above.
cheers,
jamal
> > +#define GATE_MIN_INTERVAL_NSEC 10000U
> > +
> > static ktime_t gate_get_time(struct tcf_gate *gact)
> > {
> > ktime_t mono = ktime_get();
>
> Sebastian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us
2026-11-24 16:58 ` Jamal Hadi Salim
@ 2026-11-24 17:11 ` Jamal Hadi Salim
0 siblings, 0 replies; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 17:11 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: netdev, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Clark Williams, Steven Rostedt, linux-rt-devel, Victor Nogueira,
Po Liu, stable, sashiko-bot
On Tue, Nov 24, 2026 at 11:58 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
>
> On Tue, Nov 24, 2026 at 11:13 AM Sebastian Andrzej Siewior
> <bigeasy@linutronix.de> wrote:
> >
> > On 2026-11-24 09:12:09 [-0500], Jamal Hadi Salim wrote:
> > > This is a followup of commit a51c328df310 ("net: qos: introduce a gate
> > > control flow action") as reported by Sashiko.
> > >
> > > The issue:
> > > fill_gate_entry() only rejects an interval of zero, but that interval is
> > > the period gate_timer_func() re-arms the hrtimer at, and a few
> > > nanoseconds is below the cost of servicing one expiry: the next is due
> > > before the current one finishes, so the action holds a CPU in the timer
> > > softirq for as long as it exists.
> >
> > The timer is programmed in the past, fires immediately and hogs the
> > CPU.
> >
> > > On a 2-vCPU guest, entries of 1 us and below hold 86% to 90% of a core,
> > > 2 us holds 61%, and 3 us holds 22%; from 3.5 us on the cost falls to a
> > > few percent and it reaches zero by 100 us.
> > >
> > > The Fix:
> > > Require at least 10 us per entry. An act_gate schedule is not tied to a
> > > device, so unlike taprio there is no frame time to derive a bound from;
> > > the bound has to come from the cost of servicing one expiry, with room
> > > for a kernel that services it slower.
> >
> > The 10us sound sane. With enough debug (say kasan, lockdep, …) this
> > might become tight again.
> >
>
> Agreed. Unfortunately, there is no way to derive a "good value" here
> (it depends on workload, machine, utilization, etc, etc).
> poor choice of wording on my part - should probably have said all of
> what i said above for precisiness...
And now that you bring this up - this should really have been
targetting net-next not net.
I dont want to resend (unless sashikos find something sinister) - but
Jakub/Paolo consider applying this to net-next instead when the time
comes.
cheers,
jamal
> Cant wait to see the pedantic nitpicks the sashikos will get about
> this. Regardless if this is all they came up with I am not resending.
> > …
> > >
> > > Fixes: a51c328df310 ("net: qos: introduce a gate control flow action")
> > > Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
> >
> > There is no syzbot report for this?
> >
>
> It's in 1/3
>
> > > Closes: https://sashiko.dev/#/patchset/tencent_4ED9536B0375C96183B2244CF7709768C605@qq.com
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> >
> > Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> >
> > > --- a/net/sched/act_gate.c
> > > +++ b/net/sched/act_gate.c
> > > @@ -25,6 +25,11 @@ static struct tc_action_ops act_gate_ops;
> > > */
> > > #define GATE_ENTRIES_MAX 1024U
> > >
> > > +/* An entry shorter than this lets the next expiry land before the softirq
> > > + * servicing the current one can finish, so the timer stays permanently behind.
> > > + */
> >
> > No strong opinion. I leave this here.
> >
> > | With a too small interval the next timer will be programmed in the past
> > | and will fire immediately.
> >
>
> see above.
>
> cheers,
> jamal
>
> > > +#define GATE_MIN_INTERVAL_NSEC 10000U
> > > +
> > > static ktime_t gate_get_time(struct tcf_gate *gact)
> > > {
> > > ktime_t mono = ktime_get();
> >
> > Sebastian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic
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-25 14:15 ` netdev-bot+sashiko
1 sibling, 1 reply; 13+ messages in thread
From: Alexei Starovoitov @ 2026-11-24 19:56 UTC (permalink / raw)
To: Jamal Hadi Salim, netdev
Cc: Jiri Pirko, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Victor Nogueira,
Po Liu, stable, syzbot+0054fed3dc9085390f51, shaos
On Tue, Nov 24, 2026 at 06:12 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> Conditions to recreate the bug:
> CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace:
> tc_ctl_action() tests netlink_capable(), which checks init_user_ns, so a
> user namespace of its own does not help. iproute2 parses cycle-time as
Well ...
after "unshare -Urn" an unprivileged user can add a dummy device, clsact
and a matchall filter with this gate action.
That check covers RTM_NEWACTION only.
RTM_NEWTFILTER creates the action too:
rtnetlink_rcv_msg() netlink_net_capable(CAP_NET_ADMIN)
tc_new_tfilter() no check
mall_change()
tcf_exts_validate_ex()
tcf_action_init()
tcf_gate_init()
Acked-by: Alexei Starovoitov <ast@kernel.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic
2026-11-24 19:56 ` Alexei Starovoitov
@ 2026-11-24 23:31 ` Jamal Hadi Salim
2026-11-24 23:38 ` Alexei Starovoitov
0 siblings, 1 reply; 13+ messages in thread
From: Jamal Hadi Salim @ 2026-11-24 23:31 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: netdev, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Victor Nogueira, Po Liu, stable, syzbot+0054fed3dc9085390f51,
shaos
On Tue, Nov 24, 2026 at 2:57 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Tue, Nov 24, 2026 at 06:12 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> > Conditions to recreate the bug:
> > CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace:
> > tc_ctl_action() tests netlink_capable(), which checks init_user_ns, so a
> > user namespace of its own does not help. iproute2 parses cycle-time as
>
> Well ...
> after "unshare -Urn" an unprivileged user can add a dummy device, clsact
> and a matchall filter with this gate action.
>
> That check covers RTM_NEWACTION only.
> RTM_NEWTFILTER creates the action too:
True - based it on poc i could create; should have checked that code path.
I hope the over-hyper bots dont complain this is "high" and have me
resend to fix the commit log.
cheers,
jamal
> rtnetlink_rcv_msg() netlink_net_capable(CAP_NET_ADMIN)
> tc_new_tfilter() no check
> mall_change()
> tcf_exts_validate_ex()
> tcf_action_init()
> tcf_gate_init()
>
> Acked-by: Alexei Starovoitov <ast@kernel.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic
2026-11-24 23:31 ` Jamal Hadi Salim
@ 2026-11-24 23:38 ` Alexei Starovoitov
0 siblings, 0 replies; 13+ messages in thread
From: Alexei Starovoitov @ 2026-11-24 23:38 UTC (permalink / raw)
To: Jamal Hadi Salim
Cc: netdev, Jiri Pirko, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
Victor Nogueira, Po Liu, stable, syzbot+0054fed3dc9085390f51,
shaos
On Tue Nov 24, 2026 at 11:31 PM UTC, Jamal Hadi Salim wrote:
> On Tue, Nov 24, 2026 at 2:57 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
>>
>> On Tue, Nov 24, 2026 at 06:12 AM Jamal Hadi Salim <jhs@mojatatu.com> wrote:
>> > Conditions to recreate the bug:
>> > CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace:
>> > tc_ctl_action() tests netlink_capable(), which checks init_user_ns, so a
>> > user namespace of its own does not help. iproute2 parses cycle-time as
>>
>> Well ...
>> after "unshare -Urn" an unprivileged user can add a dummy device, clsact
>> and a matchall filter with this gate action.
>>
>> That check covers RTM_NEWACTION only.
>> RTM_NEWTFILTER creates the action too:
>
>
> True - based it on poc i could create; should have checked that code path.
> I hope the over-hyper bots dont complain this is "high" and have me
> resend to fix the commit log.
Oh yeah. don't bother. small mistakes in commit logs are fine imo
(at least we don't care in bpf land).
This code will be rewritten tomorrow anyway.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 1/3] net/sched: act_gate: bound the cycle time and start time arithmetic
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-25 14:15 ` netdev-bot+sashiko
1 sibling, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 14:15 UTC (permalink / raw)
To: jhs
Cc: netdev, jiri, davem, edumazet, kuba, pabeni, willemb, horms,
alexei.starovoitov, victor, Po.Liu, stable,
syzbot+0054fed3dc9085390f51, shawnq1
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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us
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-25 14:15 ` netdev-bot+sashiko
1 sibling, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 14:15 UTC (permalink / raw)
To: jhs
Cc: netdev, jiri, davem, edumazet, kuba, pabeni, willemb, horms,
alexei.starovoitov, victor, Po.Liu, stable,
syzbot+0054fed3dc9085390f51, shawnq1
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The 10 us floor only limits a single gate action.
- [Medium] The commit message says the bug needs 'CAP_NET_ADMIN in the
initial user namespace (netlink_capable() checks init_user_ns, so a…
- [Medium] The commit message says 'An act_gate schedule is not tied to a
device, so unlike taprio there is no frame time to derive a bound…
- [Low] entry_policy still declares TCA_GATE_ENTRY_INTERVAL as a plain `{
.type = NLA_U32 }`, while fill_gate_entry() enforces the new 10000 ns…
- [Low] The 'Some context' paragraph says 'The request that reproduces
the cycle-time stall also carries a 1 ns entry interval'.
--
net/sched: act_gate: refuse schedule entries shorter than 10 us
This commit changes fill_gate_entry() so that act_gate schedule entries
must be at least 10 us long (GATE_MIN_INTERVAL_NSEC). Before, only a zero
interval was refused. The goal is to stop the soft hrtimer that
gate_timer_func() re-arms from keeping a CPU busy in the timer softirq.
Closes: https://sashiko.dev/#/patchset/tencent_4ED9536B0375C96183B2244CF7709768C605@qq.com
> Some context:
> The request that reproduces the cycle-time stall also carries a 1 ns
> entry interval. With the cycle time derived from the entries, that alone
> sets a 1 ns timer period: the report covers both defects.
[Severity: Low]
Which request does this paragraph mean?
The earlier commit in this series, "net/sched: act_gate: bound the cycle
time and start time arithmetic", documents a cycle-time reproducer that
uses TCA_GATE_BASE_TIME = 1, TCA_GATE_CYCLE_TIME = 0xffffffffffffffff and
"one schedule entry of 1000000 ns". That is 1 ms, not 1 ns.
The second sentence is accurate. gate_timer_func() advances
current_close_time by next->interval, so a single 1 ns entry does set a
1 ns period.
If this refers to a different reproducer, such as the Sashiko one, could
the message name it? As written, the two commits disagree about which
input triggers which defect.
> Conditions to recreate the bug:
> CONFIG_NET_ACT_GATE=y, and CAP_NET_ADMIN in the initial user namespace
> (netlink_capable() checks init_user_ns, so a user namespace of its own
> does not help), in a new network namespace:
[Severity: Medium]
Is this accurate for every way a gate action can be created?
The init_user_ns check is only in the standalone RTM_NEWACTION path:
net/sched/act_api.c:tc_ctl_action() {
...
if ((n->nlmsg_type != RTM_GETACTION) &&
!netlink_capable(skb, CAP_NET_ADMIN))
return -EPERM;
...
}
A gate action can also be created inline with a classifier, for example:
tc filter add dev lo ingress matchall action gate sched-entry close 1
That goes through:
RTM_NEWTFILTER
tc_new_tfilter()
tcf_exts_validate_ex()
tcf_action_init()
tcf_gate_init()
The only capability check on that path is relative to the netns:
net/core/rtnetlink.c:rtnetlink_rcv_msg() {
...
if (kind != RTNL_KIND_GET && !netlink_net_capable(skb, CAP_NET_ADMIN))
return -EPERM;
...
}
So it looks like an unprivileged user who runs unshare -Urn can set up
the 1 ns stall on kernels without this patch.
With Cc: stable on this patch, could the reachability description be
corrected? Backport and security triage will rely on it.
> diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c
> index 4835f65439011..797562dbde693 100644
> --- a/net/sched/act_gate.c
> +++ b/net/sched/act_gate.c
> @@ -25,6 +25,11 @@ static struct tc_action_ops act_gate_ops;
> */
> #define GATE_ENTRIES_MAX 1024U
>
> +/* An entry shorter than this lets the next expiry land before the softirq
> + * servicing the current one can finish, so the timer stays permanently behind.
> + */
> +#define GATE_MIN_INTERVAL_NSEC 10000U
[Severity: High]
Does a per-entry floor bound the total timer softirq load on a CPU?
Each gate action owns a soft hrtimer (HRTIMER_MODE_ABS_SOFT). That timer
re-arms itself on every expiry with no exit condition:
net/sched/act_gate.c:gate_timer_func() {
...
gact->current_close_time = ktime_add_safe(gact->current_close_time,
next->interval);
...
hrtimer_set_expires(&gact->hitimer, close_time);
spin_unlock(&gact->tcf_lock);
return HRTIMER_RESTART;
}
Nothing limits how many gate actions a netns can have. tcf_gate_init()
calls tcf_idr_check_alloc() with a u32 index, and every filter with an
inline action gate creates a new instance and starts a new timer.
The commit message puts one expiry at a few hundred ns. At that cost,
about 33 actions with a single 10000 ns entry each, created from a task
pinned to one CPU, would keep that CPU fully busy in the timer softirq.
On the debug or PREEMPT_RT kernels the message mentions, where an expiry
costs a few us, 3 to 5 actions would be enough.
Wouldn't that bring back the "holds a CPU in the timer softirq for as
long as it exists" condition this patch is meant to remove? Fully fixing
it seems to need a limit on the combined load, for example a per-netns
cap on active gate timers or on their total expiry rate.
[ ... ]
> @@ -199,8 +204,10 @@ static int fill_gate_entry(struct nlattr **tb, struct tcfg_gate_entry *entry,
> if (tb[TCA_GATE_ENTRY_INTERVAL])
> interval = nla_get_u32(tb[TCA_GATE_ENTRY_INTERVAL]);
>
> - if (interval == 0) {
> - NL_SET_ERR_MSG(extack, "Invalid interval for schedule entry");
> + if (interval < GATE_MIN_INTERVAL_NSEC) {
> + NL_SET_ERR_MSG_FMT(extack,
> + "Entry interval must be at least %u ns",
> + GATE_MIN_INTERVAL_NSEC);
> return -EINVAL;
> }
[Severity: Medium]
The commit message says:
An act_gate schedule is not tied to a device, so unlike taprio there is
no frame time to derive a bound from
Does that hold for offloaded gate actions? act_gate is offloaded as
FLOW_ACTION_GATE to 802.1Qci PSFP hardware in sja1105, felix_vsc9959,
ocelot_flower, enetc and sparx5.
fill_gate_entry() runs for every gate action before the offload path
does, including flower skip_sw rules. sja1105 accepts much finer
schedules than 10 us:
drivers/net/dsa/sja1105/sja1105_vl.c:sja1105_vl_gate() {
...
div_s64_rem(entries[i].interval,
sja1105_delta_to_ns(1), &rem);
if (rem) {
NL_SET_ERR_MSG_MOD(extack,
"Interval must be multiple of 200 ns");
rc = -ERANGE;
goto out;
}
if (!entries[i].interval) {
NL_SET_ERR_MSG_MOD(extack,
"Interval cannot be zero");
...
}
Schedules such as "sched-entry OPEN 5000 -1 -1 sched-entry CLOSE 5000
-1 -1" used to install on sja1105. They now fail with -EINVAL and "Entry
interval must be at least 10000 ns". The driver's zero-interval check also
becomes unreachable.
The software hrtimer still runs for offloaded actions, so the CPU cost
argument may still justify the floor. Could the commit message say that
this rejects schedules that offload hardware used to accept? With
Cc: stable, the new limit would also reach deployed TSN setups.
[Severity: Low]
This isn't a bug, but could the minimum go in the policy instead of being
open-coded? entry_policy still declares the interval as a plain u32:
[TCA_GATE_ENTRY_INTERVAL] = { .type = NLA_U32 },
With NLA_POLICY_MIN(NLA_U32, GATE_MIN_INTERVAL_NSEC), nla_parse_nested()
would report the bad attribute in extack, and the policy would advertise
the correct range.
Also, when TCA_GATE_ENTRY_INTERVAL is missing, interval stays 0 and the
user is told the interval must be at least 10000 ns, even though no
interval was sent. Would NL_SET_ERR_ATTR_MISS describe that case better?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/ACT-WEXM.v4.r0.20261124074514%40mojatatu.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH net v4 3/3] selftests: tc-testing: act_gate: cover the new cycle time and interval limits
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
0 siblings, 0 replies; 13+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 14:15 UTC (permalink / raw)
To: jhs
Cc: netdev, jiri, davem, edumazet, kuba, pabeni, willemb, horms,
alexei.starovoitov, victor, Po.Liu, stable,
syzbot+0054fed3dc9085390f51, shawnq1
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The four new negative tests in tools/testing/selftests/tc-
testing/tc-tests/actions/gate.json (2c35, 92b8, 8265 and 5c47) re-run…
- [Medium] Tests 92b8 and 8265 in gate.json pass the decimal string
9223372036854775808 (2^63) as base-time and cycle-time, and expect the…
- [Low] The boundary tests 7d1f and 9f10 in gate.json add a gate action
with base-time and cycle-time 9223372036854775807 (KTIME_MAX).
--
selftests: tc-testing: act_gate: cover the new cycle time and interval limits
This adds seven tdc test cases for the gate action. They cover the new
KTIME_MAX bound on base-time and cycle-time and the 10 us minimum schedule
entry interval. The negative cases re-run the failing command and match the
error text that tc prints.
> diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json b/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json
> index db645c22ad7be..1c910e07c41c9 100644
> --- a/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json
> +++ b/tools/testing/selftests/tc-testing/tc-tests/actions/gate.json
> @@ -347,5 +347,194 @@
[ ... ]
> + {
> + "id": "2c35",
> + "name": "Reject gate action with a schedule entry below the minimum interval",
[ ... ]
> + "cmdUnderTest": "$TC action add action gate sched-entry close 9999ns index 100",
> + "expExitCode": "255",
> + "verifyCmd": "$TC action add action gate sched-entry close 9999ns index 100 2>&1",
> + "matchPattern": "RTNETLINK answers: Invalid argument",
[Severity: Medium]
Will this pattern match when tc is built with libmnl?
On this path, fill_gate_entry() in net/sched/act_gate.c sets an extack
message before it fails:
NL_SET_ERR_MSG_FMT(extack, "Entry interval must be at least %u ns",
GATE_MIN_INTERVAL_NSEC);
return -EINVAL;
The extack pointer is passed down unchanged:
tc_ctl_action()->tcf_action_add()->tcf_action_init()->
tcf_action_init_1()->tcf_gate_init()
A tc linked against libmnl prints "Error: Entry interval must be at least
10000 ns." and does not print the "RTNETLINK answers: ..." line. The
matchPattern would then find zero matches, but matchCount requires one.
The same applies to 92b8, 8265 and 5c47. Those values fail the
NLA_POLICY_FULL_RANGE(NLA_U64, &gate_time_range) check in gate_policy
during nla_parse_nested() in tcf_gate_init(). That check sets the "integer
out of range" extack, so tc prints "Error: integer out of range."
instead.
tools/testing/selftests/net/bpf_offload.py already expects tc to print the
"Error: ..." form, and warns "libmnl missing?" when it is absent.
With a tc built without libmnl the patterns do match. But the strerror text
matches any -EINVAL or -ERANGE, so it can't show that the 10 us floor or
the KTIME_MAX bound caused the refusal.
The commit message says:
tc does not pass the action path's extended acknowledgment back to the
caller, so the negative cases re-run the failing command and match the
kernel's own error text instead of relying on the exit code alone.
Is this accurate? The text matched here is iproute2's strerror output, and
the kernel does deliver the extack on this path.
Would it work better to match the kernel strings ("Entry interval must be
at least 10000 ns", "integer out of range"), or to use a regex that accepts
both output forms?
[ ... ]
> + {
> + "id": "92b8",
> + "name": "Reject gate action with a base time above S64_MAX",
[ ... ]
> + "cmdUnderTest": "$TC action add action gate base-time 9223372036854775808 sched-entry close 10000ns index 200",
[Severity: Medium]
Does 2^63 reach the kernel as 0x8000000000000000 on every architecture?
In iproute2, get_s64() fails with ERANGE for this string, so tc falls back
to get_time64(). That function parses the string with strtod() and assigns
the double to an __s64. Converting 2^63 to int64 is undefined in C.
On x86-64, cvttsd2si gives 0x8000000000000000, which is above KTIME_MAX,
so the kernel refuses it.
On arm64 (FCVTZS), and likewise on riscv, powerpc and s390, the conversion
saturates to 0x7fffffffffffffff, which is exactly KTIME_MAX.
The bound in gate_time_range in net/sched/act_gate.c is inclusive:
static const struct netlink_range_validation gate_time_range = {
.min = 0,
.max = KTIME_MAX,
};
Tests 7d1f and 9f10 rely on KTIME_MAX being accepted. On those
architectures, cmdUnderTest would exit 0 instead of 255. verifyCmd would
then fail with EEXIST, not with the out of range error.
The cycle-time value in 8265 has the same problem. 5c47 covers the
base-time bound deterministically with -1. 8265 is the only refusal test
for the cycle-time upper bound, so on non-x86 hosts that bound would go
untested.
The preceding commit, "net/sched: act_gate: bound the cycle time and start
time arithmetic", already notes that iproute2 rewrites out of range values
through strtod().
Could 92b8 and 8265 fail on a correct kernel on arm64?
[ ... ]
> + {
> + "id": "7d1f",
> + "name": "Add gate action with the maximum base time",
[ ... ]
> + "cmdUnderTest": "$TC action add action gate base-time 9223372036854775807 sched-entry close 10000ns index 201",
> + "expExitCode": "0",
> + "verifyCmd": "$TC action get action gate index 201",
> + "matchPattern": "index 201",
[Severity: Low]
This isn't a bug, but should this check the stored base-time rather than
only the index? The same question applies to "index 301" in 9f10.
Other tests in this file check the read-back value, for example "base-time
200s" in 7189, "cycle-time 200s" in a721 and "base-time 400s" in 3719.
As written, 7d1f and 9f10 would still pass if the kernel clamped, zeroed or
replaced the value. For example, tcf_gate_init() replaces a cycle-time of
0 with the cycle derived from the entries.
The commit message says:
An entry interval of exactly 10000 ns installs and reads back with the
interval it was given, and so do a base time and a cycle time of exactly
KTIME_MAX.
It also claims coverage of "both ends of the cycle time range". Only the
upper bound is tested. An explicit cycle-time 0, which the preceding commit
keeps valid as "derive from entries", is not covered.
Similarly, c873 matches "interval 10us". tc prints intervals with %.3g
scaling, so any stored interval from 10000 to about 10049 ns gives the
same text. The test can't confirm that exactly 10000 ns was stored.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/ACT-WEXM.v4.r0.20261124074514%40mojatatu.com
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-11-25 14:15 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox