[Devel] [PATCH vz9] ve: cgroup -- don't use atomic lock in the sleepable context

Cyrill Gorcunov gorcunov at gmail.com
Mon Nov 8 14:35:36 MSK 2021


We should not keep @css_set_lock spinlock while removing group files
which leads to

 | BUG: sleeping function called from invalid context at kernel/locking/mutex.c:938

this is because cgroup_rm_file() function takes @kernfs_mutex itself.
To fix this we should fetch @cset under the lock and grab a reference,
then we can safely walk over set links to remove the files.

https://jira.sw.ru/browse/PSBM-135460

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 kernel/cgroup/cgroup.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Index: vzkernel/kernel/cgroup/cgroup.c
===================================================================
--- vzkernel.orig/kernel/cgroup/cgroup.c
+++ vzkernel/kernel/cgroup/cgroup.c
@@ -2163,19 +2163,27 @@ void cgroup_unmark_ve_roots(struct ve_st
 	 */
 	cset = rcu_dereference_protected(ve->ve_ns,
 			lockdep_is_held(&ve->op_sem))->cgroup_ns->root_cset;
+	BUG_ON(!cset);
+	get_css_set(cset);
+	spin_unlock_irq(&css_set_lock);
 
+	/*
+	 * Once we've grabbed a reference to cset the list
+	 * entries won't be removed so traversing is safe.
+	 */
 	list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
 		cgrp = link->cgrp;
 
 		if (!is_virtualized_cgroup(cgrp))
 			continue;
 
-		cgroup_rm_file(cgrp, cft);
+		if (!cgroup_is_dead(cgrp))
+			cgroup_rm_file(cgrp, cft);
 		rcu_assign_pointer(cgrp->ve_owner, NULL);
 		clear_bit(CGRP_VE_ROOT, &cgrp->flags);
 	}
 
-	spin_unlock_irq(&css_set_lock);
+	put_css_set(cset);
 	mutex_unlock(&cgroup_mutex);
 	/* ve_owner == NULL will be visible */
 	synchronize_rcu();


More information about the Devel mailing list