Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1363003pxb; Sun, 11 Apr 2021 17:14:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqfE84D+Zg6hdn7VYKMy9jrxgCiZcDdKASKfTcNVQQmQztE+8Kgl4c9BbHX3lpWgB3K982 X-Received: by 2002:a65:6907:: with SMTP id s7mr24332515pgq.296.1618186463861; Sun, 11 Apr 2021 17:14:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618186463; cv=none; d=google.com; s=arc-20160816; b=i3jdwOGP/0tt0wpcQTOQdRqzyFQrvLR5to4chn5DQL1BRMxjQLnWVntxJuRKTVyyiF 6hILb1n3yXCkWv+zvTmaPCPm5VDAAXoCIPQH6TeP5IDB9P5DRewfpw9zVPklVxwExTIh FQxgvJsAcHD69h9fJL9MRrr+iJl+FIOuoTC45zmMnFh5xdJI3TvxRpIPnuTFqFcJalD3 vgPIeonFuBanZa32+R05ngNfvtX4zlbn/34/sYR/2Gwwphe+mWcLdy6i3xG9RPZvE6V0 hFWsaA2QqZombn9ql6qpqsOTa348GiUsDN/aviP4wrc2c7eZLFZDE75xNJ7+Sy4UWACn CLZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lsO9wDeiKRkCueWk+Uo59AFUAIZUeyl1sLeiaU6tHFA=; b=wTzhwKhLjil3Mpa+ZeYFvHZPA4LZMjVAVxJi8QuqGxUyHVKkcZr3Tfk1SctlbGttMo FvuhfXSao9XfD8M/R/iCPpjcrDgPZMPYBuHYNyyTzK+lZfAzjE3e2qxkh+phpPYzWlI9 lGZD/2YxTSpdCsHPJ//v9Sukg6GEp8OEcKLLLUeMm3IvN/mvRmMtkKCePECzct5g2zNN t9qo1Zn8UevMV7GhWq/DISOn+BL3hWzG9dLav+30xwdex4MCnLi3cPJkcLgVhWjvRnYp ygwNIl3GQoyc1T1LXEMXmlnbzw9bp2XDHt86o0D8NRaPoO0DH1/XvKnjVGFJthDGXVbX 5keQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jiuyang-me.20150623.gappssmtp.com header.s=20150623 header.b=K2tDKT4x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nv17si11285684pjb.65.2021.04.11.17.14.07; Sun, 11 Apr 2021 17:14:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@jiuyang-me.20150623.gappssmtp.com header.s=20150623 header.b=K2tDKT4x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235484AbhDLANz (ORCPT + 99 others); Sun, 11 Apr 2021 20:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235229AbhDLANy (ORCPT ); Sun, 11 Apr 2021 20:13:54 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69F2C061574 for ; Sun, 11 Apr 2021 17:13:37 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id z22-20020a17090a0156b029014d4056663fso6105316pje.0 for ; Sun, 11 Apr 2021 17:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jiuyang-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lsO9wDeiKRkCueWk+Uo59AFUAIZUeyl1sLeiaU6tHFA=; b=K2tDKT4xzKymCVMPHvadEmcdm0a1x8aLaFoaG5MQe4e+Xn4naDTC8Nc4pWtKyrJr6I nsYRKKUxGh5KXWI2W/y/eSPFdEayyrUthlmURylu2FRDZwPiU0TJ11OVnEAWcxePPppS 76FPVpEbVWhS83sfB07nICWhN79knF5+DCYzT55maZbR2g1FB0SW7HIkwM9ThR5fdjPr VmpoWZRS7BJA7ePSqyVKXSNLdbf8JNMpUnOGvDfdFuaSdTzkTGwE6/8ozdM3BXpPnelE qXmhnUL/ME5/HjtRgqFvztDLS8n1l/32covStYD23HhzzKI0s24igywkHmyA+78upGAS LcGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lsO9wDeiKRkCueWk+Uo59AFUAIZUeyl1sLeiaU6tHFA=; b=gEoJEXsuPD9pUEtFMcQ5/FQzV8PddmPWCcGA6gGka6xrlcsWVxrIcGTrhTjsEQq3VM HaAsBr4vuD82GMoQtyfwUWHRu9HiQfzryDUGy+3qHkdelYs9VEEu3pSbKlJvCd0eQDiy PN1kDbgBr2gR/X7k9DsmH2dWkfSsUZSR3YmOPaNQ7IrkPQTxxkcDr/Gc1nqWpSx9Kaay 8X7KMoV4r5yMX9FrQY3iypskrwX59Z7OwDxUJBKDDC1ly942Opvcxazsdml2ombLSKxR 4n8Mw5Kiej7T7vI65ipVrZsCxXY5PjXKtUId54DuiO/QLWhtH9XxyQKHxNtL3FxwiCvn yQTA== X-Gm-Message-State: AOAM533LyuHyCFkFcWwtjfgOCKsZLtoAH2OM5xTJLrefVrjPTWOKfP20 eWezUmPqv9NFLPyEOhz91KlgwQ== X-Received: by 2002:a17:90a:29a5:: with SMTP id h34mr22019900pjd.158.1618186417547; Sun, 11 Apr 2021 17:13:37 -0700 (PDT) Received: from nuc.localnet ([193.110.201.196]) by smtp.gmail.com with ESMTPSA id n52sm8308138pfv.13.2021.04.11.17.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Apr 2021 17:13:37 -0700 (PDT) From: Jiuyang Liu To: Palmer Dabbelt Cc: alex@ghiti.fr, waterman@eecs.berkeley.edu, Paul Walmsley , aou@eecs.berkeley.edu, akpm@linux-foundation.org, geert@linux-m68k.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] implement flush_cache_vmap and flush_cache_vunmap for RISC-V Date: Mon, 12 Apr 2021 00:13:32 +0000 Message-ID: <1846750.LAPMfGk2HC@nuc> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sunday, April 11, 2021 9:41:07 PM UTC you wrote: > On Sun, 28 Mar 2021 18:55:09 PDT (-0700), liu@jiuyang.me wrote: > > This patch implements flush_cache_vmap and flush_cache_vunmap for > > RISC-V, since these functions might modify PTE. Without this patch, > > SFENCE.VMA won't be added to related codes, which might introduce a bug > > in some out-of-order micro-architecture implementations. > > > > Signed-off-by: Jiuyang Liu > > --- > > > > arch/riscv/include/asm/cacheflush.h | 8 ++++++++ > > 1 file changed, 8 insertions(+) > > > > diff --git a/arch/riscv/include/asm/cacheflush.h > > b/arch/riscv/include/asm/cacheflush.h index 23ff70350992..4adf25248c43 > > 100644 > > --- a/arch/riscv/include/asm/cacheflush.h > > +++ b/arch/riscv/include/asm/cacheflush.h > > @@ -8,6 +8,14 @@ > > > > #include > > > > +/* > > + * flush_cache_vmap and flush_cache_vunmap might modify PTE, needs > > SFENCE.VMA. + * - flush_cache_vmap is invoked after map_kernel_range() > > has installed the page table entries. + * - flush_cache_vunmap is invoked > > before unmap_kernel_range() deletes the page table entries > These should have line breaks. Fixed in the newest patch, thanks for pointing out. > > > + */ > > +#define flush_cache_vmap(start, end) flush_tlb_all() > > We shouldn't need cache flushes for permission upgrades: the ISA allows > the old mappings to be visible until a fence, but the theory is that > window will be sort for reasonable architectures so the overhead of > flushing the entire TLB will overwhelm the extra faults. There are a > handful of places where we preemptively flush, but those are generally > because we can't handle the faults correctly. Got it, I removed this. > If you have some benchmark that demonstrates a performance issue on real > hardware here then I'm happy to talk about this further, but this > assumption is all over arch/riscv so I'd prefer to keep things > consistent for now. We are using riscv-boom + FireSim setting up a benchmark environment, I can try it after setting this. > > +#define flush_cache_vunmap(start, end) flush_tlb_all() > > This one does seem necessary. > > > + > > > > static inline void local_flush_icache_all(void) > > { > > > > asm volatile ("fence.i" ::: "memory");