Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp326127rdb; Thu, 2 Nov 2023 05:06:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqAGPIvpchoshChg3YvdsvpDeI0pbvIsvs/TRQBcqcUuTqKkqeHgNC4FMr7FsAxpymMJAJ X-Received: by 2002:a17:902:f201:b0:1cc:1e00:f8af with SMTP id m1-20020a170902f20100b001cc1e00f8afmr14290937plc.37.1698926767642; Thu, 02 Nov 2023 05:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698926767; cv=none; d=google.com; s=arc-20160816; b=a59MUHGuoOp5PKxpfs87Flf1wQfe/D+5B0ugdc3te92n24qrRxiAFTiZxgdabreSg0 q46cesYfa8R/V5joTfI1S3nEK+AFc+cvJjYReTA4DbZLoA9Q/lmcHxjZcRGO1rFBiQYr K9mjH7sKKpjZcpwl1K4xqykJtAU+hrQ5AhixaMhvwNbM/U9AnH7R9/DM+1Z/z/jW0+1x xlXU3YdOqDonjT61ivyHktERBNR1wT6LS/xpq7psTDhSBHKH8Xdhz4te0o7FYWWsQkHR HYf/R1l+qcJJBHSHHa/o2f4qIDdFFV7AtAWDIab5VkZAHO7+VcePykR+LE6knEbEUZ3W xWAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=xJAq1yPvWqyGBi5ZsWwrpgoSqVAMHLxRpGtyjE8Lpog=; fh=HHNqnBz96gbnYUNxvRsuXhndl8Lhwx4hc0x/4pwDXng=; b=Pw9Coh6cKYNy4K5qbogkYRWqMt5XLvaoGN3VS2cjM6jhGrTjGwtsiEqFvdhrEmEir+ ZPxsVCHCK3IqvrsfzomcOuokjyLsSZ+HAjGFS/mUE3NTyU7BRLPC+gZJ9mHU5EeAxV4y 5OcSl23swOSJU/9WYIeO31pcLhsgtc6FRHHP4lZoA1FkiR2XSCvrt6MVaNQ/8BodZHCY OmnxY1tczzxrkeC27S/o8Q5Ec5PDGWj4d/BA0m8MXXGMFUMnWzESVdfxoOXgePd5tNeq +cwNL0ys4i+TUvOJfafqCLssI1LBXGOB2HibKbz9lTRhIor4IyWKQmhiwwzWBRXSaG6o R41g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=FF6zsVUm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id o16-20020a170902d4d000b001bb8c4279f5si5116829plg.148.2023.11.02.05.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 05:06:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=FF6zsVUm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E80368060379; Thu, 2 Nov 2023 05:05:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345340AbjKBMEq (ORCPT + 99 others); Thu, 2 Nov 2023 08:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235294AbjKBMEh (ORCPT ); Thu, 2 Nov 2023 08:04:37 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D007210C2 for ; Thu, 2 Nov 2023 05:01:46 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1cacde97002so6391505ad.2 for ; Thu, 02 Nov 2023 05:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698926506; x=1699531306; 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=xJAq1yPvWqyGBi5ZsWwrpgoSqVAMHLxRpGtyjE8Lpog=; b=FF6zsVUmmvmiObdm3E4jVv+YYKMBNbt1a19Y9NAfSXN/nFqrzzMfScZnJBX8kf4nZA 8FHUq2WU761da6atFkQLHgzpbAeq4tZQmzQA2z8CrWudON74aOvEAbuXyycyaVFVQ8am WF7/mXaP1pNkKtMEJ8QGmO0V8hX7lx3wZb1XkCPA7IHQSuAbwICwuXOLnvx4dgRP3gVu NTPdavCKuXQP5EcK9jW7GCvO8xy/kZRUsPZGodCC72VavmAwNTgmE+MbPz/vcQcvhlys dxq1GZixeOsV/hdb2OhnQ7pGulwDm8XJErbZtigIPYILkksJ9h2haDcrKoBM8hj3w88h KK9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698926506; x=1699531306; 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=xJAq1yPvWqyGBi5ZsWwrpgoSqVAMHLxRpGtyjE8Lpog=; b=VU5FvIFdkpVoaHiqSWctZaeyCv+nx/Nww04I9m9AFWZZq1QC7I3rzPZOqg629TJBU8 dzeN04qQjjWIlk8oEdgUWGyW/5kWMyRW0xLBzzZCASNrAJ/jVoU6I9BiOJYghsn+M2bW Pdzw4P72p79JfLMoRKDQItBW5MnfMeW/zzIrVjS4CXjauZ1KT2M6K+pLfXW2zKoGCCR6 rVb+f+Zx9LRJLmZCtta+jAO2/UsXdqKGOUa0KlCBVFGXxoP317piDeaW/9VNE7Zi2Xon TjKZlLt2esVcs5TRNCFlLUxl5Bk2iVbk5MrysP7kF/E7KMtGCFWto3dsDgkJjNS8/6cX 0dZg== X-Gm-Message-State: AOJu0YxCIQ2SX9gamjgk+Jx8Ngaxw4Rc9OZ8HhPajL2JLN0PQfzPtQkb uzFf7Yed8ftLrG6AKYWodyfQDA== X-Received: by 2002:a17:902:db10:b0:1cc:5833:cf5e with SMTP id m16-20020a170902db1000b001cc5833cf5emr10617317plx.27.1698926506097; Thu, 02 Nov 2023 05:01:46 -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 l12-20020a170902f68c00b001cc0f6028b8sm2969008plg.106.2023.11.02.05.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 05:01:45 -0700 (PDT) From: Yong-Xuan Wang To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, tjytimi@163.com, alex@ghiti.fr, conor.dooley@microchip.com, ajones@ventanamicro.com, Yong-Xuan Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Guo Ren , Daniel Henrique Barboza , Heiko Stuebner , Jisheng Zhang , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , Charlie Jenkins , Sergey Matyukevich , "Matthew Wilcox (Oracle)" , Qinglin Pan , Rick Edgecombe , Evan Green , Sunil V L , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] RISC-V: Detect and Enable Svadu Extension Support Date: Thu, 2 Nov 2023 12:01:22 +0000 Message-Id: <20231102120129.11261-2-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231102120129.11261-1-yongxuan.wang@sifive.com> References: <20231102120129.11261-1-yongxuan.wang@sifive.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 02 Nov 2023 05:05:28 -0700 (PDT) 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 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 --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/pgtable.h | 6 ++++++ arch/riscv/kernel/cpufeature.c | 1 + 4 files changed, 9 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 777cb8299551..e6935fd48c0c 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 b7b58258f6c7..1013661d6516 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -58,6 +58,7 @@ #define RISCV_ISA_EXT_ZICSR 40 #define RISCV_ISA_EXT_ZIFENCEI 41 #define RISCV_ISA_EXT_ZIHPM 42 +#define RISCV_ISA_EXT_SVADU 43 #define RISCV_ISA_EXT_MAX 64 diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index b2ba3f79cfe9..028b700cd27b 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -629,6 +629,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 1cfbba65d11a..ead378c04991 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -178,6 +178,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_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