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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7174FC433F5 for ; Fri, 19 Nov 2021 14:05:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30D686120A for ; Fri, 19 Nov 2021 14:05:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 30D686120A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7VDlWWM9MTHULwyUbYCMUs6jUIm30pGUnr2pICKdEP8=; b=OnAKS9QkVgz4NL ffGppzvOh3nSBwwOhIwFO0eKzhN67ZP68cZYyO39g0DrxHzpNNTyzqImYEKD2fSwEOpa5m1h/5+5v EP2cLnMVL/3iNuj4L1egyvpPN9j9dZlusyH6zOp9kiQFh+AOLFaxPJf4Sk+O2IDkDKpCULxqO/2+s wTa40wxqo13/mORes1v+rElHLJUrYQvkVlR/YZdDY1FPgKx1O7WfyyQHd5s2PncCUT87jl33yw+5/ xnWkmg75iM1FhCnwCkXxUz9y+nFTkkTn3B6qLZPZ9yX/Q9cIczbkHAwNm4zMiZUD2F3ngobD3qQ5/ q8SqEpV4ZWtIDH0QioJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mo4Uu-00Aayp-AP; Fri, 19 Nov 2021 14:04:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mo4Uq-00AayU-Vn for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 14:04:10 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EE8A5ED1; Fri, 19 Nov 2021 06:04:07 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66C663F5A1; Fri, 19 Nov 2021 06:04:06 -0800 (PST) Date: Fri, 19 Nov 2021 14:04:04 +0000 From: Mark Rutland To: Pingfan Liu Cc: linux-arm-kernel@lists.infradead.org, "Paul E . McKenney" , Catalin Marinas , Will Deacon , Marc Zyngier , Thomas Gleixner , Joey Gouly , Sami Tolvanen , Julien Thierry , Yuichi Ito , rcu@vger.kernel.org Subject: Re: [PATCHv3 1/4] arm64: entry: judge nmi ealier to avoid deadlock in RCU Message-ID: <20211119140404.GC25912@lakrids.cambridge.arm.com> References: <20211116082450.10357-1-kernelfans@gmail.com> <20211116082450.10357-2-kernelfans@gmail.com> <20211117113854.GA41542@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211119_060409_140892_E46FB5D8 X-CRM114-Status: GOOD ( 23.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Nov 19, 2021 at 10:01:00AM +0800, Pingfan Liu wrote: > On Wed, Nov 17, 2021 at 11:38:54AM +0000, Mark Rutland wrote: > > On Tue, Nov 16, 2021 at 04:24:47PM +0800, Pingfan Liu wrote: > > > Linux kernel places strict semantics between NMI and maskable interrupt. > > > So does the RCU component, else deadlock may happen. But the current > > > arm64 entry code can partially breach this rule through calling > > > rcu_nmi_enter(). > > > > > > *** how a deadlock can happen if NMI mistaken as IRQ *** > > > > > > rcu_nmi_enter() > > > { > > > > > > if (rcu_dynticks_curr_cpu_in_eqs()) { > > > > > > if (!in_nmi()) > > > rcu_dynticks_task_exit(); > > > ... > > > if (!in_nmi()) { > > > instrumentation_begin(); > > > rcu_cleanup_after_idle(); > > > instrumentation_end(); > > > } > > > ... > > > } else if (!in_nmi()) { > > > instrumentation_begin(); > > > rcu_irq_enter_check_tick(); > > > } > > > > > > } > > > > > > If a NMI is mistaken as a maskable interrupt, rcu_irq_enter_check_tick() > > > can hit a deadlock, which is demonstrated by the following scenario: > > > > > > note_gp_changes() runs in a task context > > > { > > > local_irq_save(flags); // this protects against irq, but not NMI > > > > Note: speecifically, this masks IRQs via ICC_PMR_EL1. > > > > > rnp = rdp->mynode; > > > ... > > > raw_spin_trylock_rcu_node(rnp) > > > -------> broken in by (p)NMI, without taking __nmi_enter() > > > > AFAICT the broken case described here *cannot* happen. > > > > If we take a pNMI here, we'll go: > > > > el1h_64_irq() > > -> el1h64_irq_handler() > > -> el1_interrupt() > > > > ... where el1_interrupt is: > > > > | static void noinstr el1_interrupt(struct pt_regs *regs, > > | void (*handler)(struct pt_regs *)) > > | { > > | write_sysreg(DAIF_PROCCTX_NOIRQ, daif); > > | > > | if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && !interrupts_enabled(regs)) > > | __el1_pnmi(regs, handler); > > | else > > | __el1_irq(regs, handler); > > | } > > > > ... and interrupts_enabled() is: > > > > | #define interrupts_enabled(regs) \ > > | (!((regs)->pstate & PSR_I_BIT) && irqs_priority_unmasked(regs)) > > > > ... and irqs_priority_unmasked is: > > > > | #define irqs_priority_unmasked(regs) \ > > | (system_uses_irq_prio_masking() ? \ > > | (regs)->pmr_save == GIC_PRIO_IRQON : \ > > | true) > > > > ... irqs_priority_unmasked(regs) *must* return false for this case, > > since the local_irq_save() above must have set the PMR to > > GIC_PRIO_IRQOFF in the interrupted context. > > > > Thus, we *must* call __el1_pnmi() in this case, where __el1_pnmi() is: > > > > Yes, you are right. And I made a mistake to think it will call > __el1_irq() > As above, I made a mistake about the condition hence the code path. > There is no problem in this case through calling __el1_pnmi() > > Sorry for the false alarm and thank you again for your detailed > explaination. No worries; thanks for confirming this was a false alarm. Glad we're now on the same page. :) Likewise, thanks for reporting what you thought was an issue; having more eyes on this is always good! Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel