Skip to content

Commit 99e44f3

Browse files
committed
netdev: depend on netdev->lock for xdp features
Writes to XDP features are now protected by netdev->lock. Other things we report are based on ops which don't change once device has been registered. It is safe to stop taking rtnl_lock, and depend on netdev->lock instead. Reviewed-by: Joe Damato <jdamato@fastly.com> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Link: https://patch.msgid.link/20250408195956.412733-7-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 03df156 commit 99e44f3

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

net/core/netdev-genl.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,
3838
u64 xdp_rx_meta = 0;
3939
void *hdr;
4040

41+
netdev_assert_locked(netdev); /* note: rtnl_lock may not be held! */
42+
4143
hdr = genlmsg_iput(rsp, info);
4244
if (!hdr)
4345
return -EMSGSIZE;
@@ -122,15 +124,14 @@ int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info)
122124
if (!rsp)
123125
return -ENOMEM;
124126

125-
rtnl_lock();
126-
127-
netdev = __dev_get_by_index(genl_info_net(info), ifindex);
128-
if (netdev)
129-
err = netdev_nl_dev_fill(netdev, rsp, info);
130-
else
127+
netdev = netdev_get_by_index_lock(genl_info_net(info), ifindex);
128+
if (!netdev) {
131129
err = -ENODEV;
130+
goto err_free_msg;
131+
}
132132

133-
rtnl_unlock();
133+
err = netdev_nl_dev_fill(netdev, rsp, info);
134+
netdev_unlock(netdev);
134135

135136
if (err)
136137
goto err_free_msg;
@@ -146,18 +147,15 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
146147
{
147148
struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb);
148149
struct net *net = sock_net(skb->sk);
149-
struct net_device *netdev;
150-
int err = 0;
150+
int err;
151151

152-
rtnl_lock();
153-
for_each_netdev_dump(net, netdev, ctx->ifindex) {
152+
for_each_netdev_lock_scoped(net, netdev, ctx->ifindex) {
154153
err = netdev_nl_dev_fill(netdev, skb, genl_info_dump(cb));
155154
if (err < 0)
156-
break;
155+
return err;
157156
}
158-
rtnl_unlock();
159157

160-
return err;
158+
return 0;
161159
}
162160

163161
static int

0 commit comments

Comments
 (0)