Skip to content

Commit 91bc482

Browse files
committed
Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: rcu: create rcu_my_thread_group_empty() wrapper memcg: css_id() must be called under rcu_read_lock() cgroup: Check task_lock in task_subsys_state() sched: Fix an RCU warning in print_task() cgroup: Fix an RCU warning in alloc_css_id() cgroup: Fix an RCU warning in cgroup_path() KEYS: Fix an RCU warning in the reading of user keys KEYS: Fix an RCU warning
2 parents e8e8fad + ee84b82 commit 91bc482

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

include/linux/cgroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ static inline struct cgroup_subsys_state *task_subsys_state(
530530
{
531531
return rcu_dereference_check(task->cgroups->subsys[subsys_id],
532532
rcu_read_lock_held() ||
533+
lockdep_is_held(&task->alloc_lock) ||
533534
cgroup_lock_is_held());
534535
}
535536

include/linux/rcupdate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ static inline int rcu_read_lock_sched_held(void)
190190

191191
#ifdef CONFIG_PROVE_RCU
192192

193+
extern int rcu_my_thread_group_empty(void);
194+
193195
/**
194196
* rcu_dereference_check - rcu_dereference with debug checking
195197
* @p: The pointer to read, prior to dereferencing

kernel/cgroup.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,9 @@ static inline struct cftype *__d_cft(struct dentry *dentry)
16461646
int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
16471647
{
16481648
char *start;
1649-
struct dentry *dentry = rcu_dereference(cgrp->dentry);
1649+
struct dentry *dentry = rcu_dereference_check(cgrp->dentry,
1650+
rcu_read_lock_held() ||
1651+
cgroup_lock_is_held());
16501652

16511653
if (!dentry || cgrp == dummytop) {
16521654
/*
@@ -1662,13 +1664,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
16621664
*--start = '\0';
16631665
for (;;) {
16641666
int len = dentry->d_name.len;
1667+
16651668
if ((start -= len) < buf)
16661669
return -ENAMETOOLONG;
1667-
memcpy(start, cgrp->dentry->d_name.name, len);
1670+
memcpy(start, dentry->d_name.name, len);
16681671
cgrp = cgrp->parent;
16691672
if (!cgrp)
16701673
break;
1671-
dentry = rcu_dereference(cgrp->dentry);
1674+
1675+
dentry = rcu_dereference_check(cgrp->dentry,
1676+
rcu_read_lock_held() ||
1677+
cgroup_lock_is_held());
16721678
if (!cgrp->parent)
16731679
continue;
16741680
if (--start < buf)
@@ -4555,13 +4561,13 @@ static int alloc_css_id(struct cgroup_subsys *ss, struct cgroup *parent,
45554561
{
45564562
int subsys_id, i, depth = 0;
45574563
struct cgroup_subsys_state *parent_css, *child_css;
4558-
struct css_id *child_id, *parent_id = NULL;
4564+
struct css_id *child_id, *parent_id;
45594565

45604566
subsys_id = ss->subsys_id;
45614567
parent_css = parent->subsys[subsys_id];
45624568
child_css = child->subsys[subsys_id];
4563-
depth = css_depth(parent_css) + 1;
45644569
parent_id = parent_css->id;
4570+
depth = parent_id->depth;
45654571

45664572
child_id = get_new_cssid(ss, depth);
45674573
if (IS_ERR(child_id))

kernel/rcupdate.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,14 @@ void wakeme_after_rcu(struct rcu_head *head)
122122
rcu = container_of(head, struct rcu_synchronize, head);
123123
complete(&rcu->completion);
124124
}
125+
126+
#ifdef CONFIG_PROVE_RCU
127+
/*
128+
* wrapper function to avoid #include problems.
129+
*/
130+
int rcu_my_thread_group_empty(void)
131+
{
132+
return thread_group_empty(current);
133+
}
134+
EXPORT_SYMBOL_GPL(rcu_my_thread_group_empty);
135+
#endif /* #ifdef CONFIG_PROVE_RCU */

kernel/sched_debug.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
114114
{
115115
char path[64];
116116

117+
rcu_read_lock();
117118
cgroup_path(task_group(p)->css.cgroup, path, sizeof(path));
119+
rcu_read_unlock();
118120
SEQ_printf(m, " %s", path);
119121
}
120122
#endif

mm/memcontrol.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,12 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
811811
* enabled in "curr" and "curr" is a child of "mem" in *cgroup*
812812
* hierarchy(even if use_hierarchy is disabled in "mem").
813813
*/
814+
rcu_read_lock();
814815
if (mem->use_hierarchy)
815816
ret = css_is_ancestor(&curr->css, &mem->css);
816817
else
817818
ret = (curr == mem);
819+
rcu_read_unlock();
818820
css_put(&curr->css);
819821
return ret;
820822
}
@@ -2312,7 +2314,9 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
23122314

23132315
/* record memcg information */
23142316
if (do_swap_account && swapout && memcg) {
2317+
rcu_read_lock();
23152318
swap_cgroup_record(ent, css_id(&memcg->css));
2319+
rcu_read_unlock();
23162320
mem_cgroup_get(memcg);
23172321
}
23182322
if (swapout && memcg)
@@ -2369,8 +2373,10 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
23692373
{
23702374
unsigned short old_id, new_id;
23712375

2376+
rcu_read_lock();
23722377
old_id = css_id(&from->css);
23732378
new_id = css_id(&to->css);
2379+
rcu_read_unlock();
23742380

23752381
if (swap_cgroup_cmpxchg(entry, old_id, new_id) == old_id) {
23762382
mem_cgroup_swap_statistics(from, false);
@@ -4038,11 +4044,16 @@ static int is_target_pte_for_mc(struct vm_area_struct *vma,
40384044
put_page(page);
40394045
}
40404046
/* throught */
4041-
if (ent.val && do_swap_account && !ret &&
4042-
css_id(&mc.from->css) == lookup_swap_cgroup(ent)) {
4043-
ret = MC_TARGET_SWAP;
4044-
if (target)
4045-
target->ent = ent;
4047+
if (ent.val && do_swap_account && !ret) {
4048+
unsigned short id;
4049+
rcu_read_lock();
4050+
id = css_id(&mc.from->css);
4051+
rcu_read_unlock();
4052+
if (id == lookup_swap_cgroup(ent)) {
4053+
ret = MC_TARGET_SWAP;
4054+
if (target)
4055+
target->ent = ent;
4056+
}
40464057
}
40474058
return ret;
40484059
}

0 commit comments

Comments
 (0)