]> Git Repo - linux.git/commitdiff
kthread: Pin the stack via try_get_task_stack()/put_task_stack() in to_live_kthread...
authorOleg Nesterov <[email protected]>
Fri, 16 Sep 2016 05:45:44 +0000 (22:45 -0700)
committerIngo Molnar <[email protected]>
Fri, 16 Sep 2016 07:18:53 +0000 (09:18 +0200)
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[email protected]>
Signed-off-by: Oleg Nesterov <[email protected]>
Signed-off-by: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Jann Horn <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/cb9b16bbc19d4aea4507ab0552e4644c1211d130.1474003868.git.luto@kernel.org
Signed-off-by: Ingo Molnar <[email protected]>
kernel/kthread.c

index 9ff173dca1aef5e09fd640dc6757fee99c7a956c..4ab4c3766a80ddf917cb988ac9c55d48957edbc4 100644 (file)
@@ -64,7 +64,7 @@ static inline struct kthread *to_kthread(struct task_struct *k)
 static struct kthread *to_live_kthread(struct task_struct *k)
 {
        struct completion *vfork = ACCESS_ONCE(k->vfork_done);
-       if (likely(vfork))
+       if (likely(vfork) && try_get_task_stack(k))
                return __to_kthread(vfork);
        return NULL;
 }
@@ -425,8 +425,10 @@ void kthread_unpark(struct task_struct *k)
 {
        struct kthread *kthread = to_live_kthread(k);
 
-       if (kthread)
+       if (kthread) {
                __kthread_unpark(k, kthread);
+               put_task_stack(k);
+       }
 }
 EXPORT_SYMBOL_GPL(kthread_unpark);
 
@@ -455,6 +457,7 @@ int kthread_park(struct task_struct *k)
                                wait_for_completion(&kthread->parked);
                        }
                }
+               put_task_stack(k);
                ret = 0;
        }
        return ret;
@@ -490,6 +493,7 @@ int kthread_stop(struct task_struct *k)
                __kthread_unpark(k, kthread);
                wake_up_process(k);
                wait_for_completion(&kthread->exited);
+               put_task_stack(k);
        }
        ret = k->exit_code;
        put_task_struct(k);
This page took 0.054044 seconds and 4 git commands to generate.