[Devel] [PATCH RHEL7 COMMIT] net: Assign net to net_namespace_list in setup_net()

Konstantin Khorenko khorenko at virtuozzo.com
Wed May 27 21:34:55 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.161.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.161.3
------>
commit cd48086b0f1b101c798900ea97db46bf7d1e3762
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Wed May 27 21:34:54 2020 +0300

    net: Assign net to net_namespace_list in setup_net()
    
    ms commit 98f6c533a3e9
    
    This patch merges two repeating pieces of code in one,
    and they will live in setup_net() now.
    
    The only change is that assignment:
    
            init_net_initialized = true;
    
    becomes reordered with:
    
            list_add_tail_rcu(&net->list, &net_namespace_list);
    
    The order does not have visible effect, and it is a simple
    cleanup because of:
    
    init_net_initialized is used in !CONFIG_NET_NS case
    to order proc_net_ns_ops registration occuring at boot time:
    
            start_kernel()->proc_root_init()->proc_net_init(),
    with
            net_ns_init()->setup_net(&init_net, &init_user_ns)
    
    also occuring in boot time from the same init_task.
    
    When there are no another tasks to race with them,
    for the single task it does not matter, which order
    two sequential independent loads should be made.
    So we make them reordered.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    Acked-by: Andrei Vagin <avagin at virtuozzo.com>
    Signed-off-by: David S. Miller <davem at davemloft.net>
    
    =====================
    Patchset description:
    
    Parallel per-net init/exit
    
    https://jira.sw.ru/browse/PSBM-104158
---
 net/core/net_namespace.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index a8b7a9ddbe7c6..954f78c526d3d 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -324,6 +324,9 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns)
 		if (error < 0)
 			goto out_undo;
 	}
+	rtnl_lock();
+	list_add_tail_rcu(&net->list, &net_namespace_list);
+	rtnl_unlock();
 out:
 	return error;
 
@@ -419,11 +422,6 @@ struct net *copy_net_ns(unsigned long flags,
 	mutex_lock(&net_mutex);
 	net->ucounts = ucounts;
 	rv = setup_net(net, user_ns);
-	if (rv == 0) {
-		rtnl_lock();
-		list_add_tail_rcu(&net->list, &net_namespace_list);
-		rtnl_unlock();
-	}
 	mutex_unlock(&net_mutex);
 	if (rv < 0) {
 		dec_net_namespaces(ucounts);
@@ -837,10 +835,6 @@ static int __init net_ns_init(void)
 	if (setup_net(&init_net, &init_user_ns))
 		panic("Could not setup the initial network namespace");
 
-	rtnl_lock();
-	list_add_tail_rcu(&init_net.list, &net_namespace_list);
-	rtnl_unlock();
-
 	mutex_unlock(&net_mutex);
 
 	register_pernet_subsys(&net_ns_ops);


More information about the Devel mailing list