Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1166770lqb; Thu, 30 May 2024 02:11:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVFL2yyK7fSoh1XWvafVPbDYgpq7f7aSY0nNoqGKYD/4Ev5BnGeMfNvQxmMqRUQtIhFP3hN9ZP4k2hQ2+QnwSZ5D99I2TLeYRuBgG8kRA== X-Google-Smtp-Source: AGHT+IE5ZTb3rxE5LiBgwMAoVi1Z40swVeE7nvCqgB58rQhg4Ho9TZCcKfY9BCuVTLttfNYQtlxL X-Received: by 2002:ac2:4d0f:0:b0:523:899f:c63d with SMTP id 2adb3069b0e04-52b7d47a073mr964878e87.47.1717060316241; Thu, 30 May 2024 02:11:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717060316; cv=pass; d=google.com; s=arc-20160816; b=E5hcHaFOqOhY1IFbQXY5UE89hwgYCgHyf+gMU04T1IoTUgOyKHeygbcGqAWCg7NQ0J KdTtr7M4lxLIRMmYcNvL1EEjR72G6R+Sn9Ct4gt1g7R32DpDprK29D2tEWW4mZNFrw00 Zm2Tta75H709FCp7iejcBI4xJNd7VwZ479czhPkxH5ejydBdNxTpQrvuKQ/LwkRJIkan dexn9K/5yOE34yxSPfr8eTe5nhJ5T3GEaelXnhbUIHSjyqRnSNfE9NjJ4XrKPa29GeBc rybLCaO+3mY7nY8FBO1Y1ZAY0nzcN0SSxG2Y9q/EMkJ2P/kCcyuKKf/XSTcYLhWuHpW9 oG6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=/DqQQ9Wbu+YPZbJaO7Fnc1iLlsp7PsxeQUPFS9+jrsA=; fh=upTkrhgePHlWLoBnC5WEfg7rRphQzmkO30umP6xrO1E=; b=d+D2rX5UTZLfcMB5Z0cAF5/6hPXXFvrRgN3rRfNzLjbgXimb9cL29CTpOgyrHqQFvP heSGG+pY0HpPPa6+4J6n7X6ZyvL09oC9qTwuex14P9NamfrxZJtx+2y3botuzedGduBt SqsLlsJii6MMOwvtzBFvVg6HjtXKrvGiPPzxAuocpRzYh8N+0KncgxRYFcH4MDNwvqml PrYXZSIinEa6TyKaSig9UuSe/33XMNxgY1cYaKfZSD/tofHQTRZPbMC/5oUosUFrvpC3 qLsY7xltk1cjeXhkCDVZO8tCfVWcZaGOFXEUxMWWOIxmF+K9sA0EOwbcekqQ7YBHE0DO dE/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=dvddpCgC; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-195145-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195145-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c80060csi723133966b.176.2024.05.30.02.11.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195145-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=dvddpCgC; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-195145-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195145-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3D9B81F23857 for ; Thu, 30 May 2024 09:11:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE1BD183989; Thu, 30 May 2024 09:11:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="dvddpCgC" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC824183974 for ; Thu, 30 May 2024 09:11:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060278; cv=none; b=L9J0YEJv+Re/eZ+w4fNC1q4IZQz2iYikrf6XCetprV/j39zMaPg4QPSLNXDvfL9lHSIayoRFbejxc07j3EUc62DjM4R3y0xdyvsL6ZZcfmmpmUs20M2dzNu2A3yi8yr2UA61YTvjxpR4mL/k3FvNVPwIkURCHchiib8icTZMsoU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060278; c=relaxed/simple; bh=OQUZqyiqRqw6MVyZNj7LqQLdWb6o8zx6lDarPSRDexw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=F0cRugZ6vUV+dFhC+EnAtBIW04NBBzqJ+N49TPEKcNCVLQYvv9rMjYAHPYxsiAs2kqYhO3WaaYOYOVuR4uvbCAnA2igFSeSjpYJsjTtnSm0mq7nO+BNYZK74cA4B4BFcH2nPaHlK2fLpO2m63HEMS0sZaHdOFFKskttbuci/7zI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=dvddpCgC; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2e6f33150bcso6382751fa.2 for ; Thu, 30 May 2024 02:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1717060275; x=1717665075; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/DqQQ9Wbu+YPZbJaO7Fnc1iLlsp7PsxeQUPFS9+jrsA=; b=dvddpCgCkGmLQubqCHIHepkdkUwJ/H3w1SnMr6+1lY9nxMY6PglE/3/A07JUOmH7oF lPXfincAzX9SYJqDYVyacwaS4nijQBbs2uzKjm1j946caYC6rxrK0OMbmT3nBgYXvqni Bp0M4KizzMv+pa8hTU8x9ih4WnkkT2GKEpEFQ+c0xhK+KinH+cwThGRmWXfNtmdH9NGr sTfy9/ul835Cy/yTf99xGH8CXgE5+DOA8pilDkT5bdRE1qn2P9aMouV2+0ua4r88lW2m E/VUosSOBQi3zGJDVng7Tmo22paiacHkOx2zdSoCFyG0PdiRNku7zPtDqLpEWLqsdQYh NhiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717060275; x=1717665075; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/DqQQ9Wbu+YPZbJaO7Fnc1iLlsp7PsxeQUPFS9+jrsA=; b=tG1Dk7InrfJXsnofP0ewmSE2TtrqJ0/9iiGnKY2hb29crtRtEJoQSbc+jZgfqO8lgZ sk6PSPUksOONiwWk707vOFS7ey6ehlK5B2OpGtblUPfVL8sjwPVfuP532heUNk10Soz7 yvGi+hAy74u0PwkswoiogWi+uAv6lW9segZnlww5jIKscwHE2W3mppWDsztMK0Bcl51E klc9jYLpP7Bbp5eg5U54hY/z1GQmycRCEmaEZLt5vQQ1I8XHjuiur4OaG6ofGvB2ZGHE bOOV6RBi5n814wBTcIbGlcoN6dYSQgp+8/bR9XXVrftJxKiQBtbNgyxjk3/Jz88IFVEc 0nMA== X-Forwarded-Encrypted: i=1; AJvYcCU/St4oYewFXrcoKW1XFVd1UzpQmX7qLP0Mv3ST93PB6g0pRG8KEOK/c2HiH246GqMku1qf6Z3jCTlHepfhawRIX0zsPzl/0IeDHogR X-Gm-Message-State: AOJu0YzUZ09myXNUrC30mf6ZQXuVcfBM5IvkXDSSHOHuHVBwznCxD99Y rlsvpcVaAsHTjrCgUISM8e6aorgNM0UucaDZYVCeYMnQ05FWh+jM39E239DvVFCYKSIIPUAp6+t pDiGyXzHKeCy8kvEdEAvJTDqNJ359FutJ8cq3Hg== X-Received: by 2002:a05:651c:90:b0:2ea:7726:4a77 with SMTP id 38308e7fff4ca-2ea8482896fmr8496551fa.35.1717060274720; Thu, 30 May 2024 02:11:14 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240524103307.2684-1-yongxuan.wang@sifive.com> <20240524103307.2684-2-yongxuan.wang@sifive.com> <20240527-41b376a2bfedb3b9cf7e9c7b@orel> <20240530-3e5538b8e4dea932e2d3edc4@orel> <3b76c46f-c502-4245-ae58-be3bd3f8a41f@ghiti.fr> In-Reply-To: <3b76c46f-c502-4245-ae58-be3bd3f8a41f@ghiti.fr> From: Anup Patel Date: Thu, 30 May 2024 14:41:02 +0530 Message-ID: Subject: Re: [RFC PATCH v4 1/5] RISC-V: Detect and Enable Svadu Extension Support To: Alexandre Ghiti Cc: Andrew Jones , Yong-Xuan Wang , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, greentime.hu@sifive.com, vincent.chen@sifive.com, cleger@rivosinc.com, Jinyu Tang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Conor Dooley , Mayuresh Chitale , Samuel Holland , Samuel Ortiz , Evan Green , Xiao Wang , Alexandre Ghiti , Andrew Morton , Kemeng Shi , "Mike Rapoport (IBM)" , Jisheng Zhang , "Matthew Wilcox (Oracle)" , Charlie Jenkins , Leonardo Bras , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 30, 2024 at 2:31=E2=80=AFPM Alexandre Ghiti wro= te: > > Hi Andrew, > > On 30/05/2024 10:47, Andrew Jones wrote: > > On Thu, May 30, 2024 at 10:19:12AM GMT, Alexandre Ghiti wrote: > >> Hi Yong-Xuan, > >> > >> On 27/05/2024 18:25, Andrew Jones wrote: > >>> On Fri, May 24, 2024 at 06:33:01PM GMT, Yong-Xuan Wang wrote: > >>>> Svadu is a RISC-V extension for hardware updating of PTE A/D bits. > >>>> > >>>> In this patch we detect Svadu extension support from DTB and enable = it > >>>> with SBI FWFT extension. Also we add arch_has_hw_pte_young() to enab= le > >>>> optimization in MGLRU and __wp_page_copy_user() if Svadu extension i= s > >>>> available. > >> > >> So we talked about this yesterday during the linux-riscv patchwork mee= ting. > >> We came to the conclusion that we should not wait for the SBI FWFT ext= ension > >> to enable Svadu but instead, it should be enabled by default by openSB= I if > >> the extension is present in the device tree. This is because we did no= t find > >> any backward compatibility issues, meaning that enabling Svadu should = not > >> break any S-mode software. > > Unfortunately I joined yesterday's patchwork call late and missed this > > discussion. I'm still not sure how we avoid concerns with S-mode softwa= re > > expecting exceptions by purposely not setting A/D bits, but then not > > getting those exceptions. > > > Most other architectures implement hardware A/D updates, so I don't see > what's specific in riscv. In addition, if an OS really needs the > exceptions, it can always play with the page table permissions to > achieve such behaviour. > > > > > >> This is what you did in your previous versions of > >> this patchset so the changes should be easy. This behaviour must be ad= ded to > >> the dtbinding description of the Svadu extension. > >> > >> Another thing that we discussed yesterday. There exist 2 schemes to ma= nage > >> the A/D bits updates, Svade and Svadu. If a platform supports both > >> extensions and both are present in the device tree, it is M-mode firmw= are's > >> responsibility to provide a "sane" device tree to the S-mode software, > >> meaning the device tree can not contain both extensions. And because o= n such > >> platforms, Svadu is more performant than Svade, Svadu should be enable= d by > >> the M-mode firmware and only Svadu should be present in the device tre= e. > > I'm not sure firmware will be able to choose svadu when it's available. > > For example, platforms which want to conform to the upcoming "Server > > Platform" specification must also conform to the RVA23 profile, which > > mandates Svade and lists Svadu as an optional extension. This implies t= o > > me that S-mode should be boot with both svade and svadu in the DT and w= ith > > svade being the active one. Then, S-mode can choose to request switchin= g > > to svadu with FWFT. > > > The problem is that FWFT is not there and won't be there for ~1y > (according to Anup). So in the meantime, we prevent all uarchs that > support Svadu to take advantage of this. SBI v3.0 is expected to freeze by the end of this year so I don't think we will have to wait for ~1yr. Plus nothing stops a company to apply patches themselves to test on their implementations. Quite a few companies have internal forks of Linux where they track upstream patches until they are merged. Regards, Anup > > > > > > Thanks, > > drew > > > >> I hope that clearly explains what we discussed yesterday, let me know = if you > >> (or anyone else) need more explanations. If no one is opposed to this > >> solution, do you think you can implement this behaviour? If not, I can= deal > >> with it, just let me know. > >> > >> Thanks > >> > >> > >>>> Co-developed-by: Jinyu Tang > >>>> Signed-off-by: Jinyu Tang > >>>> Signed-off-by: Yong-Xuan Wang > >>>> Reviewed-by: Conor Dooley > >>>> Reviewed-by: Andrew Jones > >>> I think this patch changed too much to keep r-b's. We didn't have the > >>> FWFT part before. > >>> > >>>> --- > >>>> arch/riscv/Kconfig | 1 + > >>>> arch/riscv/include/asm/csr.h | 1 + > >>>> arch/riscv/include/asm/hwcap.h | 1 + > >>>> arch/riscv/include/asm/pgtable.h | 8 +++++++- > >>>> arch/riscv/kernel/cpufeature.c | 11 +++++++++++ > >>>> 5 files changed, 21 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > >>>> index be09c8836d56..30fa558ee284 100644 > >>>> --- a/arch/riscv/Kconfig > >>>> +++ b/arch/riscv/Kconfig > >>>> @@ -34,6 +34,7 @@ config RISCV > >>>> select ARCH_HAS_PMEM_API > >>>> select ARCH_HAS_PREPARE_SYNC_CORE_CMD > >>>> select ARCH_HAS_PTE_SPECIAL > >>>> + select ARCH_HAS_HW_PTE_YOUNG > >>>> select ARCH_HAS_SET_DIRECT_MAP if MMU > >>>> select ARCH_HAS_SET_MEMORY if MMU > >>>> select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL > >>>> diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/c= sr.h > >>>> index 2468c55933cd..2ac270ad4acd 100644 > >>>> --- a/arch/riscv/include/asm/csr.h > >>>> +++ b/arch/riscv/include/asm/csr.h > >>>> @@ -194,6 +194,7 @@ > >>>> /* xENVCFG flags */ > >>>> #define ENVCFG_STCE (_AC(1, ULL) << 63) > >>>> #define ENVCFG_PBMTE (_AC(1, ULL) << 62) > >>>> +#define ENVCFG_ADUE (_AC(1, ULL) << 61) > >>>> #define ENVCFG_CBZE (_AC(1, UL) << 7) > >>>> #define ENVCFG_CBCFE (_AC(1, UL) << 6) > >>>> #define ENVCFG_CBIE_SHIFT 4 > >>>> diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm= /hwcap.h > >>>> index e17d0078a651..8d539e3f4e11 100644 > >>>> --- a/arch/riscv/include/asm/hwcap.h > >>>> +++ b/arch/riscv/include/asm/hwcap.h > >>>> @@ -81,6 +81,7 @@ > >>>> #define RISCV_ISA_EXT_ZTSO 72 > >>>> #define RISCV_ISA_EXT_ZACAS 73 > >>>> #define RISCV_ISA_EXT_XANDESPMU 74 > >>>> +#define RISCV_ISA_EXT_SVADU 75 > >>>> #define RISCV_ISA_EXT_XLINUXENVCFG 127 > >>>> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/a= sm/pgtable.h > >>>> index 9f8ea0e33eb1..1f1b326ccf63 100644 > >>>> --- a/arch/riscv/include/asm/pgtable.h > >>>> +++ b/arch/riscv/include/asm/pgtable.h > >>>> @@ -117,6 +117,7 @@ > >>>> #include > >>>> #include > >>>> #include > >>>> +#include > >>>> #define __page_val_to_pfn(_val) (((_val) & _PAGE_PFN_MASK) >> _P= AGE_PFN_SHIFT) > >>>> @@ -285,7 +286,6 @@ static inline pte_t pud_pte(pud_t pud) > >>>> } > >>>> #ifdef CONFIG_RISCV_ISA_SVNAPOT > >>>> -#include > >>>> static __always_inline bool has_svnapot(void) > >>>> { > >>>> @@ -621,6 +621,12 @@ static inline pgprot_t pgprot_writecombine(pgpr= ot_t _prot) > >>>> return __pgprot(prot); > >>>> } > >>>> +#define arch_has_hw_pte_young arch_has_hw_pte_young > >>>> +static inline bool arch_has_hw_pte_young(void) > >>>> +{ > >>>> + return riscv_has_extension_unlikely(RISCV_ISA_EXT_SVADU); > >>>> +} > >>>> + > >>>> /* > >>>> * THP functions > >>>> */ > >>>> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpuf= eature.c > >>>> index 3ed2359eae35..b023908c5932 100644 > >>>> --- a/arch/riscv/kernel/cpufeature.c > >>>> +++ b/arch/riscv/kernel/cpufeature.c > >>>> @@ -93,6 +93,16 @@ static bool riscv_isa_extension_check(int id) > >>>> return false; > >>>> } > >>>> return true; > >>>> + case RISCV_ISA_EXT_SVADU: > >>>> + if (sbi_probe_extension(SBI_EXT_FWFT) > 0) { > >>> I think we've decided the appropriate way to prove for SBI extensions= is > >>> to first ensure the SBI version and then do the probe, like we do for= STA > >>> in has_pv_steal_clock() > >>> > >>>> + struct sbiret ret; > >>>> + > >>>> + ret =3D sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET,= SBI_FWFT_PTE_AD_HW_UPDATING, > >>>> + 1, 0, 0, 0, 0); > >>>> + > >>>> + return ret.error =3D=3D SBI_SUCCESS; > >>>> + } > >>>> + return false; > >>>> case RISCV_ISA_EXT_INVALID: > >>>> return false; > >>>> } > >>>> @@ -301,6 +311,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = =3D { > >>>> __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), > >>>> __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), > >>>> __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), > >>>> + __RISCV_ISA_EXT_SUPERSET(svadu, RISCV_ISA_EXT_SVADU, riscv_xlinux= envcfg_exts), > >>> We do we need XLINUXENVCFG? > >>> > >>> Thanks, > >>> drew > >>> > >>>> __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL), > >>>> __RISCV_ISA_EXT_DATA(svnapot, RISCV_ISA_EXT_SVNAPOT), > >>>> __RISCV_ISA_EXT_DATA(svpbmt, RISCV_ISA_EXT_SVPBMT), > >>>> -- > >>>> 2.17.1 > >>>> > >>> _______________________________________________ > >>> linux-riscv mailing list > >>> linux-riscv@lists.infradead.org > >>> http://lists.infradead.org/mailman/listinfo/linux-riscv > > -- > kvm-riscv mailing list > kvm-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kvm-riscv