Commit 23196f2e authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Ingo Molnar

kthread: Pin the stack via try_get_task_stack()/put_task_stack() in to_live_kthread() function

get_task_struct(tsk) no longer pins tsk->stack so all users of
to_live_kthread() should do try_get_task_stack/put_task_stack to protect
"struct kthread" which lives on kthread's stack.

TODO: Kill to_live_kthread(), perhaps we can even kill "struct kthread" too,
and rework kthread_stop(), it can use task_work_add() to sync with the exiting
kernel thread.

Message-Id: <20160629180357.GA7178@redhat.com>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jann Horn <jann@thejh.net>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/cb9b16bbc19d4aea4507ab0552e4644c1211d130.1474003868.git.luto@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent c6c314a6
...@@ -64,7 +64,7 @@ static inline struct kthread *to_kthread(struct task_struct *k) ...@@ -64,7 +64,7 @@ static inline struct kthread *to_kthread(struct task_struct *k)
static struct kthread *to_live_kthread(struct task_struct *k) static struct kthread *to_live_kthread(struct task_struct *k)
{ {
struct completion *vfork = ACCESS_ONCE(k->vfork_done); struct completion *vfork = ACCESS_ONCE(k->vfork_done);
if (likely(vfork)) if (likely(vfork) && try_get_task_stack(k))
return __to_kthread(vfork); return __to_kthread(vfork);
return NULL; return NULL;
} }
...@@ -425,8 +425,10 @@ void kthread_unpark(struct task_struct *k) ...@@ -425,8 +425,10 @@ void kthread_unpark(struct task_struct *k)
{ {
struct kthread *kthread = to_live_kthread(k); struct kthread *kthread = to_live_kthread(k);
if (kthread) if (kthread) {
__kthread_unpark(k, kthread); __kthread_unpark(k, kthread);
put_task_stack(k);
}
} }
EXPORT_SYMBOL_GPL(kthread_unpark); EXPORT_SYMBOL_GPL(kthread_unpark);
...@@ -455,6 +457,7 @@ int kthread_park(struct task_struct *k) ...@@ -455,6 +457,7 @@ int kthread_park(struct task_struct *k)
wait_for_completion(&kthread->parked); wait_for_completion(&kthread->parked);
} }
} }
put_task_stack(k);
ret = 0; ret = 0;
} }
return ret; return ret;
...@@ -490,6 +493,7 @@ int kthread_stop(struct task_struct *k) ...@@ -490,6 +493,7 @@ int kthread_stop(struct task_struct *k)
__kthread_unpark(k, kthread); __kthread_unpark(k, kthread);
wake_up_process(k); wake_up_process(k);
wait_for_completion(&kthread->exited); wait_for_completion(&kthread->exited);
put_task_stack(k);
} }
ret = k->exit_code; ret = k->exit_code;
put_task_struct(k); put_task_struct(k);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment