From: Vinicius Costa Gomes <vinicius.gomes@intel.com>
To: Krystian Kaniewski <krystianmkaniewski@gmail.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>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 1/2] net/sched: taprio: reject software schedules that overflow their timestamps
Date: Tue, 03 Nov 2026 16:54:45 -0800 [thread overview]
Message-ID: <87ik2dwh4a.fsf@intel.com> (raw)
In-Reply-To: <20261009123309.284193-2-krystianmkaniewski@gmail.com>
Krystian Kaniewski <krystianmkaniewski@gmail.com> writes:
> taprio takes base-time as an unbounded signed 64-bit value. A base time
> in the future is used as the schedule start unchanged, and
> setup_first_end_time() then adds the cycle time, the first interval and
> the gate durations of the first entry to it. With a start close to
> KTIME_MAX these sums overflow, and the software schedule starts with end
> and gate close times that lie far in the past.
>
> If this is the first schedule, the qdisc timer is armed for its future
> start. With an operational schedule running, taprio_start_sched() keeps
> the earlier operational expiry instead. A large cycle-time-extension
> can then trigger an early handover to the pending admin schedule.
> advance_sched() uses the invalid entry end as the next expiry and can
> keep restarting inside the same timer interrupt.
>
> Before a software schedule is initialized and published, check that the
> computed start is not negative and leaves room for every timestamp
> initialized from it, and reject the schedule with -ERANGE otherwise. Full
> offload and txtime-assist do not use the software timer and are not
> affected. Schedules with a reasonable base time behave as before.
>
> Fixes: 5a781ccbd19e ("tc: Add support for configuring the taprio scheduler")
> Assisted-by: Codex:gpt-6.1-sol
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
> ---
> v2: no change
> v1: https://lore.kernel.org/all/20261006113335.241564-2-krystianmkaniewski@gmail.com/
>
> net/sched/sch_taprio.c | 46 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
> index 299234a5f0fe6..1f753911cdfec 100644
> --- a/net/sched/sch_taprio.c
> +++ b/net/sched/sch_taprio.c
> @@ -1238,6 +1238,48 @@ static int taprio_get_start_time(struct Qdisc *sch,
> return 0;
> }
>
> +static int taprio_validate_start_time(struct taprio_sched *q,
> + const struct sched_gate_list *sched,
> + ktime_t start,
> + struct netlink_ext_ack *extack)
> +{
> + int num_tc = netdev_get_num_tc(qdisc_dev(q->root));
> + const struct sched_entry *first, *entry;
> + u64 offset = 0, span;
> + int tc;
> +
> + if (TXTIME_ASSIST_IS_ENABLED(q->flags) ||
> + FULL_OFFLOAD_IS_ENABLED(q->flags))
> + return 0;
> +
> + first = list_first_entry(&sched->entries, struct sched_entry, list);
> +
> + /* setup_first_end_time() adds the cycle time, the first interval and
> + * the finite gate durations of the first entry to the start, and
> + * setup_txtime() adds the offset of every entry. None of these sums
> + * may overflow.
> + */
nitpick: In the commit message there's "Full offload and txtime-assist
do not use the software timer and are not affected", and here you say
something about setup_txtime(), I think it's better if you don't mention
anything about those other "modes" here.
> + span = max_t(u64, sched->cycle_time, first->interval);
> + list_for_each_entry(entry, &sched->entries, list) {
> + span = max(span, offset);
> + offset += entry->interval;
> + }
> +
> + for (tc = 0; tc < num_tc; tc++) {
> + if (first->gate_duration[tc] == sched->cycle_time)
> + continue;
> + span = max(span, first->gate_duration[tc]);
> + }
> +
> + if (start < 0 || span > KTIME_MAX ||
> + (u64)start > KTIME_MAX - span) {
> + NL_SET_ERR_MSG(extack, "Schedule timing is out of range");
> + return -ERANGE;
> + }
> +
> + return 0;
> +}
> +
> static void setup_first_end_time(struct taprio_sched *q,
> struct sched_gate_list *sched, ktime_t base)
> {
> @@ -1958,6 +2000,10 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
> goto unlock;
> }
>
> + err = taprio_validate_start_time(q, new_admin, start, extack);
> + if (err)
> + goto unlock;
> +
> setup_txtime(q, new_admin, start);
>
> if (TXTIME_ASSIST_IS_ENABLED(q->flags)) {
> --
> 2.53.0
>
Cheers,
--
Vinicius
next prev parent reply other threads:[~2026-11-04 0:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 12:33 [PATCH net v2 0/2] net/sched: taprio: fix RCU stall from replayed schedule entries Krystian Kaniewski
2026-10-09 12:33 ` [PATCH net v2 1/2] net/sched: taprio: reject software schedules that overflow their timestamps Krystian Kaniewski
2026-10-12 22:36 ` Vinicius Costa Gomes
2026-11-04 0:54 ` Vinicius Costa Gomes [this message]
2026-10-09 12:33 ` [PATCH net v2 2/2] net/sched: taprio: do not replay missed entries in advance_sched() Krystian Kaniewski
2026-10-12 22:53 ` Vinicius Costa Gomes
2026-10-14 9:08 ` Krystian Kaniewski
2026-10-14 20:51 ` Vinicius Costa Gomes
2026-11-02 10:19 ` Krystian Kaniewski
2026-11-04 0:56 ` Vinicius Costa Gomes
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=87ik2dwh4a.fsf@intel.com \
--to=vinicius.gomes@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=krystianmkaniewski@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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®