[PATCH] net/sched: htb: move active classes after priority changes
From: Samuel Moelius
Date: Mon Jun 08 2026 - 20:54:53 EST
HTB lets userspace change the priority of an active class, but the class
can remain linked on the scheduler row for its old priority. Dequeue can
then treat it as if the old priority were still configured.
The scheduler data structures must reflect the new priority immediately.
Relink active classes onto the correct row when their priority changes.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@xxxxxxxxxxxxxxx>
---
net/sched/sch_htb.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index eb12381795ce..dd1c11e1df42 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -1770,6 +1770,8 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
struct tc_htb_opt *hopt;
u64 rate64, ceil64;
int warn = 0;
+ bool reactivate;
+ u32 new_prio;
/* extract all subattrs from opt attr */
if (!opt)
@@ -2019,6 +2021,7 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
psched_ratecfg_precompute(&cl->rate, &hopt->rate, rate64);
psched_ratecfg_precompute(&cl->ceil, &hopt->ceil, ceil64);
+ new_prio = min_t(u32, hopt->prio, TC_HTB_NUMPRIO - 1);
/* it used to be a nasty bug here, we have to check that node
* is really leaf before changing cl->leaf !
@@ -2039,8 +2042,15 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
}
if (hopt->quantum)
cl->quantum = hopt->quantum;
- if ((cl->prio = hopt->prio) >= TC_HTB_NUMPRIO)
- cl->prio = TC_HTB_NUMPRIO - 1;
+
+ reactivate = cl->prio_activity && cl->prio != new_prio;
+ if (reactivate)
+ htb_deactivate(q, cl);
+
+ cl->prio = new_prio;
+
+ if (reactivate)
+ htb_activate(q, cl);
}
cl->buffer = PSCHED_TICKS2NS(hopt->buffer);
--
2.43.0