From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 00C4F16D9BC for ; Fri, 21 Jun 2024 08:44:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718959445; cv=none; b=mJRw50ngk0c4uEb9IYOHr/BrjisDPS6dUEv7WcEFPtvG01JQfIFI+Vzx4lAODRp8ob6G/iN8MGNnGyZd02So82f6dj17ypHh1nulx11w2XEuGZ4DhZeLGD9hPfiunmRKSrMBYiKlopI/BlUhWjwy5E8gp4YvPo+QeT0iyvufUFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718959445; c=relaxed/simple; bh=Jbwg4HBbsos0LMHx3qJn3rslKNY3axIyHOu21SZsnAQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GMXrnaS/8KtNZE+s9tjSjr7yTECVauwCGS6Etc2Anw8nq+4UBi+2hU44MaAmZAaqIY+QHlXqEqXixnddJu7aWuIax6fJHG7NTMP3+vqoMe/EDbBWNJCusZlOoPeNi7a6BuwgSD36yKkpXRbU0149Q1Opflaz2qfEr7ff0GWak5E= 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=ACUln0wN; arc=none smtp.client-ip=209.85.218.49 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="ACUln0wN" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a62ef52e837so199026766b.3 for ; Fri, 21 Jun 2024 01:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1718959440; x=1719564240; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=y0W/yXjQFyqiu4YF3eksrFfEO800rJtGZTMEqwAB9lw=; b=ACUln0wN5MBr2W0zWjXeykApLeYWCRLxefBYwuoLqahTF1ci18I+QPwmvZ0wkHn4AV VNwkHNDBLpfaWca8On9V7L1Vn1Pg8fq4i7qjubIIPnp0pFbsO37LaNA4TQNiPHE9dOfl W2FH+qwewdL/y1nRv5uzISbbqo8ekF7TlB4MpABRjSCnHIlhMDL9oGW4TCENB3UzmJa7 AbF8askcY530QM6oIkYRMex5NSOYc0Oji/coxVt76xAsbs2NK+Zg9LRkx4j8wphRDHDi Ew1TlqxuHrEDpXpuUKQ08ZjZLnSfN8C+xBmgeCZzY7GvljC5Ud9tfGlrN2e9X2cmG2z4 r9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718959440; x=1719564240; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=y0W/yXjQFyqiu4YF3eksrFfEO800rJtGZTMEqwAB9lw=; b=TlTUd9kg6nYgB5WNadDECAgCrAk4jgILTIBJY/2jGFwYA+0OvXLK+mQntUUuBGh4KO n7SBOuIZZoHwXH7MUW/hl5DHydNfGCSmag/ny16cSqVbNSwoZ8PgAYTMtStxrdqiLZl7 5TsPAzb60dWypqnP2PNhsYwKqdevi01W581uKTxnopBJcEhDjjAG58SSAHcavmDMehyP CU52TRE4b0bjyM4RSJuqNYSNypfADGWtclTfgiclyU7AwObncJ/eic3IcdXvV2m0SN6Y ICM2TNcdjVT9d9GaeTIb9k95ETL8kpaZWJTRIrTcF7w+kSarsQmHmfW/S2/pXztSK3n8 MIgw== X-Gm-Message-State: AOJu0Yx4gwTcPgtEvMBTEWkA2LsuN8/wTstgcpxZHdFtJkUZ3MOpCqbH DcmWW2lRTKUmg6U1zEtgYCT/LM47d2uV3gA9AjHDK6EDlO/LxDV5oF0/6jznhjY= X-Google-Smtp-Source: AGHT+IGCvv5/dIqWzwFU7HWVxrBDIamtXxsPzF9wPVhiKm9PMGOYERORN5v/XksMktGyjYh/7LB0lA== X-Received: by 2002:a17:907:b9d2:b0:a6f:50ae:e06 with SMTP id a640c23a62f3a-a6fab778851mr473339566b.53.1718959439838; Fri, 21 Jun 2024 01:43:59 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6fcf428bb5sm59484866b.13.2024.06.21.01.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 01:43:59 -0700 (PDT) Date: Fri, 21 Jun 2024 10:43:58 +0200 From: Andrew Jones To: Yong-Xuan Wang Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, apatel@ventanamicro.com, alex@ghiti.fr, greentime.hu@sifive.com, vincent.chen@sifive.com, Jinyu Tang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Conor Dooley , Mayuresh Chitale , Atish Patra , wchen , Samuel Ortiz , =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Evan Green , Xiao Wang , Alexandre Ghiti , Andrew Morton , "Mike Rapoport (IBM)" , Kemeng Shi , Samuel Holland , Jisheng Zhang , Charlie Jenkins , "Matthew Wilcox (Oracle)" , Leonardo Bras Subject: Re: [PATCH v5 1/4] RISC-V: Add Svade and Svadu Extensions Support Message-ID: <20240621-d1b77d43adacaa34337238c2@orel> References: <20240605121512.32083-1-yongxuan.wang@sifive.com> <20240605121512.32083-2-yongxuan.wang@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240605121512.32083-2-yongxuan.wang@sifive.com> On Wed, Jun 05, 2024 at 08:15:07PM GMT, Yong-Xuan Wang wrote: > Svade and Svadu extensions represent two schemes for managing the PTE A/D > bits. When the PTE A/D bits need to be set, Svade extension intdicates > that a related page fault will be raised. In contrast, the Svadu extension > supports hardware updating of PTE A/D bits. Since the Svade extension is > mandatory and the Svadu extension is optional in RVA23 profile, by default > the M-mode firmware will enable the Svadu extension in the menvcfg CSR > when only Svadu is present in DT. > > This patch detects Svade and Svadu extensions from DT and adds > arch_has_hw_pte_young() to enable optimization in MGLRU and > __wp_page_copy_user() when we have the PTE A/D bits hardware updating > support. > > Co-developed-by: Jinyu Tang > Signed-off-by: Jinyu Tang > Signed-off-by: Yong-Xuan Wang > --- > arch/riscv/Kconfig | 1 + > arch/riscv/include/asm/csr.h | 1 + > arch/riscv/include/asm/hwcap.h | 2 ++ > arch/riscv/include/asm/pgtable.h | 14 +++++++++++++- > arch/riscv/kernel/cpufeature.c | 2 ++ > 5 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index b94176e25be1..dbfe2be99bf9 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -36,6 +36,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/csr.h > index 25966995da04..524cd4131c71 100644 > --- a/arch/riscv/include/asm/csr.h > +++ b/arch/riscv/include/asm/csr.h > @@ -195,6 +195,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..35d7aa49785d 100644 > --- a/arch/riscv/include/asm/hwcap.h > +++ b/arch/riscv/include/asm/hwcap.h > @@ -81,6 +81,8 @@ > #define RISCV_ISA_EXT_ZTSO 72 > #define RISCV_ISA_EXT_ZACAS 73 > #define RISCV_ISA_EXT_XANDESPMU 74 > +#define RISCV_ISA_EXT_SVADE 75 > +#define RISCV_ISA_EXT_SVADU 76 > > #define RISCV_ISA_EXT_XLINUXENVCFG 127 > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index aad8b8ca51f1..7287ea4a6160 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -120,6 +120,7 @@ > #include > #include > #include > +#include > > #define __page_val_to_pfn(_val) (((_val) & _PAGE_PFN_MASK) >> _PAGE_PFN_SHIFT) > > @@ -288,7 +289,6 @@ static inline pte_t pud_pte(pud_t pud) > } > > #ifdef CONFIG_RISCV_ISA_SVNAPOT > -#include > > static __always_inline bool has_svnapot(void) > { > @@ -624,6 +624,18 @@ static inline pgprot_t pgprot_writecombine(pgprot_t _prot) > return __pgprot(prot); > } > > +/* > + * Both Svade and Svadu control the hardware behavior when the PTE A/D bits need to be set. By > + * default the M-mode firmware enables the hardware updating scheme when only Svadu is present in > + * DT. > + */ > +#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) && > + !riscv_has_extension_likely(RISCV_ISA_EXT_SVADE); It's hard to guess what is, or will be, more likely to be the correct choice of call between the _unlikely and _likely variants. But, while we assume svade is most prevalent right now, it's actually quite unlikely that 'svade' will be in the DT, since DTs haven't been putting it there yet. Anyway, it doesn't really matter much and maybe the _unlikely vs. _likely variants are better for documenting expectations than for performance. > +} > + > /* > * THP functions > */ > diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c > index 5ef48cb20ee1..58565798cea0 100644 > --- a/arch/riscv/kernel/cpufeature.c > +++ b/arch/riscv/kernel/cpufeature.c > @@ -301,6 +301,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { > __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_DATA(svade, RISCV_ISA_EXT_SVADE), > + __RISCV_ISA_EXT_DATA(svadu, RISCV_ISA_EXT_SVADU), > __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 > Reviewed-by: Andrew Jones Thanks, drew