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 93054C433DF for ; Tue, 2 Jun 2020 20:00:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B97F2072F for ; Tue, 2 Jun 2020 20:00:55 +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="i/UB9MzY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728101AbgFBUAy (ORCPT ); Tue, 2 Jun 2020 16:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgFBUAy (ORCPT ); Tue, 2 Jun 2020 16:00:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5733DC08C5C0 for ; Tue, 2 Jun 2020 13:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=AGSeP9HncYNyiI8RBc+DKgsbYmmpx4u1RvJid9IrRZk=; b=i/UB9MzYz3ISKIue6V4B+r+dFs QjC6AYT7AvwRdYE0kbVxVRtpkEDCZbXpsovIiDVdS0l5wIoP+5+EsF9TXKPINAxOvRGF8+B2CaFIE gQJUXgkMT06BF8f2TxuY6qhKSkmpr1HfLmXZ85gzhV0pQkrToN2DljKFOYLnZJHKukhkP4t56oca/ YVPArN+sgnB1fUoH4yrdfYJufkDWYoxeNSFejWpFLlXXDOCLTYqy8mBv3fS5qxl1yyacPP6alaDPy im9JUVRpaAvhHr/k64f3BdLHazxkxh2BLmf65pggPJhR55d28U7L4HjyuJtmBRw6S0ZJp2Y1x74fN MaOOPUBQ==; 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 1jgD5T-0007Jv-0x; Tue, 02 Jun 2020 20:00:39 +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 431A230081A; Tue, 2 Jun 2020 22:00:36 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3085C202436F0; Tue, 2 Jun 2020 22:00:36 +0200 (CEST) Date: Tue, 2 Jun 2020 22:00:36 +0200 From: Peter Zijlstra To: Steven Rostedt Cc: tglx@linutronix.de, luto@amacapital.net, 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, bigeasy@linutronix.de Subject: Re: [PATCH 13/14] lockdep: Prepare for NMI IRQ state tracking Message-ID: <20200602200036.GA2627@hirez.programming.kicks-ass.net> References: <20200529212728.795169701@infradead.org> <20200529213321.471984676@infradead.org> <20200529181401.1f01bdc5@oasis.local.home> <20200529222505.GW2483@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200529222505.GW2483@worktop.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 30, 2020 at 12:25:05AM +0200, Peter Zijlstra wrote: > On Fri, May 29, 2020 at 06:14:01PM -0400, Steven Rostedt wrote: > > Why remove the check for debug_locks? Isn't that there to disable > > everything at once to prevent more warnings to be printed? > > Yeah, maybe. I was thinking we could keep IRQ state running. But you're > right, if we mess up the IRQ state itself this might generate a wee > mess. How's this then? --- Subject: lockdep: Prepare for NMI IRQ state tracking From: Peter Zijlstra Date: Wed May 27 15:00:57 CEST 2020 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 | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3646,7 +3646,16 @@ static void __trace_hardirqs_on_caller(v */ void lockdep_hardirqs_on_prepare(unsigned long ip) { - if (unlikely(!debug_locks || current->lockdep_recursion)) + if (unlikely(!debug_locks)) + return; + + /* + * NMIs do not (and cannot) track lock dependencies, nothing to do. + */ + if (unlikely(in_nmi())) + return; + + if (unlikely(current->lockdep_recursion & LOCKDEP_RECURSION_MASK)) return; if (unlikely(current->hardirqs_enabled)) { @@ -3692,7 +3701,27 @@ void noinstr lockdep_hardirqs_on(unsigne { struct task_struct *curr = current; - if (unlikely(!debug_locks || curr->lockdep_recursion)) + if (unlikely(!debug_locks)) + return; + + /* + * 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 (unlikely(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 (unlikely(current->lockdep_recursion & LOCKDEP_RECURSION_MASK)) return; if (curr->hardirqs_enabled) { @@ -3720,6 +3749,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 +3765,15 @@ void noinstr lockdep_hardirqs_off(unsign { struct task_struct *curr = current; - if (unlikely(!debug_locks || curr->lockdep_recursion)) + if (unlikely(!debug_locks)) + return; + + /* + * Matching lockdep_hardirqs_on(), allow NMIs in the middle of lockdep; + * they will restore the software state. This ensures the software + * state is consistent inside NMIs as well. + */ + if (unlikely(!in_nmi() && (current->lockdep_recursion & LOCKDEP_RECURSION_MASK))) return; /*