aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorVivek Goyal <vgoyal@redhat.com>2011-05-16 09:24:08 -0400
committerJens Axboe <jaxboe@fusionio.com>2011-05-16 09:24:08 -0400
commit70087dc38cc77ca8f46059564c00338777734762 (patch)
tree2ffd5885a12acb44d90d3c3c1a578387bad94a32 /block
parent02e352287a40bd456eb78df705bf888bc3161d3f (diff)
blk-throttle: Use task_subsys_state() to determine a task's blkio_cgroup
Currentlly we first map the task to cgroup and then cgroup to blkio_cgroup. There is a more direct way to get to blkio_cgroup from task using task_subsys_state(). Use that. The real reason for the fix is that it also avoids a race in generic cgroup code. During remount/umount rebind_subsystems() is called and it can do following with and rcu protection. cgrp->subsys[i] = NULL; That means if somebody got hold of cgroup under rcu and then it tried to do cgroup->subsys[] to get to blkio_cgroup, it would get NULL which is wrong. I was running into this race condition with ltp running on a upstream derived kernel and that lead to crash. So ideally we should also fix cgroup generic code to wait for rcu grace period before setting pointer to NULL. Li Zefan is not very keen on introducing synchronize_wait() as he thinks it will slow down moun/remount/umount operations. So for the time being atleast fix the kernel crash by taking a more direct route to blkio_cgroup. One tester had reported a crash while running LTP on a derived kernel and with this fix crash is no more seen while the test has been running for over 6 days. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Reviewed-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-cgroup.c7
-rw-r--r--block/blk-cgroup.h3
-rw-r--r--block/blk-throttle.c9
-rw-r--r--block/cfq-iosched.c11
4 files changed, 19 insertions, 11 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index f0605ab2a761..471fdcc5df85 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -114,6 +114,13 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
114} 114}
115EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup); 115EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup);
116 116
117struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk)
118{
119 return container_of(task_subsys_state(tsk, blkio_subsys_id),
120 struct blkio_cgroup, css);
121}
122EXPORT_SYMBOL_GPL(task_blkio_cgroup);
123
117static inline void 124static inline void
118blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight) 125blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight)
119{ 126{
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 10919fae2d3a..c774930cc206 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -291,6 +291,7 @@ static inline void blkiocg_set_start_empty_time(struct blkio_group *blkg) {}
291#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE) 291#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
292extern struct blkio_cgroup blkio_root_cgroup; 292extern struct blkio_cgroup blkio_root_cgroup;
293extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); 293extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
294extern struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk);
294extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, 295extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
295 struct blkio_group *blkg, void *key, dev_t dev, 296 struct blkio_group *blkg, void *key, dev_t dev,
296 enum blkio_policy_id plid); 297 enum blkio_policy_id plid);
@@ -314,6 +315,8 @@ void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
314struct cgroup; 315struct cgroup;
315static inline struct blkio_cgroup * 316static inline struct blkio_cgroup *
316cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } 317cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
318static inline struct blkio_cgroup *
319task_blkio_cgroup(struct task_struct *tsk) { return NULL; }
317 320
318static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, 321static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
319 struct blkio_group *blkg, void *key, dev_t dev, 322 struct blkio_group *blkg, void *key, dev_t dev,
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 0475a22a420d..252a81a306f7 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -160,9 +160,8 @@ static void throtl_put_tg(struct throtl_grp *tg)
160} 160}
161 161
162static struct throtl_grp * throtl_find_alloc_tg(struct throtl_data *td, 162static struct throtl_grp * throtl_find_alloc_tg(struct throtl_data *td,
163 struct cgroup *cgroup) 163 struct blkio_cgroup *blkcg)
164{ 164{
165 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
166 struct throtl_grp *tg = NULL; 165 struct throtl_grp *tg = NULL;
167 void *key = td; 166 void *key = td;
168 struct backing_dev_info *bdi = &td->queue->backing_dev_info; 167 struct backing_dev_info *bdi = &td->queue->backing_dev_info;
@@ -229,12 +228,12 @@ done:
229 228
230static struct throtl_grp * throtl_get_tg(struct throtl_data *td) 229static struct throtl_grp * throtl_get_tg(struct throtl_data *td)
231{ 230{
232 struct cgroup *cgroup;
233 struct throtl_grp *tg = NULL; 231 struct throtl_grp *tg = NULL;
232 struct blkio_cgroup *blkcg;
234 233
235 rcu_read_lock(); 234 rcu_read_lock();
236 cgroup = task_cgroup(current, blkio_subsys_id); 235 blkcg = task_blkio_cgroup(current);
237 tg = throtl_find_alloc_tg(td, cgroup); 236 tg = throtl_find_alloc_tg(td, blkcg);
238 if (!tg) 237 if (!tg)
239 tg = &td->root_tg; 238 tg = &td->root_tg;
240 rcu_read_unlock(); 239 rcu_read_unlock();
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 5b52011e3a40..ab7a9e6a9b1c 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -1014,10 +1014,9 @@ void cfq_update_blkio_group_weight(void *key, struct blkio_group *blkg,
1014 cfqg->needs_update = true; 1014 cfqg->needs_update = true;
1015} 1015}
1016 1016
1017static struct cfq_group * 1017static struct cfq_group * cfq_find_alloc_cfqg(struct cfq_data *cfqd,
1018cfq_find_alloc_cfqg(struct cfq_data *cfqd, struct cgroup *cgroup, int create) 1018 struct blkio_cgroup *blkcg, int create)
1019{ 1019{
1020 struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
1021 struct cfq_group *cfqg = NULL; 1020 struct cfq_group *cfqg = NULL;
1022 void *key = cfqd; 1021 void *key = cfqd;
1023 int i, j; 1022 int i, j;
@@ -1079,12 +1078,12 @@ done:
1079 */ 1078 */
1080static struct cfq_group *cfq_get_cfqg(struct cfq_data *cfqd, int create) 1079static struct cfq_group *cfq_get_cfqg(struct cfq_data *cfqd, int create)
1081{ 1080{
1082 struct cgroup *cgroup; 1081 struct blkio_cgroup *blkcg;
1083 struct cfq_group *cfqg = NULL; 1082 struct cfq_group *cfqg = NULL;
1084 1083
1085 rcu_read_lock(); 1084 rcu_read_lock();
1086 cgroup = task_cgroup(current, blkio_subsys_id); 1085 blkcg = task_blkio_cgroup(current);
1087 cfqg = cfq_find_alloc_cfqg(cfqd, cgroup, create); 1086 cfqg = cfq_find_alloc_cfqg(cfqd, blkcg, create);
1088 if (!cfqg && create) 1087 if (!cfqg && create)
1089 cfqg = &cfqd->root_group; 1088 cfqg = &cfqd->root_group;
1090 rcu_read_unlock(); 1089 rcu_read_unlock();