summaryrefslogtreecommitdiffstats
path: root/kernel/sched
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2018-05-01 12:14:45 -0400
committerIngo Molnar <mingo@kernel.org>2018-05-03 01:38:05 -0400
commit85f1abe0019fcb3ea10df7029056cf42702283a8 (patch)
tree26e317238165c6c8389ba125a716667584358c89 /kernel/sched
parent741a76b350897604c48fb12beff1c9b77724dc96 (diff)
kthread, sched/wait: Fix kthread_parkme() completion issue
Even with the wait-loop fixed, there is a further issue with kthread_parkme(). Upon hotplug, when we do takedown_cpu(), smpboot_park_threads() can return before all those threads are in fact blocked, due to the placement of the complete() in __kthread_parkme(). When that happens, sched_cpu_dying() -> migrate_tasks() can end up migrating such a still runnable task onto another CPU. Normally the task will have hit schedule() and gone to sleep by the time we do kthread_unpark(), which will then do __kthread_bind() to re-bind the task to the correct CPU. However, when we loose the initial TASK_PARKED store to the concurrent wakeup issue described previously, do the complete(), get migrated, it is possible to either: - observe kthread_unpark()'s clearing of SHOULD_PARK and terminate the park and set TASK_RUNNING, or - __kthread_bind()'s wait_task_inactive() to observe the competing TASK_RUNNING store. Either way the WARN() in __kthread_bind() will trigger and fail to correctly set the CPU affinity. Fix this by only issuing the complete() when the kthread has scheduled out. This does away with all the icky 'still running' nonsense. The alternative is to promote TASK_PARKED to a special state, this guarantees wait_task_inactive() cannot observe a 'stale' TASK_RUNNING and we'll end up doing the right thing, but this preserves the whole icky business of potentially migating the still runnable thing. Reported-by: Gaurav Kohli <gkohli@codeaurora.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched')
-rw-r--r--kernel/sched/core.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5e10aaeebfcc..7ad60e00a6a8 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7,6 +7,8 @@
7 */ 7 */
8#include "sched.h" 8#include "sched.h"
9 9
10#include <linux/kthread.h>
11
10#include <asm/switch_to.h> 12#include <asm/switch_to.h>
11#include <asm/tlb.h> 13#include <asm/tlb.h>
12 14
@@ -2718,20 +2720,28 @@ static struct rq *finish_task_switch(struct task_struct *prev)
2718 membarrier_mm_sync_core_before_usermode(mm); 2720 membarrier_mm_sync_core_before_usermode(mm);
2719 mmdrop(mm); 2721 mmdrop(mm);
2720 } 2722 }
2721 if (unlikely(prev_state == TASK_DEAD)) { 2723 if (unlikely(prev_state & (TASK_DEAD|TASK_PARKED))) {
2722 if (prev->sched_class->task_dead) 2724 switch (prev_state) {
2723 prev->sched_class->task_dead(prev); 2725 case TASK_DEAD:
2726 if (prev->sched_class->task_dead)
2727 prev->sched_class->task_dead(prev);
2724 2728
2725 /* 2729 /*
2726 * Remove function-return probe instances associated with this 2730 * Remove function-return probe instances associated with this
2727 * task and put them back on the free list. 2731 * task and put them back on the free list.
2728 */ 2732 */
2729 kprobe_flush_task(prev); 2733 kprobe_flush_task(prev);
2730 2734
2731 /* Task is done with its stack. */ 2735 /* Task is done with its stack. */
2732 put_task_stack(prev); 2736 put_task_stack(prev);
2733 2737
2734 put_task_struct(prev); 2738 put_task_struct(prev);
2739 break;
2740
2741 case TASK_PARKED:
2742 kthread_park_complete(prev);
2743 break;
2744 }
2735 } 2745 }
2736 2746
2737 tick_nohz_task_switch(); 2747 tick_nohz_task_switch();