From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8ABB2C369AB for ; Thu, 24 Apr 2025 07:20:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32BD46B000E; Thu, 24 Apr 2025 03:20:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B0DB6B0010; Thu, 24 Apr 2025 03:20:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1051B6B0011; Thu, 24 Apr 2025 03:20:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E233F6B000E for ; Thu, 24 Apr 2025 03:20:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 55BA91CAC8E for ; Thu, 24 Apr 2025 07:20:34 +0000 (UTC) X-FDA: 83368089588.23.7A21B22 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf20.hostedemail.com (Postfix) with ESMTP id 6DBDD1C0003 for ; Thu, 24 Apr 2025 07:20:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=SQPSzxz4; dmarc=none; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745479232; a=rsa-sha256; cv=none; b=bFOpfP+8MDzhEz/FhMI8fvDGWRlYvrKI4egHz60b58yXsR+1mw+lhhiKrJwdGhMYRQgDrV vhN7TgoGjd1R+5Qsyt74/V/M7e5l29/kAp8h6FRME1si4VRa2kyf3XsIV8gE6gvakaVqDZ uXFujDN9sTugzRj5TLbhQ4D08i7uRFQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=SQPSzxz4; dmarc=none; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745479232; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=asCIAXUzDRo1up/0JSFmu+IjLgmwP2Bompu+f7bkHCo=; b=QNEsxXXIpK1HisME+P2I1LFqIB7gBRx+9ZX1pbB2IVfqFqidY6ugcPtN9knc9HYX9CVFYg Wrb/ynLPIVVIcrPZI/MlXxDXxxM8NDk0Z66tnxqgJ2EqSYvOROgYzHfoONGaMYT8uZ1+IR xOmu4Jo6i9u2AwZrger2VxK2Brh6JFY= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2295d78b433so6990485ad.2 for ; Thu, 24 Apr 2025 00:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745479231; x=1746084031; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=asCIAXUzDRo1up/0JSFmu+IjLgmwP2Bompu+f7bkHCo=; b=SQPSzxz4Or9ShaLabgwY2Nqpuvt8GIvAerMt5R+pOiFWWgfTq7kWubH4faRqrUd+cU SGqKBMOXtMQlExTomcQRVFtK46Sipe1cGeC/SSOC5vHoTgCgCJGhPdK7R/N5a3kM6bDF 3fIIJMlBrNj9QAYM5YDy8g78L3FnTxErYCOpj+JYEaBp6vnza0sinsG13yuyVL/G0g84 FVz7viVqYNzzFDzGDjkRZwSu/a1JIpGXhmLa1tYsZt0E2qdyCw4mahEGnDc/bkuzEs98 Z0Y5AA1W9mdG7BTVYU395fFZBFztefz1DF5/VqLWxGw7Sf1x++CGUfRFxPoOwJhRnuuA aTNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745479231; x=1746084031; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=asCIAXUzDRo1up/0JSFmu+IjLgmwP2Bompu+f7bkHCo=; b=MMhc8Ybf1msyXDoVYoxGimGZ8pOMcwDU0wsgnvLDF/+K/TmU8Ca4CBRuceu5N26Vc9 rxpYdAs815ypl0qEZOZVWqZ6VKuguhSB8I3Y6s4EgkTBNYaEXF4P325M/Orq2M6hX5/c RJjtyG09s/MH64hh+P0sCsTYeHr+2oC8bn6DFwrpc5vo6zHmWbanGCX3Xzn8Qa/YTxfY mvKimxylUOZT9fnxhIqo7yEr5vlaztuTRl78U6Oi4SDvtm6fzB4JfHfhtFZ/9r5SjCqJ BikPrZWkxbhtorta9nzkBXtqgM7W2cP+WGMTowZdOXdYFUaPL4ul34pE06Cbw9jWKSur KNng== X-Forwarded-Encrypted: i=1; AJvYcCXWeeEPyHhRPJ9gS5KfL9H4kEAI+CYdoubrwRZhMvKKjyNDhw+a4arsdBHKfq74jQRISaMJGrluZg==@kvack.org X-Gm-Message-State: AOJu0YxD0y4IpmYkD5F3iYVStLyAENmy80DmdKJ1zLfIo8VCOSQNZd7P qYDd7GBApqZtQT1zfLFX6vAO6PFxmHvLmqj1QxRVWZne9DnzYs44r1rgUXQELnc= X-Gm-Gg: ASbGncu8SozyY5Xn1ptm9LmUXseMcTdsHwjHxcysMf+wSoKhcxGG0HW7rTe/svBjqKV /mcEhLY0m+hboUE3aKDunBMeNKib5Yr/SXMYK7OD9+tDpvmCP2cGMKR3Z7j8PdzX2rCvNEGLz3y KcSI8ejpz/GLXANyDWLypCsVKubXZPUCJNLtOpg3mFLr4z/unCp9L3fM6eZJATpY2UlcK1yu4hP sBQ0Sy1KuKwahdY/z5rjfvo0bu8D93rFUn/YSC+Ua0WAY76OyFoLj18IT/gAk9sMg+YZtpwTsrf EOeLE+Rwcpc449rX9wsb4THCZUCF7RWXPNW6acJsuJ8mUoyOCeqvPWqwOu5a4Q== X-Google-Smtp-Source: AGHT+IHtewISg2Qylh/d/NYNsAqReuiifVQYnNIETRLUu60z3NFTKSNENr9AYd/4nxJezDALdj+kzQ== X-Received: by 2002:a17:903:22d1:b0:21f:4c8b:c514 with SMTP id d9443c01a7336-22db3d9c133mr21697835ad.45.1745479231231; Thu, 24 Apr 2025 00:20:31 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db52163d6sm6240765ad.214.2025.04.24.00.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 00:20:30 -0700 (PDT) From: Deepak Gupta Date: Thu, 24 Apr 2025 00:20:18 -0700 Subject: [PATCH v13 03/28] riscv: zicfiss / zicfilp enumeration MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250424-v5_user_cfi_series-v13-3-971437de586a@rivosinc.com> References: <20250424-v5_user_cfi_series-v13-0-971437de586a@rivosinc.com> In-Reply-To: <20250424-v5_user_cfi_series-v13-0-971437de586a@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan , Jann Horn , Conor Dooley , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, rust-for-linux@vger.kernel.org, Zong Li , Deepak Gupta X-Mailer: b4 0.13.0 X-Rspamd-Queue-Id: 6DBDD1C0003 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: ndoiff79tgahriy4b47yx5sxhju4poz6 X-HE-Tag: 1745479232-118378 X-HE-Meta: U2FsdGVkX19uch6+9zgFmgHEz/aJEtx3qU8/6nXozue8Bs+Y0bPig82VqHoUbNZAQ1y/MS8k2pTJTOx1adY8PRgu+Tweqz/JDoHbKni+2bd4zCwCC04IMfvNfaWP89MCFGerRUEueSCIZRRfeoNso20StTvw7P/YJimfkFdm3J4IueNuMGQBsxKXGxa0YyU42GVpX8h0GCdq5t3pu2OBsQKhArXUFBdoAZRZ1j36wzsDllpr+bIJ+OyGY4Xj2yQIDsGB0VFuXMZgEW8637obQ96tEpBgSD1G/CetZ5aOfaV6oGnUCOB+TPCOGmuPGdIVU1/vnTfh8RHTCVYp0XN4JWEVTjbgMaYW2RBRnKrfRerHbtqzt5X20lulQYYAOQ4dMTXcdXMa++PYt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AnIw/oYhBR57thYWn342AKO/0oSHooU77c5e503F+wR2a3XOoA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patch adds support for detecting zicfiss and zicfilp. zicfiss and zicfilp stands for unprivleged integer spec extension for shadow stack and branch tracking on indirect branches, respectively. This patch looks for zicfiss and zicfilp in device tree and accordinlgy lights up bit in cpu feature bitmap. Furthermore this patch adds detection utility functions to return whether shadow stack or landing pads are supported by cpu. Reviewed-by: Zong Li Reviewed-by: Alexandre Ghiti Signed-off-by: Deepak Gupta --- arch/riscv/include/asm/cpufeature.h | 12 ++++++++++++ arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/include/asm/processor.h | 1 + arch/riscv/kernel/cpufeature.c | 13 +++++++++++++ 4 files changed, 28 insertions(+) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 569140d6e639..603f4f23432e 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -137,4 +137,16 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); } +static inline bool cpu_supports_shadow_stack(void) +{ + return (IS_ENABLED(CONFIG_RISCV_USER_CFI) && + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICFISS)); +} + +static inline bool cpu_supports_indirect_br_lp_instr(void) +{ + return (IS_ENABLED(CONFIG_RISCV_USER_CFI) && + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICFILP)); +} + #endif diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 869da082252a..2dc4232bdb3e 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -100,6 +100,8 @@ #define RISCV_ISA_EXT_ZICCRSE 91 #define RISCV_ISA_EXT_SVADE 92 #define RISCV_ISA_EXT_SVADU 93 +#define RISCV_ISA_EXT_ZICFILP 94 +#define RISCV_ISA_EXT_ZICFISS 95 #define RISCV_ISA_EXT_XLINUXENVCFG 127 diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 5f56eb9d114a..e3aba3336e63 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -13,6 +13,7 @@ #include #include +#include #define arch_get_mmap_end(addr, len, flags) \ ({ \ diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index c6ba750536c3..82065cc55822 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -150,6 +150,15 @@ static int riscv_ext_svadu_validate(const struct riscv_isa_ext_data *data, return 0; } +static int riscv_cfi_validate(const struct riscv_isa_ext_data *data, + const unsigned long *isa_bitmap) +{ + if (!IS_ENABLED(CONFIG_RISCV_USER_CFI)) + return -EINVAL; + + return 0; +} + static const unsigned int riscv_zk_bundled_exts[] = { RISCV_ISA_EXT_ZBKB, RISCV_ISA_EXT_ZBKC, @@ -333,6 +342,10 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate), __RISCV_ISA_EXT_DATA(ziccrse, RISCV_ISA_EXT_ZICCRSE), + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicfilp, RISCV_ISA_EXT_ZICFILP, riscv_xlinuxenvcfg_exts, + riscv_cfi_validate), + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicfiss, RISCV_ISA_EXT_ZICFISS, riscv_xlinuxenvcfg_exts, + riscv_cfi_validate), __RISCV_ISA_EXT_DATA(zicntr, RISCV_ISA_EXT_ZICNTR), __RISCV_ISA_EXT_DATA(zicond, RISCV_ISA_EXT_ZICOND), __RISCV_ISA_EXT_DATA(zicsr, RISCV_ISA_EXT_ZICSR), -- 2.43.0