Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp948643ybz; Fri, 1 May 2020 11:28:12 -0700 (PDT) X-Google-Smtp-Source: APiQypLU6NOtG+SCU3Fiic0kz65ERbcqlZbnGTInvIKw2rVqUufz+WoxOuYfEQn2/Rdc/y/jKs8s X-Received: by 2002:a17:907:118b:: with SMTP id uz11mr4341600ejb.89.1588357692051; Fri, 01 May 2020 11:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588357692; cv=none; d=google.com; s=arc-20160816; b=ylc1VMWSBuUCbqU93Wg6VBaJmZPxrjvy+GXHkpjzu/DvV0JCKHTz0faYHGZurAG6Af CmYt1j7S0Nao/kAMIqVTe3X0lmK6xr2LIP/kbyvjeWpHy/zsZDkCUyVovPqpWSmUyo95 7t66KxBJbNnp58nT+HcwkT9RZy8VUqsZkhiXUW5X/Yckqtm+KJeoaU9LkKMQItOXA/ly qHkbEXwe/cDlvDfhIUYWPLi7tV6SWNSjJZsrGjJcx2gaRHra00yWKd0iojLNXu1GVBYB BP8qKomdd1/Q60IcA4bWGnmedVSLuBi7YV8WM0LotMQ90w0yLz9iSzm5OkX2dNVsGIO+ Pe9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=Qi1J2DXWBN9DA7HgbKIQmN9rH+IHQveURbTkL1XXkdg=; b=hbY4ZqQoc0MRvHGEG7Lcnzkshtx8dkz8OD/qXZ5Z6akuFiH4eaOnlat7bxXSQwBgTQ gAEcUJVcB/2SAkAeVuZwJnw0JLnqXpjYX46fRqYIHEwZUi1PWTDPFjP/QAejV/IjCVPX xiZP3IHTzUwdTtUKuZyeevikuMHZygmKTAtNH2sAzmLDvt2kbzTkcDdLaWJE9gsBeDB3 MUukJm8JY03reYyKL/E5Damowy+HMawqCSljMEHcevUNXBSriuije789fTkcawXlYs9w 9/hE13G2eKSvWfM+Gzbm+hkd1XROTUeirWRZY3/W+SdZtIs3bHIrWsP7qGIf8i6ZJXNJ oxmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si2230827ejr.249.2020.05.01.11.27.49; Fri, 01 May 2020 11:28:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730955AbgEASXi (ORCPT + 99 others); Fri, 1 May 2020 14:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730628AbgEASWW (ORCPT ); Fri, 1 May 2020 14:22:22 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C38AC061A0C; Fri, 1 May 2020 11:22:22 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jUaIj-0003aA-O6; Fri, 01 May 2020 20:22:17 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 605E41C04DD; Fri, 1 May 2020 20:22:11 +0200 (CEST) Date: Fri, 01 May 2020 18:22:11 -0000 From: "tip-bot2 for Jann Horn" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] exit: Move preemption fixup up, move blocking operations down Cc: Jann Horn , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20200305220657.46800-1-jannh@google.com> References: <20200305220657.46800-1-jannh@google.com> MIME-Version: 1.0 Message-ID: <158835733131.8414.13953310081122413619.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 586b58cac8b4683eb58a1446fbc399de18974e40 Gitweb: https://git.kernel.org/tip/586b58cac8b4683eb58a1446fbc399de18974e40 Author: Jann Horn AuthorDate: Thu, 05 Mar 2020 23:06:57 +01:00 Committer: Peter Zijlstra CommitterDate: Thu, 30 Apr 2020 20:14:38 +02:00 exit: Move preemption fixup up, move blocking operations down 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 Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200305220657.46800-1-jannh@google.com --- kernel/exit.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index ce2a75b..d56fe51 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -708,8 +708,12 @@ void __noreturn do_exit(long code) struct task_struct *tsk = current; int group_dead; - 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)); @@ -727,6 +731,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); @@ -744,13 +758,6 @@ void __noreturn do_exit(long code) exit_signals(tsk); /* sets PF_EXITING */ - 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);