rtnetlink: Remove __rtnl_link_register()
authorKuniyuki Iwashima <kuniyu@amazon.com>
Fri, 8 Nov 2024 00:48:16 +0000 (16:48 -0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 12 Nov 2024 01:26:51 +0000 (17:26 -0800)
link_ops is protected by link_ops_mutex and no longer needs RTNL,
so we have no reason to have __rtnl_link_register() separately.

Let's remove it and call rtnl_link_register() from ifb.ko and
dummy.ko.

Note that both modules' init() work on init_net only, so we need
not export pernet_ops_rwsem and can use rtnl_net_lock() there.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20241108004823.29419-4-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dummy.c
drivers/net/ifb.c
include/net/rtnetlink.h
net/core/net_namespace.c
net/core/rtnetlink.c

index 72618b6..005d799 100644 (file)
@@ -166,27 +166,22 @@ err:
 
 static int __init dummy_init_module(void)
 {
-       bool need_unregister = false;
        int i, err = 0;
 
-       down_write(&pernet_ops_rwsem);
-       rtnl_lock();
-       err = __rtnl_link_register(&dummy_link_ops);
+       err = rtnl_link_register(&dummy_link_ops);
        if (err < 0)
-               goto out;
+               return err;
+
+       rtnl_net_lock(&init_net);
 
        for (i = 0; i < numdummies && !err; i++) {
                err = dummy_init_one();
                cond_resched();
        }
-       if (err < 0)
-               need_unregister = true;
 
-out:
-       rtnl_unlock();
-       up_write(&pernet_ops_rwsem);
+       rtnl_net_unlock(&init_net);
 
-       if (need_unregister)
+       if (err < 0)
                rtnl_link_unregister(&dummy_link_ops);
 
        return err;
index a4b9ec4..6742488 100644 (file)
@@ -424,27 +424,22 @@ err:
 
 static int __init ifb_init_module(void)
 {
-       bool need_unregister = false;
        int i, err;
 
-       down_write(&pernet_ops_rwsem);
-       rtnl_lock();
-       err = __rtnl_link_register(&ifb_link_ops);
+       err = rtnl_link_register(&ifb_link_ops);
        if (err < 0)
-               goto out;
+               return err;
+
+       rtnl_net_lock(&init_net);
 
        for (i = 0; i < numifbs && !err; i++) {
                err = ifb_init_one(i);
                cond_resched();
        }
-       if (err)
-               need_unregister = true;
 
-out:
-       rtnl_unlock();
-       up_write(&pernet_ops_rwsem);
+       rtnl_net_unlock(&init_net);
 
-       if (need_unregister)
+       if (err)
                rtnl_link_unregister(&ifb_link_ops);
 
        return err;
index 7559020..ef7c11f 100644 (file)
@@ -164,8 +164,6 @@ struct rtnl_link_ops {
                                                   int *prividx, int attr);
 };
 
-int __rtnl_link_register(struct rtnl_link_ops *ops);
-
 int rtnl_link_register(struct rtnl_link_ops *ops);
 void rtnl_link_unregister(struct rtnl_link_ops *ops);
 
index 809b48c..157021c 100644 (file)
@@ -56,7 +56,6 @@ static bool init_net_initialized;
  * outside.
  */
 DECLARE_RWSEM(pernet_ops_rwsem);
-EXPORT_SYMBOL_GPL(pernet_ops_rwsem);
 
 #define MIN_PERNET_OPS_ID      \
        ((sizeof(struct net_generic) + sizeof(void *) - 1) / sizeof(void *))
index 21154ef..e8357a3 100644 (file)
@@ -495,20 +495,21 @@ static void rtnl_link_ops_put(struct rtnl_link_ops *ops, int srcu_index)
 }
 
 /**
- * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
+ * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
  * @ops: struct rtnl_link_ops * to register
  *
- * The caller must hold the rtnl_mutex. This function should be used
- * by drivers that create devices during module initialization. It
- * must be called before registering the devices.
- *
  * Returns 0 on success or a negative error code.
  */
-int __rtnl_link_register(struct rtnl_link_ops *ops)
+int rtnl_link_register(struct rtnl_link_ops *ops)
 {
        struct rtnl_link_ops *tmp;
        int err;
 
+       /* Sanity-check max sizes to avoid stack buffer overflow. */
+       if (WARN_ON(ops->maxtype > RTNL_MAX_TYPE ||
+                   ops->slave_maxtype > RTNL_SLAVE_MAX_TYPE))
+               return -EINVAL;
+
        /* The check for alloc/setup is here because if ops
         * does not have that filled up, it is not possible
         * to use the ops for creating device. So do not
@@ -536,28 +537,6 @@ unlock:
 
        return err;
 }
-EXPORT_SYMBOL_GPL(__rtnl_link_register);
-
-/**
- * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
- * @ops: struct rtnl_link_ops * to register
- *
- * Returns 0 on success or a negative error code.
- */
-int rtnl_link_register(struct rtnl_link_ops *ops)
-{
-       int err;
-
-       /* Sanity-check max sizes to avoid stack buffer overflow. */
-       if (WARN_ON(ops->maxtype > RTNL_MAX_TYPE ||
-                   ops->slave_maxtype > RTNL_SLAVE_MAX_TYPE))
-               return -EINVAL;
-
-       rtnl_lock();
-       err = __rtnl_link_register(ops);
-       rtnl_unlock();
-       return err;
-}
 EXPORT_SYMBOL_GPL(rtnl_link_register);
 
 static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)