From: Lin Jiapeng <ljp1205831794@gmail.com>
To: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, paolo.valente@unimore.it,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Lin Jiapeng <jiapenglin@tencent.com>,
TencentOS Corvus AI <corvus@tencent.com>
Subject: [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation
Date: Tue, 24 Nov 2026 12:01:43 +0800 [thread overview]
Message-ID: <20261124040208.13282-1-ljp1205831794@gmail.com> (raw)
From: Lin Jiapeng <jiapenglin@tencent.com>
QFQ+ keeps aggregates in timestamp-ordered slots and rotates the
occupied-slot bitmap when a group's start time decreases, avoiding the
need to move the aggregates themselves. Insertions are capped so that
occupied slots leave room for a later backward adjustment.
A stale aggregate can make the decrease larger than the slots can
represent. Rotation can then drop occupied bits or alias distinct logical
slots onto one physical hlist, and a later removal can clear bits in the
following slot-list pointers or leave stale bits. KASAN reports a
slab-use-after-free read of size 8 in qfq_choose_next_agg+0xd04/0xd90 by
task repro/92 after the corrupted group is selected, followed by a panic.
Limit backward rotation using the highest occupied bit so every occupied
offset remains below QFQ_MAX_SLOTS. If the decrease exceeds that limit,
move the activating aggregate's S/F and rounded start time forward by the
same slot-aligned delta before rotating. This preserves its service
interval and the logical-to-physical slot mapping, including repeated
rotations, while leaving representable rotations unchanged.
Fixes: 462dbc9101ac ("pkt_sched: QFQ Plus: fair-queueing service at DRR cost")
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Link: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
v2:
- Derive the backward rotation limit from the highest occupied slot.
- Keep occupied offsets below QFQ_MAX_SLOTS to prevent hlist aliasing.
- Update the insertion and rotation comments.
v1: https://lore.kernel.org/all/20261116121710.77403-1-ljp1205831794@gmail.com/
net/sched/sch_qfq.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index e900890e9c54..3e2b40bea668 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -843,9 +843,9 @@ static void qfq_make_eligible(struct qfq_sched *q)
* The index of the slot in which the input aggregate agg is to be
* inserted must not be higher than QFQ_MAX_SLOTS-2. There is a '-2'
* and not a '-1' because the start time of the group may be moved
- * backward by one slot after the aggregate has been inserted, and
- * this would cause non-empty slots to be right-shifted by one
- * position.
+ * backward after the aggregate has been inserted, and this would cause
+ * non-empty slots to be right-shifted. Backward rotation is separately
+ * bounded so that every occupied slot stays below QFQ_MAX_SLOTS.
*
* QFQ+ fully satisfies this bound to the slot index if the parameters
* of the classes are not changed dynamically, and if QFQ+ never
@@ -965,7 +965,8 @@ static struct qfq_aggregate *qfq_slot_scan(struct qfq_group *grp)
* because we use ffs() to find the first non-empty slot.
* This covers decreases in the group's start time, but what about
* increases of the start time ?
- * Here too we should make sure that i is less than 32
+ * The caller keeps every occupied slot below QFQ_MAX_SLOTS after the
+ * shift, preserving the one-to-one mapping between bits and bucket lists.
*/
static void qfq_slot_rotate(struct qfq_group *grp, u64 roundedS)
{
@@ -1300,7 +1301,8 @@ static int qfq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg)
{
struct qfq_group *grp = agg->grp;
- u64 roundedS;
+ u64 roundedS, slot;
+ unsigned int max_back;
int s;
roundedS = qfq_round_down(agg->S, grp->slot_shift);
@@ -1318,6 +1320,17 @@ static void qfq_schedule_agg(struct qfq_sched *q, struct qfq_aggregate *agg)
if (!qfq_gt(grp->S, agg->S))
goto skip_update;
+ slot = (grp->S - roundedS) >> grp->slot_shift;
+ max_back = QFQ_MAX_SLOTS - 1 - __fls(grp->full_slots);
+ if (unlikely(slot > max_back)) {
+ u64 deltaS = grp->S - roundedS -
+ ((u64)max_back << grp->slot_shift);
+
+ agg->S += deltaS;
+ agg->F += deltaS;
+ roundedS += deltaS;
+ }
+
/* create a slot for this agg->S */
qfq_slot_rotate(grp, roundedS);
/* group was surely ineligible, remove */
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.55.0
next reply other threads:[~2026-11-24 4:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 4:01 Lin Jiapeng [this message]
2026-11-30 17:22 ` [PATCH v2 net] net/sched: sch_qfq: bound backward slot rotation Paolo Abeni
2026-12-01 9:19 ` Jamal Hadi Salim
2026-12-01 9:22 ` Lin Jiapeng
2026-12-01 9:28 ` Jamal Hadi Salim
2026-12-01 21:24 ` Paolo Abeni
2026-12-02 9:18 ` [PATCH v3 " Lin Jiapeng
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=20261124040208.13282-1-ljp1205831794@gmail.com \
--to=ljp1205831794@gmail.com \
--cc=corvus@tencent.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiapenglin@tencent.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=paolo.valente@unimore.it \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.