Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6151000ybf; Thu, 5 Mar 2020 14:15:54 -0800 (PST) X-Google-Smtp-Source: ADFU+vtdo1JMLGKJhltImwYHda/Lc58EpveVFY80AR70Mo2e3FEL4jo9ydiQYzXVaaJtT1yap6/e X-Received: by 2002:a9d:6c13:: with SMTP id f19mr48854otq.175.1583446554551; Thu, 05 Mar 2020 14:15:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583446554; cv=none; d=google.com; s=arc-20160816; b=1CNzZuGF9ndnY0km0bMgQVyZFIKgxcP4YfDI7LcJAf8zfIsDQclGbaWMnyryWZT4N/ ELt0Nl7KsOmlQHdfywotEJdOepsgyhS9vYHnHSZ1/MAhsN0z49Ek2oykUyFIoF2bTEv9 leiKyk3hD5boXjwwHYj0T24tt13CNJNlsLJk47SzaaIORPakb2r9/L8bBQm85kU0WqZY fHoY1pe01hdy0srEzS8Q1YqvaT4nJoDEjiKAGsSpMpSm0Y/vB6GEY7Mku3SvATAWP3Fw Ur0D7fFp+mNaE0usNZzUcRtu/TzKKsE64lLi9eIuQPsHrjbcaEFAnNPd1a8DSvf9a5yC IAhA== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=4deVKZoc+tOzZEf8sEObE8f8TiLkfpKwXsd56fpwTbE=; b=czEThQynZ8N7ljDZwuJbBxFixxdPPbF56U5XCWCQcC5sE0a/4zPmAwjfwbiYei4fuH c3St02UwlcOy8PK3oqAjaPDka+qZ684bSauTz1la7RPFOGI/9clndqX/na/NpKeSZB7Y 1zPWE+PxthB5Fe+WCDkRTUNLhMSY9jaXovjezeqAr1s0gqJWma6SkUa5HHiu/yB4NSgK 85j+NDLhqqH6k3nugfDLIB7j5e21tgfOPl15HANMT0KlGzCcmjl0qcAIU32RhvB2TyzD 726gRKx3/pVVQ8GS4ZbZb2mc8VuLpfzwvyptVT6mVymQwsrK/4RIIUz2LO9aR9DB6rxZ mKkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si196746oii.60.2020.03.05.14.15.42; Thu, 05 Mar 2020 14:15:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbgCEWNr (ORCPT + 99 others); Thu, 5 Mar 2020 17:13:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:49734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726184AbgCEWNr (ORCPT ); Thu, 5 Mar 2020 17:13:47 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 35F2320801; Thu, 5 Mar 2020 22:13:46 +0000 (UTC) Date: Thu, 5 Mar 2020 17:13:44 -0500 From: Steven Rostedt To: Jann Horn Cc: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Andrew Morton , Frederic Weisbecker , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] exit: Move preemption fixup up, move blocking operations down Message-ID: <20200305171344.1f35d971@gandalf.local.home> In-Reply-To: <20200305220657.46800-1-jannh@google.com> References: <20200305220657.46800-1-jannh@google.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 5 Mar 2020 23:06:57 +0100 Jann Horn wrote: > 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 > --- > @@ -732,6 +736,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()); This should be more than a pr_info. It should also probably state the "Dazed and confused, best to reboot" message. Because if something crashed in a non preempt section, it may likely be holding a lock that it will never release, causing a soon to be deadlock! -- Steve > + 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); > @@ -749,13 +763,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); > > base-commit: 9f65ed5fe41ce08ed1cb1f6a950f9ec694c142ad