Skip to content

Commit 1b3ef46

Browse files
edumazetdavem330
authored andcommitted
net: remove dev_base_lock
dev_base_lock is not needed anymore, all remaining users also hold RTNL. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e51b962 commit 1b3ef46

File tree

2 files changed

+4
-37
lines changed

2 files changed

+4
-37
lines changed

include/linux/netdevice.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,8 +3077,6 @@ int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
30773077
int call_netdevice_notifiers_info(unsigned long val,
30783078
struct netdev_notifier_info *info);
30793079

3080-
extern rwlock_t dev_base_lock; /* Device list lock */
3081-
30823080
#define for_each_netdev(net, d) \
30833081
list_for_each_entry(d, &(net)->dev_base_head, dev_list)
30843082
#define for_each_netdev_reverse(net, d) \

net/core/dev.c

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,6 @@ static int call_netdevice_notifiers_extack(unsigned long val,
168168
struct net_device *dev,
169169
struct netlink_ext_ack *extack);
170170

171-
/*
172-
* The @dev_base_head list is protected by @dev_base_lock and the rtnl
173-
* semaphore.
174-
*
175-
* Pure readers hold dev_base_lock for reading, or rcu_read_lock()
176-
*
177-
* Writers must hold the rtnl semaphore while they loop through the
178-
* dev_base_head list, and hold dev_base_lock for writing when they do the
179-
* actual updates. This allows pure readers to access the list even
180-
* while a writer is preparing to update it.
181-
*
182-
* To put it another way, dev_base_lock is held for writing only to
183-
* protect against pure readers; the rtnl semaphore provides the
184-
* protection against other writers.
185-
*
186-
* See, for example usages, register_netdevice() and
187-
* unregister_netdevice(), which must be called with the rtnl
188-
* semaphore held.
189-
*/
190-
DEFINE_RWLOCK(dev_base_lock);
191-
EXPORT_SYMBOL(dev_base_lock);
192-
193171
static DEFINE_MUTEX(ifalias_mutex);
194172

195173
/* protects napi_hash addition/deletion and napi_gen_id */
@@ -395,12 +373,10 @@ static void list_netdevice(struct net_device *dev)
395373

396374
ASSERT_RTNL();
397375

398-
write_lock(&dev_base_lock);
399376
list_add_tail_rcu(&dev->dev_list, &net->dev_base_head);
400377
netdev_name_node_add(net, dev->name_node);
401378
hlist_add_head_rcu(&dev->index_hlist,
402379
dev_index_hash(net, dev->ifindex));
403-
write_unlock(&dev_base_lock);
404380

405381
netdev_for_each_altname(dev, name_node)
406382
netdev_name_node_add(net, name_node);
@@ -427,11 +403,9 @@ static void unlist_netdevice(struct net_device *dev)
427403
netdev_name_node_del(name_node);
428404

429405
/* Unlink dev from the device chain */
430-
write_lock(&dev_base_lock);
431406
list_del_rcu(&dev->dev_list);
432407
netdev_name_node_del(dev->name_node);
433408
hlist_del_rcu(&dev->index_hlist);
434-
write_unlock(&dev_base_lock);
435409

436410
dev_base_seq_inc(dev_net(dev));
437411
}
@@ -752,9 +726,9 @@ EXPORT_SYMBOL_GPL(dev_fill_forward_path);
752726
* @net: the applicable net namespace
753727
* @name: name to find
754728
*
755-
* Find an interface by name. Must be called under RTNL semaphore
756-
* or @dev_base_lock. If the name is found a pointer to the device
757-
* is returned. If the name is not found then %NULL is returned. The
729+
* Find an interface by name. Must be called under RTNL semaphore.
730+
* If the name is found a pointer to the device is returned.
731+
* If the name is not found then %NULL is returned. The
758732
* reference counters are not incremented so the caller must be
759733
* careful with locks.
760734
*/
@@ -835,8 +809,7 @@ EXPORT_SYMBOL(netdev_get_by_name);
835809
* Search for an interface by index. Returns %NULL if the device
836810
* is not found or a pointer to the device. The device has not
837811
* had its reference counter increased so the caller must be careful
838-
* about locking. The caller must hold either the RTNL semaphore
839-
* or @dev_base_lock.
812+
* about locking. The caller must hold the RTNL semaphore.
840813
*/
841814

842815
struct net_device *__dev_get_by_index(struct net *net, int ifindex)
@@ -1241,15 +1214,11 @@ int dev_change_name(struct net_device *dev, const char *newname)
12411214

12421215
netdev_adjacent_rename_links(dev, oldname);
12431216

1244-
write_lock(&dev_base_lock);
12451217
netdev_name_node_del(dev->name_node);
1246-
write_unlock(&dev_base_lock);
12471218

12481219
synchronize_net();
12491220

1250-
write_lock(&dev_base_lock);
12511221
netdev_name_node_add(net, dev->name_node);
1252-
write_unlock(&dev_base_lock);
12531222

12541223
ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev);
12551224
ret = notifier_to_errno(ret);

0 commit comments

Comments
 (0)