From c2c505197124ba9cc2daf7bd059c215e42b65836 Mon Sep 17 00:00:00 2001 From: Vlastimil Babka Date: May 29 2023 16:15:19 +0000 Subject: Merge branch 'users/mkoutny/SLE15-SP4/for-next' into SLE15-SP4 Pull cgroup fixes from Michal Koutný. --- diff --git a/blacklist.conf b/blacklist.conf index 8e96dcb..6e0a91a 100644 --- a/blacklist.conf +++ b/blacklist.conf @@ -472,7 +472,6 @@ f7b16f51753a845b08e977184fb0b76b145ae0ba # clk:ti: reverting the above in 5.15.y 3de360c3fdb34fbdbaf6da3af94367d3fded95d3 # kABI break for no reason 2a735e4b5580a2a6bbd6572109b4c4f163c57462 # this requires 33fb697ec7e58c4f9b6a68d2786441189cd2df92, which is extremely risky c530a3c716b963625e43aa915e0de6b4d1ce8ad9 # PSI unused, see bsc#1204751 -4534dee941056a4ab9dca4a9e2edff28692800b2 # unimportant, scsi/appid must be set by privileged user anyway 5ec9c514d4a0e1749781c4c61485f9a69c212716 # already applied d351c90ce248601ce34fbc5ac817e3362b441b55 # already applied fdabc3f10e774ddc86ba715b9bc0c861d7e0834c # ASoC:wm8997: reverted in below @@ -751,7 +750,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 @@ -828,3 +826,4 @@ dc2ab23b992c9d5dab93b9bf01b10b10465e537e # does not fix an actual bug 9097fc793f74ef9c677f8c4aed0c24f6f07f0133 # s390 kABI breakage ed0192bc644f3553d64a5cb461bdd0b1fbae3fdf # does not fix an actual bug 03cab65a07e083b6c1010fbc8f9b817e9aca75d9 # clang builds +659c0ce1cb9efc7f58d380ca4bb2a51ae9e30553 # keep logging unnecessary capability use (while we don't enforce LSM by default) diff --git a/patches.suse/cgroup-Homogenize-cgroup_get_from_id-return-value.patch b/patches.suse/cgroup-Homogenize-cgroup_get_from_id-return-value.patch new file mode 100644 index 0000000..b75a2e2 --- /dev/null +++ b/patches.suse/cgroup-Homogenize-cgroup_get_from_id-return-value.patch @@ -0,0 +1,80 @@ +From: =?utf-8?b?TWljaGFsIEtvdXRuw70gPG1rb3V0bnlAc3VzZS5jb20+?= +Date: Fri, 26 Aug 2022 18:52:37 +0200 +Subject: cgroup: Homogenize cgroup_get_from_id() return value +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Git-commit: fa7e439cf90ba23ea473d0b7d85efd02ae6ccf94 +Patch-mainline: v6.1-rc1 +References: bsc#1205650 + +Cgroup id is user provided datum hence extend its return domain to +include possible error reason (similar to cgroup_get_from_fd()). + +This change also fixes commit d4ccaf58a847 ("bpf: Introduce cgroup +iter") that would use NULL instead of proper error handling in +d4ccaf58a847 ("bpf: Introduce cgroup iter"). + +Additionally, neither of: fc_appid_store, bpf_iter_attach_cgroup, +mem_cgroup_get_from_ino (callers of cgroup_get_from_fd) is built without +CONFIG_CGROUPS (depends via CONFIG_BLK_CGROUP, direct, transitive +CONFIG_MEMCG respectively) transitive, so drop the singular definition +not needed with !CONFIG_CGROUPS. + +Fixes: d4ccaf58a847 ("bpf: Introduce cgroup iter") +Signed-off-by: Michal Koutný +Signed-off-by: Tejun Heo +[mkoutny: drop mem_cgroup_get_from_ino() hunk] +--- + block/blk-cgroup-fc-appid.c | 4 ++-- + include/linux/cgroup.h | 5 ----- + kernel/cgroup/cgroup.c | 4 ++-- + 3 files changed, 4 insertions(+), 9 deletions(-) + +--- a/block/blk-cgroup-fc-appid.c ++++ b/block/blk-cgroup-fc-appid.c +@@ -19,8 +19,8 @@ int blkcg_set_fc_appid(char *app_id, u64 + return -EINVAL; + + cgrp = cgroup_get_from_id(cgrp_id); +- if (!cgrp) +- return -ENOENT; ++ if (IS_ERR(cgrp)) ++ return PTR_ERR(cgrp); + css = cgroup_get_e_css(cgrp, &io_cgrp_subsys); + if (!css) { + ret = -ENOENT; +--- a/include/linux/cgroup.h ++++ b/include/linux/cgroup.h +@@ -751,11 +751,6 @@ static inline bool task_under_cgroup_hie + + static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) + {} +- +-static inline struct cgroup *cgroup_get_from_id(u64 id) +-{ +- return NULL; +-} + #endif /* !CONFIG_CGROUPS */ + + #ifdef CONFIG_CGROUPS +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -6002,7 +6002,7 @@ void cgroup_path_from_kernfs_id(u64 id, + /* + * cgroup_get_from_id : get the cgroup associated with cgroup id + * @id: cgroup id +- * On success return the cgrp, on failure return NULL ++ * On success return the cgrp or ERR_PTR on failure + * Only cgroups within current task's cgroup NS are valid. + */ + struct cgroup *cgroup_get_from_id(u64 id) +@@ -6038,7 +6038,7 @@ put: + cgrp = NULL; + } + out: +- return cgrp; ++ return cgrp ?: ERR_PTR(-ENOENT); + } + EXPORT_SYMBOL_GPL(cgroup_get_from_id); + diff --git a/patches.suse/cgroup-Honor-caller-s-cgroup-NS-when-resolving-path.patch b/patches.suse/cgroup-Honor-caller-s-cgroup-NS-when-resolving-path.patch new file mode 100644 index 0000000..1ef4ee1 --- /dev/null +++ b/patches.suse/cgroup-Honor-caller-s-cgroup-NS-when-resolving-path.patch @@ -0,0 +1,44 @@ +From: =?utf-8?b?TWljaGFsIEtvdXRuw70gPG1rb3V0bnlAc3VzZS5jb20+?= +Date: Fri, 26 Aug 2022 18:52:35 +0200 +Subject: cgroup: Honor caller's cgroup NS when resolving path +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Git-commit: 74e4b956eb1cac0e4c10c240339b1bbfbc9a4c48 +Patch-mainline: v6.1-rc1 +References: bsc#1205650 + +cgroup_get_from_path() is not widely used function. Its callers presume +the path is resolved under cgroup namespace. (There is one caller +currently and resolving in init NS won't make harm (netfilter). However, +future users may be subject to different effects when resolving +globally.) +Since, there's currently no use for the global resolution, modify the +existing function to take cgroup NS into account. + +Fixes: a79a908fd2b0 ("cgroup: introduce cgroup namespaces") +Signed-off-by: Michal Koutný +Signed-off-by: Tejun Heo +--- + kernel/cgroup/cgroup.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index 627ff0f07da7..1c7ab4109251 100644 +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -6602,8 +6602,12 @@ struct cgroup *cgroup_get_from_path(const char *path) + { + struct kernfs_node *kn; + struct cgroup *cgrp = ERR_PTR(-ENOENT); ++ struct cgroup *root_cgrp; + +- kn = kernfs_walk_and_get(cgrp_dfl_root.cgrp.kn, path); ++ spin_lock_irq(&css_set_lock); ++ root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root); ++ kn = kernfs_walk_and_get(root_cgrp->kn, path); ++ spin_unlock_irq(&css_set_lock); + if (!kn) + goto out; + + diff --git a/patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch b/patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch new file mode 100644 index 0000000..b48d21f --- /dev/null +++ b/patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch @@ -0,0 +1,80 @@ +From: Tejun Heo +Date: Fri, 23 Sep 2022 07:23:06 -1000 +Subject: cgroup: Make cgroup_get_from_id() prettier +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Git-commit: 7e1eb5437d3c3fdb61d45378579aab383cafc694 +Patch-mainline: v6.1-rc1 +References: bsc#1205650 + +After merging 836ac87d ("cgroup: fix cgroup_get_from_id") into for-6.1, its +combination with two commits in for-6.1 - 4534dee9 ("cgroup: cgroup: Honor +caller's cgroup NS when resolving cgroup id") and fa7e439c ("cgroup: +Homogenize cgroup_get_from_id() return value") - makes the gotos in the +error handling path too ugly while not adding anything of value. + +All that the gotos are saving is one extra kernfs_put() call. Let's remove +the gotos and perform error returns directly. + +Signed-off-by: Tejun Heo +Cc: Ming Lei +Cc: Michal Koutný + +Acked-by: Michal Koutný +--- + kernel/cgroup/cgroup.c | 19 ++++++++++--------- + 1 file changed, 10 insertions(+), 9 deletions(-) + +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index 0d93cd17548c..c1f1ef6090da 100644 +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -6066,14 +6066,16 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) + struct cgroup *cgroup_get_from_id(u64 id) + { + struct kernfs_node *kn; +- struct cgroup *cgrp = NULL, *root_cgrp; ++ struct cgroup *cgrp, *root_cgrp; + + kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id); + if (!kn) +- goto out; ++ return ERR_PTR(-ENOENT); + +- if (kernfs_type(kn) != KERNFS_DIR) +- goto put; ++ if (kernfs_type(kn) != KERNFS_DIR) { ++ kernfs_put(kn); ++ return ERR_PTR(-ENOENT); ++ } + + rcu_read_lock(); + +@@ -6082,21 +6084,20 @@ struct cgroup *cgroup_get_from_id(u64 id) + cgrp = NULL; + + rcu_read_unlock(); +-put: + kernfs_put(kn); + + if (!cgrp) +- goto out; ++ return ERR_PTR(-ENOENT); + + spin_lock_irq(&css_set_lock); + root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root); + spin_unlock_irq(&css_set_lock); + if (!cgroup_is_descendant(cgrp, root_cgrp)) { + cgroup_put(cgrp); +- cgrp = NULL; ++ return ERR_PTR(-ENOENT); + } +-out: +- return cgrp ?: ERR_PTR(-ENOENT); ++ ++ return cgrp; + } + EXPORT_SYMBOL_GPL(cgroup_get_from_id); + + diff --git a/patches.suse/cgroup-Reorganize-css_set_lock-and-kernfs-path-processing.patch b/patches.suse/cgroup-Reorganize-css_set_lock-and-kernfs-path-processing.patch new file mode 100644 index 0000000..9a181d5 --- /dev/null +++ b/patches.suse/cgroup-Reorganize-css_set_lock-and-kernfs-path-processing.patch @@ -0,0 +1,131 @@ +From: =?utf-8?b?TWljaGFsIEtvdXRuw70gPG1rb3V0bnlAc3VzZS5jb20+?= +Date: Mon, 10 Oct 2022 10:29:18 +0200 +Subject: cgroup: Reorganize css_set_lock and kernfs path processing +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Git-commit: 46307fd6e27a3f678a1678b02e667678c22aa8cc +Patch-mainline: v6.1-rc2 +References: bsc#1205650 + +The commit 74e4b956eb1c incorrectly wrapped kernfs_walk_and_get +(might_sleep) under css_set_lock (spinlock). css_set_lock is needed by +__cset_cgroup_from_root to ensure stable cset->cgrp_links but not for +kernfs_walk_and_get. + +We only need to make sure that the returned root_cgrp won't be freed +under us. This is given in the case of global root because it is static +(cgrp_dfl_root.cgrp). When the root_cgrp is lower in the hierarchy, it +is pinned by cgroup_ns->root_cset (and `current` task cannot switch +namespace asynchronously so ns_proxy pins cgroup_ns). + +Note this reasoning won't hold for root cgroups in v1 hierarchies, +therefore create a special-cased helper function just for the default +hierarchy. + +Fixes: 74e4b956eb1c ("cgroup: Honor caller's cgroup NS when resolving path") +Reported-by: Dan Carpenter +Signed-off-by: Michal Koutný +Signed-off-by: Tejun Heo +--- + kernel/cgroup/cgroup.c | 40 +++++++++++++++++++++++++++------------- + 1 file changed, 27 insertions(+), 13 deletions(-) + +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index 764bdd5fd8d1..ecf409e3c3a7 100644 +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -1392,6 +1392,9 @@ static void cgroup_destroy_root(struct cgroup_root *root) + cgroup_free_root(root); + } + ++/* ++ * Returned cgroup is without refcount but it's valid as long as cset pins it. ++ */ + static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset, + struct cgroup_root *root) + { +@@ -1403,6 +1406,7 @@ static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset, + res_cgroup = cset->dfl_cgrp; + } else { + struct cgrp_cset_link *link; ++ lockdep_assert_held(&css_set_lock); + + list_for_each_entry(link, &cset->cgrp_links, cgrp_link) { + struct cgroup *c = link->cgrp; +@@ -1414,6 +1418,7 @@ static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset, + } + } + ++ BUG_ON(!res_cgroup); + return res_cgroup; + } + +@@ -1436,23 +1441,36 @@ current_cgns_cgroup_from_root(struct cgroup_root *root) + + rcu_read_unlock(); + +- BUG_ON(!res); + return res; + } + ++/* ++ * Look up cgroup associated with current task's cgroup namespace on the default ++ * hierarchy. ++ * ++ * Unlike current_cgns_cgroup_from_root(), this doesn't need locks: ++ * - Internal rcu_read_lock is unnecessary because we don't dereference any rcu ++ * pointers. ++ * - css_set_lock is not needed because we just read cset->dfl_cgrp. ++ * - As a bonus returned cgrp is pinned with the current because it cannot ++ * switch cgroup_ns asynchronously. ++ */ ++static struct cgroup *current_cgns_cgroup_dfl(void) ++{ ++ struct css_set *cset; ++ ++ cset = current->nsproxy->cgroup_ns->root_cset; ++ return __cset_cgroup_from_root(cset, &cgrp_dfl_root); ++} ++ + /* look up cgroup associated with given css_set on the specified hierarchy */ + static struct cgroup *cset_cgroup_from_root(struct css_set *cset, + struct cgroup_root *root) + { +- struct cgroup *res = NULL; +- + lockdep_assert_held(&cgroup_mutex); + lockdep_assert_held(&css_set_lock); + +- res = __cset_cgroup_from_root(cset, root); +- +- BUG_ON(!res); +- return res; ++ return __cset_cgroup_from_root(cset, root); + } + + /* +@@ -6105,9 +6123,7 @@ struct cgroup *cgroup_get_from_id(u64 id) + if (!cgrp) + return ERR_PTR(-ENOENT); + +- spin_lock_irq(&css_set_lock); +- root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root); +- spin_unlock_irq(&css_set_lock); ++ root_cgrp = current_cgns_cgroup_dfl(); + if (!cgroup_is_descendant(cgrp, root_cgrp)) { + cgroup_put(cgrp); + return ERR_PTR(-ENOENT); +@@ -6686,10 +6702,8 @@ struct cgroup *cgroup_get_from_path(const char *path) + struct cgroup *cgrp = ERR_PTR(-ENOENT); + struct cgroup *root_cgrp; + +- spin_lock_irq(&css_set_lock); +- root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root); ++ root_cgrp = current_cgns_cgroup_dfl(); + kn = kernfs_walk_and_get(root_cgrp->kn, path); +- spin_unlock_irq(&css_set_lock); + if (!kn) + goto out; + + diff --git a/patches.suse/cgroup-cgroup-Honor-caller-s-cgroup-NS-when-resolving-cgroup-id.patch b/patches.suse/cgroup-cgroup-Honor-caller-s-cgroup-NS-when-resolving-cgroup-id.patch new file mode 100644 index 0000000..9d7e1a7 --- /dev/null +++ b/patches.suse/cgroup-cgroup-Honor-caller-s-cgroup-NS-when-resolving-cgroup-id.patch @@ -0,0 +1,69 @@ +From: =?utf-8?b?TWljaGFsIEtvdXRuw70gPG1rb3V0bnlAc3VzZS5jb20+?= +Date: Fri, 26 Aug 2022 18:52:36 +0200 +Subject: cgroup: cgroup: Honor caller's cgroup NS when resolving cgroup id +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Git-commit: 4534dee941056a4ab9dca4a9e2edff28692800b2 +Patch-mainline: v6.1-rc1 +References: bsc#1205650 + +Cgroup ids are resolved in the global scope. That may be needed sometime +(in future) but currently it violates virtual view provided through +cgroup namespaces. + +There are currently following users of the resolution: +- fc_appid_store +- bpf_iter_attach_cgroup +- mem_cgroup_get_from_ino + +None of the is a called on behalf of kernel but the resolution is made +with proper userspace context, hence the default to current->nsproxy +makes sens. (This doesn't rule out cgroup_get_from_id with cgroup NS +parameter in the future.) + +Since cgroup ids are defined on v2 hierarchy only, we simply check +existence in the cgroup namespace by looking at ancestry on the default +hierarchy. + +Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()") +Signed-off-by: Michal Koutný +Signed-off-by: Tejun Heo +--- + kernel/cgroup/cgroup.c | 14 +++++++++++++- + 1 file changed, 13 insertions(+), 1 deletion(-) + +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -6003,11 +6003,12 @@ void cgroup_path_from_kernfs_id(u64 id, + * cgroup_get_from_id : get the cgroup associated with cgroup id + * @id: cgroup id + * On success return the cgrp, on failure return NULL ++ * Only cgroups within current task's cgroup NS are valid. + */ + struct cgroup *cgroup_get_from_id(u64 id) + { + struct kernfs_node *kn; +- struct cgroup *cgrp = NULL; ++ struct cgroup *cgrp = NULL, *root_cgrp; + + kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id); + if (!kn) +@@ -6025,6 +6026,17 @@ struct cgroup *cgroup_get_from_id(u64 id + rcu_read_unlock(); + put: + kernfs_put(kn); ++ ++ if (!cgrp) ++ goto out; ++ ++ spin_lock_irq(&css_set_lock); ++ root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root); ++ spin_unlock_irq(&css_set_lock); ++ if (!cgroup_is_descendant(cgrp, root_cgrp)) { ++ cgroup_put(cgrp); ++ cgrp = NULL; ++ } + out: + return cgrp; + } 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/patches.suse/cgroup.c-add-helper-__cset_cgroup_from_root-to-cleanup-duplicated-codes.patch b/patches.suse/cgroup.c-add-helper-__cset_cgroup_from_root-to-cleanup-duplicated-codes.patch new file mode 100644 index 0000000..a297b6c --- /dev/null +++ b/patches.suse/cgroup.c-add-helper-__cset_cgroup_from_root-to-cleanup-duplicated-codes.patch @@ -0,0 +1,103 @@ +From: Lin Feng +Date: Thu, 16 Jun 2022 18:38:30 +0800 +Subject: cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated + codes +Git-commit: e210a89f5b07680fe21d21e846e6817346c5ba3b +Patch-mainline: v6.0-rc1 +References: bsc#1203906 + +No funtionality change, but save us some lines. + +Signed-off-by: Lin Feng +Acked-by: Mukesh Ojha +Signed-off-by: Tejun Heo +Acked-by: Michal Koutný +--- + kernel/cgroup/cgroup.c | 58 +++++++++++++++++++++++--------------------------- + 1 file changed, 27 insertions(+), 31 deletions(-) + +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index 90a654cb8a1e..4b67e6da6bf2 100644 +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -1376,6 +1376,31 @@ static void cgroup_destroy_root(struct cgroup_root *root) + cgroup_free_root(root); + } + ++static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset, ++ struct cgroup_root *root) ++{ ++ struct cgroup *res_cgroup = NULL; ++ ++ if (cset == &init_css_set) { ++ res_cgroup = &root->cgrp; ++ } else if (root == &cgrp_dfl_root) { ++ res_cgroup = cset->dfl_cgrp; ++ } else { ++ struct cgrp_cset_link *link; ++ ++ list_for_each_entry(link, &cset->cgrp_links, cgrp_link) { ++ struct cgroup *c = link->cgrp; ++ ++ if (c->root == root) { ++ res_cgroup = c; ++ break; ++ } ++ } ++ } ++ ++ return res_cgroup; ++} ++ + /* + * look up cgroup associated with current task's cgroup namespace on the + * specified hierarchy +@@ -1391,22 +1416,8 @@ current_cgns_cgroup_from_root(struct cgroup_root *root) + rcu_read_lock(); + + cset = current->nsproxy->cgroup_ns->root_cset; +- if (cset == &init_css_set) { +- res = &root->cgrp; +- } else if (root == &cgrp_dfl_root) { +- res = cset->dfl_cgrp; +- } else { +- struct cgrp_cset_link *link; +- +- list_for_each_entry(link, &cset->cgrp_links, cgrp_link) { +- struct cgroup *c = link->cgrp; ++ res = __cset_cgroup_from_root(cset, root); + +- if (c->root == root) { +- res = c; +- break; +- } +- } +- } + rcu_read_unlock(); + + BUG_ON(!res); +@@ -1422,22 +1433,7 @@ static struct cgroup *cset_cgroup_from_root(struct css_set *cset, + lockdep_assert_held(&cgroup_mutex); + lockdep_assert_held(&css_set_lock); + +- if (cset == &init_css_set) { +- res = &root->cgrp; +- } else if (root == &cgrp_dfl_root) { +- res = cset->dfl_cgrp; +- } else { +- struct cgrp_cset_link *link; +- +- list_for_each_entry(link, &cset->cgrp_links, cgrp_link) { +- struct cgroup *c = link->cgrp; +- +- if (c->root == root) { +- res = c; +- break; +- } +- } +- } ++ res = __cset_cgroup_from_root(cset, root); + + BUG_ON(!res); + return res; + diff --git a/series.conf b/series.conf index 29796ee..0bf70e9 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 @@ -14808,6 +14809,7 @@ patches.suse/Documentation-siphash-Fix-typo-in-the-name-of-offset.patch patches.suse/selftests-timers-valid-adjtimex-build-fix-for-newer-.patch patches.suse/selftests-timers-clocksource-switch-fix-passing-erro.patch + patches.suse/cgroup.c-add-helper-__cset_cgroup_from_root-to-cleanup-duplicated-codes.patch patches.suse/btrfs-send-use-boolean-types-for-current-inode-statu.patch patches.suse/btrfs-properly-flag-filesystem-with-btrfs_feature_incompat_big_metadata.patch patches.suse/btrfs-send-introduce-recorded_ref_alloc-and-recorded.patch @@ -16705,7 +16707,11 @@ patches.suse/sched-core-Introduce-sched_asym_cpucap_active.patch patches.suse/perf-x86-uncore-Add-new-Raptor-Lake-S-support.patch patches.suse/locking-rwsem-Disable-preemption-while-trying-for-rw.patch + patches.suse/cgroup-Honor-caller-s-cgroup-NS-when-resolving-path.patch + patches.suse/cgroup-cgroup-Honor-caller-s-cgroup-NS-when-resolving-cgroup-id.patch + patches.suse/cgroup-Homogenize-cgroup_get_from_id-return-value.patch patches.suse/cgroup-cpuset-Enable-update_tasks_cpumask-on-top_cpuset.patch + patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch patches.suse/livepatch-fix-race-between-fork-and-KLP-transition.patch patches.suse/livepatch-Add-a-missing-newline-character-in-klp_mod.patch patches.suse/kbuild-remove-the-target-in-signal-traps-when-interr.patch @@ -16889,6 +16895,7 @@ patches.suse/cifs-lease-key-is-uninitialized-in-two-additional-functions-when-sm.patch patches.suse/smb3-improve-SMB3-change-notification-support.patch patches.suse/clk-at91-fix-the-build-with-binutils-2.27.patch + patches.suse/cgroup-Reorganize-css_set_lock-and-kernfs-path-processing.patch patches.suse/btrfs-fix-processing-of-delayed-data-refs-during-bac.patch patches.suse/btrfs-fix-processing-of-delayed-tree-block-refs-duri.patch patches.suse/0017-dm-remove-unnecessary-assignment-statement-in-alloc_.patch