From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796053607; b=etB5WSAQF4QFk74uqINjzm8GKLhP9v7PbAu2nPlA5wlmIQvt9/hSh3c+vH/QNOqu+EN0 AqFv7cMLMExJDAPm2sX5StVfWl54QKbmkPafp0mG6lXmTPuxrUexC76VzGO6wWTsKcLwd Tpf0Am5XXIGvWo41v92tinoxE5ny6WOMzhsR98VRXYfLD41wp7Kn/wG18/rpJ6pQzNka8 eI4lOOIQU8t0L4p6K/naFIM2p/iBRDqNF2joLMhH8v/0R/ClkDA6yYGuBoWb9PtQRb/Wf diznibXw5AwQLEO0G0Q7FGxoo/s7laRcc4w9+dqGGe9mouvlCRDNPhCruW7MQN/IHFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053607; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=eVXaOTP0X/8NjT6F0JSwA7qdL67ZPgz63oYYUiE8ckE=; b=AkJGjFyjsck/m0FrwkHYmJBOu9qLTU4QGk3rxNZV7vCq/rBfOYPBk/Xxd29gugyLfN1F U3V/KLT4D21FjpULsYIC2g0zCz82TJ7dy4mdVmLqGZHQAHiTQ+qJe2Y/UrfgTlxwhgSF1 /XGd6wf0vMWmjc5OvcJAad2jkcvfygPPQBNOfUQOCzY+DOVZHaEtmHuLUa0og7BQR9vuW ZZjb81xRsnYlA3wfAelgZ1cWy+Nq5SincsifvcGBWnBxD4rjGqPPw8o+v/NciPOMqGSF9 4YBlnnL2q1MtFI+IJUKbhlergPpLmGGxhSqjQrGoSZJwpndag+rXrOYdMsYvXEGkVfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AWF+I12+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D909606A697 for ; Mon, 30 Nov 2026 15:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AWF+I12+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id B21431F00932; Mon, 30 Nov 2026 15:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796053607; bh=eVXaOTP0X/8NjT6F0JSwA7qdL67ZPgz63oYYUiE8ckE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=AWF+I12+iooLRoVW5U4B8Z5cdt/k8uB7uE+157DHOVg8TMHKHBTGo7fWweFzMomae flleOJA0tc0fGBk0emwpKS80qsHFS+LW0HcyFlBbBi/a4QH2P+0pfFTHMJ8GbyGgAr SSj+2aChIv9ZJPZbp9yGDXodXXBAtl+Uzit5yu4SqkSXRQ7TOWhrGNXHpREb5gi9IR UNjsQZ+sGFyMuA0Ymz4Y8zTxSWtCmTO6yTALoq111B+9s7HXmpym+hCYvV9032YzVU COnd9dULQYZK2D4QWUKa4Ojv6lkSRHX3YckWybr0bQXmKGEWxhO8j5QmYpYD/Z9Rur bWBiqFIbpobrA== Subject: Re: [PATCH net-next 3/4] net/sched: sch_cake: keep short GSO aggregates whole 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 Date: Mon, 30 Nov 2026 15:46:46 +0000 Message-ID: <179605360627.3146.17382186652659852380@kernel.org> In-Reply-To: <20261129151144.2194312-4-julius@bairaktaris.de> References: <20261129151144.2194312-4-julius@bairaktaris.de> X-sashiko-severity: Critical Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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