From patchwork Fri May 24 10:33:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 13673053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E23D0C25B74 for ; Fri, 24 May 2024 10:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=us/nl35rU3ydjv6qB90EzVcehiwxl5dmtzwkllx5EoM=; b=2jFM9qSxlFnGUZ VcqAEHEdUsxt5ILxZ6g3awdEyNcAMCDwMmQxbdIDccJhc5u15gJjid0POciidzkvImNF6wj52uSEt Dxs42vtOHJ/dszLyZVswwQixqbqJTiRiwNqpfpb1XUmMf/KIX8w8sfBBGgcldbwC2ezumXZp69vL9 KkZ4kkmr/lsuD4FyleAUIpxDgjAXVQIQPbF3CapUdOoI0J229zwk1BGOaYlXst+rXwPSc80kyXLSP r8ibXw1fMAQ2t4HvDkWpQxkrGTJztLEytdFlcj0TiDWt/eYMMQq+AnrsLMbzp8Sgp6sq24IKPtG2f 9dj5hrjlxRHZJBYxBjFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sASEo-00000008g2w-3hEf; Fri, 24 May 2024 10:33:26 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sASEl-00000008g10-14t4 for linux-riscv@lists.infradead.org; Fri, 24 May 2024 10:33:25 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1f44b59f8daso4840745ad.2 for ; Fri, 24 May 2024 03:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1716546802; x=1717151602; darn=lists.infradead.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=G9kYSqKaSU7T7Wr1zWjLXwvcmF/pEoMGkVFi+zEYzzDZn4iJNQAXTve632PBbQeIK8 zNGlJ1r3TfJCe6gIxjRgPU1Mur+oh+lOO9ZNHFy3xItWd9PcGEa0jMRWjKASCzoTrzIX e2AYsyGMRhag2loZsTXeWkYfAdchyhnDRbAdOGGaVGG9OiM15SW5FI7/Q3q5jKRvCltq rl+FOzrkyhu3WTvhDdEZ3b6/4wSJR4lHUgMNLpoaWpuIaMX5HX9TaXkjx94SX92p0iBL nAdY1mgGHTuNP9INlDzAI2q1LzMJ0E09IoQmYLBzHUT4S5gp+znNxNfPb0StwRkFCHZL CIYQ== 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=p0qGrFLOCZnqclc3hfJF2FkETUHi7+tz5SHEU2itRs2m0IlnE9bK7zmRCwHjeSqvLe KXGlTrxOeFMEOtKIWOLqup2k2tIP/Rjc31+GqhFvZF/Bm+G9iTkod2IU6ZPoX5d8Xd4T Hjht4H7YTSn08+KEnOCevzZSKdCsXPBuI72jSkCfBW9KfJ9xZhb38yCdfSjHIHA+hpSr E39uHnr5IUVz//vqlucXSdLz/jxOMMbRG257L10dXsV1tYo1b88rhUKnRn1oFosXlcK3 ubkU20xB1WBrwQFJA8vaqNtLYb+ZVO0I/XXsNTkvubnaXS9TpQJGnW6N5oMMyLrU+pOK 5QNQ== X-Gm-Message-State: AOJu0YyePyqXKdmkyTs0fDE9jgCRcB3aKHUIJnJJrVM4oFA3/GtQiCVV QKzMQL7TJB2aJCvFRac8JLpVBPc5PAgVkL3G/DI3P2Lt3Wylhwa9d4U96SHrYXbKon07t3MWM+V 47VW1zpAVPN44e1CwFYuwBWK+UWpnO2PnD9xwpcxGLKcKY56Qa463YAxmBaqZFFpclIfKq5P8BO cdKt9oJZ3kJ61bf5tEmBieHR8q6qEY5NVaPXmA0leOkQashWoGTekmsAo= X-Google-Smtp-Source: AGHT+IGZkHk0hDAkw/PomhjO7YSvVfqM6r0xCi5DIf8SQK5AaolNvn3ev2WmhcaqHjcHFZYozsTycQ== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240524_033323_315035_1E3AAA68 X-CRM114-Status: GOOD ( 13.35 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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),