mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krystian Kaniewski <krystianmkaniewski@gmail.com>
To: 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@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Vedang Patel <vedang.patel@intel.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v3 2/3] net/sched: taprio: prevent cycle time extension overflow
Date: Wed,  4 Nov 2026 15:17:12 +0100	[thread overview]
Message-ID: <20261104141713.355958-3-krystianmkaniewski@gmail.com> (raw)
In-Reply-To: <20261104141713.355958-1-krystianmkaniewski@gmail.com>

cycle_time_extension is an unrestricted signed 64-bit netlink value.
should_change_schedules() and get_interval_end_time() add it to an
absolute time without checking for overflow. A positive extension can
therefore wrap the result negative. The schedule handover test then
ignores an extension that should cover the admin base time. The
txtime-assist path can use the same wrapped value as its extended cycle
boundary.

Add one helper that saturates positive overflow at KTIME_MAX and use it
for both sums. Values that do not overflow, including negative
extensions, keep their existing behavior.

Fixes: c25031e99344 ("taprio: Add support for cycle-time-extension")
Fixes: 4cfd5779bd6e ("taprio: Add support for txtime-assist mode")
Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
---
v3:
 - split the overflow handling from the advance_sched() change (Vinicius)
 - use the same helper for the sum in get_interval_end_time()
 - add Acked-by from Vinicius
 - drop the obsolete Assisted-by trailers
 - rebase onto current net/main
v2: https://lore.kernel.org/all/20261009123309.284193-3-krystianmkaniewski@gmail.com/

 net/sched/sch_taprio.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 2a31b189d654e2..e4c937cf74c10f 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -239,6 +239,18 @@ static s32 get_cycle_time_elapsed(struct sched_gate_list *sched, ktime_t time)
 	return time_elapsed;
 }
 
+/*
+ * Netlink accepts any s64 cycle_time_extension. Saturate positive overflow
+ * so comparisons remain monotonic in end_time.
+ */
+static ktime_t taprio_cycle_ext_end(ktime_t end_time, s64 extension)
+{
+	if (extension > 0 && end_time > KTIME_MAX - extension)
+		return KTIME_MAX;
+
+	return ktime_add_ns(end_time, extension);
+}
+
 static ktime_t get_interval_end_time(struct sched_gate_list *sched,
 				     struct sched_gate_list *admin,
 				     struct sched_entry *entry,
@@ -249,7 +261,8 @@ static ktime_t get_interval_end_time(struct sched_gate_list *sched,
 
 	cycle_end = ktime_add_ns(intv_start, sched->cycle_time - cycle_elapsed);
 	intv_end = ktime_add_ns(intv_start, entry->interval);
-	cycle_ext_end = ktime_add(cycle_end, sched->cycle_time_extension);
+	cycle_ext_end =
+		taprio_cycle_ext_end(cycle_end, sched->cycle_time_extension);
 
 	if (ktime_before(intv_end, cycle_end))
 		return intv_end;
@@ -916,7 +929,8 @@ static bool should_change_schedules(const struct sched_gate_list *admin,
 	 * next schedule base_time, we can extend the current schedule
 	 * for that amount.
 	 */
-	extension_time = ktime_add_ns(end_time, oper->cycle_time_extension);
+	extension_time = taprio_cycle_ext_end(end_time,
+					      oper->cycle_time_extension);
 
 	/* FIXME: the IEEE 802.1Q-2018 Specification isn't clear about
 	 * how precisely the extension should be made. So after
-- 
2.53.0


  parent reply	other threads:[~2026-11-04 14:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 14:17 [PATCH net v3 0/3] net/sched: taprio: fix RCU stall from replayed schedule entries Krystian Kaniewski
2026-11-04 14:17 ` [PATCH net v3 1/3] net/sched: taprio: reject software schedules that overflow their timestamps Krystian Kaniewski
2026-11-04 14:17 ` Krystian Kaniewski [this message]
2026-11-04 14:17 ` [PATCH net v3 3/3] net/sched: taprio: do not replay missed entries in advance_sched() Krystian Kaniewski

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=20261104141713.355958-3-krystianmkaniewski@gmail.com \
    --to=krystianmkaniewski@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=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vedang.patel@intel.com \
    --cc=vinicius.gomes@intel.com \
    --cc=vladimir.oltean@nxp.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®