From 249c983df767c6c5097df2923ce1cd1e19a83b60 Mon Sep 17 00:00:00 2001 From: Michal Koutný Date: May 29 2023 13:51:35 +0000 Subject: - cgroup: reduce dependency on cgroup_mutex (bsc#1205650). - Refresh patches.suse/cgroup-cgroup_get_from_id-must-check-the-looked-up-kn-is-a-directory.patch. - blacklist.conf: Remove patch from blacklist (became prereq) --- diff --git a/blacklist.conf b/blacklist.conf index 609d23c..99d81b4 100644 --- a/blacklist.conf +++ b/blacklist.conf @@ -751,7 +751,6 @@ fe413a074a93d56f89e322c786aad8639afe76b4 # does change a bizarre but existing be c16bdeb5a39ffa3f32b32f812831a2092d2a3061 # we don't have breaker 2863643fb8b9 9df918698408fd914493aba0b7858fef50eba63a # refactoring only 9360d035a579d95d1e76c471061b9065b18a0eb1 # unnecessary, see bsc#1207328 -be288169712f3dea0bc6b50c00b3ab53d85f1435 # performance optimization 671c11f0619e5ccb380bcf0f062f69ba95fc974a # performance optimization b860b9346e2d5667fbae2cefc571bdb6ce665b53 # a cleanup for de5012b41e5c ("s390/ftrace: implement hotpatching") which was not taken e26ef3af964acfea311403126acee8c56c89e26b # cleanup designed to break kABI diff --git a/patches.suse/cgroup-cgroup_get_from_id-must-check-the-looked-up-kn-is-a-directory.patch b/patches.suse/cgroup-cgroup_get_from_id-must-check-the-looked-up-kn-is-a-directory.patch index 8a47c73..1f7ffe8 100644 --- a/patches.suse/cgroup-cgroup_get_from_id-must-check-the-looked-up-kn-is-a-directory.patch +++ b/patches.suse/cgroup-cgroup_get_from_id-must-check-the-looked-up-kn-is-a-directory.patch @@ -16,26 +16,32 @@ Signed-off-by: Ming Lei Acked-by: Mukesh Ojha Cc: stable@vger.kernel.org # v5.14+ Signed-off-by: Tejun Heo -[mkoutny: adjust context] Acked-by: Michal Koutný --- - kernel/cgroup/cgroup.c | 4 ++++ - 1 file changed, 4 insertions(+) + kernel/cgroup/cgroup.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index e4bb5d57f4d1..5f2090d051ac 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c -@@ -6018,9 +6018,13 @@ struct cgroup *cgroup_get_from_id(u64 id +@@ -6049,6 +6049,9 @@ struct cgroup *cgroup_get_from_id(u64 id) if (!kn) - goto out_unlock; + goto out; + if (kernfs_type(kn) != KERNFS_DIR) + goto put; + - cgrp = kn->priv; - if (cgroup_is_dead(cgrp) || !cgroup_tryget(cgrp)) + rcu_read_lock(); + + cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv); +@@ -6056,7 +6059,7 @@ struct cgroup *cgroup_get_from_id(u64 id) cgrp = NULL; + + rcu_read_unlock(); +- +put: kernfs_put(kn); - out_unlock: - mutex_unlock(&cgroup_mutex); + out: + return cgrp; diff --git a/patches.suse/cgroup-reduce-dependency-on-cgroup_mutex.patch b/patches.suse/cgroup-reduce-dependency-on-cgroup_mutex.patch new file mode 100644 index 0000000..4857f65 --- /dev/null +++ b/patches.suse/cgroup-reduce-dependency-on-cgroup_mutex.patch @@ -0,0 +1,109 @@ +From: Shakeel Butt +Date: Sun, 24 Oct 2021 23:19:14 -0700 +Subject: cgroup: reduce dependency on cgroup_mutex +Git-commit: be288169712f3dea0bc6b50c00b3ab53d85f1435 +Patch-mainline: v5.16-rc1 +References: bsc#1205650 + +Currently cgroup_get_from_path() and cgroup_get_from_id() grab +cgroup_mutex before traversing the default hierarchy to find the +kernfs_node corresponding to the path/id and then extract the linked +cgroup. Since cgroup_mutex is still held, it is guaranteed that the +cgroup will be alive and the reference can be taken on it. + +However similar guarantee can be provided without depending on the +cgroup_mutex and potentially reducing avenues of cgroup_mutex contentions. +The kernfs_node's priv pointer is RCU protected pointer and with just +rcu read lock we can grab the reference on the cgroup without +cgroup_mutex. So, remove cgroup_mutex from them. + +Signed-off-by: Shakeel Butt +Signed-off-by: Tejun Heo +Acked-by: Michal Koutný +--- + kernel/cgroup/cgroup.c | 51 ++++++++++++++++++++++++++++---------------------- + 1 file changed, 29 insertions(+), 22 deletions(-) + +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index 2e98db4558f2..003204c85893 100644 +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -5932,17 +5932,20 @@ struct cgroup *cgroup_get_from_id(u64 id) + struct kernfs_node *kn; + struct cgroup *cgrp = NULL; + +- mutex_lock(&cgroup_mutex); + kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id); + if (!kn) +- goto out_unlock; ++ goto out; ++ ++ rcu_read_lock(); + +- cgrp = kn->priv; +- if (cgroup_is_dead(cgrp) || !cgroup_tryget(cgrp)) ++ cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv); ++ if (cgrp && !cgroup_tryget(cgrp)) + cgrp = NULL; ++ ++ rcu_read_unlock(); ++ + kernfs_put(kn); +-out_unlock: +- mutex_unlock(&cgroup_mutex); ++out: + return cgrp; + } + EXPORT_SYMBOL_GPL(cgroup_get_from_id); +@@ -6495,30 +6498,34 @@ struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss) + * + * Find the cgroup at @path on the default hierarchy, increment its + * reference count and return it. Returns pointer to the found cgroup on +- * success, ERR_PTR(-ENOENT) if @path doesn't exist and ERR_PTR(-ENOTDIR) +- * if @path points to a non-directory. ++ * success, ERR_PTR(-ENOENT) if @path doesn't exist or if the cgroup has already ++ * been released and ERR_PTR(-ENOTDIR) if @path points to a non-directory. + */ + struct cgroup *cgroup_get_from_path(const char *path) + { + struct kernfs_node *kn; +- struct cgroup *cgrp; +- +- mutex_lock(&cgroup_mutex); ++ struct cgroup *cgrp = ERR_PTR(-ENOENT); + + kn = kernfs_walk_and_get(cgrp_dfl_root.cgrp.kn, path); +- if (kn) { +- if (kernfs_type(kn) == KERNFS_DIR) { +- cgrp = kn->priv; +- cgroup_get_live(cgrp); +- } else { +- cgrp = ERR_PTR(-ENOTDIR); +- } +- kernfs_put(kn); +- } else { +- cgrp = ERR_PTR(-ENOENT); ++ if (!kn) ++ goto out; ++ ++ if (kernfs_type(kn) != KERNFS_DIR) { ++ cgrp = ERR_PTR(-ENOTDIR); ++ goto out_kernfs; + } + +- mutex_unlock(&cgroup_mutex); ++ rcu_read_lock(); ++ ++ cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv); ++ if (!cgrp || !cgroup_tryget(cgrp)) ++ cgrp = ERR_PTR(-ENOENT); ++ ++ rcu_read_unlock(); ++ ++out_kernfs: ++ kernfs_put(kn); ++out: + return cgrp; + } + EXPORT_SYMBOL_GPL(cgroup_get_from_path); + diff --git a/series.conf b/series.conf index d1ef8fa..a869005 100644 --- a/series.conf +++ b/series.conf @@ -5967,6 +5967,7 @@ patches.suse/xfs-punch-out-data-fork-delalloc-blocks-on-COW-write.patch patches.suse/workqueue-make-sysfs-of-unbound-kworker-cpumask-more.patch patches.suse/cgroup-Make-rebind_subsystems-disable-v2-controllers.patch + patches.suse/cgroup-reduce-dependency-on-cgroup_mutex.patch patches.suse/cgroup-Fix-rootcg-cpu.stat-guest-double-counting.patch patches.suse/ucounts-In-set_cred_ucounts-assume-new-ucounts-is-no.patch patches.suse/perf-qcom_l2_pmu-ACPI-Use-ACPI_COMPANION-directly.patch