mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net/sched: codel: refresh CAN_BYPASS when limit changes
@ 2026-06-09  0:12 Samuel Moelius
  2026-06-10  3:28 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Moelius @ 2026-06-09  0:12 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: Samuel Moelius, Jiri Pirko, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman,
	open list:TC subsystem, open list

sch_codel and sch_fq_codel update their packet limit without refreshing
the queue bypass state.  Changing the limit to zero can leave CAN_BYPASS
set from the previous configuration.

The enqueue path can then bypass limit enforcement even though the new
limit should prevent queued packets.

Recompute the bypass flag whenever the configured limit changes.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
 net/sched/sch_codel.c    | 17 ++++++++++++-----
 net/sched/sch_fq_codel.c | 17 ++++++++++++-----
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/net/sched/sch_codel.c b/net/sched/sch_codel.c
index 317aae0ec7bd..b8de40e63822 100644
--- a/net/sched/sch_codel.c
+++ b/net/sched/sch_codel.c
@@ -97,6 +97,14 @@ static const struct nla_policy codel_policy[TCA_CODEL_MAX + 1] = {
 	[TCA_CODEL_CE_THRESHOLD]= { .type = NLA_U32 },
 };
 
+static void codel_set_can_bypass(struct Qdisc *sch)
+{
+	if (sch->limit >= 1)
+		sch->flags |= TCQ_F_CAN_BYPASS;
+	else
+		sch->flags &= ~TCQ_F_CAN_BYPASS;
+}
+
 static int codel_change(struct Qdisc *sch, struct nlattr *opt,
 			struct netlink_ext_ack *extack)
 {
@@ -133,9 +141,11 @@ static int codel_change(struct Qdisc *sch, struct nlattr *opt,
 			   ((u64)interval * NSEC_PER_USEC) >> CODEL_SHIFT);
 	}
 
-	if (tb[TCA_CODEL_LIMIT])
+	if (tb[TCA_CODEL_LIMIT]) {
 		WRITE_ONCE(sch->limit,
 			   nla_get_u32(tb[TCA_CODEL_LIMIT]));
+		codel_set_can_bypass(sch);
+	}
 
 	if (tb[TCA_CODEL_ECN])
 		WRITE_ONCE(q->params.ecn,
@@ -176,10 +186,7 @@ static int codel_init(struct Qdisc *sch, struct nlattr *opt,
 			return err;
 	}
 
-	if (sch->limit >= 1)
-		sch->flags |= TCQ_F_CAN_BYPASS;
-	else
-		sch->flags &= ~TCQ_F_CAN_BYPASS;
+	codel_set_can_bypass(sch);
 
 	sch->flags |= TCQ_F_DEQUEUE_DROPS;
 
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index 24db54684e8a..2695181cb046 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -364,6 +364,14 @@ static const struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
 	[TCA_FQ_CODEL_CE_THRESHOLD_MASK] = { .type = NLA_U8 },
 };
 
+static void fq_codel_set_can_bypass(struct Qdisc *sch)
+{
+	if (sch->limit >= 1)
+		sch->flags |= TCQ_F_CAN_BYPASS;
+	else
+		sch->flags &= ~TCQ_F_CAN_BYPASS;
+}
+
 static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
 			   struct netlink_ext_ack *extack)
 {
@@ -422,9 +430,11 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
 			   (interval * NSEC_PER_USEC) >> CODEL_SHIFT);
 	}
 
-	if (tb[TCA_FQ_CODEL_LIMIT])
+	if (tb[TCA_FQ_CODEL_LIMIT]) {
 		WRITE_ONCE(sch->limit,
 			   nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]));
+		fq_codel_set_can_bypass(sch);
+	}
 
 	if (tb[TCA_FQ_CODEL_ECN])
 		WRITE_ONCE(q->cparams.ecn,
@@ -514,10 +524,7 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
 			codel_vars_init(&flow->cvars);
 		}
 	}
-	if (sch->limit >= 1)
-		sch->flags |= TCQ_F_CAN_BYPASS;
-	else
-		sch->flags &= ~TCQ_F_CAN_BYPASS;
+	fq_codel_set_can_bypass(sch);
 
 	sch->flags |= TCQ_F_DEQUEUE_DROPS;
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/sched: codel: refresh CAN_BYPASS when limit changes
  2026-06-09  0:12 [PATCH] net/sched: codel: refresh CAN_BYPASS when limit changes Samuel Moelius
@ 2026-06-10  3:28 ` Eric Dumazet
  2026-06-10 19:02   ` Samuel Moelius
  2026-06-28 13:59   ` Samuel Moelius
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2026-06-10  3:28 UTC (permalink / raw)
  To: Samuel Moelius
  Cc: Jamal Hadi Salim, Jiri Pirko, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, open list:TC subsystem, open list

On Mon, Jun 8, 2026 at 5:12 PM Samuel Moelius
<sam.moelius@trailofbits.com> wrote:
>
> sch_codel and sch_fq_codel update their packet limit without refreshing
> the queue bypass state.  Changing the limit to zero can leave CAN_BYPASS
> set from the previous configuration.
>
> The enqueue path can then bypass limit enforcement even though the new
> limit should prevent queued packets.
>
> Recompute the bypass flag whenever the configured limit changes.
>
> Assisted-by: Codex:gpt-5.5-cyber-preview
> Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
> ---

We can't change sch->flags in a change() method even under qdisc
spinlock, look at __dev_xmit_skb() which reads q->flags locklessly.

pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/sched: codel: refresh CAN_BYPASS when limit changes
  2026-06-10  3:28 ` Eric Dumazet
@ 2026-06-10 19:02   ` Samuel Moelius
  2026-06-28 13:59   ` Samuel Moelius
  1 sibling, 0 replies; 4+ messages in thread
From: Samuel Moelius @ 2026-06-10 19:02 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jamal Hadi Salim, Jiri Pirko, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, open list:TC subsystem, open list

On Tue, Jun 9, 2026 at 11:28 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Mon, Jun 8, 2026 at 5:12 PM Samuel Moelius
> <sam.moelius@trailofbits.com> wrote:
> >
> > sch_codel and sch_fq_codel update their packet limit without refreshing
> > the queue bypass state.  Changing the limit to zero can leave CAN_BYPASS
> > set from the previous configuration.
> >
> > The enqueue path can then bypass limit enforcement even though the new
> > limit should prevent queued packets.
> >
> > Recompute the bypass flag whenever the configured limit changes.
> >
> > Assisted-by: Codex:gpt-5.5-cyber-preview
> > Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
> > ---
>
> We can't change sch->flags in a change() method even under qdisc
> spinlock, look at __dev_xmit_skb() which reads q->flags locklessly.
>
> pw-bot: cr

I am getting ready to travel and I will address this when I return in
about two weeks. Thank you for understanding.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/sched: codel: refresh CAN_BYPASS when limit changes
  2026-06-10  3:28 ` Eric Dumazet
  2026-06-10 19:02   ` Samuel Moelius
@ 2026-06-28 13:59   ` Samuel Moelius
  1 sibling, 0 replies; 4+ messages in thread
From: Samuel Moelius @ 2026-06-28 13:59 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jamal Hadi Salim, Jiri Pirko, David S. Miller, Jakub Kicinski,
	Paolo Abeni, Simon Horman, open list:TC subsystem, open list

On Tue, Jun 9, 2026 at 11:28 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Mon, Jun 8, 2026 at 5:12 PM Samuel Moelius
> <sam.moelius@trailofbits.com> wrote:
> >
> > sch_codel and sch_fq_codel update their packet limit without refreshing
> > the queue bypass state.  Changing the limit to zero can leave CAN_BYPASS
> > set from the previous configuration.
> >
> > The enqueue path can then bypass limit enforcement even though the new
> > limit should prevent queued packets.
> >
> > Recompute the bypass flag whenever the configured limit changes.
> >
> > Assisted-by: Codex:gpt-5.5-cyber-preview
> > Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
> > ---
>
> We can't change sch->flags in a change() method even under qdisc
> spinlock, look at __dev_xmit_skb() which reads q->flags locklessly.

Your point is well taken. Thank you for the feedback.

I withdraw this patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-28 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-09  0:12 [PATCH] net/sched: codel: refresh CAN_BYPASS when limit changes Samuel Moelius
2026-06-10  3:28 ` Eric Dumazet
2026-06-10 19:02   ` Samuel Moelius
2026-06-28 13:59   ` Samuel Moelius

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®