On Tue, Dec 1, 2026 at 2:43 PM <netd…@kernel.org> wrote:
> > Thank you for your contribution! Sashiko AI review found 10 potential > issue(s) to consider. > > Critical: 0 · High: 3 · Medium: 6 · Low: 1 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwork > know by including "pw-bot: cr" as a separate line at the end of your reply > (one such reply per series is enough). > > - [High] qdisc_ancestors_backlog_room() (net/sched/sch_api.c) now walks > past TCQ_F_NOPARENT and compares every non-offloaded ancestor's… > - [High] The ceiling is skipped only while TCQ_F_OFFLOADED is set. > - [High] net/sched: netem_enqueue() re-duplicates GSO corrupt segments > and wraps backlog
makes sense. v16 coming .. pw-bot: cr cheers, jamal
> - [Medium] The commit message leaves out several user-visible behaviour > changes that the patch makes: (a) hhf_enqueue() and skbprio_enqueue()… > - [Medium] The patch makes qstats_backlog_sub() and > qdisc_qstats_backlog_dec() saturate at 0. > - [Medium] The new ceiling refusals in tbf_segment() and > dualpi2_qdisc_enqueue() free the skb_gso_segment() list with… > - [Medium] TCQ_F_OFFLOADED now decides whether the enqueue path drops > packets, but qdisc_offload_dump_helper() still updates sch->flags with… > - [Medium] net/sched: qdisc_ancestors_backlog_room() under-reserves when > orig_len > 1 MiB > - [Medium] net/sched: taprio backlog still wraps via stale mirror across > NOPARENT > - [Low] In this patch, cake_enqueue()'s CAKE_FLAG_SPLIT_GSO path books > the full segment sum with qstats_backlog_add(sch, slen) and calls… > > -- > > net/sched: cap the accounted backlog before it can wrap > > This patch adds an enqueue-time check, qdisc_backlog_overflow(), to most > qdiscs. Packets are dropped once sch->qstats.backlog gets close to > wrapping its u32. > > The per-qdisc backlog decrements now saturate at 0, and the tree > reconciliation becomes a signed modular apply. A new helper, > qdisc_ancestors_backlog_room(), refuses GSO splits that would push an > ancestor past the ceiling. taprio is reworked to mirror its children's > accounting and to resync in ->dump(). > > Closes: https://lore.kernel.org/netdev/2026…@mojatatu.com/ > Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…@mojatatu.com > Link: https://lore.kernel.org/netdev/CANn…@mail.gmail.com/ > Link: https://lore.kernel.org/netdev/CANn…@mail.gmail.com/ > Link: https://lore.kernel.org/netdev/87a4…@toke.dk/ > Link: https://lore.kernel.org/netdev/87pk…@toke.dk/ > Link: https://lore.kernel.org/netdev/1792…@kernel.org/ > Link: https://lore.kernel.org/netdev/1792…@kernel.org/ > > [Severity: Medium] > The commit message describes the backlog ceiling. The patch also makes > several behaviour changes that the message does not mention. > > - hhf_enqueue() and skbprio_enqueue() now call qdisc_tree_reduce_backlog() > on the NET_XMIT_CN path. This fixes an older drift in the parent > backlog that has nothing to do with wrapping. > > - plug_enqueue() now compares qdisc_pkt_len() against the user configured > byte limit instead of skb->len. Stab overhead and GSO header > replication now count against the plug limit. > > - netem_enqueue() pre-books the original packet on itself and its > ancestors (qstats_backlog_add() plus qdisc_qlen_inc()) while the > duplicate re-enters the root. The duplicate sees netem's qlen one > higher, so near the limit it can hit sch->q.qlen >= sch->limit sooner. > > - taprio_enqueue_segmented() no longer calls qdisc_qstats_drop(sch) when > a child rejects a segment. slen now counts only the bytes that were > enqueued. > > - taprio's default children now get TCQ_F_NOPARENT. taprio_dump() > rebuilds qlen and backlog under qdisc_lock(), so a read path now > changes qdisc state. Only the text below the --- line mentions this. > > This is tagged Fixes: 175f9c1bba9b and is likely to be backported. > Could these changes be described in the commit message, or split out? >
> > diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h > > index 1acaadb3e2cf0..b195b2ee5ca38 100644 > > --- a/include/net/sch_generic.h > > +++ b/include/net/sch_generic.h
> > [ ... ] >
> > @@ -991,13 +1018,28 @@ static inline void qdisc_bstats_update(struct Qdisc *sch, > > > > static inline void qstats_backlog_sub(struct Qdisc *sch, u32 val) > > { > > - WRITE_ONCE(sch->qstats.backlog, sch->qstats.backlog - val); > > + u32 backlog = READ_ONCE(sch->qstats.backlog); > > + > > + /* Saturate: an offload update can leave the counter short. */ > > + WRITE_ONCE(sch->qstats.backlog, backlog > val ? backlog - val : 0); > > +} > > + > > +/* Apply a signed net change: positive removes, negative grows. */ > > +static inline void qdisc_qstats_backlog_apply(struct Qdisc *sch, s64 delta) > > +{ > > + u32 backlog = READ_ONCE(sch->qstats.backlog); > > + > > + WRITE_ONCE(sch->qstats.backlog, (u32)(backlog - delta)); > > }
> > [Severity: Medium] > Is it safe to mix saturating and modular writers now that the guard fails > closed? > > qstats_backlog_sub() and qdisc_qstats_backlog_dec() now clamp at 0. > qdisc_qstats_backlog_apply() still wraps. qdisc_tree_reduce_backlog() > applies it to every ancestor and has no TCQ_F_OFFLOADED exemption, > unlike qdisc_backlog_overflow() and qdisc_ancestors_backlog_room(). > > Suppose an ancestor's counter is lower than what a child later removes, > for example an offloaded ancestor whose counter holds bytes written by > the driver. The result wraps to near U32_MAX. From then on, > qdisc_backlog_overflow() returns true for every packet: > > if (likely(len <= QDISC_PKT_LEN_MAX)) > return backlog > QDISC_MAX_BACKLOG; > > The saturating dequeues cannot bring the counter back under the ceiling > unless more than about 2 MiB of real packets is queued. > > Does the qdisc then drop every enqueue until it is reset? Before this > patch, the same mismatch only produced a wrong statistic. > > I could not find a pure software path that leaves a booking ancestor > short. The trigger I found needs a counter written from outside the > qdisc code. >
> > > > static inline void qdisc_qstats_backlog_dec(struct Qdisc *sch, > > const struct sk_buff *skb) > > { > > - qstats_backlog_sub(sch, qdisc_pkt_len(skb)); > > + u32 backlog = READ_ONCE(sch->qstats.backlog); > > + u32 len = qdisc_pkt_len(skb); > > + > > + /* An offload update can leave the counter short; saturate. */ > > + WRITE_ONCE(sch->qstats.backlog, backlog > len ? backlog - len : 0); > > }
> > [ ... ] >
> > diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c > > index f36c41224bccf..09312d2f23862 100644 > > --- a/net/sched/sch_api.c > > +++ b/net/sched/sch_api.c
> > [ ... ] >
> > +/* Room left for @extra bytes on every ancestor of @sch; a split's growth > > + * reaches them without passing their own enqueue guard. > > + */ > > +bool qdisc_ancestors_backlog_room(const struct Qdisc *sch, u64 extra) > > +{ > > + const struct Qdisc *p = sch; > > + u32 parentid; > > + > > + if (!extra) > > + return true; > > + > > + rcu_read_lock(); > > + while ((parentid = p->parent)) { > > + if (parentid == TC_H_ROOT) > > + break; > > + > > + /* Cross NOPARENT: a mirror parent still books the child's > > + * growth. A parent that does not book it cannot overflow. > > + */ > > + p = qdisc_lookup_rcu(qdisc_dev(p), TC_H_MAJ(parentid)); > > + if (!p) > > + break; > > + > > + /* Hardware bytes are not ours to bound. */ > > + if (unlikely(READ_ONCE(p->flags) & TCQ_F_OFFLOADED)) > > + continue; > > + > > + if (unlikely((u64)READ_ONCE(p->qstats.backlog) + extra > > > + QDISC_MAX_BACKLOG)) { > > + rcu_read_unlock(); > > + return false; > > + } > > + }
> > [Severity: Medium] > Can taprio's counter still wrap through this apply? > > qdisc_ancestors_backlog_room() crosses TCQ_F_NOPARENT to check > taprio. However, taprio's qstats.backlog is only brought up to date > here, after the outermost enqueue or the child's peek()/dequeue has > returned. qdisc_tree_reduce_backlog() still stops at the NOPARENT > child. > > Take netem as a taprio child with tbf, dualpi2 or cake below it. A > single child->ops->peek() from taprio_dequeue_from_txq() runs > netem_dequeue(). Its tfifo loop can move many expired GSO packets > into q->qdisc in one call. Each split checks the room against the > same pre-peek taprio value, and each admitted growth is added only > to netem. If another TXQ is already close to QDISC_MAX_BACKLOG, the > summed growth can exceed what taprio has left. > > taprio_mirror_child() then applies the whole delta through > qdisc_qstats_backlog_apply(), which wraps instead of saturating. > Once the counter has wrapped low, taprio_backlog_overflow() no longer > sees an overflow. taprio_resync_backlog() is then not called until > the next dump. > > The enqueue side is similar. While q->mirror_child == child, the > re-entrant netem duplicate and its segments skip the mirror. The > pre-booking in netem_enqueue() stops at NOPARENT. taprio's value > therefore stays frozen for every room check inside that enqueue. > > Should taprio_mirror_child() saturate the way taprio_resync_backlog() > does, so that a large delta at least forces a resync on the next > enqueue? Or does the room walk need to account for the child's > in-flight change when it crosses into a mirror parent? > > [Severity: Medium] > Does this headroom account for a pre-split packet longer than > QDISC_PKT_LEN_MAX? > > qdisc_backlog_overflow() admits a packet with len above > QDISC_PKT_LEN_MAX on an ancestor as long as backlog + 2 * len stays > within U32_MAX. The ancestor books len only after its child returns. > So when tbf_segment(), dualpi2_qdisc_enqueue() or > netem_split_over_ceiling() run, the ancestor still owes 2 * orig_len > plus the split growth. > > The comparison against QDISC_MAX_BACKLOG only holds back > 2 * QDISC_PKT_LEN_MAX for that unbooked packet. If orig_len is above > 1 MiB and slen > orig_len, the check passes even though > backlog + 2 * slen can exceed U32_MAX by up to > 2 * (orig_len - QDISC_PKT_LEN_MAX). > > tbf_segment() hands the segments to q->qdisc before tbf or its > ancestors book slen. A netem child that duplicates each small segment > back into the root only meets the backlog > QDISC_MAX_BACKLOG test. > The ancestor can fill to the ceiling and then wrap when the remaining > bytes are booked on the way back up. > > Should the callers pass the full 2 * slen here? Alternatively, the > helper could take the pre-split length and reserve > 2 * max(orig_len, QDISC_PKT_LEN_MAX) on top of the growth. > > [Severity: High] > The comment says a parent that does not book the growth cannot overflow. > The loop never skips such parents, though. Can it refuse splits because > of counters that are never decremented? > > multiq_enqueue() and multiq_dequeue() only touch q.qlen. multiq's > children are not TCQ_F_NOPARENT. So multiq's qstats.backlog is just the > running sum of the children's qdisc_tree_reduce_backlog() deltas, > applied with the wrapping qdisc_qstats_backlog_apply(). > > A child drop, such as fq_codel_drop() or a codel dequeue drop, passes a > positive length. That wraps multiq's counter from about 0 to > U32_MAX - dropped, which is above QDISC_MAX_BACKLOG whenever less than > 2 MiB was dropped. Every tbf, dualpi2 or netem split also adds its > growth, and nothing removes it. > > After that, every later split under multiq with growth > 0 is refused, > and tbf_segment() drops the whole list: > > consume_skb(skb); > qdisc_qstats_overlimit(sch); > return qdisc_drop_all(segs, sch, to_free); > > dualpi2_qdisc_enqueue() and netem_split_over_ceiling() behave the same > way. > > A refused split adds no delta, and multiq never decrements. Does this > state last until the qdisc is reset? > > mq has a similar problem. Its backlog is written only in > mq_dump_common(), as a dump-time u32 sum over the TX queue children. > mqprio_dump() does the same, and so does taprio_resync_backlog() for > full-offload taprio. > > After one tc -s qdisc show records a high aggregate, would splits in any > child be refused against that stale snapshot until the next dump? > > The commit message says the NOPARENT crossing exists for taprio's mirror > parent. Should the walk stop at mq, mqprio and multiq, which do not book > bytes? >
> > + rcu_read_unlock(); > > + > > + return true; > > +} > > +EXPORT_SYMBOL(qdisc_ancestors_backlog_room); > > + > > int qdisc_offload_dump_helper(struct Qdisc *sch, enum tc_setup_type type, > > void *type_data) > > { > > struct net_device *dev = qdisc_dev(sch); > > int err; > > > > - sch->flags &= ~TCQ_F_OFFLOADED; > > - if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc) > > + if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc) { > > + sch->flags &= ~TCQ_F_OFFLOADED; > > return 0; > > + } > > > > err = dev->netdev_ops->ndo_setup_tc(dev, type, type_data); > > - if (err == -EOPNOTSUPP) > > - return 0; > > - > > - if (!err) > > + if (!err) { > > sch->flags |= TCQ_F_OFFLOADED;
> > [Severity: Medium] > TCQ_F_OFFLOADED now decides whether the datapath drops packets. This is > still a plain read-modify-write of sch->flags, run from ->dump() under > RTNL only. Can it race with the datapath writing the same word? > > qdisc_warn_nonwc() does qdisc->flags |= TCQ_F_WARN_NONWC from the > parent's dequeue under the root lock. One example is > ets_qdisc_dequeue() calling qdisc_peek_len() on an offloaded red or tbf > child. > > If the two updates interleave, the OFFLOADED bit can be lost until the > next dump. The ceiling then applies to a counter that holds hardware > bytes. > > There is also an ordering gap. Inside ndo_setup_tc() the driver writes > hardware bytes into sch->qstats.backlog before the flag is set here. > Nothing orders those writes against the lockless READ_ONCE() in > qdisc_backlog_overflow(). > > The commit message says a dump in progress keeps the exemption. That > seems to assume a stable flags word. Is that guaranteed? >
> > + return 0; > > + } > > > > - return err; > > + /* Also the ceiling's offload exemption: clear only on failure, so a > > + * dump in progress keeps it. > > + */ > > + sch->flags &= ~TCQ_F_OFFLOADED; > > + /* -EOPNOTSUPP means "no hardware stats", not a dump failure. */ > > + return err == -EOPNOTSUPP ? 0 : err; > > }
> > [Severity: High] > What happens to the bytes the driver wrote once the exemption is dropped > here? > > Drivers update qstats.backlog with modular arithmetic, for example: > > mlxsw_sp_qdisc_update_stats(): > stats_ptr->qstats->backlog += mlxsw_sp_cells_bytes(mlxsw_sp, backlog); > > mlxsw_sp_qdisc_leaf_unoffload(): > qstats->backlog -= backlog; > > nfp_abm_stats_calculate(): > qstats->backlog += new->backlog_bytes - old->backlog_bytes; > > qdisc_reset() zeroes qdisc->qstats.backlog but leaves the driver's > stats_base alone. The next stats read can then apply a negative delta and > wrap the counter to about U32_MAX - cells(B). > > Then suppose offload stops while the kernel qdisc stays, as on mlxsw's > replace-failure unoffload path. mlxsw_sp_qdisc_get_stats() returns > -EOPNOTSUPP, and this code clears TCQ_F_OFFLOADED with the wrapped value > still in place. > > qdisc_backlog_overflow() would then see backlog > QDISC_MAX_BACKLOG and > drop every software enqueue on that port, including CPU-originated > control traffic. Nothing is admitted, so nothing dequeues, and the > counter never comes down. > > Would the qdisc keep black-holing traffic until it is reset? The commit > message only covers the safe direction of the coarse exemption, where > the flag is set but no hardware bytes are held. >
> > EXPORT_SYMBOL(qdisc_offload_dump_helper); > > > > diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c > > index 2bc0dac9123a9..25c7e20ec1239 100644 > > --- a/net/sched/sch_cake.c > > +++ b/net/sched/sch_cake.c > > @@ -1783,6 +1783,13 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, > > return ret; > > } > > > > + /* Drop before touching the hash or shaper state. */ > > + if (unlikely(qdisc_backlog_overflow(sch, skb))) { > > + qdisc_qstats_overlimit(sch); > > + return qdisc_drop_reason(skb, sch, to_free, > > + QDISC_DROP_OVERLIMIT); > > + } > > +
> > [Severity: Low] > The commit message says: > > The ancestor-room check covers a split whose segments would grow an > ancestor past the room: tbf, dualpi2, netem's corrupt split and cake. > > At this commit, does the CAKE_FLAG_SPLIT_GSO path in cake_enqueue() > actually get that check? It still books the segment sum with > qstats_backlog_add(sch, slen) and calls > qdisc_tree_reduce_backlog(sch, 1-numsegs, len-slen). It never calls > qdisc_ancestors_backlog_room() or checks cake's own counter. > > The next patch in the series ("net/sched: cake: hash before segmenting > and reject an overlong split") adds both checks, so the code is fixed by > the end of the series. The commit message for this patch still does not > match its code. >
> > /* choose flow to insert into */ > > b = cake_select_tin(sch, skb); > > idx = cake_hash(b, skb, q->config->flow_mode, flow_override, > > diff --git a/net/sched/sch_dualpi2.c b/net/sched/sch_dualpi2.c > > index 4947def7c49ef..bebffc3965a64 100644 > > --- a/net/sched/sch_dualpi2.c > > +++ b/net/sched/sch_dualpi2.c
> > [ ... ] >
> > @@ -467,6 +468,24 @@ static int dualpi2_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch, > > cnt = 0; > > byte_len = 0; > > orig_len = qdisc_pkt_len(skb); > > + { > > + struct sk_buff *seg; > > + u64 slen = 0; > > + u64 growth; > > + > > + skb_list_walk_safe(nskb, seg, next) > > + slen += seg->len; > > + > > + /* A duplicate can book its clone twice; reserve two. */ > > + growth = slen > (u64)orig_len ? > > + slen - orig_len : 0; > > + if (growth && > > + !qdisc_ancestors_backlog_room(sch, 2 * growth)) { > > + consume_skb(skb); > > + qdisc_qstats_overlimit(sch); > > + return qdisc_drop_all(nskb, sch, to_free);
> > [Severity: Medium] > Does this drop path report the right drop reason for the segments? > > qdisc_drop_all() sets no reason on the list. tc_skb_cb's drop_reason > sits at cb offset 32, and SKB_GSO_CB_OFFSET is also 32. So > __skb_gso_segment() leaves SKB_GSO_CB(skb)->mac_offset in that slot on > every segment. > > __tcf_kfree_skb_list() reads tc_skb_cb(skb)->drop_reason and passes it > to kfree_skb_reason(). drop_monitor and the tracepoints would then see an > unrelated skb_drop_reason. A mac_offset of 0 would also trip the > SKB_NOT_DROPPED_YET check. > > tbf_segment() uses the same pattern. > > netem's new refusal in this patch tags each segment with > qdisc_drop_reason(..., QDISC_DROP_OVERLIMIT). The following cake patch > fixes the same aliasing for cake. tbf and dualpi2 are still unchanged at > the end of the series. > > tbf and dualpi2 also count one drop for the whole list, while netem > counts one drop per segment. >
> > + } > > + } > > skb_list_walk_safe(nskb, nskb, next) { > > skb_mark_not_on_list(nskb); > >
> > [ ... ] >
> > diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c > > --- a/net/sched/sch_netem.c > > +++ b/net/sched/sch_netem.c > > @@ -450,6 +450,25 @@ static struct sk_buff *netem_segment(struct sk_buff *skb, struct Qdisc *sch, > > return segs; > > } > > > > +/* The split replicates headers per segment, so the sum outgrows what the > > + * guard admitted; refuse it if an ancestor has no room. > > + */ > > +static bool netem_split_over_ceiling(struct Qdisc *sch, > > + const struct sk_buff *skb, > > + const struct sk_buff *segs, > > + unsigned int prev_len) > > +{ > > + const struct sk_buff *seg; > > + u64 slen; > > + > > + slen = skb ? skb->len : 0; > > + for (seg = segs; seg; seg = seg->next) > > + slen += seg->len; > > + > > + return slen > prev_len && > > + !qdisc_ancestors_backlog_room(sch, 2 * (slen - prev_len)); > > +} > > + > > /* > > * Insert one skb into qdisc. > > * Note: parent depends on return value to account for queue length.
> > [Severity: High] > Does the two-copy reservation here hold when netem both duplicates > and corrupt-splits the same GSO packet? > > When q->duplicate fires, skb2 is cloned from the unsegmented GSO skb > before netem_segment() runs, while skb->tc_depth is still 0. Only > skb2->tc_depth is bumped, so segments 2..N in segs keep tc_depth 0. > > The pre-booking around rootq->enqueue(skb2) covers prev_len, not the > segment sum, and it is undone before finish_segs. The finish_segs > loop then feeds each trailing segment back through qdisc_enqueue() > into netem_enqueue(). Each one passes the duplicate test again and > sends its own clone to the root. At that point none of the outer > packet's bytes are booked on the ancestors. > > One enqueue can then book close to 3 * slen on an ancestor: the full > GSO duplicate, a second duplicate of segments 2..N, and the segments > themselves. QDISC_MAX_BACKLOG and the 2 * (slen - prev_len) passed to > qdisc_ancestors_backlog_room() both assume at most two copies. > Unlike tbf_segment(), this path also never checks netem's own > counter against 2 * slen. > > Under taprio, the q->mirror_child == child short-circuit skips the > mirror for the recursive enqueues. taprio_mirror_child() then applies > all of it at once afterwards. > > Near the ceiling this can still wrap an ancestor's qstats.backlog, > which is the state the patch is meant to rule out. Should the > trailing segments get a bumped tc_depth when a duplicate was already > made? Or should the reservation cover the extra copy? > > -- > Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40mojatatu.com