Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4987538rwb; Tue, 8 Aug 2023 18:11:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzosWd4GZ1qqsVAJpI2Wxm43T5WBeS7BfF12tGV0nxmQHy4lHaYmsk2bbM3eQ/cNKqL15j X-Received: by 2002:a05:6a21:998b:b0:13d:5b8e:db83 with SMTP id ve11-20020a056a21998b00b0013d5b8edb83mr1452730pzb.9.1691543512625; Tue, 08 Aug 2023 18:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691543512; cv=none; d=google.com; s=arc-20160816; b=zkrsxY+65JU9rxQMT0PVOaWBRG6fZqoqkK3m0stgEteDMU+Aww1tcD+h41giROjaFx IvLjLfpu1Ci3j3nnS5SOuIs7Y2MGiSmfdXRm/s8HmuP4DrSvsoz6dUd4fvIOyaWZvI55 L0wORkKjDEGZB+8URO3aaRGUqmAlCp6cxRHBKb9lB5UDGdZIGbZPxPKmndkHVvJ3L6fT 0WUzDLmJJOl687PanhuPkADqB6iolFtIa5odMpPvG4i7RdqTuv9zjlt3GsrNMKYbGUvN O59lgC4NOXOqzAJrMKumbINmDR2C1mNiGtqtNPfRrfaZY4MjSP7k8+72url5QWu8R91l /9kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=iGE76MJt7nfUHC+AIX5b4rwN648fcJcK6b14gOIValU=; fh=UCZmxIQvdquKbmPdDjikoMlX8HKdABy0ry+hCKjOEi4=; b=bNbUQNsH9jO862hAmUXMs6ev/jofHzpaQRqt80vvRmH4MJzWep/GYVdqSmLwf4P7qp VIKGkVnavmveF9cefm02/3PxTXiCmv16NmPBgJTP7ziG3QZ0iAyn/j1QTE860wq5fCYr y+DkYKc0juVADW8qyXIe1PHrhXWgL8oYUtkgpeUIt/1bk1enua+qwMsDUeGhiQCnpEvY 7NlxtuQeP6bDQgYOykzgNxhkMrZo1hKzYo95yvZ5RKJQqakSFqpHOQdKJqRyJijUxoY8 tD+9uYDK1rvPmX1N1LPiXKtyOaD9cULWgleRQlpF5HX8VE/wv96fy/+szdQkscEauctu lRjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z7Ax2CJ1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ce11-20020a056a002a0b00b006876299bc18si8172333pfb.286.2023.08.08.18.11.40; Tue, 08 Aug 2023 18:11:52 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z7Ax2CJ1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbjHHXrq (ORCPT + 99 others); Tue, 8 Aug 2023 19:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjHHXrp (ORCPT ); Tue, 8 Aug 2023 19:47:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C457F0 for ; Tue, 8 Aug 2023 16:47:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 20D1B62E4B for ; Tue, 8 Aug 2023 23:47:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81503C433D9 for ; Tue, 8 Aug 2023 23:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691538463; bh=389UaCJRCPWbGhB538d72pDJuAiVDJ/Ht7Zki/SMrHw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Z7Ax2CJ1h6ttitp46s+XIWct3qdaEHuFoRUIICdcSOQfk5ZGeIoHwmYAcxnTg3nGZ zLzKcMgvEebiIhvKgbEytj99g/mj94rgeGhh1vL/KRSmVyg6JtwbzlBukKkVGFN327 On7fungrwYtaOW6Hod6BYnuyzfzNyETzGUHgCfty1Km/V4DeRjdB4B6VapNdI/4Mho kEyK7ZKcLJO7Ulr248KHrhE4L6AHfDjqRN4w/a9mlBMYIH56LJ7bn/w4K5S981dip7 GbzyTd6ddQAsTD+9f/NjoRozXmEHh7CTEFsm6jtKSf01ea3P7grGxW/3d06E8xKEXx x+eBNwKsq+x/A== Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-99c47ef365cso919805066b.0 for ; Tue, 08 Aug 2023 16:47:43 -0700 (PDT) X-Gm-Message-State: AOJu0YxfsnZir6uChwIEfRyWb+QFkrftFpD3jaeoJLedPYnLP8CHqyTh mEeH7L2dK0B2nOA1WNVkRk5zzXrKKrJpMEJO7kY= X-Received: by 2002:a17:906:84:b0:99b:674c:44eb with SMTP id 4-20020a170906008400b0099b674c44ebmr945758ejc.9.1691538461697; Tue, 08 Aug 2023 16:47:41 -0700 (PDT) MIME-Version: 1.0 References: <20230725132246.817726-1-alexghiti@rivosinc.com> In-Reply-To: From: Guo Ren Date: Wed, 9 Aug 2023 07:47:30 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH -fixes] riscv: Implement flush_cache_vmap() To: dylan Cc: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Thu, Aug 3, 2023 at 5:14=E2=80=AFPM dylan wrote: > > On Sun, Jul 30, 2023 at 01:08:17AM -0400, Guo Ren wrote: > > On Tue, Jul 25, 2023 at 9:22=E2=80=AFAM 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 no= w 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 gene= ric > > > 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 perfo= rmance > in this case. The "preventive" SFENCE.VMA became necessary due to the RIS= C-V > specification allowing invalidation entries to be cached in the TLB. > > The problem[1] we are currently encountering is caused by not updating th= e TLB > after the page table is created, and the solution to this problem can onl= y 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 f= lush_cache_vmap(). > The name of this function indicates that it should be related to cache op= erations, 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 Not all machines need it, and some CPUs prevent PTE.V=3D0 into TLB during PTW, which is stronger than ISA's requirement. So could we put an errata alternative here? > > 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 --=20 Best Regards Guo Ren