From: netdev-bot+sashiko@kernel.org
To: julius@bairaktaris.de
Cc: toke@toke.dk, netdev@vger.kernel.org, jhs@mojatatu.com,
jiri@resnulli.us, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
horms@kernel.org, victor@mojatatu.com
Subject: Re: [PATCH net-next 3/4] net/sched: sch_cake: keep short GSO aggregates whole
Date: Mon, 30 Nov 2026 15:46:46 +0000 [thread overview]
Message-ID: <179605360627.3146.17382186652659852380@kernel.org> (raw)
In-Reply-To: <20261129151144.2194312-4-julius@bairaktaris.de>
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 1 · High: 0 · Medium: 2 · Low: 3
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).
- [Critical] In net/sched/sch_cake.c, cake_split_head() changes the u64
memory counter by a difference computed in unsigned int, which can…
- [Medium] When cake_drop() splits an aggregate on the memory-limit path
(cake_split_head() with notify=false), sch->q.qlen grows by numsegs-1…
- [Medium] net/sched: sch_cake: avg_window_bytes underflow in
cake_split_head()
- [Low] The commit message and the comment on cake_gso_dequeue_whole()
(net/sched/sch_cake.c) treat the test `sojourn + cake_wire_ns(q, b,…
- [Low] The kernel-doc of cake_split_head() (net/sched/sch_cake.c) says
"The tin's packet count already holds every segment." That is only…
- [Low] cake_split_head() publishes the new flow head with a plain store,
`flow->head = segs;` (net/sched/sch_cake.c:1708).
--
net/sched: sch_cake: keep short GSO aggregates whole
With split-gso set, this commit lets CAKE keep a GSO aggregate unsplit at
enqueue when its wire time at the shaper rate is at most 1/8 of the tin's
COBALT target. At dequeue, or when the memory limit is hit, the new
cake_split_head() splits such an aggregate in place, unless COBALT has
nothing to signal for it. The ACK filter is skipped for whole aggregates.
> diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
> index 281c72ac530d3..e7bf7bc97d9f1 100644
> --- a/net/sched/sch_cake.c
> +++ b/net/sched/sch_cake.c
> @@ -1566,7 +1566,178 @@ static int cake_advance_shaper(struct cake_sched_data *q,
[ ... ]
> +/* Whether the whole aggregate @skb at the head of @flow may leave as one
> + * packet now: it is still short at the current rate, and COBALT has nothing
> + * to signal for any of its segments, so that judging it once is the same as
> + * judging each of them. That holds with no BLUE probability, outside the
> + * dropping state, and when even its last byte, sent behind all the others,
> + * leaves within the target: no segment is then over the target when it leaves,
> + * so none enters the dropping state, and a drop schedule still decaying from an
> + * earlier one (a non-zero count) decays with the time alone.
> + */
> +static bool cake_gso_dequeue_whole(const struct cake_sched_data *q,
> + const struct cake_tin_data *b,
> + const struct cake_flow *flow, ktime_t now,
> + const struct sk_buff *skb)
> +{
> + const struct cobalt_vars *vars = &flow->cvars;
> + u32 adjlen = get_cobalt_cb(skb)->adjusted_len;
> + u64 sojourn;
> +
> + if (vars->p_drop || vars->dropping ||
> + !cake_gso_keep_whole(q, b, adjlen))
> + return false;
> +
> + sojourn = ktime_to_ns(ktime_sub(now, cobalt_get_enqueue_time(skb)));
> + return sojourn + cake_wire_ns(q, b, adjlen) <= b->cparams.target;
> +}
[Severity: Low]
The commit message says:
At dequeue the head aggregate leaves whole only while it is still short
at the current rate and COBALT has nothing to signal for any of its
segments
The comment above also says "judging it once is the same as judging each
of them". Does that still hold when other flows are active in the same
tin?
cake_wire_ns() uses the tin or global shaper rate, so it assumes the
segments would leave back to back. When the aggregate is split,
cake_dequeue() serves the flow only until its deficit is used up. It then
moves the flow to the tail of old_flows, behind the other active flows.
With M competing flows, segment k leaves roughly k*M packet times after
the first, not k.
In that split schedule the later segments can go over the target and put
COBALT into the dropping state. With this patch the aggregate leaves whole
with no signal, and the mark or drop only lands on a later packet of the
flow.
The extra delay is bounded by about one aggregate. Could the commit
message and the comment call this a difference rather than an
equivalence? The single download measured in the message doesn't cover
the multi-flow case.
> +
> +/* Replace the aggregate at the head of flow @idx by its segments, so that the
> + * queue is what splitting at enqueue would have left: each segment with its
> + * own length and overhead, the enqueue time of the aggregate, and the backlog,
> + * memory and byte counts of the segments. The tin's packet count already holds
> + * every segment. @notify tells the parents about the change; cake_drop()
[Severity: Low]
Is "The tin's packet count already holds every segment" always true?
cake_enqueue() only counts every segment when whole is set:
WRITE_ONCE(b->packets, b->packets +
(whole ? qdisc_pkt_segs(skb) : 1));
whole is only computed while CAKE_FLAG_SPLIT_GSO is set, so an aggregate
queued under no-split-gso adds 1 to b->packets.
TCA_CAKE_SPLIT_GSO can be switched on at runtime through cake_change().
The split checks in cake_dequeue() and cake_drop() look only at the
current rate_flags and at qdisc_pkt_segs(flow->head) > 1, so such an
aggregate can be split later. cake_split_head() never adjusts b->packets,
which leaves the per-tin packet count short by those segments.
[ ... ]
> +static int cake_split_head(struct cake_sched_data *q, struct Qdisc *sch,
> + struct cake_tin_data *b, u32 idx, bool notify,
> + struct sk_buff **to_free,
> + enum qdisc_drop_reason *reason)
> +{
> + struct cake_flow *flow = &b->flows[idx];
> + struct sk_buff *skb = flow->head, *next = skb->next;
> + struct sk_buff *segs, *seg, *nskb, *last = NULL;
> + netdev_features_t features = netif_skb_features(skb);
> + ktime_t enqueue_time = cobalt_get_enqueue_time(skb);
> + unsigned int truesize = skb->truesize, segsize = 0;
[ ... ]
> + /* the list ends at the packet behind the aggregate */
> + last->next = next;
> + flow->head = segs;
[Severity: Low]
Should this be WRITE_ONCE(flow->head, segs)? cake_dump_class_stats()
reads flow->head without the qdisc lock:
if (READ_ONCE(flow->head)) {
sch_tree_lock(sch);
All the other writers (dequeue_head(), flow_queue_add() and
cake_ack_filter()) use WRITE_ONCE(). KCSAN will probably report this
plain store.
> + if (flow->tail == skb)
> + flow->tail = last;
> +
> + dlen = (s64)slen - len;
> + WRITE_ONCE(sch->q.qlen, sch->q.qlen + numsegs - 1);
> + qstats_backlog_add(sch, dlen);
> + WRITE_ONCE(b->backlogs[idx], b->backlogs[idx] + dlen);
> + WRITE_ONCE(b->tin_backlog, b->tin_backlog + dlen);
> + WRITE_ONCE(b->bytes, b->bytes + dlen);
> + q->avg_window_bytes += dlen;
> + q->buffer_used += segsize - truesize;
[Severity: Medium]
Can this wrap q->avg_window_bytes? It is a u64, and dlen is negative
whenever the length the aggregate was queued with is larger than the
sum of its segments' lengths. That is the case the backlog check above
was written for. With a size table, qdisc_pkt_len() includes the stab
overhead, cell alignment or size_log rounding of the whole aggregate,
while each segment is accounted here with plain seg->len.
The backlog counters still hold len for the queued aggregate, so they
are fine. avg_window_bytes is different: it only holds the bytes that
arrived in the current autorate-ingress window. cake_enqueue() resets
it to 0 when a window closes, and that happens after it has added the
aggregate's len and before the cake_drop() loop runs.
A split later in cake_dequeue(), or in cake_drop() on that same
enqueue, then subtracts -dlen from a counter that never held those
bytes. With a small or zero value it wraps to near U64_MAX.
The next window close in cake_enqueue() computes:
u64 b = q->avg_window_bytes * (u64)NSEC_PER_SEC;
b = div64_u64(b, window_interval);
from that value. The result goes into avg_peak_bandwidth with the fast
EWMA weight when it is larger, and cake_reconfigure() then sets
rate_bps and buffer_limit from it. With autorate-ingress and a size
table, the shaper rate can end up set to an arbitrary value. The
autorate setup is also where whole GRO aggregates are most likely,
since autorate gives the qdisc a rate.
Even without the wrap, those bytes were already counted in the window
the aggregate arrived in, so changing the current window's count
attributes them to the wrong window. Is there a reason for
cake_split_head() to touch avg_window_bytes at all? Would you rather
drop this update, or clamp it at zero?
[Severity: Critical]
Can this subtraction wrap? segsize and truesize are both unsigned int. If
the segments' total truesize is lower than the aggregate's, segsize -
truesize becomes 2^32 - d. That value is zero-extended into the u64
q->buffer_used, so the counter goes up by almost 4 GiB instead of down
by d.
The segments can have a smaller total. skb_segment() gives each new
segment a fresh head plus its data_len:
net/core/skbuff.c:skb_segment() {
...
nskb->truesize += nskb->data_len;
...
}
A GRO aggregate, by contrast, carries the full rx buffer truesize of
every frame merged into it. tcp_gso_segment() notes the same thing: "In
some pathological cases, delta can be negative". The enqueue time split
only ever added segs->truesize, so it could not wrap.
The unsplit path has the same pattern:
unsplit:
/* the drop paths uncharge the skb's own truesize */
q->buffer_used += skb->truesize - truesize;
There, skb_segment() can lower the head skb's truesize when it swaps head
and tail truesize for sock_wfree.
Each segment later uncharges only its own truesize, so once buffer_used
is above the u32 buffer_limit nothing brings it back down. Every
cake_enqueue() then runs:
while (q->buffer_used > q->buffer_limit) {
drop_id = cake_drop(sch, to_free, &grown);
and drops every queued packet. Once all flows are empty, cake_drop()
reaches:
if (unlikely(!skb)) {
/* heap has gone wrong, rebuild it next time */
q->overflow_timeout = 0;
return idx + (tin << 16);
}
and returns without lowering buffer_used.
Wouldn't the enqueue loop then spin forever, with the root qdisc lock
held and BH disabled?
This looks reachable with the default split-gso plus a shaper rate. A
forwarded bulk TCP flow arrives as GRO aggregates, which are queued whole.
They are split later, either in cake_dequeue() once sojourn plus wire time
exceeds the target, or in cake_drop() on the memory limit path.
Would a signed delta, for example (s64)segsize - truesize, avoid this?
[ ... ]
> @@ -1591,6 +1762,16 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free)
>
> b = &q->tins[tin];
> flow = &b->flows[idx];
> + /* drop one segment, as with split packets, not the whole aggregate */
> + if (flow->head && qdisc_pkt_segs(flow->head) > 1 &&
> + (q->config->rate_flags & CAKE_FLAG_SPLIT_GSO)) {
> + int added = cake_split_head(q, sch, b, idx, false, to_free,
> + NULL);
> +
> + /* else the aggregate is dropped below */
> + if (added > 0)
> + *grown += added;
> + }
[ ... ]
> @@ -1969,7 +2162,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,
> prev_backlog = sch->qstats.backlog;
>
> while (q->buffer_used > q->buffer_limit) {
> - drop_id = cake_drop(sch, to_free);
> + drop_id = cake_drop(sch, to_free, &grown);
> if ((drop_id >> 16) == tin &&
> (drop_id & 0xFFFF) == idx)
> same_flow = true;
> @@ -1977,7 +2170,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,
>
> prev_qlen -= sch->q.qlen;
> prev_backlog -= sch->qstats.backlog;
> - b->drop_overlimit += prev_qlen;
> + b->drop_overlimit += prev_qlen + grown;
>
> if (same_flow) {
> qdisc_tree_reduce_backlog(sch, prev_qlen - 1,
[Severity: Medium]
drop_overlimit is corrected for the growth from a split, but prev_qlen
still mixes growth and drops when it is passed to the parents. Would
parent qdiscs undercount drops here?
When cake_drop() splits an aggregate through cake_split_head() with
notify set to false, sch->q.qlen grows by numsegs - 1 and the parents are
not told. prev_qlen then equals drops - grown, which can be negative, and
it is passed on as n:
qdisc_tree_reduce_backlog(sch, prev_qlen - 1,
prev_backlog - len);
...
qdisc_tree_reduce_backlog(sch, prev_qlen, prev_backlog);
qdisc_tree_reduce_backlog() uses n both as the qlen change and as the drop
count:
drops = max_t(int, n, 0);
...
__qdisc_qstats_drop(sch, drops);
For example, splitting a 44 segment aggregate and dropping one segment
gives n = -42, so a parent such as an HTB class counts 0 drops. Parent
qlen and backlog stay correct; only the parents' drop counters are
wrong.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129151144.2194312-1-julius%40bairaktaris.de
next prev parent reply other threads:[~2026-11-30 15:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 15:11 [PATCH net-next 0/4] net/sched: sch_cake: per-packet cost of a shaping CAKE Julius Bairaktaris
2026-11-29 15:11 ` [PATCH net-next 1/4] net/sched: sch_cake: give the shaper timer slack Julius Bairaktaris
2026-11-30 15:46 ` netdev-bot+sashiko
2026-11-29 15:11 ` [PATCH net-next 2/4] net/sched: sch_cake: dither the flow quantum from a per-tin generator Julius Bairaktaris
2026-11-30 15:46 ` netdev-bot+sashiko
2026-11-29 15:11 ` [PATCH net-next 3/4] net/sched: sch_cake: keep short GSO aggregates whole Julius Bairaktaris
2026-11-30 15:46 ` netdev-bot+sashiko [this message]
2026-11-29 15:11 ` [PATCH net-next 4/4] net/sched: sch_cake: skip the dissection for a packet of an active flow Julius Bairaktaris
2026-11-30 15:46 ` netdev-bot+sashiko
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=179605360627.3146.17382186652659852380@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=julius@bairaktaris.de \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=toke@toke.dk \
--cc=victor@mojatatu.com \
--cc=willemb@google.com \
/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