Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp640629yba; Thu, 16 May 2019 06:46:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb1pv0fuMJprshhs5GZ2wVFeMPIgH3utoVY+c+ilhmCMcSCyMpvXg50Ug0jX3qHbI6uca6 X-Received: by 2002:a17:902:8214:: with SMTP id x20mr28268944pln.308.1558014394260; Thu, 16 May 2019 06:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558014394; cv=none; d=google.com; s=arc-20160816; b=U1PtztY0CtnisD364KkmFZYMc0jDCypJMiWsXUAN2bwFrtGecM8hz9WYwmivQEdGiR Zx0u1bhw3mZ7y2u7Fikna8X4x8+8F+0GvyiXEY4WxQtQr5AstJ6AaB1fzzZPJK98ae34 8wsHuM80o3N04NnVlhhDXFCbk0GpkbVMF23mG8EKDrz8Lxo5xR4NimNhbSEmfZp4etqp TyuaRjVV+/t/fXWGzBs6to7G/KfECZ8pRGCv7VG54TZnwRtFFwobgbg2ZE/cChrBCIYW mwIkhhspU5CudLF4sgV0d/R4y7BaVGTfNji+50nBlstItztaJByzYC3/JlGrXzmklqkl V48Q== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=+3TC6bsMak3jRI0YLpXhZAcx8cyxYJKskjJ+L2vsBSo=; b=TqVku5Y13coYvsfogKnd38KbGve8TsXTULiv+41+GZOnasN628dftGY0lG7fvCAsXf QvJmtzvzaUQaU2MErpl3KGhsYsfWiq8S82JyhCE7Y/7diyOnjFNTE5drZgw7/XUCBSfc p1IDzvXg2QlwhnYpzFtsgDxkrqsYaFZadFQKaXjnoALUqiucapyWwlzVlUPxpzSvXqDw v/tyXiSOuzKZcJxMwXeARC9k6Jp20+5om9SxyQR3w9L64DfZCIaazHpahB1MuMCgkgdU dQG1vxC7R74LCYBeKGYxQZ9RGq0dRENUCeAi++kemYLPzqru+VDUuFR2+SAVks3u123c yhkA== 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 r6si4778629pgp.466.2019.05.16.06.46.18; Thu, 16 May 2019 06:46:34 -0700 (PDT) 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 S1727604AbfEPNne (ORCPT + 99 others); Thu, 16 May 2019 09:43:34 -0400 Received: from foss.arm.com ([217.140.101.70]:46308 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbfEPNnd (ORCPT ); Thu, 16 May 2019 09:43:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 939901715; Thu, 16 May 2019 06:43:33 -0700 (PDT) Received: from [10.1.197.45] (e112298-lin.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AE5F23F575; Thu, 16 May 2019 06:43:27 -0700 (PDT) Subject: Re: [PATCH v2 4/5] arm64: irqflags: Introduce explicit debugging for IRQ priorities To: Marc Zyngier , linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org, yuzenghui@huawei.com, wanghaibin.wang@huawei.com, james.morse@arm.com, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, liwei391@huawei.com References: <1556553607-46531-1-git-send-email-julien.thierry@arm.com> <1556553607-46531-5-git-send-email-julien.thierry@arm.com> <9b27cb2c-5159-3001-672e-9391d7490944@arm.com> From: Julien Thierry Message-ID: <890a91fd-da1e-50b4-6567-d732a850e32c@arm.com> Date: Thu, 16 May 2019 14:43:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <9b27cb2c-5159-3001-672e-9391d7490944@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/05/2019 09:44, Marc Zyngier wrote: > On 29/04/2019 17:00, Julien Thierry wrote: >> Using IRQ priority masking to enable/disable interrupts is a bit >> sensitive as it requires to deal with both ICC_PMR_EL1 and PSR.I. >> >> Introduce some validity checks to both highlight the states in which >> functions dealing with IRQ enabling/disabling can (not) be called, and >> bark a warning when called in an unexpected state. >> >> Since these checks are done on hotpaths, introduce a build option to >> choose whether to do the checking. >> >> Signed-off-by: Julien Thierry >> Cc: Catalin Marinas >> Cc: Will Deacon >> --- >> arch/arm64/Kconfig | 11 +++++++++++ >> arch/arm64/include/asm/daifflags.h | 9 +++++++++ >> arch/arm64/include/asm/irqflags.h | 14 ++++++++++++++ >> 3 files changed, 34 insertions(+) >> >> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig >> index 7e34b9e..3fb38f3 100644 >> --- a/arch/arm64/Kconfig >> +++ b/arch/arm64/Kconfig >> @@ -1359,6 +1359,17 @@ config ARM64_PSEUDO_NMI >> >> If unsure, say N >> >> +if ARM64_PSEUDO_NMI >> +config ARM64_DEBUG_PRIORITY_MASKING >> + bool "Debug interrupt priority masking" >> + help >> + This adds runtime checks to functions enabling/disabling >> + interrupts when using priority masking. The additional checks verify >> + the validity of ICC_PMR_EL1 when calling concerned functions. >> + >> + If unsure, say N >> +endif >> + >> config RELOCATABLE >> bool >> help >> diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h >> index a32ece9..9512968 100644 >> --- a/arch/arm64/include/asm/daifflags.h >> +++ b/arch/arm64/include/asm/daifflags.h >> @@ -28,6 +28,11 @@ >> /* mask/save/unmask/restore all exceptions, including interrupts. */ >> static inline void local_daif_mask(void) >> { >> + WARN_ON(IS_ENABLED(CONFIG_ARM64_DEBUG_PRIORITY_MASKING) && >> + system_uses_irq_prio_masking() && > > Given that you repeat these conditions all over the place, how about a > helper: > > #define DEBUG_PRIORITY_MASKING_CHECK(x) \ > (IS_ENABLED(CONFIG_ARM64_DEBUG_PRIORITY_MASKING) && \ > system_uses_irq_prio_masking() && (x)) > > or some variant thereof. > Yes, good point, I'll do that. >> + (read_sysreg_s(SYS_ICC_PMR_EL1) == (GIC_PRIO_IRQOFF | >> + GIC_PRIO_IGNORE_PMR))); >> + >> asm volatile( >> "msr daifset, #0xf // local_daif_mask\n" >> : >> @@ -62,6 +67,10 @@ static inline void local_daif_restore(unsigned long flags) >> { >> bool irq_disabled = flags & PSR_I_BIT; >> >> + WARN_ON(IS_ENABLED(CONFIG_ARM64_DEBUG_PRIORITY_MASKING) && >> + system_uses_irq_prio_masking() && >> + !(read_sysreg(daif) & PSR_I_BIT)); >> + >> if (!irq_disabled) { >> trace_hardirqs_on(); >> >> diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h >> index 516cdfc..a40abc2 100644 >> --- a/arch/arm64/include/asm/irqflags.h >> +++ b/arch/arm64/include/asm/irqflags.h >> @@ -40,6 +40,13 @@ >> */ >> static inline void arch_local_irq_enable(void) >> { >> + if (IS_ENABLED(CONFIG_ARM64_DEBUG_PRIORITY_MASKING) && >> + system_uses_irq_prio_masking()) { >> + u32 pmr = read_sysreg_s(SYS_ICC_PMR_EL1); >> + >> + WARN_ON(pmr != GIC_PRIO_IRQON && pmr != GIC_PRIO_IRQOFF); >> + } >> + >> asm volatile(ALTERNATIVE( >> "msr daifclr, #2 // arch_local_irq_enable\n" >> "nop", >> @@ -53,6 +60,13 @@ static inline void arch_local_irq_enable(void) >> >> static inline void arch_local_irq_disable(void) >> { >> + if (IS_ENABLED(CONFIG_ARM64_DEBUG_PRIORITY_MASKING) && >> + system_uses_irq_prio_masking()) { >> + u32 pmr = read_sysreg_s(SYS_ICC_PMR_EL1); >> + >> + WARN_ON(pmr != GIC_PRIO_IRQON && pmr != GIC_PRIO_IRQOFF); >> + } >> + >> asm volatile(ALTERNATIVE( >> "msr daifset, #2 // arch_local_irq_disable", >> "msr_s " __stringify(SYS_ICC_PMR_EL1) ", %0", >> -- >> 1.9.1 >> > > nit: There is also the question of using WARN_ON in a context that will > be extremely noisy if we're in a condition where this fires. > WARN_ON_ONCE, maybe? This is a debugging thing, so maybe we just don't care. > Yes, thinking about it, it did get pretty noisy when I checked this was working. WARN_ON_ONCE might be a good option. Thanks, -- Julien Thierry