Skip to content

net/sched: cap the accounted backlog before it can wrap

Jamal Hadi Salim netdev 11 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v12 Latest4 patches 0 repliesNew
  2. v114 patches 0 repliesSuperseded
  3. v104 patches 1 replySuperseded
Earlier versions · 8
VersionPostedPatchesRepliesStatus
v94 patches4 repliesSuperseded
v84 patches5 repliesSuperseded
v74 patches11 repliesSuperseded
v64 patches2 repliesSuperseded
v51 patch5 repliesSuperseded
v41 patch3 repliesSuperseded
v31 patch1 replySuperseded
v21 patch3 repliesSuperseded

Changes in v12 from the cover letter

- 3/4: taprio mirrors the child's net backlog and queue-length change instead of booking the packet once the child returned success. Two problems with the v11 shape: a child may free the skb and still report NET_XMIT_SUCCESS (tbf_segment(), cake's split path), so the booking read the packet after it was gone; and because taprio_graft() marks every child TCQ_F_NOPARENT, a child that evicts a packet on NET_XMIT_CN never reaches taprio through qdisc_tree_reduce_backlog(), so booking only on success let the dequeue subtraction run ahead of the booking until the counter wrapped. The segmented path reads the segment length before the handoff and no longer counts a segment drop twice.
- 3/4: RED books the packet on success again, as the tree did before v11. The v11 delta arithmetic re-derived the aggregate from snapshots and therefore dropped an offload-driver update that landed while the child ran, and it passed that same amount on to the ancestors. With the child and the netem duplicate propagating their own changes, the plain accounting is correct and cannot wrap.
- 3/4: qdisc_qstats_backlog_dec() stops at zero. An offload driver updates sch->qstats.backlog from the dump path while holding only RTNL, so a datapath increment can be lost; the matching decrement then wrapped the counter below zero and the new enqueue guard turned that into a permanent egress stop.
- 3/4: the standing ceiling leaves room for two full-size packets, because netem books a duplicate before it re-enters the tree and one enqueue can then add twice the packet length.
- 3/4: pfifo's backlog drops report QDISC_DROP_OVERLIMIT and count an overlimit, like the other guards in the series.
- 4/4: compare the split's segment sum against U32_MAX, the wrap boundary qdisc_backlog_overflow() uses, instead of the post-add ceiling that rejected a split up to two packet lengths before it could wrap.
- 1/4 and 2/4 are unchanged from the v11 posting. 3/4 no longer carries a Reviewed-by, because the taprio and RED accounting it covered was replaced here.

Patches in v12 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4net/sched: cake: return the classifier result to the callernet/sched/sch_cake.c+23 -130 replies
2/4net/sched: cake: use a dedicated split-GSO list iteratornet/sched/sch_cake.c+11 -110 replies
3/4net/sched: cap the accounted backlog before it can wrapinclude/net/pkt_sched.h include/net/sch_generic.h net/sched/sch_cake.c +26 more+258 -280 replies
4/4net/sched: cake: hash before segmenting and reject an overlong splitnet/sched/sch_cake.c+97 -360 replies

Reviews trailers per patch

3 of 4 patches have a Reviewed-by or Acked-by.

PatchVictor NogueiraToke Høiland-Jørgensen
1/4R-b A-b
2/4R-b A-b
3/4
4/4R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v12 thread

Cover letter [PATCH net-next v12 0/4] net/sched: cap the accounted backlog before it can wrap

This series bounds the accounted backlog of the AQM qdiscs so that it cannot wrap mod 2^32.

v1 widened the counters to u64 and was rejected; from v2 on the fix drops at enqueue instead. The v5 posting was a single patch; at the reviewer's request it is split into four:

1/4 cake: classifier refactor: cake_tcf_classify() returns its result
to the caller.
2/4 cake: use a dedicated split-GSO list iterator.
3/4 the fix: drop at enqueue once the stored backlog cannot
represent the packet's accounted length -- the standing QDISC_MAX_BACKLOG ceiling for ordinary packets, a per-packet representability check for the larger wire estimates. Covers every qdisc in net/sched that adds the incoming packet's qdisc_pkt_len() to its own 32-bit backlog: fq_codel, cake, codel, pie, fq_pie, dualpi2, RED, pfifo, gred, the leaves fq, sfq, hhf, skbprio, netem, choke, etf and taprio, the classful parents prio, htb, drr, ets, qfq, hfsc, cbs and sfb, and tbf's direct enqueue path.
4/4 cake: split cake_hash() into side-effect-free key extraction (on
the unsegmented skb) and set-associative resolution (after admission), move the split-GSO path ahead of the resolution, and tag every deferred split segment.

For the sashikos: This series targets net-next with no Fixes: (the aggregate wrap predates every touched qdisc). Unfortunately something broke in the sashiko reviews. Review for v7 showed up a while later after v8. So you will see that this series has fixes (majority in comments and commit logs) from both.

Changes in v12 (Sashiko nipa and gemini reviews of v11):
- 3/4: taprio mirrors the child's net backlog and queue-length change instead of booking the packet once the child returned success. Two problems with the v11 shape: a child may free the skb and still report NET_XMIT_SUCCESS (tbf_segment(), cake's split path), so the booking read the packet after it was gone; and because taprio_graft() marks every child TCQ_F_NOPARENT, a child that evicts a packet on NET_XMIT_CN never reaches taprio through qdisc_tree_reduce_backlog(), so booking only on success let the dequeue subtraction run ahead of the booking until the counter wrapped. The segmented path reads the segment length before the handoff and no longer counts a segment drop twice.
- 3/4: RED books the packet on success again, as the tree did before v11. The v11 delta arithmetic re-derived the aggregate from snapshots and therefore dropped an offload-driver update that landed while the child ran, and it passed that same amount on to the ancestors. With the child and the netem duplicate propagating their own changes, the plain accounting is correct and cannot wrap.
- 3/4: qdisc_qstats_backlog_dec() stops at zero. An offload driver updates sch->qstats.backlog from the dump path while holding only RTNL, so a datapath increment can be lost; the matching decrement then wrapped the counter below zero and the new enqueue guard turned that into a permanent egress stop.
- 3/4: the standing ceiling leaves room for two full-size packets, because netem books a duplicate before it re-enters the tree and one enqueue can then add twice the packet length.
- 3/4: pfifo's backlog drops report QDISC_DROP_OVERLIMIT and count an overlimit, like the other guards in the series.
- 4/4: compare the split's segment sum against U32_MAX, the wrap boundary qdisc_backlog_overflow() uses, instead of the post-add ceiling that rejected a split up to two packet lengths before it could wrap.
- 1/4 and 2/4 are unchanged from the v11 posting. 3/4 no longer carries a Reviewed-by, because the taprio and RED accounting it covered was replaced here.

Changes in v11 (Sashiko gemini and nipa reviews of v10, delivered on lore):
- 3/4: taprio books the packet only once the child accepted it, and the segmented path adds a segment to the tree adjustment only when it was accepted, so the two counters move by the bytes that were really accounted. A child that dropped used to leave its length in taprio's backlog, and after 4 GiB of those drops the new guard turned the leak into a permanent egress stop.
- 3/4: netem accounts the duplicate before it re-enters the root and undoes it afterwards. The re-entry used to reach every guard with a backlog that did not hold the clone yet, so a guard with room for one packet admitted two.
- 3/4: hhf and skbprio pass the net change of an eviction on to the ancestors when they return NET_XMIT_CN. The parent does not book the incoming packet on CN, so a leaf that evicted a differently sized packet left the two counters drifting, and a drain-time undercount of a few hundred bytes put the parent's backlog just below zero -- above QDISC_MAX_BACKLOG -- where the new guard stops every class.
- 3/4: htb classifies after the guard, so a terminal action verdict is reported as that verdict instead of an overlimit drop.
- 3/4: RED applies its correction as a delta instead of restoring the snapshot taken before the child enqueue, so a concurrent update from an offload driver is not lost.
- 1/4, 2/4 and 4/4 are unchanged from the v10 posting; 2/4 carries the Acked-by it received on the v9 posting.

Changes in v10 (late Sashiko nipa review of v9, delivered on lore):
- Fixed all the commit log complaints
- 3/4: cover the rest of net/sched. The leaves fq, sfq, hhf, skbprio, netem, choke, etf and taprio, the classful parents prio, htb, drr, ets, qfq, hfsc, cbs and sfb, and tbf's direct enqueue path all add the incoming packet's qdisc_pkt_len() to their own 32-bit backlog, so an unguarded leaf can wrap its own counter and an unguarded parent can wrap the aggregate it keeps over its children.
- 3/4: drop plug's redundant qdisc_backlog_overflow() test. plug is classless and q->limit is a u32, so its byte test alone already bounds the stored backlog below U32_MAX.
- 3/4: refresh the RED comment that still described the pre-rework behaviour.
- 3/4: drop the Acked-by from the v9 posting, since the patch now covers 29 files and the earlier ack no longer applies to it.
- 2/4: carry the Acked-by from the v9 posting; the patch is unchanged.

Changes in v9 (late Sashiko nipa reviews of v7 and v8, delivered on lore):
- 1/4: reword the "The Fix:" heading; this patch is preparation, not a fix.
- 1/4: the classifier helper's comments now say the caller must drop the skb, since a terminal action does not take ownership of it.
- 3/4: bound the child backlog as well as RED's aggregate, and re-derive the aggregate from snapshots taken before the reservation when the enqueue does not succeed. A child that returns NET_XMIT_CN may or may not have reduced its ancestors already: pfifo_head_drop, sfq and fq_codel do, while hhf and skbprio evict a packet and return without qdisc_tree_reduce_backlog(). Keep what the child actually accounted for and pass any difference on to the ancestors above RED, so neither counter can diverge. Verified with two A/B witnesses: RED over a grafted hhf child (control ends with red_backlog 2042016 != child_backlog 6177600) and RED under an HTB class over a grafted pfifo_head_drop limit 1, where an unequal shrinking replacement otherwise wraps the aggregate and wedges the new admission guard -- control 4294966052, fixed 92 with RED == child == HTB.
- 3/4: note that CAKE's own split-GSO branch is the second exception; the segments it accounts are summed and checked against QDISC_MAX_BACKLOG by 4/4 before any of them is linked.
- 4/4: add the split-GSO "Conditions to recreate the bug" recipe for the segment-sum rejection at the split ceiling.
- 4/4: the IS_ERR_OR_NULL(segs) segmentation-failure return uses qdisc_drop_reason(..., QDISC_DROP_GENERIC); __skb_gso_segment() has already clobbered tc_skb_cb.drop_reason through SKB_GSO_CB, so the old qdisc_drop() reported an unrelated core reason and skipped trace_qdisc_drop.
- 4/4: pass the flow_mode snapshot to the later flowchain calls (cake_get_flow_quantum(), cake_inc_srchost_bulk_flow_count(), cake_inc_dsthost_bulk_flow_count()) as well, so one enqueue sees one mode (KCSAN-visible race and stale host index).

Changes in v8:
- 1/4 is cake-only. fq_codel_classify() is line-for-line the same as fq_pie_classify(), and fq_pie is not changed by this series, so the two stay in lockstep: fq_codel keeps its original classify shape and the fq_codel backlog guard is placed inline in its enqueue path (3/4) instead. (Toke Høiland-Jørgensen)
- 3/4: the fq_codel guard sits between idx-- and codel_set_enqueue_time(), so a dropped packet cannot touch flow state. The commit message is reworded as suggested. (Toke Høiland-Jørgensen)
- 4/4: the original skb is consumed unconditionally right after a successful split -- that is the caller's reference, since a fraglist GSO takes the list's own reference on the same skb in skb_segment_list() -- so the reject branch tags every deferred segment and drops the whole list with qdisc_drop_all(), and the admitted path no longer consumes the skb after the walk. (Toke Høiland-Jørgensen)

Changes in v7:
- 1/4: complete the fq_codel_classify() comment (Sashiko nipa v6 main-2-1, Low). The comment listed only the terminal-action and no-class-ID cases; the function also returns true when no filter matched or when the selected class minor is above q->flows_cnt, and those packets are BYPASS drops, not a fallback to hashing as in cake. Comment-only, no code change; folded into this resend since the series is revised anyway.
- 3/4: do not clamp the shared qdisc_pkt_len() (Sashiko nipa v6 main-2-6, Medium). The clamp silently undercharged BPF __sk_buff.wire_len, act_police and the HTB/TBF shapers for a valid large GSO estimate. The initializer now stays truthful for every input and the overflow protection is enqueue admission: each affected qdisc drops a packet once the stored backlog cannot represent its accounted length -- the standing QDISC_MAX_BACKLOG ceiling covers ordinary packets, and a per-packet representability check covers the larger wire estimates, which a supported small-MSS BIG TCP aggregate can legitimately carry above 1 MiB while its raw length stays within GSO_MAX_SIZE. The consumers read the real length, and sch_handle_ingress() keeps complete pkt_segs metadata.
- 4/4: tag every deferred split-GSO segment with QDISC_DROP_OVERLIMIT (Sashiko nipa v6 gpt-6-astra-2-5, Medium). __skb_gso_segment() stores SKB_GSO_CB at cb offset 32, aliasing tc_skb_cb.drop_reason, and the cb is copied into every segment, so tagging only the head left the rest with GSO scratch as their drop reason.
- 4/4: snapshot q->config->flow_mode once with READ_ONCE() and pass it to both hash helpers (Sashiko nipa v6 gpt-6-astra-5-9, Low). The split introduced two loads with the segmentation work between them.
- Not folded: the 3/4 intermediate-commit split-GSO limitation (4/4 closes it; the pre-series path was already unbounded) and the Fixes:/stable suggestions (intentional net-next target). The gemini v6 TC_ACT_CONSUMED High is the v5 finding already rebutted as unreachable from a qdisc classify switch.

v6 rewrite as a four-patch series per Toke Høiland-Jørgensen's review of
v5 (split the classifier refactor, the split-GSO iterator, the overflow guard and the cake hash split; drop the machine-written prose). Considered the Sashiko gemini v5 TC_ACT_CONSUMED report and did not fold it (unreachable; see below). Reworded the cake block comment that had an embedded "/*" (Simon Horman's W=1 warning) and reworded a comment that overstated the classifier's return cases. The TC_ACT_CONSUMED switch case was dropped from the final 0001 because it still reached __qdisc_drop(); no in-tree producer can deliver TC_ACT_CONSUMED to a qdisc classify switch (act_ct returns it only on a clsact/ingress qdisc, act_mirred only for a non-cloning ingress redirect, and cls_bpf/act_bpf remap an unknown verdict to UNSPEC).

v5/v4/v3/v2 history: see the v6 posting. In short, v3 adopted the stored
backlog compare qdisc_backlog_at_max() (no double-count of the 1 MiB headroom, no per-enqueue 64-bit add), moved the classifier and the ceiling check ahead of the hash/shaper state, and added pfifo; v4 split the hash keys from the set-associative resolution and handled the fraglist-GSO self-link; v2 replaced the rejected u64 widening with the enqueue drop; v1 widened the counters.

Jamal Hadi Salim (4):
net/sched: cake: return the classifier result to the caller net/sched: cake: use a dedicated split-GSO list iterator net/sched: cap the accounted backlog before it can wrap net/sched: cake: hash before segmenting and reject an overlong split

 include/net/pkt_sched.h   |   1 -
 include/net/sch_generic.h |  33 ++++++-
 net/sched/sch_cake.c      | 186 +++++++++++++++++++++++++++-----------
 net/sched/sch_cbs.c       |   6 ++
 net/sched/sch_choke.c     |   6 ++
 net/sched/sch_codel.c     |  16 ++--
 net/sched/sch_drr.c       |   6 ++
 net/sched/sch_dualpi2.c   |   1 +
 net/sched/sch_etf.c       |   6 ++
 net/sched/sch_ets.c       |   6 ++
 net/sched/sch_fifo.c      |  12 +++
 net/sched/sch_fq.c        |   6 ++
 net/sched/sch_fq_codel.c  |   9 ++
 net/sched/sch_fq_pie.c    |   3 +-
 net/sched/sch_gred.c      |   9 ++
 net/sched/sch_hfsc.c      |   6 ++
 net/sched/sch_hhf.c       |  18 +++-
 net/sched/sch_htb.c       |  14 ++-
 net/sched/sch_netem.c     |  18 ++++
 net/sched/sch_pie.c       |   3 +-
 net/sched/sch_plug.c      |   3 +-
 net/sched/sch_prio.c      |   6 ++
 net/sched/sch_qfq.c       |   6 ++
 net/sched/sch_red.c       |  10 ++
 net/sched/sch_sfb.c       |   6 ++
 net/sched/sch_sfq.c       |   6 ++
 net/sched/sch_skbprio.c   |  17 +++-
 net/sched/sch_taprio.c    |  40 ++++++--
 net/sched/sch_tbf.c       |   6 ++
 29 files changed, 382 insertions(+), 83 deletions(-)
Signature · 1 line
2.43.0