Received: by 10.213.65.68 with SMTP id h4csp550966imn; Tue, 27 Mar 2018 04:35:56 -0700 (PDT) X-Google-Smtp-Source: AG47ELu7HEaAhSl+cFKimdS+dqY3RzGMNwX/li7nTUmU8bnyAS6Dju6D2+3pNp0I68dbvCgYzDcq X-Received: by 10.101.69.1 with SMTP id n1mr11564419pgq.12.1522150556297; Tue, 27 Mar 2018 04:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522150556; cv=none; d=google.com; s=arc-20160816; b=OHy+Rv/Dky/5JZ7XADrLlIQGxauggFcmBElSu/2yBqMej91W5RGwSHJ6UnznEHG7WK F7EFKOWObTTuk2PLtaSbFwQFDo/OWYHChJncHpKws1yBuXoqdsvN1v/6fRbBMNga7Hor ls8iG1vSVpvxY8nMd9h9UtEl8DLsUGWL6faFhfFcEZlYasaxhoNphV8vEjH7Kgmf21Pu W4JZBF9wbschtOxd/MilFIuDJ0q369TOWzzKtmK1MocUkyrbnKo+utV5OTOvi4vrSYgT de5jfaHRtobtAWDQxB/nK8LlfXTPcxIkF07AUKdVhVbg3vmyU1SoJZghjBCmDxAa0Ha0 wibw== 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:arc-authentication-results; bh=3oblvZFpJtmorYLQSVo464FS3TUyim+mRAiELE9kFbE=; b=EJVBwKXmZiSpjndJ/1GaKvEHH4qtn31h05uQCK5QGZu2HlvPTQu7vd94FOcOTcuYcV 6DxPb8nNBDnHl34392cNCJZCmVYouisf74+Qm0ZjnzLNdndxL+rGXCn1jDcwst8Tov4i a4s7B8vuZIq+jk6b/aooHMxuV77xkTrzzFALXnPnheBVduaXQyp5UcW11rZiwntzAFqp q+kDefL7mXJR7ReT2xc1JEfu53WZvOrtxfiCzrxfnFjO2U0TR0gB+BqhYNBNES7ED7FT DFo7Jh1EcYTnQX9hfqeK0legqz8S0Cttmv+vjTInDEqywgYTMKC7wF0noYsC9ZvToZdu +uoQ== 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 m9-v6si1037846plk.464.2018.03.27.04.35.41; Tue, 27 Mar 2018 04:35:56 -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 S1752180AbeC0Len (ORCPT + 99 others); Tue, 27 Mar 2018 07:34:43 -0400 Received: from foss.arm.com ([217.140.101.70]:53278 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751092AbeC0Lek (ORCPT ); Tue, 27 Mar 2018 07:34:40 -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 5306480D; Tue, 27 Mar 2018 04:34:40 -0700 (PDT) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EEA713F590; Tue, 27 Mar 2018 04:34:38 -0700 (PDT) Subject: Re: [PATCH V2] arm64: tlbflush: avoid writing RES0 bits To: Philip Elcan , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Mark Rutland , linux-kernel@vger.kernel.org Cc: Thomas Speier , Shanker Donthineni References: <1522120877-9136-1-git-send-email-pelcan@codeaurora.org> From: Robin Murphy Message-ID: <985a0edd-e388-dade-8824-30cc58a236f3@arm.com> Date: Tue, 27 Mar 2018 12:34:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1522120877-9136-1-git-send-email-pelcan@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed 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 27/03/18 04:21, 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 | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h > index 9e82dd7..b1205e9 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; \ > + }) I'd be inclined to make this a static inline function rather than a macro, since it doesn't need to do any wacky type-dodging, but either way the overall change now looks appropriate; Acked-by: Robin Murphy Thanks, Robin. > + > /* > * 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); > @@ -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); >