From: Kyle Zeng <kylebot@openai.com>
To: netdev@vger.kernel.org
Cc: jhs@mojatatu.com, jiri@resnulli.us, kuba@kernel.org,
edumazet@kernel.org, horms@kernel.org, pabeni@redhat.com,
Kyle Zeng <kylebot@openai.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH net v3 2/2] net/sched: sfq: perturb the hash from the enqueue path
Date: Tue, 24 Nov 2026 09:38:14 -0800 [thread overview]
Message-ID: <f2f59b9b0f7391a3b4c366cb0b04252af8e94eaa.1795540952.git.kylebot@openai.com> (raw)
In-Reply-To: <cover.1795540952.git.kylebot@openai.com>
A backlogged SFQ can remain alive after its root is unpublished. Its
perturbation timer takes the current sleeping-root lock, but rehashing
can still resolve the old parent handles through the live device. A
missing parent triggers a warning; a reused handle can make
qdisc_tree_reduce_backlog() subtract packets from a replacement tree.
Perform a due perturbation before classifying the next enqueued packet.
The packet path holds the queue's lock, so the key change and rehash
happen together without an autonomous callback. Preserve the initial
perturbation interval and pass dropped skbs through enqueue's
deferred-free list. Idle queues keep their key until another packet
arrives.
An AI review found this path.
Fixes: 18cb809850fb ("net_sched: sfq: extend limits")
Fixes: 47e8dbb6e763 ("net/sched: do not reset queues in graft operations")
Cc: <stable@vger.kernel.org> # d6f81fd6abe2: net: sched: prevent scheduling deactivated qdiscs
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
net/sched/sch_sfq.c | 49 ++++++++++++++-------------------------------
1 file changed, 15 insertions(+), 34 deletions(-)
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 2bd3fc65053a..5810c458586e 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -130,11 +130,10 @@ struct sfq_sched_data {
* dep[X] : list of flows with X packets
*/
+ unsigned long perturb_time; /* next hash perturbation */
unsigned int maxflows; /* number of flows in flows array */
int perturb_period;
unsigned int quantum; /* Allotment per round: MUST BE >= MTU */
- struct timer_list perturb_timer;
- struct Qdisc *sch;
};
/*
@@ -340,6 +339,8 @@ static int sfq_headdrop(const struct sfq_sched_data *q)
return q->headdrop;
}
+static void sfq_perturbation(struct Qdisc *sch, struct sk_buff **to_free);
+
static int
sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
{
@@ -351,6 +352,10 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
struct sk_buff *head;
int delta;
+ if (q->perturb_period &&
+ unlikely(time_after_eq(jiffies, q->perturb_time)))
+ sfq_perturbation(sch, to_free);
+
hash = sfq_classify(skb, sch, &ret);
if (hash == 0) {
if (ret & __NET_XMIT_BYPASS)
@@ -531,7 +536,7 @@ sfq_reset(struct Qdisc *sch)
* We dont use sfq_dequeue()/sfq_enqueue() because we dont want to change
* counters.
*/
-static void sfq_rehash(struct Qdisc *sch)
+static void sfq_rehash(struct Qdisc *sch, struct sk_buff **to_free)
{
struct sfq_sched_data *q = qdisc_priv(sch);
struct sk_buff *skb;
@@ -569,7 +574,7 @@ static void sfq_rehash(struct Qdisc *sch)
drop:
qdisc_qstats_backlog_dec(sch, skb);
drop_len += qdisc_pkt_len(skb);
- kfree_skb(skb);
+ __qdisc_drop(skb, to_free);
dropped++;
continue;
}
@@ -601,29 +606,14 @@ static void sfq_rehash(struct Qdisc *sch)
qdisc_tree_reduce_backlog(sch, dropped, drop_len);
}
-static void sfq_perturbation(struct timer_list *t)
+static void sfq_perturbation(struct Qdisc *sch, struct sk_buff **to_free)
{
- struct sfq_sched_data *q = timer_container_of(q, t, perturb_timer);
- struct Qdisc *sch = q->sch;
- spinlock_t *root_lock;
- siphash_key_t nkey;
- int period;
+ struct sfq_sched_data *q = qdisc_priv(sch);
- get_random_bytes(&nkey, sizeof(nkey));
- rcu_read_lock();
- root_lock = qdisc_lock_root_sleeping(sch);
- q->perturbation = nkey;
+ q->perturb_time = jiffies + q->perturb_period;
+ get_random_bytes(&q->perturbation, sizeof(q->perturbation));
if (!q->filter_list && q->tail)
- sfq_rehash(sch);
- spin_unlock(root_lock);
-
- /* q->perturb_period can change under us from
- * sfq_change() and sfq_destroy().
- */
- period = READ_ONCE(q->perturb_period);
- if (period)
- mod_timer(&q->perturb_timer, jiffies + period);
- rcu_read_unlock();
+ sfq_rehash(sch, to_free);
}
static int sfq_change(struct Qdisc *sch, struct nlattr *opt,
@@ -746,11 +736,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,
rtnl_kfree_skbs(to_free, tail);
qdisc_tree_reduce_backlog(sch, qlen - sch->q.qlen, dropped);
- timer_delete(&q->perturb_timer);
- if (q->perturb_period) {
- mod_timer(&q->perturb_timer, jiffies + q->perturb_period);
- get_random_bytes(&q->perturbation, sizeof(q->perturbation));
- }
+ q->perturb_time = jiffies + q->perturb_period;
sch_tree_unlock(sch);
kfree(p);
return 0;
@@ -771,8 +757,6 @@ static void sfq_destroy(struct Qdisc *sch)
struct sfq_sched_data *q = qdisc_priv(sch);
tcf_block_put(q->block);
- WRITE_ONCE(q->perturb_period, 0);
- timer_delete_sync(&q->perturb_timer);
sfq_free(q->ht);
sfq_free(q->slots);
kfree(q->red_parms);
@@ -785,9 +769,6 @@ static int sfq_init(struct Qdisc *sch, struct nlattr *opt,
int i;
int err;
- q->sch = sch;
- timer_setup(&q->perturb_timer, sfq_perturbation, TIMER_DEFERRABLE);
-
err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
if (err)
return err;
--
2.55.0.openai.911.g06873a30d2f3
prev parent reply other threads:[~2026-11-24 17:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 4:44 [PATCH net v2] net/sched: serialize autonomous timers with qdisc resets Kyle Zeng
2026-11-14 12:12 ` netdev-bot+sashiko
2026-11-20 21:57 ` Kyle Zeng
2026-11-20 22:28 ` Jakub Kicinski
2026-11-24 17:38 ` [PATCH net v3 0/2] net/sched: serialize qdisc timers and defer SFQ rehashing Kyle Zeng
2026-11-24 17:38 ` [PATCH net v3 1/2] net/sched: serialize autonomous timers with qdisc resets Kyle Zeng
2026-11-24 17:38 ` Kyle Zeng [this message]
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=f2f59b9b0f7391a3b4c366cb0b04252af8e94eaa.1795540952.git.kylebot@openai.com \
--to=kylebot@openai.com \
--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=stable@vger.kernel.org \
/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®