Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp625329imu; Wed, 23 Jan 2019 02:45:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN4LtqUR2pE4fiLqdiBnD99+LpdlsnjCFugMi/AmktE939ePGOT+ncqssFzJk40dHtZzR9JJ X-Received: by 2002:a62:ae04:: with SMTP id q4mr1593819pff.126.1548240358761; Wed, 23 Jan 2019 02:45:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548240358; cv=none; d=google.com; s=arc-20160816; b=vGor5Lwpt3CyUDFcp95ZvFgCa1+rJsH52R2QNAeoIMkaS4Cott+b7vwuXeo5cW63o7 t714iEtxI/mJkRcBiVnw6RGjgaz01+E8VGwAX2Kp6eteomvEjdKcUF+j5SVMawQmxx/m Fm1Hcxz0X7baNtZJLmU5lKrppwwIBO4cFRAPm1uTyNPPYWcxSl5hdaeeV2jD6x+zThZG K7lZyMqLDn8rNYfFkaM29r7fN0JMORCjYqXkeV1XL4pKKFFVLxzXYVqondlBV91tcGz8 Gs2KBV7bdg2c0rWeAyCqtNzMyinNEFYydsjxN/sIHygkAMVta/ExHGvdGv5XGrHB2E7G nLJA== 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=g2epIOnvIgh9gABTCTXqjWxe8CNpJF49ZwkgSyeK3ns=; b=GIVHPQYHPVTL0SozTEg2WRDTh6wAtYwg/DkJuUrDnnLc2DGCf7ZW0+DCTTAN1DYJle R+f2tIOor0ukCNVu96g0prcsMc0Mdr7DysU1JyCKitG5td9hhv00dScIYBepvxtZpncn XEWOIurogR8JJd0uo6vPGkpYoHcInA1WLeWSdh0SD7X/qEQn5EZAYoyuLFNYMkc3dXtv gUR/ZSefivLCWxCSFMrNo57kkuVLJ0ELkrEe43IEbw1rILKyZkitAGPGL6s2C+MqElbg pJvwiL5REtqTBzn90o2GamN0yk85ylBDOgdLfo6yCsYB1dmipHMHHAa+EgqsKvSsydJy QGjg== 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 85si17507199pfc.145.2019.01.23.02.45.43; Wed, 23 Jan 2019 02:45:58 -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 S1727430AbfAWKog (ORCPT + 99 others); Wed, 23 Jan 2019 05:44:36 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39256 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbfAWKof (ORCPT ); Wed, 23 Jan 2019 05:44:35 -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 1C22A15AB; Wed, 23 Jan 2019 02:44: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 13B3C3F5C1; Wed, 23 Jan 2019 02:44:32 -0800 (PST) Subject: Re: [PATCH v9 12/26] arm64: irqflags: Use ICC_PMR_EL1 for interrupt masking To: Catalin Marinas 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 References: <1548084825-8803-1-git-send-email-julien.thierry@arm.com> <1548084825-8803-13-git-send-email-julien.thierry@arm.com> <20190122152149.GD187049@arrakis.emea.arm.com> From: Julien Thierry Message-ID: <2eabb029-4efe-6829-7fb1-6174a2edb154@arm.com> Date: Wed, 23 Jan 2019 10:44: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: <20190122152149.GD187049@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 22/01/2019 15:21, Catalin Marinas wrote: > 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). > Good point, I'll do that. >> @@ -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. > It's a bit hard to talk about the code generated from the C version as it can lie within several layers of inline, so the instructions for that section are a bit more scattered. However, it seems like the compiler is more clever (maybe the asm volatile prevents some optimizations regarding register allocation or instruction ordering) and the C version seems to perform slightly better (although it could be within the noise) despite the branch. So, I'll just switch up to the C version. > Reviewed-by: Catalin Marinas > -- Julien Thierry