From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Jiri Pirko <jiri@resnulli.us>,
Kuniyuki Iwashima <kuniyu@google.com>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 3/4] net/sched: switch tc_dump_qdisc() to for_each_netdev_dump()
Date: Mon, 27 Apr 2026 13:25:54 +0000 [thread overview]
Message-ID: <20260427132555.1791636-4-edumazet@google.com> (raw)
In-Reply-To: <20260427132555.1791636-1-edumazet@google.com>
Use for_each_netdev_dump() instead of for_each_netdev().
This is more scalable, and will ease RCU conversion.
This also offer better behavior when other threads
are adding or deleting netdevices concurrently.
This enables dumping qdiscs for a single device
at user space request in the following patch.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/sched/sch_api.c | 61 ++++++++++++++++++++++-----------------------
1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 322eab3bd2b1327af323c44333318bdd52c7ee52..c4e8059acdd324441e0d069f6878bbfcab5a0cc7 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -1873,18 +1873,18 @@ static int tc_dump_qdisc_root(struct Qdisc *root, struct sk_buff *skb,
static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
{
- struct net *net = sock_net(skb->sk);
- int idx, q_idx;
- int s_idx, s_q_idx;
- struct net_device *dev;
const struct nlmsghdr *nlh = cb->nlh;
+ struct net *net = sock_net(skb->sk);
struct nlattr *tca[TCA_MAX + 1];
+ struct {
+ unsigned long ifindex;
+ int q_idx;
+ } *ctx = (void *)cb->ctx;
+ unsigned long s_ifindex;
+ struct net_device *dev;
+ int s_q_idx, q_idx;
int err;
- s_idx = cb->args[0];
- s_q_idx = q_idx = cb->args[1];
-
- idx = 0;
ASSERT_RTNL();
err = nlmsg_parse_deprecated(nlh, sizeof(struct tcmsg), tca, TCA_MAX,
@@ -1892,42 +1892,41 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
if (err < 0)
return err;
- for_each_netdev(net, dev) {
+ s_ifindex = ctx->ifindex;
+ s_q_idx = ctx->q_idx;
+
+ for_each_netdev_dump(net, dev, ctx->ifindex) {
struct netdev_queue *dev_queue;
+ struct Qdisc *q;
- if (idx < s_idx)
- goto cont;
- if (idx > s_idx)
+ if (ctx->ifindex > s_ifindex)
s_q_idx = 0;
q_idx = 0;
netdev_lock_ops(dev);
- if (tc_dump_qdisc_root(rtnl_dereference(dev->qdisc),
- skb, cb, &q_idx, s_q_idx,
- true, tca[TCA_DUMP_INVISIBLE]) < 0) {
- netdev_unlock_ops(dev);
- goto done;
- }
+ q = rtnl_dereference(dev->qdisc);
+ err = tc_dump_qdisc_root(q, skb, cb, &q_idx, s_q_idx,
+ true, tca[TCA_DUMP_INVISIBLE]);
+ if (err < 0)
+ goto error_unlock;
dev_queue = dev_ingress_queue(dev);
- if (dev_queue &&
- tc_dump_qdisc_root(rtnl_dereference(dev_queue->qdisc_sleeping),
- skb, cb, &q_idx, s_q_idx, false,
- tca[TCA_DUMP_INVISIBLE]) < 0) {
- netdev_unlock_ops(dev);
- goto done;
+ if (dev_queue) {
+ q = rtnl_dereference(dev_queue->qdisc_sleeping);
+ err = tc_dump_qdisc_root(q, skb, cb, &q_idx, s_q_idx,
+ false, tca[TCA_DUMP_INVISIBLE]);
+ if (err < 0)
+ goto error_unlock;
}
netdev_unlock_ops(dev);
-
-cont:
- idx++;
}
+ return skb->len;
-done:
- cb->args[0] = idx;
- cb->args[1] = q_idx;
+error_unlock:
+ netdev_unlock_ops(dev);
+ ctx->q_idx = q_idx;
- return skb->len;
+ return err;
}
--
2.54.0.545.g6539524ca2-goog
next prev parent reply other threads:[~2026-04-27 13:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 13:25 [PATCH net-next 0/4] net/sched: tc_dump_qdisc() optimizations Eric Dumazet
2026-04-27 13:25 ` [PATCH net-next 1/4] net/sched: propagate tc_fill_tclass() error Eric Dumazet
2026-04-27 13:25 ` [PATCH net-next 2/4] net/sched: tc_dump_qdisc_root() refactor Eric Dumazet
2026-04-27 23:08 ` Jakub Kicinski
2026-04-28 15:48 ` Eric Dumazet
2026-04-27 13:25 ` Eric Dumazet [this message]
2026-04-27 23:13 ` [PATCH net-next 3/4] net/sched: switch tc_dump_qdisc() to for_each_netdev_dump() Jakub Kicinski
2026-04-28 15:57 ` Eric Dumazet
2026-04-27 13:25 ` [PATCH net-next 4/4] net/sched: speedup tc_dump_qdisc() when tcm_ifindex is provided Eric Dumazet
2026-04-27 23:18 ` Jakub Kicinski
2026-04-28 15:40 ` Eric Dumazet
2026-04-28 17:20 ` Jakub Kicinski
2026-04-28 17:26 ` Eric Dumazet
2026-04-27 23:02 ` [PATCH net-next 0/4] net/sched: tc_dump_qdisc() optimizations Jakub Kicinski
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=20260427132555.1791636-4-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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