]> www.infradead.org Git - nvme.git/commitdiff
netdevsim: add dummy device notifiers
authorStanislav Fomichev <sdf@fomichev.me>
Tue, 1 Apr 2025 16:34:46 +0000 (09:34 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 3 Apr 2025 22:32:08 +0000 (15:32 -0700)
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>
drivers/net/netdevsim/netdev.c
drivers/net/netdevsim/netdevsim.h
include/net/netdev_lock.h
net/core/lock_debug.c

index b67af4651185be5acb22b8b7a244e108a3e096fa..ddda0c1e7a6d454f7dd4a34340d3182e4857a26c 100644 (file)
@@ -939,6 +939,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
        ns->netdev->netdev_ops = &nsim_netdev_ops;
        ns->netdev->stat_ops = &nsim_stat_ops;
        ns->netdev->queue_mgmt_ops = &nsim_queue_mgmt_ops;
+       netdev_lockdep_set_classes(ns->netdev);
 
        err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev);
        if (err)
@@ -960,6 +961,14 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
        if (err)
                goto err_ipsec_teardown;
        rtnl_unlock();
+
+       if (IS_ENABLED(CONFIG_DEBUG_NET)) {
+               ns->nb.notifier_call = netdev_debug_event;
+               if (register_netdevice_notifier_dev_net(ns->netdev, &ns->nb,
+                                                       &ns->nn))
+                       ns->nb.notifier_call = NULL;
+       }
+
        return 0;
 
 err_ipsec_teardown:
@@ -1043,6 +1052,10 @@ void nsim_destroy(struct netdevsim *ns)
        debugfs_remove(ns->qr_dfs);
        debugfs_remove(ns->pp_dfs);
 
+       if (ns->nb.notifier_call)
+               unregister_netdevice_notifier_dev_net(ns->netdev, &ns->nb,
+                                                     &ns->nn);
+
        rtnl_lock();
        peer = rtnl_dereference(ns->peer);
        if (peer)
index 665020d18f2947fbefeeaa72c9b260ecc6e3042a..d04401f0bdf79eff4327b58aca66a9f856a8c3a3 100644 (file)
@@ -144,6 +144,9 @@ struct netdevsim {
 
        struct nsim_ethtool ethtool;
        struct netdevsim __rcu *peer;
+
+       struct notifier_block nb;
+       struct netdev_net_notifier nn;
 };
 
 struct netdevsim *
index 1c0c9a94cc224ae592ab6227babd0c59c119529f..c316b551df8d61b748a9489e40225cea667cf5ac 100644 (file)
@@ -98,4 +98,7 @@ static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
                                  &qdisc_xmit_lock_key);        \
 }
 
+int netdev_debug_event(struct notifier_block *nb, unsigned long event,
+                      void *ptr);
+
 #endif
index f3272b09c25568123b214213dffe42fb24d92a78..b7f22dc92a6f30fbb47a6a53f08a2802d9e82ff3 100644 (file)
@@ -6,10 +6,11 @@
 #include <linux/notifier.h>
 #include <linux/rtnetlink.h>
 #include <net/net_namespace.h>
+#include <net/netdev_lock.h>
 #include <net/netns/generic.h>
 
-static int rtnl_net_debug_event(struct notifier_block *nb,
-                               unsigned long event, void *ptr)
+int netdev_debug_event(struct notifier_block *nb, unsigned long event,
+                      void *ptr)
 {
        struct net_device *dev = netdev_notifier_info_to_dev(ptr);
        struct net *net = dev_net(dev);
@@ -17,11 +18,13 @@ static int rtnl_net_debug_event(struct notifier_block *nb,
 
        /* Keep enum and don't add default to trigger -Werror=switch */
        switch (cmd) {
+       case NETDEV_REGISTER:
        case NETDEV_UP:
+               netdev_ops_assert_locked(dev);
+               fallthrough;
        case NETDEV_DOWN:
        case NETDEV_REBOOT:
        case NETDEV_CHANGE:
-       case NETDEV_REGISTER:
        case NETDEV_UNREGISTER:
        case NETDEV_CHANGEMTU:
        case NETDEV_CHANGEADDR:
@@ -66,6 +69,7 @@ static int rtnl_net_debug_event(struct notifier_block *nb,
 
        return NOTIFY_DONE;
 }
+EXPORT_SYMBOL_NS_GPL(netdev_debug_event, "NETDEV_INTERNAL");
 
 static int rtnl_net_debug_net_id;
 
@@ -74,7 +78,7 @@ static int __net_init rtnl_net_debug_net_init(struct net *net)
        struct notifier_block *nb;
 
        nb = net_generic(net, rtnl_net_debug_net_id);
-       nb->notifier_call = rtnl_net_debug_event;
+       nb->notifier_call = netdev_debug_event;
 
        return register_netdevice_notifier_net(net, nb);
 }
@@ -95,7 +99,7 @@ static struct pernet_operations rtnl_net_debug_net_ops __net_initdata = {
 };
 
 static struct notifier_block rtnl_net_debug_block = {
-       .notifier_call = rtnl_net_debug_event,
+       .notifier_call = netdev_debug_event,
 };
 
 static int __init rtnl_net_debug_init(void)