From patchwork Fri Sep 15 08:26:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 140391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp999222vqi; Fri, 15 Sep 2023 05:17:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5bnjPkedJBUEMG/CwWigsrmgqzQtvs2NfOh5M+d8C9Iko20uV6moCUDbs/LFiXe3DiosX X-Received: by 2002:a92:c566:0:b0:34e:2060:40eb with SMTP id b6-20020a92c566000000b0034e206040ebmr1992353ilj.28.1694780241799; Fri, 15 Sep 2023 05:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694780241; cv=none; d=google.com; s=arc-20160816; b=aoGWXBGUsR8z+dEsNvY00rz75n1jkmwcp5DX7KyXJmHkZmOh1oJUWotXvr1L9o4v+C p2jvc/NSL5CMQxMYioA7PslZZQYwJzLHaDn/l5v0jW8bU/FomVGuj1eM5U4JrfuwlU+U v9yx8UPflJZFujNZ1A5sk3S+zO9w5TvllCkTs/rU6nuhZFmTpC+QUJMtcmEWCer5a0OU RzHAmuj/WVWJXsk5D55OltztKMoUKqVUr4cv3s33RMs/ACMewba7t1Hd8T0mthKzDkIw LkTIk4TifXXz5Gg/5Jeh+0XSg0YK0mxQBNquyAQWvsJimaPq+cIT14GnJMGQJmM9lHLM +umQ== 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=/d7/3Obm53ZQCMrVF3c99mLRUxxcGODrgFkkmXmmWh0=; fh=pglOtI1A4vJBnnwcOyMDm0nuF5QQq5sdJWQLYQGDa+Q=; b=bId4mv0tUwizq2ygyEL8x1NyQKodFJD+vKe/6qNQfvyQoJnwvcfJwTACNVv3s/lbkx 8IaW9LwtZISmqOAS4KqgI22jixMbMgl6PuJIysTcxdevtHUmwM3UARHB9ILN9BJyYn36 Rst6BqS0Zrm7+GozQCPUPRyqx4cxbD413/f3RC5KL6S4aNmr9RbBOXuVZAk7iYfOZKOD cmy2Y6PwpWfJ3++KdDSmYMqQ/zoR7mN54O+Vpou988XjxNtVMuL05pMQ0G7hcyrmi27N urSuaXPg4SxDQbqTgY0blRxBOVnv3lEasCN8wZtUrAfDPiqh4iTb125WqoY8SmgXFU2J EqnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=QHOm3Gw7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id n123-20020a632781000000b005777535a67bsi3200188pgn.746.2023.09.15.05.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:17:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=QHOm3Gw7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 396FC82CDF73; Fri, 15 Sep 2023 01:29:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232242AbjIOI3J (ORCPT + 32 others); Fri, 15 Sep 2023 04:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232435AbjIOI3H (ORCPT ); Fri, 15 Sep 2023 04:29:07 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D76D72720 for ; Fri, 15 Sep 2023 01:27:18 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c364fb8a4cso17244315ad.1 for ; Fri, 15 Sep 2023 01:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1694766438; x=1695371238; 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=/d7/3Obm53ZQCMrVF3c99mLRUxxcGODrgFkkmXmmWh0=; b=QHOm3Gw7e6m6el/CLOvbN5PcwyOqHuMKAwNywmcAq4L4eqF2Mgxl9GdN1ZA3Nh2Tk7 Y878T6k/NpsbZyZxxVorq9gZufaU3ua0cXqlexHmVLoOjAqIyiyw1y4w16k8GqoYgL9i yLBv3TmQ7cL4QRFbNuvvDs30fZGaDRnxYAdzMZjG5zkDweYr7zBD/1rb+pnHp55WCtaS jhhwfB/aiQAvXhILJCDF6tr0NS487cnNq4fax2A0hPP/j0oDeGoaBCeNQbh327KhjH+n H6+Onp5R+d+dL6Joh9SorYvMVrTbzdUbDt+YZrJELwFLZ5KoPRBYwp0dMEEhtUH7lH9H 0iqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694766438; x=1695371238; 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=/d7/3Obm53ZQCMrVF3c99mLRUxxcGODrgFkkmXmmWh0=; b=ThVoeju3hBU5R2tVrd2E1zKRoyvD8dltDYCBMqoCIItIcCXY5OrMT9Plhlp/GGSAuy WIPCkzFBAQknMs49Ky7G2xxWu13BlVv09ak1q21IkhiObB9+wKWp+bx9vLlB/+v4gHEQ cdyF8BmoRceHxQfmGEfGN8mjSm/W4rf+EzZSNh7++ICoEELubiyhTWNc5TLgQ7YbSJxp MUqomfqNrmuCNjt1xk81k27utaKOEg72OplvG7S0cWM5Td+dp8x1R3vK/xaFCn6gZj7E iWV0bfXeID5TbiRCMbPY2bunUxVelSsleZZHsIuYHle/UfeJqVU9CHOveX7uFiKedNOC +zIQ== X-Gm-Message-State: AOJu0Yz7opQqMHi4bQLJMEBkBpOl/rhkLHnJ8XyddtrrFihmsAYhiGYk uqFYQ/bswpx0gISwN2OiM7uzzw== X-Received: by 2002:a17:902:d2cd:b0:1c3:e5bf:a9f8 with SMTP id n13-20020a170902d2cd00b001c3e5bfa9f8mr1188084plc.19.1694766438315; Fri, 15 Sep 2023 01:27:18 -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 f4-20020a170902ab8400b001c0af36dd64sm2912806plr.162.2023.09.15.01.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 01:27:18 -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, Yong-Xuan Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Guo Ren , Andrew Jones , Conor Dooley , wchen , Heiko Stuebner , Jisheng Zhang , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , Sergey Matyukevich , "Matthew Wilcox (Oracle)" , Charlie Jenkins , Qinglin Pan , Rick Edgecombe , Evan Green , Sunil V L , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] RISC-V: Detect and Enable Svadu Extension Support Date: Fri, 15 Sep 2023 08:26:57 +0000 Message-Id: <20230915082701.3643-2-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230915082701.3643-1-yongxuan.wang@sifive.com> References: <20230915082701.3643-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 01:29:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777105886934377587 X-GMAIL-MSGID: 1777105886934377587 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. Signed-off-by: Jinyu Tang Signed-off-by: Yong-Xuan Wang --- 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..10648b372a2a 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_HADE (_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..f3d077dff8ac 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_likely(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),