[Devel] [PATCH hci-8.1 v6 3/5] ve: Defer ve creds drop until ve is completely destroyed

Vladimir Riabchun vladimir.riabchun at virtuozzo.com
Mon Nov 16 19:06:03 MSK 2026


We may have a case, when VE is dead, but there are some users of it,
overlayfs superblock for example.

This user may want to use VE creds, so we need to keep ve->init_cred alive.
Drop creds in ve_destroy. We need to drop ve_nsproxy early because
ploop waits for refcount going to zero, dropping ve_nsproxy in destroy
causes CT suspend/resume hangs.

https://virtuozzo.atlassian.net/browse/VSTOR-142405
Signed-off-by: Vladimir Riabchun <vladimir.riabchun at virtuozzo.com>
---
 kernel/capability.c | 4 ++--
 kernel/ve/ve.c      | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/capability.c b/kernel/capability.c
index 6de4dcba2283..68c3d5288ba7 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -395,7 +395,7 @@ bool ve_capable(int cap)
 	rcu_read_lock();
 	cred = ve->init_cred;
 
-	if (cred == NULL) /* ve isn't running */
+	if (cred == NULL) /* ve isn't started */
 		cred = ve0.init_cred;
 
 	ret = ns_capable(cred->user_ns, cap);
@@ -413,7 +413,7 @@ bool ve_capable_noaudit(int cap)
 	rcu_read_lock();
 	cred = ve->init_cred;
 
-	if (cred == NULL) /* ve isn't running */
+	if (cred == NULL) /* ve isn't started */
 		cred = ve0.init_cred;
 
 	ret = ns_capable_noaudit(cred->user_ns, cap);
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index b3988a8d590f..1e0c092f080e 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -378,7 +378,10 @@ static void ve_drop_context(struct ve_struct *ve)
 	rcu_assign_pointer(ve->ve_nsproxy, NULL);
 	synchronize_rcu();
 	put_nsproxy(ve_nsproxy);
+}
 
+static void ve_drop_cred(struct ve_struct *ve)
+{
 	put_cred(ve->init_cred);
 	ve->init_cred = NULL;
 }
@@ -929,6 +932,7 @@ static void ve_destroy(struct cgroup_subsys_state *css)
 {
 	struct ve_struct *ve = css_to_ve(css);
 
+	ve_drop_cred(ve);
 	free_ve_devmnts(ve);
 
 	kmapset_unlink(&ve->sysfs_perms_key, &sysfs_ve_perms_set);

-- 
2.52.0



More information about the Devel mailing list