[Devel] [PATCH RH7 10/11] net: Kill net_mutex

Kirill Tkhai ktkhai at virtuozzo.com
Wed May 27 18:54:30 MSK 2020


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

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();




More information about the Devel mailing list