From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH v3 net-next 13/13] net: remove dev_base_lock
Date: Fri, 9 Feb 2024 20:34:28 +0000 [thread overview]
Message-ID: <20240209203428.307351-14-edumazet@google.com> (raw)
In-Reply-To: <20240209203428.307351-1-edumazet@google.com>
dev_base_lock is not needed anymore, all remaining users also hold RTNL.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/linux/netdevice.h | 2 --
net/core/dev.c | 39 ++++-----------------------------------
2 files changed, 4 insertions(+), 37 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d4d1e438ab8f1d2bd6426837b504ad6891fe83b7..94968baa7da172b69cc8ac148d39315018893420 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3077,8 +3077,6 @@ int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
int call_netdevice_notifiers_info(unsigned long val,
struct netdev_notifier_info *info);
-extern rwlock_t dev_base_lock; /* Device list lock */
-
#define for_each_netdev(net, d) \
list_for_each_entry(d, &(net)->dev_base_head, dev_list)
#define for_each_netdev_reverse(net, d) \
diff --git a/net/core/dev.c b/net/core/dev.c
index a1cb7d3cab2c521fc28bd5f522c147bffca8d15e..456877e4b5d165878b3886db56d934c9e8c9cedc 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -166,28 +166,6 @@ static int call_netdevice_notifiers_extack(unsigned long val,
struct net_device *dev,
struct netlink_ext_ack *extack);
-/*
- * The @dev_base_head list is protected by @dev_base_lock and the rtnl
- * semaphore.
- *
- * Pure readers hold dev_base_lock for reading, or rcu_read_lock()
- *
- * Writers must hold the rtnl semaphore while they loop through the
- * dev_base_head list, and hold dev_base_lock for writing when they do the
- * actual updates. This allows pure readers to access the list even
- * while a writer is preparing to update it.
- *
- * To put it another way, dev_base_lock is held for writing only to
- * protect against pure readers; the rtnl semaphore provides the
- * protection against other writers.
- *
- * See, for example usages, register_netdevice() and
- * unregister_netdevice(), which must be called with the rtnl
- * semaphore held.
- */
-DEFINE_RWLOCK(dev_base_lock);
-EXPORT_SYMBOL(dev_base_lock);
-
static DEFINE_MUTEX(ifalias_mutex);
/* protects napi_hash addition/deletion and napi_gen_id */
@@ -393,12 +371,10 @@ static void list_netdevice(struct net_device *dev)
ASSERT_RTNL();
- write_lock(&dev_base_lock);
list_add_tail_rcu(&dev->dev_list, &net->dev_base_head);
netdev_name_node_add(net, dev->name_node);
hlist_add_head_rcu(&dev->index_hlist,
dev_index_hash(net, dev->ifindex));
- write_unlock(&dev_base_lock);
netdev_for_each_altname(dev, name_node)
netdev_name_node_add(net, name_node);
@@ -425,11 +401,9 @@ static void unlist_netdevice(struct net_device *dev)
netdev_name_node_del(name_node);
/* Unlink dev from the device chain */
- write_lock(&dev_base_lock);
list_del_rcu(&dev->dev_list);
netdev_name_node_del(dev->name_node);
hlist_del_rcu(&dev->index_hlist);
- write_unlock(&dev_base_lock);
dev_base_seq_inc(dev_net(dev));
}
@@ -744,9 +718,9 @@ EXPORT_SYMBOL_GPL(dev_fill_forward_path);
* @net: the applicable net namespace
* @name: name to find
*
- * Find an interface by name. Must be called under RTNL semaphore
- * or @dev_base_lock. If the name is found a pointer to the device
- * is returned. If the name is not found then %NULL is returned. The
+ * Find an interface by name. Must be called under RTNL semaphore.
+ * If the name is found a pointer to the device is returned.
+ * If the name is not found then %NULL is returned. The
* reference counters are not incremented so the caller must be
* careful with locks.
*/
@@ -827,8 +801,7 @@ EXPORT_SYMBOL(netdev_get_by_name);
* Search for an interface by index. Returns %NULL if the device
* is not found or a pointer to the device. The device has not
* had its reference counter increased so the caller must be careful
- * about locking. The caller must hold either the RTNL semaphore
- * or @dev_base_lock.
+ * about locking. The caller must hold the RTNL semaphore.
*/
struct net_device *__dev_get_by_index(struct net *net, int ifindex)
@@ -1233,15 +1206,11 @@ int dev_change_name(struct net_device *dev, const char *newname)
netdev_adjacent_rename_links(dev, oldname);
- write_lock(&dev_base_lock);
netdev_name_node_del(dev->name_node);
- write_unlock(&dev_base_lock);
synchronize_rcu();
- write_lock(&dev_base_lock);
netdev_name_node_add(net, dev->name_node);
- write_unlock(&dev_base_lock);
ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev);
ret = notifier_to_errno(ret);
--
2.43.0.687.g38aa6559b0-goog
prev parent reply other threads:[~2024-02-09 20:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 20:34 [PATCH v3 net-next 00/13] net: complete dev_base_lock removal Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 01/13] net: annotate data-races around dev->name_assign_type Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 02/13] ip_tunnel: annotate data-races around t->parms.link Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 03/13] dev: annotate accesses to dev->link Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 04/13] net: convert dev->reg_state to u8 Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 05/13] net-sysfs: convert netdev_show() to RCU Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 06/13] net-sysfs: use dev_addr_sem to remove races in address_show() Eric Dumazet
2024-02-13 1:58 ` Jakub Kicinski
2024-02-13 6:08 ` Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 07/13] net-sysfs: convert dev->operstate reads to lockless ones Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 08/13] net-sysfs: convert netstat_show() to RCU Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 09/13] net: remove stale mentions of dev_base_lock in comments Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 10/13] net: add netdev_set_operstate() helper Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 11/13] net: remove dev_base_lock from do_setlink() Eric Dumazet
2024-02-09 20:34 ` [PATCH v3 net-next 12/13] net: remove dev_base_lock from register_netdevice() and friends Eric Dumazet
2024-02-09 20:34 ` Eric Dumazet [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240209203428.307351-14-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).