From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E3C4C433E0 for ; Fri, 29 May 2020 21:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 184FD2071A for ; Fri, 29 May 2020 21:35:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="hQy3oPi4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728451AbgE2VfO (ORCPT ); Fri, 29 May 2020 17:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728166AbgE2Ve5 (ORCPT ); Fri, 29 May 2020 17:34:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55645C08C5CB for ; Fri, 29 May 2020 14:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=WjKsi8bOcrknQ30a5TuleMU1PWiSqMKGWhCDIGz69Ek=; b=hQy3oPi4DgckeGMaNPZVQFYsN6 jPUvCbhD81Dn8UIgs8M1NRuty3bLkWfpty33j+o6hRXz1EcWRW0tfhGR6qVyGBIle3WK+ld6FQlaT 9sWTi/JZZv7h8GnowttuHr4RkamLL5ZUBUP8271eYtCFZ+45WQBuw0E0ta563k83OTLaIyO8x1+tJ U1HFNsbVgehWoUEgENtyI0G9cD8TKtAImN2RvW/80fNO5tw4i5LkCAN7urT5J7wjGkP6BQT9EMp0a 1oUlHgsOU9IeRcY1svUE7ew/Kf47+zXEybxJdRlwOn2Lvw9HPkpZQweRIs5BiYi/Azlkm5IgkxS0T 1IEcMOPQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jemeN-0000LJ-6D; Fri, 29 May 2020 21:34:47 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0F128307886; Fri, 29 May 2020 23:34:42 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 4E3682B9B1BC5; Fri, 29 May 2020 23:34:41 +0200 (CEST) Message-ID: <20200529213321.471984676@infradead.org> User-Agent: quilt/0.66 Date: Fri, 29 May 2020 23:27:41 +0200 From: Peter Zijlstra To: tglx@linutronix.de, luto@amacapital.net, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Lai Jiangshan , sean.j.christopherson@intel.com, andrew.cooper3@citrix.com, daniel.thompson@linaro.org, a.darwish@linutronix.de, rostedt@goodmis.org, bigeasy@linutronix.de Subject: [PATCH 13/14] lockdep: Prepare for NMI IRQ state tracking References: <20200529212728.795169701@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no reason not to always, accurately, track IRQ state. This change also makes IRQ state tracking ignore lockdep_off(). Signed-off-by: Peter Zijlstra (Intel) --- kernel/locking/lockdep.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3646,7 +3646,13 @@ static void __trace_hardirqs_on_caller(v */ void lockdep_hardirqs_on_prepare(unsigned long ip) { - if (unlikely(!debug_locks || current->lockdep_recursion)) + /* + * NMIs do not (and cannot) track lock dependencies, nothing to do. + */ + if (in_nmi()) + return; + + if (DEBUG_LOCKS_WARN_ON(current->lockdep_recursion & LOCKDEP_RECURSION_MASK)) return; if (unlikely(current->hardirqs_enabled)) { @@ -3692,7 +3698,24 @@ void noinstr lockdep_hardirqs_on(unsigne { struct task_struct *curr = current; - if (unlikely(!debug_locks || curr->lockdep_recursion)) + /* + * NMIs can happen in the middle of local_irq_{en,dis}able() where the + * tracking state and hardware state are out of sync. + * + * NMIs must save lockdep_hardirqs_enabled() to restore IRQ state from, + * and not rely on hardware state like normal interrupts. + */ + if (in_nmi()) { + /* + * Skip: + * - recursion check, because NMI can hit lockdep; + * - hardware state check, because above; + * - chain_key check, see lockdep_hardirqs_on_prepare(). + */ + goto skip_checks; + } + + if (DEBUG_LOCKS_WARN_ON(curr->lockdep_recursion & LOCKDEP_RECURSION_MASK)) return; if (curr->hardirqs_enabled) { @@ -3720,6 +3743,7 @@ void noinstr lockdep_hardirqs_on(unsigne DEBUG_LOCKS_WARN_ON(current->hardirq_chain_key != current->curr_chain_key); +skip_checks: /* we'll do an OFF -> ON transition: */ curr->hardirqs_enabled = 1; curr->hardirq_enable_ip = ip; @@ -3735,7 +3759,10 @@ void noinstr lockdep_hardirqs_off(unsign { struct task_struct *curr = current; - if (unlikely(!debug_locks || curr->lockdep_recursion)) + /* + * NMIs can happen in lockdep. + */ + if (!in_nmi() && DEBUG_LOCKS_WARN_ON(curr->lockdep_recursion & LOCKDEP_RECURSION_MASK)) return; /*