diff options
author | Jann Horn <jannh@google.com> | 2020-03-05 23:06:57 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-06-20 10:24:16 +0200 |
commit | 1e587ce792e3803f42a8ef19bdcd3ae2cec2892f (patch) | |
tree | c8839f8aaa30f5be40aa5fefc76ffd51ad03a541 | |
parent | ed3cbbfeba8dd13aefb5e89b6ef40f5342723b9b (diff) | |
download | linux-stable-1e587ce792e3803f42a8ef19bdcd3ae2cec2892f.tar.gz linux-stable-1e587ce792e3803f42a8ef19bdcd3ae2cec2892f.tar.bz2 linux-stable-1e587ce792e3803f42a8ef19bdcd3ae2cec2892f.zip |
exit: Move preemption fixup up, move blocking operations down
[ Upstream commit 586b58cac8b4683eb58a1446fbc399de18974e40 ]
With CONFIG_DEBUG_ATOMIC_SLEEP=y and CONFIG_CGROUPS=y, kernel oopses in
non-preemptible context look untidy; after the main oops, the kernel prints
a "sleeping function called from invalid context" report because
exit_signals() -> cgroup_threadgroup_change_begin() -> percpu_down_read()
can sleep, and that happens before the preempt_count_set(PREEMPT_ENABLED)
fixup.
It looks like the same thing applies to profile_task_exit() and
kcov_task_exit().
Fix it by moving the preemption fixup up and the calls to
profile_task_exit() and kcov_task_exit() down.
Fixes: 1dc0fffc48af ("sched/core: Robustify preemption leak checks")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200305220657.46800-1-jannh@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | kernel/exit.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index d9394fcd0e2c..27f4168eaeb1 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -739,8 +739,12 @@ void __noreturn do_exit(long code) int group_dead; TASKS_RCU(int tasks_rcu_i); - profile_task_exit(tsk); - kcov_task_exit(tsk); + /* + * We can get here from a kernel oops, sometimes with preemption off. + * Start by checking for critical errors. + * Then fix up important state like USER_DS and preemption. + * Then do everything else. + */ WARN_ON(blk_needs_flush_plug(tsk)); @@ -758,6 +762,16 @@ void __noreturn do_exit(long code) */ set_fs(USER_DS); + if (unlikely(in_atomic())) { + pr_info("note: %s[%d] exited with preempt_count %d\n", + current->comm, task_pid_nr(current), + preempt_count()); + preempt_count_set(PREEMPT_ENABLED); + } + + profile_task_exit(tsk); + kcov_task_exit(tsk); + ptrace_event(PTRACE_EVENT_EXIT, code); validate_creds_for_do_exit(tsk); @@ -794,13 +808,6 @@ void __noreturn do_exit(long code) */ raw_spin_unlock_wait(&tsk->pi_lock); - if (unlikely(in_atomic())) { - pr_info("note: %s[%d] exited with preempt_count %d\n", - current->comm, task_pid_nr(current), - preempt_count()); - preempt_count_set(PREEMPT_ENABLED); - } - /* sync mm's RSS info before statistics gathering */ if (tsk->mm) sync_mm_rss(tsk->mm); |