From: Jakub Kicinski <kuba@kernel.org>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>,
<edumazet@google.com>, <pabeni@redhat.com>,
<andrew+netdev@lunn.ch>, <horms@kernel.org>, <sdf@fomichev.me>,
<hramamurthy@google.com>, <kuniyu@amazon.com>,
<jdamato@fastly.com>
Subject: Re: [PATCH net-next v2 8/8] netdev: depend on netdev->lock for qstats in ops locked drivers
Date: Thu, 10 Apr 2025 16:46:14 -0700 [thread overview]
Message-ID: <20250410164614.407e6d98@kernel.org> (raw)
In-Reply-To: <a2768226-854e-464d-8e76-240f7c76e987@intel.com>
On Wed, 9 Apr 2025 22:23:28 -0700 Jacob Keller wrote:
> > +struct netdev_stat_ops
> > +----------------------
> > +
> > +"qstat" ops are invoked under the instance lock for "ops locked" drivers,
> > +and under rtnl_lock for all other drivers.
> > +
> > struct net_shaper_ops
> > ---------------------
> >
>
> What determines if a driver is "ops locked"? Is that defined above this
> chunk in the doc? I see its when netdev_need_ops_lock() is set? Ok.
Yup, it was hiding in the previous patch:
Code comments and docs refer to drivers which have ops called under
the instance lock as "ops locked".
> Sounds like it would be good to start migrating drivers over to this
> locking paradigm over time.
At least for the drivers which implement queue stats its nice to be able
to dump stats without taking the global lock.
> > if (ifindex) {
> > - netdev = __dev_get_by_index(net, ifindex);
> > - if (netdev && netdev->stat_ops) {
> > + netdev = netdev_get_by_index_lock_ops_compat(net, ifindex);
> > + if (!netdev) {
> > + NL_SET_BAD_ATTR(info->extack,
> > + info->attrs[NETDEV_A_QSTATS_IFINDEX]);
> > + return -ENODEV;
> > + }
>
> I guess netdev_get_by_index_lock_ops_compat acquires the lock when it
> returns success?
Yes.
> > + if (netdev->stat_ops) {
> > err = netdev_nl_qstats_get_dump_one(netdev, scope, skb,
> > info, ctx);
> > } else {
> > NL_SET_BAD_ATTR(info->extack,
> > info->attrs[NETDEV_A_QSTATS_IFINDEX]);
> > - err = netdev ? -EOPNOTSUPP : -ENODEV;
> > - }
> > - } else {
>
> But there's an else branch here so now I'm confused with how this
> locking works.
The diff is really hard to read, sorry, I should have done two patches.
The else branch is _removed_. The code is now:
if (ifindex) {
netdev = netdev_get_by_index_lock_ops_compat(net, ifindex);
...
netdev_unlock_ops_compat(netdev);
return ;
}
for_each_lock_scoped() {
}
next prev parent reply other threads:[~2025-04-10 23:46 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 19:59 [PATCH net-next v2 0/8] net: depend on instance lock for queue related netlink ops Jakub Kicinski
2025-04-08 19:59 ` [PATCH net-next v2 1/8] net: avoid potential race between netdev_get_by_index_lock() and netns switch Jakub Kicinski
2025-04-08 19:59 ` [PATCH net-next v2 2/8] net: designate XSK pool pointers in queues as "ops protected" Jakub Kicinski
2025-04-08 19:59 ` [PATCH net-next v2 3/8] netdev: add "ops compat locking" helpers Jakub Kicinski
2025-04-08 19:59 ` [PATCH net-next v2 4/8] netdev: don't hold rtnl_lock over nl queue info get when possible Jakub Kicinski
2025-04-08 19:59 ` [PATCH net-next v2 5/8] xdp: double protect netdev->xdp_flags with netdev->lock Jakub Kicinski
2025-04-08 22:15 ` Harshitha Ramamurthy
2025-04-09 18:40 ` Martin KaFai Lau
2025-04-08 19:59 ` [PATCH net-next v2 6/8] netdev: depend on netdev->lock for xdp features Jakub Kicinski
2025-04-10 17:10 ` Kuniyuki Iwashima
2025-04-11 2:10 ` Jakub Kicinski
2025-04-11 2:23 ` Jakub Kicinski
2025-04-11 17:41 ` Stanislav Fomichev
2025-04-11 19:19 ` Jakub Kicinski
2025-04-11 2:36 ` Kuniyuki Iwashima
2025-04-08 19:59 ` [PATCH net-next v2 7/8] docs: netdev: break down the instance locking info per ops struct Jakub Kicinski
2025-04-09 2:59 ` Joe Damato
2025-04-10 6:01 ` Jacob Keller
2025-04-10 16:08 ` Jakub Kicinski
2025-04-10 22:35 ` Keller, Jacob E
2025-04-10 23:39 ` Jakub Kicinski
2025-04-11 21:26 ` Jacob Keller
2025-04-08 19:59 ` [PATCH net-next v2 8/8] netdev: depend on netdev->lock for qstats in ops locked drivers Jakub Kicinski
2025-04-10 5:23 ` Jacob Keller
2025-04-10 23:46 ` Jakub Kicinski [this message]
2025-04-11 21:29 ` Jacob Keller
2025-04-10 0:40 ` [PATCH net-next v2 0/8] net: depend on instance lock for queue related netlink ops patchwork-bot+netdevbpf
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=20250410164614.407e6d98@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=hramamurthy@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jdamato@fastly.com \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/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;
as well as URLs for NNTP newsgroup(s).