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=1796498262; b=g9sHfuz3H34tABT3KWKyuWMOUPE+N/Yucr2JqpYFoOlxfBfRrCYj2YKv7B3VdCoy58xT KFeRot7yG9h65eLFfHbhByxg9bsn0YeVfrkj52n+DYPpukx7kcxprPF6e6+UfUZPsx+BR sIU1efsiGWPHA21R8JekK9S5UWIfnzeIiuuI1Mn4fOfzFRB8BIJkN4mqQ5+sD3pfCORCM +F5tuJFS8K2O072xib2Q8q7YlUSYPTSVCF0eYP1DSFqAESBCs/fGtJg7APqDD88pmScW0 2LoDtiwDJQGgWnRynJkNr+Qdaju4/8XDKoYdMTKRj9nyTbpC/ZuhZxFJ09mxp4HvCsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796498262; 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=HNMQg8F9ehWxmELjj/+oBqrgOBGgGla+6zNZyXyga8s=; b=1y2uSsgn3fgnuTYq6f5wTpdeloqY5A64AzI+1xKbAnUzIZlVep6KxC1jJwlH0dG5PygO LHAu3hn4XLxHAMjLDvZSvQ20SxL7EezT8YoMFNXr/fS6L/vvuss6HUcrvUg1AMlKnQMhA ZxD67OMy7ccr0Giay6amFzTaU8MNH0ESuJUYM+WX2c7yfVMdV6m4vud3bLlLV/dd18mpK xWCpHLMhcupzJiRXdet3ywP2r2Xx0Bac7saAReMpTj7R4SJudSajoGz3n7lwtdvYBOz7y TylFyzEb+wnXCvMkMAT63RaoDsMRGiQnMdfy6R/8DsbSo/vJR/CoJsJGHhQIAAWrbiw== 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=XvAFuGz6; 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 1FC00606A31F; Sat, 5 Dec 2026 19:17:42 +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=XvAFuGz6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DED2B1F0092B; Sat, 5 Dec 2026 19:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796498261; bh=HNMQg8F9ehWxmELjj/+oBqrgOBGgGla+6zNZyXyga8s=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=XvAFuGz6uB87hP8mpUjp3AGr8BXID/zD9nEpZlbUVXct/RKy5IsczooigC1/1NnrB OKKtZx7QYTzzY8afh088rP4utG8xAzrXKm2/2QPEAlslENcv8IHQmcyvfq/S9J7ZLv eTX0n96uihQQ7DjoJ3r9HAMn0LXS+sgIAX1XRzp2x5DjNNBJSLj8jUNc9EgU0xQcMt a8dkHJZ+9Gsiqpwn3n1nbATB2JlFVYkAg/9Pq7oG1EWLEQXcgcI1lk1xGMiUdMxsLL FAYXnnsSOH5KG1+63aiE8triDg6Y18hJLjnkcoRangr86fKkUiXsC/I/7CYXkDOBMd XzZ4eWvs3Gg9w== Subject: Re: [PATCH net-next v11 1/4] net/sched: sch_fq_pie: add per-flow statistics via class ops From: netdev-bot+sashiko@kernel.org To: hemendranaik@gmail.com Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, jiri@resnulli.us, jhs@mojatatu.com, shuah@kernel.org, donald.hunter@gmail.com, ast@fiberby.net, toke@redhat.com, liuhangbin@kylinos.cn, j.koeppeler@tu-berlin.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, vishy0777@gmail.com, tahiliani@nitk.edu.in Date: Sat, 05 Dec 2026 19:17:40 +0000 Message-ID: <179649826042.3148.1503525650306575001@kernel.org> In-Reply-To: <20261204190143.633361-2-hemendranaik@gmail.com> References: <20261204190143.633361-2-hemendranaik@gmail.com> X-sashiko-severity: Medium 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: 0 · High: 0 · Medium: 2 · Low: 4 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). - [Medium] net/sched: sch_fq_pie: unclamped flow->vars.prob shift wraps on congestion - [Medium] net/sched: fq_pie: 32-bit avg_dq_rate truncation in fq_pie_dump_class_stats() - [Low] The WRITE_ONCE() annotations added for the new lockless class- stats reader do not match what that reader reads, and the commit… - [Low] The patch grows the UAPI `struct tc_fq_pie_xstats` from 36 to 64 bytes. - [Low] Setting `.cl_ops = &fq_pie_class_ops` in `fq_pie_qdisc_ops` makes fq_pie classful as far as the tc core is concerned. - [Low] When `flows_cnt` is 65536, the last flow is reported as class X:0, the same handle as the fq_pie qdisc itself. -- net/sched: sch_fq_pie: add per-flow statistics via class ops This patch adds class ops to fq_pie so that tc -s class show reports per-flow PIE state (prob, delay, deficit, avg_dq_rate). It extends struct tc_fq_pie_xstats with a type discriminator and a per-class stats struct, which grows it from 36 to 64 bytes. It also converts several per-flow field updates to WRITE_ONCE(). > diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h > index 490efd2885267..fef848eaaab23 100644 > --- a/include/uapi/linux/pkt_sched.h > +++ b/include/uapi/linux/pkt_sched.h [ ... ] > @@ -963,6 +978,8 @@ struct tc_fq_pie_xstats { > __u32 new_flows_len; /* count of flows in new list */ > __u32 old_flows_len; /* count of flows in old list */ > __u32 memory_usage; /* total memory across all queues */ > + __u32 type; > + struct tc_fq_pie_cl_stats class_stats; > }; [Severity: Low] Is this the uAPI layout we want to keep for good? Two mutually exclusive payloads share one flat struct, and the type discriminator comes after the nine legacy counters. With this layout, fq_pie_dump_stats() always sends 28 bytes of zeroed class_stats at qdisc level. fq_pie_dump_class_stats() sends 64 bytes, and the first 36 of them (the qdisc counters) are always zero. Userspace built against the 36-byte struct never reads type. Before this patch fq_pie had no cl_ops, so tc -s class show printed nothing for it. With this patch, an older iproute2 would probably decode each per-flow TCA_STATS_APP with its qdisc print_xstats handler. It would then print all-zero pkts_in, dropped, overlimit and similar counters that look like real values. I inferred the iproute2 behaviour and did not check it here. Could the commit message explain this compatibility trade-off? It would also help to say how the companion iproute2 change handles 36-byte payloads from older kernels. Separately, the new type member has no doc comment, unlike the fields around it. > diff --git a/net/sched/sch_fq_pie.c b/net/sched/sch_fq_pie.c > index a5e2a83efb679..b9ada9ded8213 100644 > --- a/net/sched/sch_fq_pie.c > +++ b/net/sched/sch_fq_pie.c > @@ -190,17 +190,17 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch, [ ... ] > out: > q->stats.dropped++; > - sel_flow->vars.accu_prob = 0; > + WRITE_ONCE(sel_flow->vars.accu_prob, 0); > qdisc_drop_reason(skb, sch, to_free, reason); > return NET_XMIT_CN; > } [Severity: Low] Which lockless reader of accu_prob does this WRITE_ONCE() pair with? tc_fill_tclass() passes a NULL lock, so fq_pie_dump_class_stats() runs without the qdisc lock. It never reads accu_prob, though, and struct tc_fq_pie_cl_stats does not export it. The main writers of accu_prob still use plain stores: net/sched/sch_pie.c:pie_drop_early() { ... if (local_prob == 0) vars->accu_prob = 0; else vars->accu_prob += local_prob; ... } pie_qdisc_enqueue() and pie_vars_init() also use plain stores. The commit message says: Used WRITE_ONCE() macro to guard following variables: - deficit - qlen - backlog - vars.accu_prob Would it be more accurate to drop vars.accu_prob from that list, along with this annotation? The class dump does read vars.prob, vars.qdelay and vars.avg_dq_rate with READ_ONCE() and without the qdisc lock. Those reads depend on WRITE_ONCE() annotations that already exist in sch_pie.c and pie.h. Should the message mention them instead? Also, fq_pie_reset() still writes backlog with a plain store, although the new dump reads it with READ_ONCE(): net/sched/sch_fq_pie.c:fq_pie_reset() { ... flow->head = NULL; flow->backlog = 0; ... } Both paths seem to run under RTNL, so this looks like an inconsistency rather than a real race. [ ... ] > @@ -565,7 +569,89 @@ static void fq_pie_destroy(struct Qdisc *sch) > kvfree(q->flows); > } > [ ... ] > +static int fq_pie_dump_class(struct Qdisc *sch, unsigned long cl, > + struct sk_buff *skb, struct tcmsg *tcm) > +{ > + tcm->tcm_handle |= TC_H_MIN(cl); > + return 0; > +} [Severity: Low] What happens here when flows_cnt is 65536? fq_pie_change() accepts that value: if (!q->flows_cnt || q->flows_cnt > 65536) { fq_pie_walk() then passes cl = i + 1: if (!tc_qdisc_stats_dump(sch, i + 1, arg)) For the last flow that gives cl = 65536. TC_H_MIN(65536) is 0, so tcm_handle stays equal to the qdisc handle. fq_pie_dump_class_stats() still treats cl = 65536 as valid, since idx 65535 < flows_cnt, and emits real per-flow stats. Userspace would see an active flow class with classid X:0, the same handle as the fq_pie qdisc, and could not map it to that flow. fq_codel_walk() has the same pattern, but this behaviour is new for fq_pie. [ ... ] > static struct Qdisc_ops fq_pie_qdisc_ops __read_mostly = { > + .cl_ops = &fq_pie_class_ops, > .id = "fq_pie", [Severity: Low] Setting cl_ops makes the tc core treat fq_pie as classful. Should the commit message mention the user-visible error changes that follow? It currently says only that the filter callbacks are omitted. Before this patch, tc filter add ... parent : failed in __tcf_qdisc_find() with -EINVAL "Qdisc not classful". It now gets one check further: net/sched/cls_api.c:__tcf_qdisc_find() { ... if (!cops->tcf_block) { NL_SET_ERR_MSG(extack, "Class doesn't support blocks"); err = -EOPNOTSUPP; goto errout_qdisc; } ... } RTM_NEWTCLASS, RTM_DELTCLASS and RTM_GETTCLASS used to return -EINVAL in __tc_ctl_tclass() when cops == NULL. They now reach fq_pie_find(), which always returns 0, so they return -ENOENT. Grafting a qdisc under an fq_pie class used to fail with -EOPNOTSUPP "Parent qdisc is not classful". It now fails with -ENOENT "Specified class not found". So classes that tc class show lists (for example 2:5) cannot be looked up with tc class get. fq_codel behaves the same way, but scripts that match on these errors may see the difference. [ ... ] > @@ -563,7 +567,89 @@ static void fq_pie_destroy(struct Qdisc *sch) > kvfree(q->flows); > } > > +static struct Qdisc *fq_pie_leaf(struct Qdisc *sch, unsigned long arg) > +{ > + return NULL; > +} > + > +static unsigned long fq_pie_find(struct Qdisc *sch, u32 classid) > +{ > + return 0; > +} > + > +static int fq_pie_dump_class(struct Qdisc *sch, unsigned long cl, > + struct sk_buff *skb, struct tcmsg *tcm) > +{ > + tcm->tcm_handle |= TC_H_MIN(cl); > + return 0; > +} > + > +static int fq_pie_dump_class_stats(struct Qdisc *sch, unsigned long cl, > + struct gnet_dump *d) > +{ > + struct fq_pie_sched_data *q = qdisc_priv(sch); > + struct gnet_stats_queue qs = { 0 }; > + struct tc_fq_pie_xstats xstats; > + u32 idx = cl - 1; > + > + if (idx < q->flows_cnt) { > + const struct fq_pie_flow *flow = &q->flows[idx]; > + > + memset(&xstats, 0, sizeof(xstats)); > + xstats.type = TCA_FQ_PIE_XSTATS_CLASS; > + xstats.class_stats.prob = > + READ_ONCE(flow->vars.prob) << BITS_PER_BYTE; > + xstats.class_stats.delay = > + div_u64(PSCHED_TICKS2NS(READ_ONCE(flow->vars.qdelay)), > + NSEC_PER_USEC); > + xstats.class_stats.deficit = READ_ONCE(flow->deficit); > + xstats.class_stats.dq_rate_estimating = > + READ_ONCE(q->p_params.dq_rate_estimator); > + > + if (xstats.class_stats.dq_rate_estimating) { > + xstats.class_stats.avg_dq_rate = [Severity: Medium] Can the converted rate exceed U32_MAX here? The product is computed in u64, but it is stored into the __u32 avg_dq_rate field of struct tc_fq_pie_cl_stats without any clamping, so the upper 32 bits are silently dropped. flow->vars.avg_dq_rate is in bytes per psched tick, scaled by PIE_SCALE. With PSCHED_TICKS_PER_SEC at 15625000, an avg_dq_rate of 70369 or more converts to more than U32_MAX bytes/second. That is about 4.3 GB/s, or roughly 34 Gbit/s, for a single flow. pie_process_dequeue() reaches it whenever QUEUE_THRESHOLD (16384 bytes) drains in 59 ticks or fewer, about 3.8 us. For example, 71089 converts to 4338928222 bytes/second, which wraps to 43960926. One flow at that rate is realistic on 40G and faster NICs, over veth or on loopback, especially with GSO. With dq_rate_estimator enabled, tc -s class show would then report a wrapped rate that is far too low. struct tc_fq_pie_cl_stats is new uAPI and its layout cannot change once released. Should avg_dq_rate be a __u64? Placing it next to prob, with an explicit pad member at the end, would keep the struct free of implicit holes. If __u32 is kept for consistency with tc_pie_xstats, could the value at least saturate with min_t(u64, ..., U32_MAX), with the limit documented next to the field? Either way, the tc.yaml spec update later in this series would need to match. > + ((u64)READ_ONCE(flow->vars.avg_dq_rate) > + * PSCHED_TICKS_PER_SEC) >> PIE_SCALE; > + } > + > + qs.qlen = READ_ONCE(flow->qlen); > + qs.backlog = READ_ONCE(flow->backlog); > + } > + if (gnet_stats_copy_queue(d, NULL, &qs, qs.qlen) < 0) > + return -1; > + if (idx < q->flows_cnt) > + return gnet_stats_copy_app(d, &xstats, sizeof(xstats)); > + return 0; > +} > + > +static void fq_pie_walk(struct Qdisc *sch, struct qdisc_walker *arg) > +{ > + struct fq_pie_sched_data *q = qdisc_priv(sch); > + unsigned int i; > + > + if (arg->stop) > + return; > + > + for (i = 0; i < q->flows_cnt; i++) { > + if (list_empty(&q->flows[i].flowchain)) { > + arg->count++; > + continue; > + } > + if (!tc_qdisc_stats_dump(sch, i + 1, arg)) > + break; > + } > +} > + > +static const struct Qdisc_class_ops fq_pie_class_ops = { > + .leaf = fq_pie_leaf, > + .find = fq_pie_find, > + .dump = fq_pie_dump_class, > + .dump_stats = fq_pie_dump_class_stats, > + .walk = fq_pie_walk, > +}; > + > static struct Qdisc_ops fq_pie_qdisc_ops __read_mostly = { > + .cl_ops = &fq_pie_class_ops, > .id = "fq_pie", > .priv_size = sizeof(struct fq_pie_sched_data), > .enqueue = fq_pie_qdisc_enqueue, [Severity: Medium] Can flow->vars.prob be larger than MAX_PROB at this point? MAX_PROB is U64_MAX >> 8, and the shift by BITS_PER_BYTE assumes the top byte of prob is always zero. pie_calculate_probability() only clamps when the u64 addition wraps around completely: net/sched/sch_pie.c:pie_calculate_probability() { ... WRITE_ONCE(vars->prob, vars->prob + delta); if (delta > 0) { /* prevent overflow */ if (vars->prob < oldprob) { WRITE_ONCE(vars->prob, MAX_PROB); ... } Under sustained congestion, with qdelay well above target, the positive delta steps can carry prob past MAX_PROB into the range (MAX_PROB, U64_MAX] without wrapping, so the check above never fires. Nothing in sch_pie.c or sch_fq_pie.c caps it there, and pie_drop_early() then drops essentially every packet of the flow. fq_pie_dump_class_stats() shifts that non-zero top byte out. A prob of 0x0100000000000000, for example, is reported as 0. A flow that is losing nearly all of its packets could therefore appear in tc -s class show with a drop probability close to 0%, or with some other arbitrary value. Would clamping with min_t(u64, READ_ONCE(flow->vars.prob), MAX_PROB) before the shift be enough here? Or should pie_calculate_probability() cap prob at MAX_PROB itself? That would also cover pie_dump_stats() in sch_pie.c, which appears to use the same shift. However, it changes how quickly prob decays once congestion ends, so it may be better as a separate fix. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204190143.633361-1-hemendranaik%40gmail.com