]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: convert dev->rtnl_link_state to a bool
authorJakub Kicinski <kuba@kernel.org>
Thu, 10 Apr 2025 01:42:46 +0000 (18:42 -0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 14 Apr 2025 21:29:54 +0000 (14:29 -0700)
netdevice reg_state was split into two 16 bit enums back in 2010
in commit a2835763e130 ("rtnetlink: handle rtnl_link netlink
notifications manually"). Since the split the fields have been
moved apart, and last year we converted reg_state to a normal
u8 in commit 4d42b37def70 ("net: convert dev->reg_state to u8").

rtnl_link_state being a 16 bitfield makes no sense. Convert it
to a single bool, it seems very unlikely after 15 years that
we'll need more values in it.

We could drop dev->rtnl_link_ops from the conditions but feels
like having it there more clearly points at the reason for this
hack.

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250410014246.780885-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Documentation/networking/net_cachelines/net_device.rst
include/linux/netdevice.h
net/core/dev.c
net/core/rtnetlink.c

index 6327e689e8a84c7af9ae5213e9bf9224184c00e9..ca8605eb82ffc084b8974a326492d18c30c452bb 100644 (file)
@@ -131,7 +131,7 @@ struct ref_tracker_dir              refcnt_tracker
 struct list_head                    link_watch_list
 enum:8                              reg_state
 bool                                dismantle
-enum:16                             rtnl_link_state
+bool                                rtnl_link_initilizing
 bool                                needs_free_netdev
 void*priv_destructor                struct net_device
 struct netpoll_info*                npinfo                                          read_mostly         napi_poll/napi_poll_lock
index d8544f6a680cd5e5bd6c64265813a7d4a09fe37a..e6036b82ef4cf6375ec63bcb782bd6ee75bd40d6 100644 (file)
@@ -1946,9 +1946,6 @@ enum netdev_reg_state {
  *
  *     @reg_state:             Register/unregister state machine
  *     @dismantle:             Device is going to be freed
- *     @rtnl_link_state:       This enum represents the phases of creating
- *                             a new link
- *
  *     @needs_free_netdev:     Should unregister perform free_netdev?
  *     @priv_destructor:       Called from unregister
  *     @npinfo:                XXX: need comments on this one
@@ -2363,11 +2360,8 @@ struct net_device {
 
        /** @moving_ns: device is changing netns, protected by @lock */
        bool moving_ns;
-
-       enum {
-               RTNL_LINK_INITIALIZED,
-               RTNL_LINK_INITIALIZING,
-       } rtnl_link_state:16;
+       /** @rtnl_link_initializing: Device being created, suppress events */
+       bool rtnl_link_initializing;
 
        bool needs_free_netdev;
        void (*priv_destructor)(struct net_device *dev);
index d0563ddff6ca98c532f9c9832da359f7488e6c19..03d20a98f8b70f0092a0a14186d822927317078d 100644 (file)
@@ -11110,8 +11110,7 @@ int register_netdevice(struct net_device *dev)
         *      Prevent userspace races by waiting until the network
         *      device is fully setup before sending notifications.
         */
-       if (!dev->rtnl_link_ops ||
-           dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
+       if (!(dev->rtnl_link_ops && dev->rtnl_link_initializing))
                rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U, GFP_KERNEL, 0, NULL);
 
 out:
@@ -12025,8 +12024,7 @@ void unregister_netdevice_many_notify(struct list_head *head,
                 */
                call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
 
-               if (!dev->rtnl_link_ops ||
-                   dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
+               if (!(dev->rtnl_link_ops && dev->rtnl_link_initializing))
                        skb = rtmsg_ifinfo_build_skb(RTM_DELLINK, dev, ~0U, 0,
                                                     GFP_KERNEL, NULL, 0,
                                                     portid, nlh);
index 39a5b72e861f683bfdc56f857303670be524c37f..38526210b8fdd96da3adf24a1f5339c75dc779da 100644 (file)
@@ -3580,7 +3580,7 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
 int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm,
                        u32 portid, const struct nlmsghdr *nlh)
 {
-       unsigned int old_flags;
+       unsigned int old_flags, changed;
        int err;
 
        old_flags = dev->flags;
@@ -3591,12 +3591,13 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm,
                        return err;
        }
 
-       if (dev->rtnl_link_state == RTNL_LINK_INITIALIZED) {
-               __dev_notify_flags(dev, old_flags, (old_flags ^ dev->flags), portid, nlh);
-       } else {
-               dev->rtnl_link_state = RTNL_LINK_INITIALIZED;
-               __dev_notify_flags(dev, old_flags, ~0U, portid, nlh);
+       changed = old_flags ^ dev->flags;
+       if (dev->rtnl_link_initializing) {
+               dev->rtnl_link_initializing = false;
+               changed = ~0U;
        }
+
+       __dev_notify_flags(dev, old_flags, changed, portid, nlh);
        return 0;
 }
 EXPORT_SYMBOL(rtnl_configure_link);
@@ -3654,7 +3655,7 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
 
        dev_net_set(dev, net);
        dev->rtnl_link_ops = ops;
-       dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
+       dev->rtnl_link_initializing = true;
 
        if (tb[IFLA_MTU]) {
                u32 mtu = nla_get_u32(tb[IFLA_MTU]);