Skip to content

Commit 1901066

Browse files
Stanislav Fomichevkuba-moo
authored andcommitted
netdevsim: add dummy device notifiers
In order to exercise and verify notifiers' locking assumptions, register dummy notifiers (via register_netdevice_notifier_dev_net). Share notifier event handler that enforces the assumptions with lock_debug.c (rename and export rtnl_net_debug_event as netdev_debug_event). Add ops lock asserts to netdev_debug_event. Signed-off-by: Stanislav Fomichev <sdf@fomichev.me> Link: https://patch.msgid.link/20250401163452.622454-6-sdf@fomichev.me Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b912d59 commit 1901066

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

drivers/net/netdevsim/netdev.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
939939
ns->netdev->netdev_ops = &nsim_netdev_ops;
940940
ns->netdev->stat_ops = &nsim_stat_ops;
941941
ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops;
942+
netdev_lockdep_set_classes(ns->netdev);
942943

943944
err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev);
944945
if (err)
@@ -960,6 +961,14 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
960961
if (err)
961962
goto err_ipsec_teardown;
962963
rtnl_unlock();
964+
965+
if (IS_ENABLED(CONFIG_DEBUG_NET)) {
966+
ns->nb.notifier_call = netdev_debug_event;
967+
if (register_netdevice_notifier_dev_net(ns->netdev, &ns->nb,
968+
&ns->nn))
969+
ns->nb.notifier_call = NULL;
970+
}
971+
963972
return 0;
964973

965974
err_ipsec_teardown:
@@ -1043,6 +1052,10 @@ void nsim_destroy(struct netdevsim *ns)
10431052
debugfs_remove(ns->qr_dfs);
10441053
debugfs_remove(ns->pp_dfs);
10451054

1055+
if (ns->nb.notifier_call)
1056+
unregister_netdevice_notifier_dev_net(ns->netdev, &ns->nb,
1057+
&ns->nn);
1058+
10461059
rtnl_lock();
10471060
peer = rtnl_dereference(ns->peer);
10481061
if (peer)

drivers/net/netdevsim/netdevsim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ struct netdevsim {
144144

145145
struct nsim_ethtool ethtool;
146146
struct netdevsim __rcu *peer;
147+
148+
struct notifier_block nb;
149+
struct netdev_net_notifier nn;
147150
};
148151

149152
struct netdevsim *

include/net/netdev_lock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,7 @@ static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
9898
&qdisc_xmit_lock_key); \
9999
}
100100

101+
int netdev_debug_event(struct notifier_block *nb, unsigned long event,
102+
void *ptr);
103+
101104
#endif

net/core/lock_debug.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
#include <linux/notifier.h>
77
#include <linux/rtnetlink.h>
88
#include <net/net_namespace.h>
9+
#include <net/netdev_lock.h>
910
#include <net/netns/generic.h>
1011

11-
static int rtnl_net_debug_event(struct notifier_block *nb,
12-
unsigned long event, void *ptr)
12+
int netdev_debug_event(struct notifier_block *nb, unsigned long event,
13+
void *ptr)
1314
{
1415
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1516
struct net *net = dev_net(dev);
1617
enum netdev_cmd cmd = event;
1718

1819
/* Keep enum and don't add default to trigger -Werror=switch */
1920
switch (cmd) {
21+
case NETDEV_REGISTER:
2022
case NETDEV_UP:
23+
netdev_ops_assert_locked(dev);
24+
fallthrough;
2125
case NETDEV_DOWN:
2226
case NETDEV_REBOOT:
2327
case NETDEV_CHANGE:
24-
case NETDEV_REGISTER:
2528
case NETDEV_UNREGISTER:
2629
case NETDEV_CHANGEMTU:
2730
case NETDEV_CHANGEADDR:
@@ -66,6 +69,7 @@ static int rtnl_net_debug_event(struct notifier_block *nb,
6669

6770
return NOTIFY_DONE;
6871
}
72+
EXPORT_SYMBOL_NS_GPL(netdev_debug_event, "NETDEV_INTERNAL");
6973

7074
static int rtnl_net_debug_net_id;
7175

@@ -74,7 +78,7 @@ static int __net_init rtnl_net_debug_net_init(struct net *net)
7478
struct notifier_block *nb;
7579

7680
nb = net_generic(net, rtnl_net_debug_net_id);
77-
nb->notifier_call = rtnl_net_debug_event;
81+
nb->notifier_call = netdev_debug_event;
7882

7983
return register_netdevice_notifier_net(net, nb);
8084
}
@@ -95,7 +99,7 @@ static struct pernet_operations rtnl_net_debug_net_ops __net_initdata = {
9599
};
96100

97101
static struct notifier_block rtnl_net_debug_block = {
98-
.notifier_call = rtnl_net_debug_event,
102+
.notifier_call = netdev_debug_event,
99103
};
100104

101105
static int __init rtnl_net_debug_init(void)

0 commit comments

Comments
 (0)