Commit ca7d6bd4 authored by Waiman Long's avatar Waiman Long Committed by Chen Ridong
Browse files

cgroup: Move rcu_head up near the top of cgroup_root

stable inclusion
from stable-v6.6.47
commit f3c60ab676bb62e01d004d5b1cf2963a296c8e6a
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAP55A

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f3c60ab676bb62e01d004d5b1cf2963a296c8e6a



--------------------------------

commit a7fb0423c201ba12815877a0b5a68a6a1710b23a upstream.

Commit 331654dc5f40 ("cgroup: Make operations on the cgroup root_list RCU
safe") adds a new rcu_head to the cgroup_root structure and kvfree_rcu()
for freeing the cgroup_root.

The current implementation of kvfree_rcu(), however, has the limitation
that the offset of the rcu_head structure within the larger data
structure must be less than 4096 or the compilation will fail. See the
macro definition of __is_kvfree_rcu_offset() in include/linux/rcupdate.h
for more information.

By putting rcu_head below the large cgroup structure, any change to the
cgroup structure that makes it larger run the risk of causing build
failure under certain configurations. Commit 77070eeb8821 ("cgroup:
Avoid false cacheline sharing of read mostly rstat_cpu") happens to be
the last straw that breaks it. Fix this problem by moving the rcu_head
structure up before the cgroup structure.

Fixes: 331654dc5f40 ("cgroup: Make operations on the cgroup root_list RCU safe")
Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/lkml/20231207143806.114e0a74@canb.auug.org.au/


Signed-off-by: default avatarWaiman Long <longman@redhat.com>
Acked-by: default avatarYafang Shao <laoar.shao@gmail.com>
Reviewed-by: default avatarYosry Ahmed <yosryahmed@google.com>
Reviewed-by: default avatarMichal Koutný <mkoutny@suse.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>

Conflicts:
	include/linux/cgroup-defs.h
[Context is mismatched for wait_queue_head_t wait was merged]
Signed-off-by: default avatarChen Ridong <chenridong@huawei.com>
parent 486eff6a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -573,6 +573,10 @@ struct cgroup_root {
	/* Unique id for this hierarchy. */
	int hierarchy_id;

	/* A list running through the active hierarchies */
	struct list_head root_list;
	struct rcu_head rcu;    /* Must be near the top */

	/*
	 * The root cgroup. The containing cgroup_root will be destroyed on its
	 * release. cgrp->ancestors[0] will be used overflowing into the
@@ -589,10 +593,6 @@ struct cgroup_root {
	/* Wait while cgroups are being destroyed */
	wait_queue_head_t wait;

	/* A list running through the active hierarchies */
	struct list_head root_list;
	struct rcu_head rcu;

	/* Hierarchy-specific flags */
	unsigned int flags;