Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6511029imu; Mon, 21 Jan 2019 10:07:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN7vqi8/8hiDzI7Mn/9r9k8VoK9KXzDJCkFZ1zrgdQJLTBiW0B6vexKXXnZAjtc9pVcWbU27 X-Received: by 2002:a17:902:1105:: with SMTP id d5mr30070566pla.47.1548094073449; Mon, 21 Jan 2019 10:07:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548094073; cv=none; d=google.com; s=arc-20160816; b=Hj6vNVtUNLd0INwLsv5KJBRv0dqi+N9K9SY81v11NSdo25YHgoGBrIDk5gW6uClg/o ft9ZebopOS0rs8mS8/XMGefo6fKioZoZef/+BSzWKXihZqKYi+hxJZRGYRqWreWeV4Ob BNYsPHl5ICbcc2AAvzDKgcDLt+3x7AjVHkhMwEWP/LpW2JwZwylRrhocetVK8JD0ar01 YGVB90ozVSt/uBQ87R7K2TK12kG1B0bxbvxOmPO+QyIsYIwv+yt0ft3bdzSz3sM9FmFx 6/A9JQ9Q6dolBjOAffxSKEQsslEvZTc+z7eU6PCI2f4rnPjnSK0+Tcuuv6wNgYhvAqgP AAFw== 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=1lh+oQexibDs8YYY/vEY3m5q4VWQo68NoKsYBthxkRM=; b=MTq9UGv4HWDdwcC8lfU0wkCTJP3YwMG8GyIW9yoh+usCMg8k3TYVSBcBHK00CpwbTC GvO98a6J8mxhNWJXtAc/LT0aabc+NglY+JdP7303nrouTKJ7RMvmNg0BN95yQ4L8fv4a Ib48pGE4YziVq7+yE+qOXZTXgsAovA0ZCvWNAy153dgyWhiJdEM3Do77Q6A9ssC54RiL mCuLRaouStjhIsRk/Jxh9dcZ3HprXTISH7pTsqzNMal4keipQclr5qRWi/2mP9Uq87Qj INNwvX5HPcNsc9xuoxt6y3tIAMBcc8My+nzYNte8JYqspHhPCJq8qXX0ARLXyAGKBrtk vl3g== 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 s123si8762368pgs.93.2019.01.21.10.07.38; Mon, 21 Jan 2019 10:07:53 -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 S1727599AbfAUSFg (ORCPT + 99 others); Mon, 21 Jan 2019 13:05:36 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:40606 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAUSFg (ORCPT ); Mon, 21 Jan 2019 13:05:36 -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 B118315AB; Mon, 21 Jan 2019 10:05:35 -0800 (PST) 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 7EC943F6A8; Mon, 21 Jan 2019 10:05:32 -0800 (PST) Subject: Re: [PATCH v9 12/26] arm64: irqflags: Use ICC_PMR_EL1 for interrupt masking To: Ard Biesheuvel Cc: linux-arm-kernel , Linux Kernel Mailing List , Daniel Thompson , Joel Fernandes , Marc Zyngier , Christoffer Dall , James Morse , Catalin Marinas , Will Deacon , Mark Rutland , Oleg Nesterov References: <1548084825-8803-1-git-send-email-julien.thierry@arm.com> <1548084825-8803-13-git-send-email-julien.thierry@arm.com> From: Julien Thierry Message-ID: <35daeeda-c3fe-83bb-09ee-77480064c67d@arm.com> Date: Mon, 21 Jan 2019 18:05:31 +0000 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: 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 21/01/2019 15:45, Ard Biesheuvel wrote: > On Mon, 21 Jan 2019 at 16:34, Julien Thierry wrote: >> >> Instead disabling interrupts by setting the PSR.I bit, use a priority >> higher than the one used for interrupts to mask them via PMR. >> >> When using PMR to disable interrupts, the value of PMR will be used >> instead of PSR.[DAIF] for the irqflags. >> >> Signed-off-by: Julien Thierry >> Suggested-by: Daniel Thompson >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: Ard Biesheuvel >> Cc: Oleg Nesterov >> --- >> arch/arm64/include/asm/efi.h | 6 +++ >> arch/arm64/include/asm/irqflags.h | 104 ++++++++++++++++++++++++++++---------- >> 2 files changed, 82 insertions(+), 28 deletions(-) >> >> diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h >> index 7ed3208..3db6772 100644 >> --- a/arch/arm64/include/asm/efi.h >> +++ b/arch/arm64/include/asm/efi.h >> @@ -44,6 +44,12 @@ >> >> #define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) >> >> +#define arch_efi_save_flags(state_flags) \ >> + ((void)((state_flags) = read_sysreg(daif))) >> + >> +#define arch_efi_restore_flags(state_flags) write_sysreg(state_flags, daif) >> + >> + >> /* arch specific definitions used by the stub code */ >> >> /* > > For the EFI changes > > Acked-by: Ard Biesheuvel Thanks! > > although it deserves a comment as to why it is unaffected by > ARM64_HAS_IRQ_PRIO_MASKING So far we've relied on EFI not modifying PMR, otherwise we could've ended up without any interrupts in Linux after coming back from an EFI service. Now, the ARM64_HAS_IRQ_PRIO_MASKING only modifies the behaviour of Linux, but we should have the same expectations from EFI. If we want to be paranoid we could save/restore PMR along with the DAIF flags. But you're right, it is fair to add a comment clearly stating that we expect EFI not to modify PMR. I'll include that in the next posting. Thanks, Julien > > >> diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h >> index 24692ed..7e82a92 100644 >> --- a/arch/arm64/include/asm/irqflags.h >> +++ b/arch/arm64/include/asm/irqflags.h >> @@ -18,7 +18,9 @@ >> >> #ifdef __KERNEL__ >> >> +#include >> #include >> +#include >> >> /* >> * Aarch64 has flags for masking: Debug, Asynchronous (serror), Interrupts and >> @@ -36,33 +38,31 @@ >> /* >> * CPU interrupt mask handling. >> */ >> -static inline unsigned long arch_local_irq_save(void) >> -{ >> - unsigned long flags; >> - asm volatile( >> - "mrs %0, daif // arch_local_irq_save\n" >> - "msr daifset, #2" >> - : "=r" (flags) >> - : >> - : "memory"); >> - return flags; >> -} >> - >> static inline void arch_local_irq_enable(void) >> { >> - asm volatile( >> - "msr daifclr, #2 // arch_local_irq_enable" >> - : >> + unsigned long unmasked = GIC_PRIO_IRQON; >> + >> + asm volatile(ALTERNATIVE( >> + "msr daifclr, #2 // arch_local_irq_enable\n" >> + "nop", >> + "msr_s " __stringify(SYS_ICC_PMR_EL1) ",%0\n" >> + "dsb sy", >> + ARM64_HAS_IRQ_PRIO_MASKING) >> : >> + : "r" (unmasked) >> : "memory"); >> } >> >> static inline void arch_local_irq_disable(void) >> { >> - asm volatile( >> - "msr daifset, #2 // arch_local_irq_disable" >> - : >> + unsigned long masked = GIC_PRIO_IRQOFF; >> + >> + asm volatile(ALTERNATIVE( >> + "msr daifset, #2 // arch_local_irq_disable", >> + "msr_s " __stringify(SYS_ICC_PMR_EL1) ", %0", >> + ARM64_HAS_IRQ_PRIO_MASKING) >> : >> + : "r" (masked) >> : "memory"); >> } >> >> @@ -71,12 +71,44 @@ static inline void arch_local_irq_disable(void) >> */ >> static inline unsigned long arch_local_save_flags(void) >> { >> + unsigned long daif_bits; >> unsigned long flags; >> - asm volatile( >> - "mrs %0, daif // arch_local_save_flags" >> - : "=r" (flags) >> - : >> + >> + daif_bits = read_sysreg(daif); >> + >> + /* >> + * The asm is logically equivalent to: >> + * >> + * if (system_uses_irq_prio_masking()) >> + * flags = (daif_bits & PSR_I_BIT) ? >> + * GIC_PRIO_IRQOFF : >> + * read_sysreg_s(SYS_ICC_PMR_EL1); >> + * else >> + * flags = daif_bits; >> + */ >> + asm volatile(ALTERNATIVE( >> + "mov %0, %1\n" >> + "nop\n" >> + "nop", >> + "mrs_s %0, " __stringify(SYS_ICC_PMR_EL1) "\n" >> + "ands %1, %1, " __stringify(PSR_I_BIT) "\n" >> + "csel %0, %0, %2, eq", >> + ARM64_HAS_IRQ_PRIO_MASKING) >> + : "=&r" (flags), "+r" (daif_bits) >> + : "r" (GIC_PRIO_IRQOFF) >> : "memory"); >> + >> + return flags; >> +} >> + >> +static inline unsigned long arch_local_irq_save(void) >> +{ >> + unsigned long flags; >> + >> + flags = arch_local_save_flags(); >> + >> + arch_local_irq_disable(); >> + >> return flags; >> } >> >> @@ -85,16 +117,32 @@ static inline unsigned long arch_local_save_flags(void) >> */ >> static inline void arch_local_irq_restore(unsigned long flags) >> { >> - asm volatile( >> - "msr daif, %0 // arch_local_irq_restore" >> - : >> - : "r" (flags) >> - : "memory"); >> + asm volatile(ALTERNATIVE( >> + "msr daif, %0\n" >> + "nop", >> + "msr_s " __stringify(SYS_ICC_PMR_EL1) ", %0\n" >> + "dsb sy", >> + ARM64_HAS_IRQ_PRIO_MASKING) >> + : "+r" (flags) >> + : >> + : "memory"); >> } >> >> static inline int arch_irqs_disabled_flags(unsigned long flags) >> { >> - return flags & PSR_I_BIT; >> + int res; >> + >> + asm volatile(ALTERNATIVE( >> + "and %w0, %w1, #" __stringify(PSR_I_BIT) "\n" >> + "nop", >> + "cmp %w1, #" __stringify(GIC_PRIO_IRQOFF) "\n" >> + "cset %w0, ls", >> + ARM64_HAS_IRQ_PRIO_MASKING) >> + : "=&r" (res) >> + : "r" ((int) flags) >> + : "memory"); >> + >> + return res; >> } >> #endif >> #endif >> -- >> 1.9.1 >> -- Julien Thierry