Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10488229imu; Thu, 6 Dec 2018 01:51:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xj91IO0MD5ZT3w4SzKoILSxI07hhBidKgzKDiii+HWNtcmzRRqtpP7HeL41cT73vI6etTG X-Received: by 2002:a62:4851:: with SMTP id v78mr28112696pfa.97.1544089911546; Thu, 06 Dec 2018 01:51:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544089911; cv=none; d=google.com; s=arc-20160816; b=0PKxScsO22DZnGoi1s+iJ/R6E4ZLYDHGzCGF9yGhEDTO2nxZj3M7AfZvT2O+PYeshv 8HbYmVMb00hW7s8TexSPgHsN6KAWPHlSjIxHREb6yGzR2hp1RNqLuiXP95FPieQIQYMW 3GIZQEChVDGv5WQ3csILKD+dvscwvqpxxP7wYL838v5JAahJSWNppbyufSpcve5aF2Rw ejV+XZpPIbP+/33WxJejzFkNrUV3IGvV5PkuXi8jP8O8HWx5yXjdqdA8lJXu7LQJI//u lijmwu3Jf7U6LpE4HCXIlIP6pATEv635OZCZp2bJ0ufb2Q9z92Z17yD4YRlg0MFR1lii U+Bw== 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=1WTLtTnFz9OmK17ydpQ2ke0+bwEXIkC3sOeZQ3CRTzU=; b=UaVYV20RNdZt+GdxND7k1m4hO15yd2BctAIPiU2KBf0CYCeyovC8ztiBK/4CFmTwWP HOtNnFzPf+FM3NYS5OnHj1syky4jJGnSXZjLxwPgKL64esEb4eDF0zGSFTPSjeRwpqdm dLy0ZnwAlc1Ou+mCeXQNPO7WeoDdWK3EDK9+OribM/Vny0W3TZ5gtMK7oQHKfQ2l4Drq ri0rgfDOOKoGKbAy8l/kF7bOXbtjUQithGwQkBqVQYl3dGulriPJnZAE10tAsbqUuAcs EI7dEPxjqrWKQrnbCCb/ZHvUeyDcKxF4EHPB4GYfjmvoMnGa3wFqn2JwPAkLLSM/VWDO /mvg== 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 z14si19782713pgj.73.2018.12.06.01.51.35; Thu, 06 Dec 2018 01:51:51 -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 S1729393AbeLFJuX (ORCPT + 99 others); Thu, 6 Dec 2018 04:50:23 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:43138 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727783AbeLFJuW (ORCPT ); Thu, 6 Dec 2018 04:50:22 -0500 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 95F8CA78; Thu, 6 Dec 2018 01:50:22 -0800 (PST) Received: from [10.1.197.36] (e112298-lin.cambridge.arm.com [10.1.197.36]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BEB013F5AF; Thu, 6 Dec 2018 01:50:20 -0800 (PST) Subject: Re: [PATCH v6 10/24] arm64: irqflags: Use ICC_PMR_EL1 for interrupt masking To: Catalin Marinas Cc: daniel.thompson@linaro.org, Ard Biesheuvel , marc.zyngier@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, christoffer.dall@arm.com, james.morse@arm.com, Oleg Nesterov , joel@joelfernandes.org, linux-arm-kernel@lists.infradead.org References: <1542023835-21446-1-git-send-email-julien.thierry@arm.com> <1542023835-21446-11-git-send-email-julien.thierry@arm.com> <20181204173610.GC19210@arrakis.emea.arm.com> <20181205182616.GE27881@arrakis.emea.arm.com> From: Julien Thierry Message-ID: Date: Thu, 6 Dec 2018 09:50:18 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20181205182616.GE27881@arrakis.emea.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 05/12/18 18:26, Catalin Marinas wrote: > On Wed, Dec 05, 2018 at 04:55:54PM +0000, Julien Thierry wrote: >> On 04/12/18 17:36, Catalin Marinas wrote: >>> On Mon, Nov 12, 2018 at 11:57:01AM +0000, Julien Thierry wrote: >>>> diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h >>>> index 24692ed..e0a32e4 100644 >>>> --- a/arch/arm64/include/asm/irqflags.h >>>> +++ b/arch/arm64/include/asm/irqflags.h >>>> @@ -18,7 +18,27 @@ >>>> >>>> #ifdef __KERNEL__ >>>> >>>> +#include >>>> +#include >>>> #include >>>> +#include >>>> + >>>> + >>>> +/* >>>> + * When ICC_PMR_EL1 is used for interrupt masking, only the bit indicating >>>> + * whether the normal interrupts are masked is kept along with the daif >>>> + * flags. >>>> + */ >>>> +#define ARCH_FLAG_PMR_EN 0x1 >>>> + >>>> +#define MAKE_ARCH_FLAGS(daif, pmr) \ >>>> + ((daif) | (((pmr) >> GIC_PRIO_STATUS_SHIFT) & ARCH_FLAG_PMR_EN)) >>>> + >>>> +#define ARCH_FLAGS_GET_PMR(flags) \ >>>> + ((((flags) & ARCH_FLAG_PMR_EN) << GIC_PRIO_STATUS_SHIFT) \ >>>> + | GIC_PRIO_IRQOFF) >>>> + >>>> +#define ARCH_FLAGS_GET_DAIF(flags) ((flags) & ~ARCH_FLAG_PMR_EN) >>> >>> I wonder whether we could just use the PSR_I_BIT here to decide whether >>> to set the GIC_PRIO_IRQ{ON,OFF}. We could clear the PSR_I_BIT in >>> _restore_daif() with an alternative. >> >> So, the issue with it is that some contexts might be using PSR.I to >> disable interrupts (any contexts with async errors or debug exceptions >> disabled, kvm guest entry paths, pseudo-NMIs, ...). >> >> If any of these contexts calls local_irq_save()/local_irq_restore() or >> local_daif_save()/local_daif_restore(), by only relying on PSR_I_BIT to >> represent the PMR status, we might end up clearing PSR.I when we shouldn't. >> >> I'm not sure whether there are no callers of these functions in those >> context. But if that is the case, we could simplify things, yes. > > There are callers of local_daif_save() (3) and local_daif_mask() (7) but > do they all need to disable the pseudo-NMIs? > Hmmm, I really think that both of those should be disabling NMIs. Otherwise, if we take an NMI, the first thing the el1_irq handler is going to do is "enable_da_f()" which could lead to potential issues. One thing that could be done is: - local_daif_save() and local_daif_mask() both mask all daif bits (taking care to represent PMR value in the I bit of the saved flags) - local_daif_restore() restores da_f as expected and decides values to put for PMR and PSR.I as follows: * do the da_f restore * if PSR.A bit is cleared in the saved flags, then we also do a start_nmi() However, this would not work with a local_daif_save()/restore() on the return path of an NMI because I think it is the only context with NMIs "stopped" that can take aborts. I can add a WARN_ON(in_nmi()) for local_daif_restore() if that doesn't affect performance too much. Does that sound alright? > At a brief look at x86, it seems that they have something like > stop_nmi() and restart_nmi(). These don't have save/restore semantics, > so we could do something similar on arm64 that only deals with the > PSTATE.I bit directly and keep the software (flags) PSR.I as the PMR > bit. But we'd have to go through the 10 local_daif_* cases above to see > which actually need the stop_nmi() semantics. > Yes, having those could be useful to deal with the above and maybe some other places. Thanks, -- Julien Thierry