Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2053334rdb; Mon, 9 Oct 2023 10:53:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzvirUIseCsX53tEx4D8NesU9YA7VGW1oQ4IzQguoZdURr4nIMX10PUtWiOs1flTBYoIyq X-Received: by 2002:a05:6808:1446:b0:3ae:26cb:9756 with SMTP id x6-20020a056808144600b003ae26cb9756mr22074500oiv.3.1696874020709; Mon, 09 Oct 2023 10:53:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696874020; cv=none; d=google.com; s=arc-20160816; b=R2mipXbSeNECPGIOBZ1sSp8TnlgvMCFUBwGPL1tjrMAIphle/lr6+uVMhSN6ms+R0b WlMK/uCxcxjNIWwin6eukkVCIxDfPZkARbkOsfTDNF41+ZU9bcW8RzC9G7trGQdPHnKx gVdt0KCIvd/Gf4rj66VTmrw8XDeua++CLPOOcy892cOai6AUmEXYREuDlixAzhgljsIu gNDvsoPpIqji2bCn1MeX+Vw2qF9Uav5NWMAPlvvUl9+tF0H7SOH5GxrGsvJsWRTc6k7S L20EZVjQC8d1r6HWgrSES4XZ4GLP+3/kRIxvQAmzunLJAdrMbLeY4I3mvmapnd21dsBk Sx6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=IoyXQp0nB/IWm6dvckPcOr8vbJO99u9ZUrMCMrf5qWM=; fh=51rR4qhGrYiduECZyFD8g6KgLvkgq5qU0ylVkeOcF0M=; b=LM6OeMxEn167QjCuCnaZZdnIEaiRI1dgPIbVbnLhPpPli2LJxr2WYCsaAdQwngfylv Cp4XvPQ3mRjoVWbg7XYai2DbuOChBrmmLkIXyYBXN8bOWLIU8RJUpb3813egkimkd+bs gySOcWKDZGdh/bhSA2M0zARFYmaWjuU6wSsxPdtv+HLhXGwGZKBIGFH79eBXMV3d8ts/ WSAh9ioIxFLZ1Pl32xkH1lwBGk02eLpggvAk/6No6RVQ3Z2lkvv9wKEDd4+5566VDRp+ MDztUS5pmW1LEex7gP+SCir7jLqtq5Ko/REgKUl1Meb/JfIpsqSKf8Z8vpCodHJT+khL NOyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XxDesE0p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w190-20020a6382c7000000b00577bf1de778si10022238pgd.585.2023.10.09.10.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:53:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XxDesE0p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9189A801C027; Mon, 9 Oct 2023 10:53:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233372AbjJIRxg (ORCPT + 99 others); Mon, 9 Oct 2023 13:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233250AbjJIRxe (ORCPT ); Mon, 9 Oct 2023 13:53:34 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D71C91 for ; Mon, 9 Oct 2023 10:53:31 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-77575233633so330725885a.0 for ; Mon, 09 Oct 2023 10:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1696874010; x=1697478810; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IoyXQp0nB/IWm6dvckPcOr8vbJO99u9ZUrMCMrf5qWM=; b=XxDesE0pMy1h4OblGmF9MMUOwZYdCFHNb4KAAR56hGOuqVYQc4pKkJWF37JUpKlI7V nBUbXd4Ct3PiZl9RI83vfbjnOb8Qf285XkaKyNwk0lsOloRhFEejqDNK7CGHyoEMsKw5 +sTekenXDJsjQifkatll6qhJITYNFfi+cwljCPEXFn5FK7gaOETJGwPM80W0aamwjCqC 8wuAzE/lpb8ZmksO5k0WbDumNd9PVG3cSbLwAwxj7atewsqreq9ON0qsSP3vzW7dxmWt vNQW0upgpQoP5RhCw6qQlBib70H6G6ykIyMF9sK5gFhp70E6WXe+mcXAqr6cHQudsSUV OgZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696874010; x=1697478810; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IoyXQp0nB/IWm6dvckPcOr8vbJO99u9ZUrMCMrf5qWM=; b=gyGH7pUR/T6DhEIRvuKnYhCMn35JZ+BkZpU0JFiRWVkaBgXxM8YeO3dVoksyv+aWdj Au05JdrOjonZjwRBHWW6ZdREfRqJVB527pSyrdcn/NbJ4Uh67TkNP/917hIXhLCUqwla uqDucKw2ZVHk8gnrhe4W+yHTuQjdHUpRQqJ1SbovQHAVDI+K8/05Ye41Ntu6wAJvOOnb RWgge33B0kgmqsp1mmeZEphlzDZn6/XfNB08LkRvP1BybAGnI+CtUCxvEV4CYPs4SZA6 QFpewxTER+zj1gA/aN151CQIVoQxlwbxBDQxUeiJe0VadBZEfULz+RoL1lcm4KMm9hvy pFSg== X-Gm-Message-State: AOJu0YwZu044buPZ2fEuOAdoULVFZCQJ8WNaFZw3VbOrw1xpTFxZJXGo ppGhImxtjhvqyRSQAj5HgqMfoQ== X-Received: by 2002:a05:620a:16c9:b0:76f:f11:7d1 with SMTP id a9-20020a05620a16c900b0076f0f1107d1mr14894821qkn.77.1696874010272; Mon, 09 Oct 2023 10:53:30 -0700 (PDT) Received: from ?IPV6:2600:1700:2000:b002:41c4:1832:a984:34e2? ([2600:1700:2000:b002:41c4:1832:a984:34e2]) by smtp.gmail.com with ESMTPSA id f10-20020a05620a15aa00b007659935ce64sm3681308qkk.71.2023.10.09.10.53.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 10:53:29 -0700 (PDT) Message-ID: <2047b2c2-bf37-4c02-9297-d89f95863ed5@sifive.com> Date: Mon, 9 Oct 2023 12:53:28 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/4] riscv: Improve flush_tlb() Content-Language: en-US To: Alexandre Ghiti Cc: Andrew Jones , Will Deacon , "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Mayuresh Chitale , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland , Lad Prabhakar References: <20230911131224.61924-1-alexghiti@rivosinc.com> <20230911131224.61924-2-alexghiti@rivosinc.com> From: Samuel Holland In-Reply-To: <20230911131224.61924-2-alexghiti@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 10:53:39 -0700 (PDT) On 2023-09-11 8:12 AM, Alexandre Ghiti wrote: > For now, flush_tlb() simply calls flush_tlb_mm() which results in a s/flush_tlb/tlb_flush/ here and in the subject. Otherwise: Reviewed-by: Samuel Holland > flush of the whole TLB. So let's use mmu_gather fields to provide a more > fine-grained flush of the TLB. > > Signed-off-by: Alexandre Ghiti > Reviewed-by: Andrew Jones > --- > arch/riscv/include/asm/tlb.h | 8 +++++++- > arch/riscv/include/asm/tlbflush.h | 3 +++ > arch/riscv/mm/tlbflush.c | 7 +++++++ > 3 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/include/asm/tlb.h b/arch/riscv/include/asm/tlb.h > index 120bcf2ed8a8..1eb5682b2af6 100644 > --- a/arch/riscv/include/asm/tlb.h > +++ b/arch/riscv/include/asm/tlb.h > @@ -15,7 +15,13 @@ static void tlb_flush(struct mmu_gather *tlb); > > static inline void tlb_flush(struct mmu_gather *tlb) > { > - flush_tlb_mm(tlb->mm); > +#ifdef CONFIG_MMU > + if (tlb->fullmm || tlb->need_flush_all) > + flush_tlb_mm(tlb->mm); > + else > + flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end, > + tlb_get_unmap_size(tlb)); > +#endif > } > > #endif /* _ASM_RISCV_TLB_H */ > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h > index a09196f8de68..f5c4fb0ae642 100644 > --- a/arch/riscv/include/asm/tlbflush.h > +++ b/arch/riscv/include/asm/tlbflush.h > @@ -32,6 +32,8 @@ static inline void local_flush_tlb_page(unsigned long addr) > #if defined(CONFIG_SMP) && defined(CONFIG_MMU) > void flush_tlb_all(void); > void flush_tlb_mm(struct mm_struct *mm); > +void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, > + unsigned long end, unsigned int page_size); > void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); > void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, > unsigned long end); > @@ -52,6 +54,7 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, > } > > #define flush_tlb_mm(mm) flush_tlb_all() > +#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() > #endif /* !CONFIG_SMP || !CONFIG_MMU */ > > /* Flush a range of kernel pages */ > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > index 77be59aadc73..fa03289853d8 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -132,6 +132,13 @@ void flush_tlb_mm(struct mm_struct *mm) > __flush_tlb_range(mm, 0, -1, PAGE_SIZE); > } > > +void flush_tlb_mm_range(struct mm_struct *mm, > + unsigned long start, unsigned long end, > + unsigned int page_size) > +{ > + __flush_tlb_range(mm, start, end - start, page_size); > +} > + > void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) > { > __flush_tlb_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE);