Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a4ea1cc9 authored by Tejun Heo's avatar Tejun Heo
Browse files

cgroup: always use RCU accessors for protected accesses



kernel/cgroup.c still has places where a RCU pointer is set and
accessed directly without going through RCU_INIT_POINTER() or
rcu_dereference_protected().  They're all properly protected accesses
so nothing is broken but it leads to spurious sparse RCU address space
warnings.

Substitute direct accesses with RCU_INIT_POINTER() and
rcu_dereference_protected().  Note that %true is specified as the
extra condition for all derference updates.  This isn't ideal as all
it does is suppressing warning without actually policing
synchronization rules; however, most are scheduled to be removed
pretty soon along with css_id itself, so no reason to be more
elaborate.

Combined with the previous changes, this removes all RCU related
sparse warnings from cgroup.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Acked-by; Li Zefan <lizefan@huawei.com>
parent a8ad805c
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -1427,7 +1427,7 @@ static void init_cgroup_root(struct cgroupfs_root *root)
	INIT_LIST_HEAD(&root->root_list);
	INIT_LIST_HEAD(&root->root_list);
	root->number_of_cgroups = 1;
	root->number_of_cgroups = 1;
	cgrp->root = root;
	cgrp->root = root;
	cgrp->name = &root_cgroup_name;
	RCU_INIT_POINTER(cgrp->name, &root_cgroup_name);
	init_cgroup_housekeeping(cgrp);
	init_cgroup_housekeeping(cgrp);
}
}


@@ -2558,7 +2558,7 @@ static int cgroup_rename(struct inode *old_dir, struct dentry *old_dentry,
		return ret;
		return ret;
	}
	}


	old_name = cgrp->name;
	old_name = rcu_dereference_protected(cgrp->name, true);
	rcu_assign_pointer(cgrp->name, name);
	rcu_assign_pointer(cgrp->name, name);


	kfree_rcu(old_name, rcu_head);
	kfree_rcu(old_name, rcu_head);
@@ -4177,13 +4177,15 @@ static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files,
	/* This cgroup is ready now */
	/* This cgroup is ready now */
	for_each_root_subsys(cgrp->root, ss) {
	for_each_root_subsys(cgrp->root, ss) {
		struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id];
		struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id];
		struct css_id *id = rcu_dereference_protected(css->id, true);

		/*
		/*
		 * Update id->css pointer and make this css visible from
		 * Update id->css pointer and make this css visible from
		 * CSS ID functions. This pointer will be dereferened
		 * CSS ID functions. This pointer will be dereferened
		 * from RCU-read-side without locks.
		 * from RCU-read-side without locks.
		 */
		 */
		if (css->id)
		if (id)
			rcu_assign_pointer(css->id->css, css);
			rcu_assign_pointer(id->css, css);
	}
	}


	return 0;
	return 0;
@@ -4863,7 +4865,7 @@ int __init cgroup_init_early(void)
	css_set_count = 1;
	css_set_count = 1;
	init_cgroup_root(&cgroup_dummy_root);
	init_cgroup_root(&cgroup_dummy_root);
	cgroup_root_count = 1;
	cgroup_root_count = 1;
	init_task.cgroups = &init_css_set;
	RCU_INIT_POINTER(init_task.cgroups, &init_css_set);


	init_cgrp_cset_link.cset = &init_css_set;
	init_cgrp_cset_link.cset = &init_css_set;
	init_cgrp_cset_link.cgrp = cgroup_dummy_top;
	init_cgrp_cset_link.cgrp = cgroup_dummy_top;
@@ -5380,7 +5382,8 @@ bool css_is_ancestor(struct cgroup_subsys_state *child,


void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css)
void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css)
{
{
	struct css_id *id = css->id;
	struct css_id *id = rcu_dereference_protected(css->id, true);

	/* When this is called before css_id initialization, id can be NULL */
	/* When this is called before css_id initialization, id can be NULL */
	if (!id)
	if (!id)
		return;
		return;
@@ -5446,8 +5449,8 @@ static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss,
		return PTR_ERR(newid);
		return PTR_ERR(newid);


	newid->stack[0] = newid->id;
	newid->stack[0] = newid->id;
	newid->css = rootcss;
	RCU_INIT_POINTER(newid->css, rootcss);
	rootcss->id = newid;
	RCU_INIT_POINTER(rootcss->id, newid);
	return 0;
	return 0;
}
}


@@ -5461,7 +5464,7 @@ static int alloc_css_id(struct cgroup_subsys *ss, struct cgroup *parent,
	subsys_id = ss->subsys_id;
	subsys_id = ss->subsys_id;
	parent_css = parent->subsys[subsys_id];
	parent_css = parent->subsys[subsys_id];
	child_css = child->subsys[subsys_id];
	child_css = child->subsys[subsys_id];
	parent_id = parent_css->id;
	parent_id = rcu_dereference_protected(parent_css->id, true);
	depth = parent_id->depth + 1;
	depth = parent_id->depth + 1;


	child_id = get_new_cssid(ss, depth);
	child_id = get_new_cssid(ss, depth);