[RH7,10/11] net: Kill net_mutex

Submitted by Kirill Tkhai on May 27, 2020, 3:54 p.m.

Details

Message ID 159059487088.408928.15136863247459170660.stgit@localhost.localdomain
State New
Series "Parallel per-net init/exit"
Headers show

Commit Message

Kirill Tkhai May 27, 2020, 3:54 p.m.
ms commit 19efbd93e6fb

We take net_mutex, when there are !async pernet_operations
registered, and read locking of net_sem is not enough. But
we may get rid of taking the mutex, and just change the logic
to write lock net_sem in such cases. This obviously reduces
the number of lock operations, we do.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[vz7: many intermediate and following patches skipped]
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 net/core/net_namespace.c |   11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 15bfd1306141..7c80d00e4f75 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -31,7 +31,6 @@ 
 
 static LIST_HEAD(pernet_list);
 static struct list_head *first_device = &pernet_list;
-DEFINE_MUTEX(net_mutex);
 /*
  * net_sem: protects: pernet_list, net_generic_ids,
  * init_net_initialized and first_device pointer.
@@ -73,11 +72,10 @@  int net_assign_generic(struct net *net, int id, void *data)
 {
 	struct net_generic *ng, *old_ng;
 
-	BUG_ON(!mutex_is_locked(&net_mutex));
 	BUG_ON(id == 0);
 
 	old_ng = rcu_dereference_protected(net->gen,
-					   lockdep_is_held(&net_mutex));
+					   lockdep_is_held(&net_sem));
 	ng = old_ng;
 	if (old_ng->len >= id)
 		goto assign;
@@ -432,13 +430,7 @@  struct net *copy_net_ns(unsigned long flags,
 	if (rv < 0)
 		goto put_userns;
 
-	rv = mutex_lock_killable(&net_mutex);
-	if (rv < 0)
-		goto up_read;
-
 	rv = setup_net(net, user_ns);
-	mutex_unlock(&net_mutex);
-up_read:
 	up_read(&net_sem);
 	if (rv < 0) {
 put_userns:
@@ -496,7 +488,6 @@  static void cleanup_net(struct work_struct *work)
 	spin_unlock_irq(&cleanup_list_lock);
 
 	down_read(&net_sem);
-	mutex_lock(&net_mutex);
 
 	/* Don't let anyone else find us. */
 	rtnl_lock();