Received: by 10.213.65.68 with SMTP id h4csp271989imn; Wed, 28 Mar 2018 03:20:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+g0/vkFrG1cIP3jAFGUmKSQmRfJWtK3bihdBwgg2M+SakX9sLG151k9Rmc9p1+LAkCMorp X-Received: by 10.98.200.130 with SMTP id i2mr2444953pfk.221.1522232451211; Wed, 28 Mar 2018 03:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522232451; cv=none; d=google.com; s=arc-20160816; b=SRUPYLlrn7EPH3sVRlUWxXQf8mL1PqNhD8b471c/m1Uhe6FTlSMd+/vnWV15PFh8iQ 5prtxPrXZOe5979GIMXRqCZdEPjw5GAn5BuVW2vCHUoIOFGGDa6S9eO5nDcyTy6I0yA6 nhW/fPOlfWs4f0e+du1Y8vK6MJuBAnWCW77xZYdM0IefIci7tykvS/NJ0EAdmxzdGEgJ 6tt9XZIW0y+lZZVmn+FXlHFuKetbISIIxPx21xztl4tSTTR6oigzWNpIULa+79vgBg7w qWrWHWOBnO3Q1/q6loZk9kUigkvLyJPcH7mODuzOfwXez9Qr9dDJxhzQNK5ZLiPtA12T rbog== 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:arc-authentication-results; bh=Mqjnx/jJT7xcSb5hhPcpedFWwl4HXYcq3dAQ+SDnNXQ=; b=PAPx8B03drzGWSajR0tumBHori9sPBcLr4jnBbNYasb/ATu4UoA6GIKew/zQlYwkgU COCOlm6dkQK5bJ+KRtgjitkNoGDAiBfhhWO6cYed1WvoDWBpRT00Lf4tY6DmCT7ZJvwI e8kPyb56S+78V23jeUG61mxGW9ldHLinrQF7qEXiU9HPMD8Q6D1u/sxQtuBYYCXTiA7O A+wOyaOZuf3UyNCq4Rr+NbLN0/Jp9TKvebU0UQ+cUdljUyjY3ytButCLaXAkKkdQF2/4 PTi5WPE3s/TOw+SN64OCdxzyujzARsu4yD78qAmza8VeyHh9QmDysa9p7Sbpvy5lhy+Q lLvg== 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 h1-v6si3486255pli.645.2018.03.28.03.20.36; Wed, 28 Mar 2018 03:20:51 -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 S1752106AbeC1KTg (ORCPT + 99 others); Wed, 28 Mar 2018 06:19:36 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39078 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750799AbeC1KTf (ORCPT ); Wed, 28 Mar 2018 06:19:35 -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 9479B1529; Wed, 28 Mar 2018 03:19:34 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1CEEA3F590; Wed, 28 Mar 2018 03:19:32 -0700 (PDT) Date: Wed, 28 Mar 2018 11:19:30 +0100 From: Mark Rutland To: Philip Elcan Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Robin Murphy , linux-kernel@vger.kernel.org, Thomas Speier , Shanker Donthineni Subject: Re: [PATCH V3] arm64: tlbflush: avoid writing RES0 bits Message-ID: <20180328101928.tidudm6p4rtqie44@lakrids.cambridge.arm.com> References: <1522202132-16998-1-git-send-email-pelcan@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522202132-16998-1-git-send-email-pelcan@codeaurora.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 27, 2018 at 09:55:32PM -0400, Philip Elcan wrote: > Several of the bits of the TLBI register operand are RES0 per the ARM > ARM, so TLBI operations should avoid writing non-zero values to these > bits. > > This patch adds a macro __TLBI_VADDR(addr, asid) that creates the > operand register in the correct format and honors the RES0 bits. > > Signed-off-by: Philip Elcan > --- > arch/arm64/include/asm/tlbflush.h | 25 +++++++++++++++++-------- > 1 file changed, 17 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h > index 9e82dd7..dfc61d7 100644 > --- a/arch/arm64/include/asm/tlbflush.h > +++ b/arch/arm64/include/asm/tlbflush.h > @@ -60,6 +60,15 @@ > __tlbi(op, (arg) | USER_ASID_FLAG); \ > } while (0) > > +/* This macro creates a properly formatted VA operand for the TLBI */ > +#define __TLBI_VADDR(addr, asid) \ > + ({ \ > + unsigned long __ta = (addr) >> 12; \ > + __ta &= GENMASK_ULL(43, 0); \ > + __ta |= (unsigned long)(asid) << 48; \ > + __ta; \ > + }) As a minor nit, we typically don't indent the start of the macro function body, and we could drop the leading tab on each line, but either way: Acked-by: Mark Rutland Thanks, Mark. > + > /* > * TLB Management > * ============== > @@ -117,7 +126,7 @@ static inline void flush_tlb_all(void) > > static inline void flush_tlb_mm(struct mm_struct *mm) > { > - unsigned long asid = ASID(mm) << 48; > + unsigned long asid = __TLBI_VADDR(0, ASID(mm)); > > dsb(ishst); > __tlbi(aside1is, asid); > @@ -128,7 +137,7 @@ static inline void flush_tlb_mm(struct mm_struct *mm) > static inline void flush_tlb_page(struct vm_area_struct *vma, > unsigned long uaddr) > { > - unsigned long addr = uaddr >> 12 | (ASID(vma->vm_mm) << 48); > + unsigned long addr = __TLBI_VADDR(uaddr, ASID(vma->vm_mm)); > > dsb(ishst); > __tlbi(vale1is, addr); > @@ -146,7 +155,7 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, > unsigned long start, unsigned long end, > bool last_level) > { > - unsigned long asid = ASID(vma->vm_mm) << 48; > + unsigned long asid = ASID(vma->vm_mm); > unsigned long addr; > > if ((end - start) > MAX_TLB_RANGE) { > @@ -154,8 +163,8 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, > return; > } > > - start = asid | (start >> 12); > - end = asid | (end >> 12); > + start = __TLBI_VADDR(start, asid); > + end = __TLBI_VADDR(end, asid); > > dsb(ishst); > for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) { > @@ -185,8 +194,8 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end > return; > } > > - start >>= 12; > - end >>= 12; > + start = __TLBI_VADDR(start, 0); > + end = __TLBI_VADDR(end, 0); > > dsb(ishst); > for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) > @@ -202,7 +211,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end > static inline void __flush_tlb_pgtable(struct mm_struct *mm, > unsigned long uaddr) > { > - unsigned long addr = uaddr >> 12 | (ASID(mm) << 48); > + unsigned long addr = __TLBI_VADDR(uaddr, ASID(mm)); > > __tlbi(vae1is, addr); > __tlbi_user(vae1is, addr); > -- > Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. > Qualcomm Technologies, Inc. is a member of the > Code Aurora Forum, a Linux Foundation Collaborative Project. >