aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Baron <jbaron@akamai.com>2014-07-02 11:52:44 -0400
committerIngo Molnar <mingo@kernel.org>2014-07-16 07:38:21 -0400
commit5cd08fbfdb6baa9fe98f530b76898fc5725a6289 (patch)
treeb4f9df78a954c306cacea7372d920d1eb373140f
parent6e76ea8a8209386c3cc7ee5594e6ea5d25525cf2 (diff)
sched: Fix static_key race with sched_feat()
As pointed out by Andi Kleen, the usage of static keys can be racy in sched_feat_disable() vs. sched_feat_enable(). Currently, we first check the value of keys->enabled, and subsequently update the branch direction. This, can be racy and can potentially leave the keys in an inconsistent state. Take the i_mutex around these calls to resolve the race. Reported-by: Andi Kleen <andi@firstfloor.org> Signed-off-by: Jason Baron <jbaron@akamai.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: rostedt@goodmis.org Link: http://lkml.kernel.org/r/9d7780c83db26683955cd01e6bc654ee2586e67f.1404315388.git.jbaron@akamai.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--kernel/sched/core.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2f960813c582..8705125bb9b1 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -245,6 +245,7 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
245 char buf[64]; 245 char buf[64];
246 char *cmp; 246 char *cmp;
247 int i; 247 int i;
248 struct inode *inode;
248 249
249 if (cnt > 63) 250 if (cnt > 63)
250 cnt = 63; 251 cnt = 63;
@@ -255,7 +256,11 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
255 buf[cnt] = 0; 256 buf[cnt] = 0;
256 cmp = strstrip(buf); 257 cmp = strstrip(buf);
257 258
259 /* Ensure the static_key remains in a consistent state */
260 inode = file_inode(filp);
261 mutex_lock(&inode->i_mutex);
258 i = sched_feat_set(cmp); 262 i = sched_feat_set(cmp);
263 mutex_unlock(&inode->i_mutex);
259 if (i == __SCHED_FEAT_NR) 264 if (i == __SCHED_FEAT_NR)
260 return -EINVAL; 265 return -EINVAL;
261 266