Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: convert dev->rtnl_link_state to a bool

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>

+13 -20
+1 -1
Documentation/networking/net_cachelines/net_device.rst
··· 131 131 struct list_head link_watch_list 132 132 enum:8 reg_state 133 133 bool dismantle 134 - enum:16 rtnl_link_state 134 + bool rtnl_link_initilizing 135 135 bool needs_free_netdev 136 136 void*priv_destructor struct net_device 137 137 struct netpoll_info* npinfo read_mostly napi_poll/napi_poll_lock
+2 -8
include/linux/netdevice.h
··· 1946 1946 * 1947 1947 * @reg_state: Register/unregister state machine 1948 1948 * @dismantle: Device is going to be freed 1949 - * @rtnl_link_state: This enum represents the phases of creating 1950 - * a new link 1951 - * 1952 1949 * @needs_free_netdev: Should unregister perform free_netdev? 1953 1950 * @priv_destructor: Called from unregister 1954 1951 * @npinfo: XXX: need comments on this one ··· 2360 2363 2361 2364 /** @moving_ns: device is changing netns, protected by @lock */ 2362 2365 bool moving_ns; 2363 - 2364 - enum { 2365 - RTNL_LINK_INITIALIZED, 2366 - RTNL_LINK_INITIALIZING, 2367 - } rtnl_link_state:16; 2366 + /** @rtnl_link_initializing: Device being created, suppress events */ 2367 + bool rtnl_link_initializing; 2368 2368 2369 2369 bool needs_free_netdev; 2370 2370 void (*priv_destructor)(struct net_device *dev);
+2 -4
net/core/dev.c
··· 11110 11110 * Prevent userspace races by waiting until the network 11111 11111 * device is fully setup before sending notifications. 11112 11112 */ 11113 - if (!dev->rtnl_link_ops || 11114 - dev->rtnl_link_state == RTNL_LINK_INITIALIZED) 11113 + if (!(dev->rtnl_link_ops && dev->rtnl_link_initializing)) 11115 11114 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U, GFP_KERNEL, 0, NULL); 11116 11115 11117 11116 out: ··· 12024 12025 */ 12025 12026 call_netdevice_notifiers(NETDEV_UNREGISTER, dev); 12026 12027 12027 - if (!dev->rtnl_link_ops || 12028 - dev->rtnl_link_state == RTNL_LINK_INITIALIZED) 12028 + if (!(dev->rtnl_link_ops && dev->rtnl_link_initializing)) 12029 12029 skb = rtmsg_ifinfo_build_skb(RTM_DELLINK, dev, ~0U, 0, 12030 12030 GFP_KERNEL, NULL, 0, 12031 12031 portid, nlh);
+8 -7
net/core/rtnetlink.c
··· 3580 3580 int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm, 3581 3581 u32 portid, const struct nlmsghdr *nlh) 3582 3582 { 3583 - unsigned int old_flags; 3583 + unsigned int old_flags, changed; 3584 3584 int err; 3585 3585 3586 3586 old_flags = dev->flags; ··· 3591 3591 return err; 3592 3592 } 3593 3593 3594 - if (dev->rtnl_link_state == RTNL_LINK_INITIALIZED) { 3595 - __dev_notify_flags(dev, old_flags, (old_flags ^ dev->flags), portid, nlh); 3596 - } else { 3597 - dev->rtnl_link_state = RTNL_LINK_INITIALIZED; 3598 - __dev_notify_flags(dev, old_flags, ~0U, portid, nlh); 3594 + changed = old_flags ^ dev->flags; 3595 + if (dev->rtnl_link_initializing) { 3596 + dev->rtnl_link_initializing = false; 3597 + changed = ~0U; 3599 3598 } 3599 + 3600 + __dev_notify_flags(dev, old_flags, changed, portid, nlh); 3600 3601 return 0; 3601 3602 } 3602 3603 EXPORT_SYMBOL(rtnl_configure_link); ··· 3655 3654 3656 3655 dev_net_set(dev, net); 3657 3656 dev->rtnl_link_ops = ops; 3658 - dev->rtnl_link_state = RTNL_LINK_INITIALIZING; 3657 + dev->rtnl_link_initializing = true; 3659 3658 3660 3659 if (tb[IFLA_MTU]) { 3661 3660 u32 mtu = nla_get_u32(tb[IFLA_MTU]);