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
Subject: Re: [PATCH net-next v11 1/4] net/sched: sch_fq_pie: add per-flow statistics via class ops
Date: Sat, 05 Dec 2026 19:17:40 +0000 [thread overview]
Message-ID: <179649826042.3148.1503525650306575001@kernel.org> (raw)
In-Reply-To: <20261204190143.633361-2-hemendranaik@gmail.com>
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 <fq_pie handle>: 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
next prev parent reply other threads:[~2026-12-05 19:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:01 [PATCH net-next v11 0/4] net/sched: sch_fq_pie: add per-flow class statistics Hemendra M. Naik
2026-12-04 19:01 ` [PATCH net-next v11 1/4] net/sched: sch_fq_pie: add per-flow statistics via class ops Hemendra M. Naik
2026-12-05 19:17 ` netdev-bot+sashiko [this message]
2026-12-04 19:01 ` [PATCH net-next v11 2/4] selftests: tc-testing: add fq_pie per-flow class stats test Hemendra M. Naik
2026-12-05 19:17 ` netdev-bot+sashiko
2026-12-04 19:01 ` [PATCH net-next v11 3/4] net/sched: pie: correct tc_pie_xstats field documentation Hemendra M. Naik
2026-12-04 19:01 ` [PATCH net-next v11 4/4] Documentation/netlink/specs: tc: describe fq_pie per-flow class stats Hemendra M. Naik
2026-12-05 19:17 ` 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=179649826042.3148.1503525650306575001@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=ast@fiberby.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@kernel.org \
--cc=hemendranaik@gmail.com \
--cc=horms@kernel.org \
--cc=j.koeppeler@tu-berlin.de \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=liuhangbin@kylinos.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=tahiliani@nitk.edu.in \
--cc=toke@redhat.com \
--cc=vishy0777@gmail.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