Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp447426lqb; Fri, 24 May 2024 03:33:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVr2O3h2RjfRIVHCWGSJbK+AdZjTOckSB6mPQbAJw/Okjhm7/CCzyeW/CCIy+MqK2eiQCnPWd//PKtO8vlQBUuepuiK80s1XJ53JBIJlA== X-Google-Smtp-Source: AGHT+IHGCAcQ+GQtnj56RNSwMPtK1PslheCWmOmBGBe+OsezjHj7COVfNQxx42OEjPXP1GhuSGFP X-Received: by 2002:ae9:ec17:0:b0:794:802b:a61 with SMTP id af79cd13be357-794ab122735mr182278285a.76.1716546816748; Fri, 24 May 2024 03:33:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716546816; cv=pass; d=google.com; s=arc-20160816; b=WmA8S7bjJpEJ7+iK86zlhl7tvVCK6Vawi9SmN1uz1d0Zd5AjcbN6hDzcVCsUiQpcPf 57HXcSeNjODsGK44Aqwi8Bz0fytstM9k+3KqzD6tsWyIIBVBk84WH5GlOx5RNZ51atVA teUHJyrszf+QrcNdrW7vRINvv+zv0yDNXU8f1mLg1QZmz6kAywBFYbm3d4b22nF5o/V6 7FsSDoXGbPAjz45+4+vfN0AekHtOHNdD3olRRPcyTp2NbyHvgqUflDCIYEmVhnZ1loN0 do9rPv3pqNE5HUF6lnU8FcDqt1svUUA3lHMflNXZ8VXMk4WT4xjWz3P/1rRfFqTFvITJ 0z1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=MoFwl5jgI9P4wERx21aewJa37413Jz2hjVnsLA6GlCk=; fh=2vzqjP3n/UCnb3/mEbWHuLObhHBrEC85YoCrj8AA4mM=; b=O8rMXv0PorVepcQQNX9fY5cflkoXBb+VODSFCYnmQxSfTm0cgz7P5PPTapUJcbSw67 rhycHmytc1QQSQPP862E/gAQ3KYIkbQ0ockNy/EOkZJ/oE2d0vRUDMr4Cw3KU2tBigO6 el6ZQFrnnzbwc5LgcNXaIPkXDRrM2EXzmm9I9I474E1QWlk9CKeLVsyrD9kmnK/pebe3 0K+6D6nQpImyLl0gBYejaP09M+RJYvfNTBbUScCF81U86cZ08m4+YgZYLmfG5hJR83MO h2t7QeDCV5TuDA2OBuII296Xc4Nlkwl8odOJqtPpefY7ZlEY3xHSQtH8kWb7o8AQcW2d CMpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=lMyjVast; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-188603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd539desi121502785a.684.2024.05.24.03.33.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 03:33:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=lMyjVast; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-188603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188603-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 626651C215B6 for ; Fri, 24 May 2024 10:33:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D68538594E; Fri, 24 May 2024 10:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="lMyjVast" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 EEE4C6EB4A for ; Fri, 24 May 2024 10:33:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716546804; cv=none; b=tKu/0yRRizegDmve8njgbQwceZ5MBPpDTxH8R86dHULuvTkbcEaYo841+UOoPEK41L0oAUfZ/Mz9LsgV266sSzHd21tsB/C4EYkVO6dWdIO7F9aUQ9FHp28Fffrylalxze8Mdv3PZFfd/frr9JuIa5ou3hzKrBIUlwGszr9PWxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716546804; c=relaxed/simple; bh=XpfArSK4JOfwihieXqJhzCafcap7mnaqPeGAkpz9WIU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=uYmeVuTM3uEJprocY9kYWD1ODo6cueKCQIR02IbJqZdnEIJTiMJbo3jgJ/nivvs18xksskyjijPI5ly4ELpzL/mNuQvTRyU/EHMFbYL7zwLhXJZjSIqK270iD2eb/rBnc/TP5da0x1hm/Mxtpm94I0j2VDA/CL8SolSOBXkbzcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=lMyjVast; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f05b669b6cso27721375ad.3 for ; Fri, 24 May 2024 03:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1716546802; x=1717151602; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=MoFwl5jgI9P4wERx21aewJa37413Jz2hjVnsLA6GlCk=; b=lMyjVastwK/kq/svfjDLdhnnQKUKLuLAPnrHXDit/LKhjJDlcqh+J6t0gMC3jxPeG9 ZlkvgUrOBSyr2EvJufZNndutP1GHwOjyu7dqhpmmaY+bI/I+mEa2YI/ZZm5PPKe+uMxp b0eeCZMzc3usOWCqRTDn7Fe79TCV+HiRvHJyb0Zctu+fZPcW0Ky40qlPYaz+i4+tSv1P OOwicXPLc8mRbTuXU8HSImHSt9u5t0kGI6txguy53lxKnxFsXxqhda0yqPsZXNfX98D/ UxWoca0gJHxs0lq8MBhInh8m33BYcilSFNiZg386u7GZxNOA8LvvHG4HaFBDbzeM0gFe MnUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716546802; x=1717151602; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MoFwl5jgI9P4wERx21aewJa37413Jz2hjVnsLA6GlCk=; b=jcEhcWTExudOtvsAwIkle4bu8NamI5H0R8/7TZ1fK60LgVaiwj0kLEbLkfWWfdfLfS ERcjslbzQhilUsG0ybkqwFemhg6uiW3TrJ5A+bMOWasGMBwhhHNR6jAPBxx2CY3rn1Iz hKoZmb01VT+2OlCcjP9ZqFiaSLYtlZCYyU6zna14tCoEQ4BGmjzj7JdCdU8jADw8Ylyv 0UTqhLYS4XVTx7XvXt3t3T49I7oTg+lrqaNDhczpo+TsKX88qZapYjZmJvfyGOojFLNV bjWcnhxwKZKoiXt+CRzg2VqMI5WeBhfAbsz5v27jge8+6mPYTSoInDuomlEw15wmMsGc DBCQ== X-Forwarded-Encrypted: i=1; AJvYcCUMVkN4nc/Mgp7/RByttuovjWqmubh4y4OU2B/zGG0iSWd0NDl5evjS5Zhn2uPhgLo/Y9Ma0oEDErX9eiaV8rEHuAOt65P8gsGWBOK0 X-Gm-Message-State: AOJu0YxDEyOQzfObjdjLw4z9Yk0Qmhlf9gonyqjegKi8lix0bWqPfkCU OzkxsQJJxeyg+nlp1XViOE6aBaA/RXv+tWruGiCHKdWGxcoCYP3q6mK5r6wTNN8= X-Received: by 2002:a17:902:ce87:b0:1f3:91c:740e with SMTP id d9443c01a7336-1f44883ba5cmr21287595ad.40.1716546802214; Fri, 24 May 2024 03:33:22 -0700 (PDT) Received: from hsinchu26.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c756996sm10936625ad.8.2024.05.24.03.33.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 03:33:21 -0700 (PDT) From: Yong-Xuan Wang To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, cleger@rivosinc.com, alex@ghiti.fr, Yong-Xuan Wang , Jinyu Tang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Jones , 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 Subject: [RFC PATCH v4 1/5] RISC-V: Detect and Enable Svadu Extension Support Date: Fri, 24 May 2024 18:33:01 +0800 Message-Id: <20240524103307.2684-2-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240524103307.2684-1-yongxuan.wang@sifive.com> References: <20240524103307.2684-1-yongxuan.wang@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 enable optimization in MGLRU and __wp_page_copy_user() if Svadu extension is available. Co-developed-by: Jinyu Tang Signed-off-by: Jinyu Tang Signed-off-by: Yong-Xuan Wang Reviewed-by: Conor Dooley Reviewed-by: Andrew Jones --- 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/csr.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/asm/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) >> _PAGE_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(pgprot_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/cpufeature.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) { + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET, SBI_FWFT_PTE_AD_HW_UPDATING, + 1, 0, 0, 0, 0); + + return ret.error == SBI_SUCCESS; + } + return false; case RISCV_ISA_EXT_INVALID: return false; } @@ -301,6 +311,7 @@ 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_SUPERSET(svadu, RISCV_ISA_EXT_SVADU, riscv_xlinuxenvcfg_exts), __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