Netdev List
 help / color / mirror / Atom feed
From: Jamal Hadi Salim <jhs@mojatatu.com>
To: netdev@vger.kernel.org
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-rt-devel@lists.linux.dev,
	Victor Nogueira <victor@mojatatu.com>, Po Liu <Po.Liu@nxp.com>,
	stable@vger.kernel.org, sashiko-bot@kernel.org
Subject: [PATCH net v4 2/3] net/sched: act_gate: refuse schedule entries shorter than 10 us
Date: Tue, 24 Nov 2026 09:12:09 -0500	[thread overview]
Message-ID: <ACT-WEXM.v4.r0.20261124074514-2@mojatatu.com> (raw)
In-Reply-To: <ACT-WEXM.v4.r0.20261124074514@mojatatu.com>

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


  parent reply	other threads:[~2026-11-24 14:12 UTC|newest]

Thread overview: 4+ 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 14:12 ` Jamal Hadi Salim [this message]
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

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=ACT-WEXM.v4.r0.20261124074514-2@mojatatu.com \
    --to=jhs@mojatatu.com \
    --cc=Po.Liu@nxp.com \
    --cc=bigeasy@linutronix.de \
    --cc=clrkwllms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    --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