Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1965880rwo; Thu, 3 Aug 2023 02:40:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlESMQtu4ZULcH25hN+aAB/Ic5Ag5blJeakMVr00yuWcGn2SpwQ8jfGfPgufoTXspSmXVPNQ X-Received: by 2002:ac2:4e06:0:b0:4fd:d6ba:73ba with SMTP id e6-20020ac24e06000000b004fdd6ba73bamr8244605lfr.37.1691055656161; Thu, 03 Aug 2023 02:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691055656; cv=none; d=google.com; s=arc-20160816; b=Mj7iQBZ2UmE6V3V/KEGa6YW/If7l5Rzugs4Wvy/yW4rp9a1UaHKeQziNe+QRL+RSTm bN3kt9phwfpDozNQu1jUyvACuwpGhW4Mwcc39sfWQwYLqDiHkEuQXMvIfj0ZhdcweOYd gapyF245S0Kc7o3odCb4ynAgwRhniWgSCbSTfAFgOhcjE+2diQJ7Eok2HeDbK2o8YnHl 34ETXhx1Uxzu49rlPHPheUNbML2im+oTfj8WhvH01jDPfuteiyz1o2MVmjAqpgA42NCF +sC6cf5mJXVvhJ6QAAFeyPz+ULCEfCH5c9EEZmwgiXPsh81jpKhm0rU90m71WBR0CelO F2ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/P3JSbQ5B0NSJAuHeE2g8Wm0ulaaLaGIgFBuN0gi4fA=; fh=k+IF/KrDVP7NJ7k70ieIGz1h9rz7vbr/vc2Io6cn/lo=; b=z9DJAuO1dS/jnSBQEa7IW51/GffrHQ8GMRCulVEFaPrVfZzjSaL96/2QHmz0yOYXTA yEVmO7k/j5/jfTmtQdvqxrIFJ3n015TrzFXpUtDBNza8yud8o+gFIVJOaQV8wPi4ZkaE JftSE9ccwkgu9ArlDLU+rq/CJNLVCt5AxvZt3+riPF3Jhe/nYx8BfVE3F4xN8pSDLmio Lhgx8OFhlHxLqPgeYoG/k00oh9563liwL0VP9dnbzN0UgJ9nsIv/lWyqCmaTf/RFvoGv 8oNgGbO4Ryw6JtzNZI5nBSMTCa677w4IvCYcH+CxdRqP1JPZcy+ke240J1KD9t6t6SuG Ia7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020aa7d455000000b0052254b379b1si11369972edr.165.2023.08.03.02.40.30; Thu, 03 Aug 2023 02:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232051AbjHCJOa (ORCPT + 99 others); Thu, 3 Aug 2023 05:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbjHCJO1 (ORCPT ); Thu, 3 Aug 2023 05:14:27 -0400 Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 083CFAC for ; Thu, 3 Aug 2023 02:14:24 -0700 (PDT) Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 3739EJV0017070; Thu, 3 Aug 2023 17:14:19 +0800 (+08) (envelope-from dylan@andestech.com) Received: from atctrx.andestech.com (10.0.15.173) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 3 Aug 2023 17:14:16 +0800 Date: Thu, 3 Aug 2023 17:14:15 +0800 From: dylan To: Guo Ren CC: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , , Subject: Re: [PATCH -fixes] riscv: Implement flush_cache_vmap() Message-ID: References: <20230725132246.817726-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) X-Originating-IP: [10.0.15.173] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 3739EJV0017070 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sun, Jul 30, 2023 at 01:08:17AM -0400, Guo Ren wrote: > On Tue, Jul 25, 2023 at 9:22 AM Alexandre Ghiti wrote: > > > > The RISC-V kernel needs a sfence.vma after a page table modification: we > > used to rely on the vmalloc fault handling to emit an sfence.vma, but > > commit 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for > > vmalloc/modules area") got rid of this path for 64-bit kernels, so now we > > need to explicitly emit a sfence.vma in flush_cache_vmap(). > > > > Note that we don't need to implement flush_cache_vunmap() as the generic > > code should emit a flush tlb after unmapping a vmalloc region. > > > > Fixes: 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") > > Signed-off-by: Alexandre Ghiti > > --- > > arch/riscv/include/asm/cacheflush.h | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h > > index 8091b8bf4883..b93ffddf8a61 100644 > > --- a/arch/riscv/include/asm/cacheflush.h > > +++ b/arch/riscv/include/asm/cacheflush.h > > @@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page) > > #define flush_icache_user_page(vma, pg, addr, len) \ > > flush_icache_mm(vma->vm_mm, 0) > > > > +#ifdef CONFIG_64BIT > > +#define flush_cache_vmap(start, end) flush_tlb_kernel_range(start, end) > Sorry, I couldn't agree with the above in a PIPT cache machine. It's > not worth for. > > It would reduce the performance of vmap_pages_range, > ioremap_page_range ... API, which may cause some drivers' performance > issues when they install/uninstall memory frequently. > Hi All, I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB. The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created. There are currently two possible approaches to flush TLB: 1. Flush TLB in flush_cache_vmap() 2. Flush TLB in arch_sync_kernel_mappings() But I'm not quite sure if it's a good idea to operate on the TLB inside flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush in arch_sync_kernel_mappings()? [1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html Best regards, Dylan > > +#endif > > + > > #ifndef CONFIG_SMP > > > > #define flush_icache_all() local_flush_icache_all() > > -- > > 2.39.2 > > > > > -- > Best Regards > Guo Ren > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv