[Devel] [PATCH RHEL7 COMMIT] net: Bring clearness to ve_netns deassignment

Konstantin Khorenko khorenko at virtuozzo.com
Wed May 27 14:34:53 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.2
------>
commit 30e99ad0b77d1a13b0e545cf14e4710edd1a5592
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Wed May 27 14:34:52 2020 +0300

    net: Bring clearness to ve_netns deassignment
    
    ve_netns is cleared in two places and this looks strange.
    ve_drop_context() puts net right before it clears ve_netns,
    so the probability of that cleanup_net() will be first is
    very small. So, let's just reorder lines in ve_drop_context(),
    and the situation (ve->ve_netns == net) in cleanup_net()
    will become impossible.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 kernel/ve/ve.c           | 4 +++-
 net/core/net_namespace.c | 2 --
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index b423a96766794..f88452d0396d0 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -462,8 +462,10 @@ static void ve_grab_context(struct ve_struct *ve)
 static void ve_drop_context(struct ve_struct *ve)
 {
 	struct nsproxy *ve_ns = ve->ve_ns;
-	put_net(ve->ve_netns);
+	struct net *net = ve->ve_netns;
+
 	ve->ve_netns = NULL;
+	put_net(net);
 
 	/* Allows to dereference init_cred and init_task if ve_ns is set */
 	rcu_assign_pointer(ve->ve_ns, NULL);
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 3348f7c550e19..69893c8ae6a02 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -499,8 +499,6 @@ static void cleanup_net(struct work_struct *work)
 		struct ve_struct *ve = net->owner_ve;
 
 		atomic_inc(&ve->netns_avail_nr);
-		if (ve->ve_netns == net)
-			ve->ve_netns = NULL;
 		put_ve(ve);
 	}
 


More information about the Devel mailing list