Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7524996imu; Tue, 22 Jan 2019 07:23:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN7GB3oasurb/4XcqH/XeLSKzDQb/7NrxvhPJIP13TO1C3O/VukmFmpnUJ4jl3KENr4txu2E X-Received: by 2002:a63:981:: with SMTP id 123mr32578856pgj.444.1548170623246; Tue, 22 Jan 2019 07:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548170623; cv=none; d=google.com; s=arc-20160816; b=SQ6MCiolky8PK1d1Od8Py6GCddpBsU3sKsZ/oOfwRcwyey7JbHTT73jNS3TW5z6jE5 PkVHTh6d4aDo1rBQwd3G3kOh8aVFz1XlOplpYoestlHkHTdAqd/sXeArItiMQIQ3MCdt FYu1RTCIlnkSJ3KYQgRPnN8MCopPlegJUiqrSd2x76rOfrUITaO3u5V+hFF7zBRYWvDJ CNaEYtPECMDmnNyp/S/AlicOGsi0u6jH4Bv8KKZZeOLoT2Zm/Wzxx/Bq7Mdplbdd5iOH xqM40+lWAiuTIbtlLbVZVvHkbdac3nRm+Rens4xHgfsFxcwspffTYySmxNvVtmZ5W6LS 2Dnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hGDqFw7ULAg3F4NzDMEKM4ZWcKp9uIAfqySPolJtcmE=; b=i5xJqTP8rEvGwX7jADUmWikgrczT8fqPTowWzv/ikDajGVWPtIZU+9UCG1ZxlnJ/k8 2h/ToKPyM/5rCiACSB04Bh+p27Y8TULsVyBUPwP+MaAvF7s9wbNT64EinmwI/Z+Q5Cgj ew46ndwCJJR0arGf84m8Qgz2VZV6C3yCxai1fhcKbxBXg9WJh8G/DGvinX+VLQ7pdBt6 7WhpRVrH74qDYYqeHHA0ql5UjBflid3+zKDbnoDz5PALYIOgf3qmmnc3JSQHFK8PJnhw xpRl4Fu3f1LFnEsOfXDnRCUWhgNNOJplgrgoU5OSXj98RmEYhGDVQWLPEoNFVC5CcMXq haIQ== 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 203si11567089pgb.440.2019.01.22.07.23.27; Tue, 22 Jan 2019 07:23:43 -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 S1729450AbfAVPV4 (ORCPT + 99 others); Tue, 22 Jan 2019 10:21:56 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55696 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728829AbfAVPVy (ORCPT ); Tue, 22 Jan 2019 10:21:54 -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 ED3C3A78; Tue, 22 Jan 2019 07:21:53 -0800 (PST) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.196.113]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA39D3F589; Tue, 22 Jan 2019 07:21:51 -0800 (PST) Date: Tue, 22 Jan 2019 15:21:49 +0000 From: Catalin Marinas To: Julien Thierry Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, christoffer.dall@arm.com, james.morse@arm.com, will.deacon@arm.com, mark.rutland@arm.com, Ard Biesheuvel , Oleg Nesterov Subject: Re: [PATCH v9 12/26] arm64: irqflags: Use ICC_PMR_EL1 for interrupt masking Message-ID: <20190122152149.GD187049@arrakis.emea.arm.com> References: <1548084825-8803-1-git-send-email-julien.thierry@arm.com> <1548084825-8803-13-git-send-email-julien.thierry@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1548084825-8803-13-git-send-email-julien.thierry@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 21, 2019 at 03:33:31PM +0000, Julien Thierry wrote: > 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"); > } Nitpicks: you could drop masked/unmasked variables here (it's up to you, it wouldn't make any difference on the generated asm). > @@ -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; > +} BTW, how's the code generated from the C version? It will have a branch but may not be too bad. Either way is fine by me. Reviewed-by: Catalin Marinas