From nobody Tue Dec 16 13:33:16 2025 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 AB15F348886 for ; Fri, 5 Dec 2025 18:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764959820; cv=none; b=mfv2zrW3U29rlpEQnLEXA8NH/AYOg/jIdvu+qRzIfQChFmaeh0Aes3fIm06DJPTo6P1PXWYAGkrX9Ho7Oz5fwPIbA6U7vHyUSjzFV33NY/PtxFyIPV4VT+ELQEJhbg6Z7cSHMT3ZX6gKiAeEfBjPq2P9cUwIuzEcqBjuUvh4LqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764959820; c=relaxed/simple; bh=ZNC9a/En39m8CKIDJtxwHFeTcpc9wzeOUsHgDemdXXU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=smf44bX9IAt0CH3lMmn/h9iOe80FXkx6pUwy24n1Lmi/Wqz+c508oyTSeDr0NPChr2XA6gdDBEOpwi5kMAAudb7DqiXafwGpAIpIq71VqlYVzvy1u17GuvrLQmrMm7L+lVRf3K5yQ+15R/DFCacfzmnr8Vk2JWEF0ig55Oy6qqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b=ZuP+ifYd; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b="ZuP+ifYd" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-bf1b402fa3cso2231753a12.3 for ; Fri, 05 Dec 2025 10:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1764959817; x=1765564617; darn=vger.kernel.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=Dse2BU+tFA5XFpg+kLbFKrS+f5gCoIar5kBy1XNyEFE=; b=ZuP+ifYdPGC9qE2gjHktuuH1kRkkg5nrMt2AbjmwlxmXK6FZ1Glht2NHFPVKhNKkK2 3dhAGoMRCjt/THPUrwa4zLLg6xeV0ChYSnaNY9FR5hqnxju7o9MX4gODYbs66hT3pSYi idUZD8PxJH4QrpfU23uhLNsPTqbluw4zhShToNdH4W3DirmUeAGiGDqo/CX33H7OvaCy Zq0ETv8Hz6k6AcmPVskj7BuX43w0kwSGqhoLnun0r5z4PJ074EPHY/zzgBLDnpkXdwmA 9yDWGAnqKj0SVxS0WCDfEk+H/8GA0ME4Jseh0OHIjcv4WHte2rSfc+UCXT5e+iN5lZWo S+uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764959817; x=1765564617; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Dse2BU+tFA5XFpg+kLbFKrS+f5gCoIar5kBy1XNyEFE=; b=Hc5ATeDiKqA8waNdXp3LDXtSFXWYst6WgQiSD+9cU5d0jiB3T1ZB+fULz+BrnirxrQ Ff+sd0aLHdZ4eNvw9R4NOsb0OIWE2VH9IjM24wcRhwVNQgPohrSFfTdPi2VlUfTZ5k+s 3bq72pGh5lcFqeLSDcHjqcbWGXloIZ4oq3g1P3m7ApFKaBfNVSpZnHNLJLymDrr80aDC /B4EJhMvG/rIoTtYWtrW8diZBHxcJ4F5DfmLggls2zw250z1PWzoCNKBpFSksZu62IsD c547k6gUBtq3b8EnnqbYRMy2zuoAm1S7SZxc07IV71Z3bVhFdOLUZE0vBGk5NW9RoDAd YJqg== X-Gm-Message-State: AOJu0YxJG9AF1asPeRFVRKL7TY6a/qHZIzB6HlgURrAZF0TUFn50IGc3 9AGd5+3G3n1KfFM9cDx9YSHMiOM2PVpz627COaWlyNzbQluystsXwxSONRf8Xi851wA= X-Gm-Gg: ASbGncuPKXiqtM4E7rYi5qB18qavyvpYnrbM5xB7mTlNANm20qQXriEd/NdJwUaHf2l Uh6kqBnBpLOKk5FJuiKPCaG/PyGt5PdGRmwCHG94Akz6Rt+2D0rjmw6BuJd6ppYpoUnEcTiClIn eia8TXaK8kXy+xlPtXwbpqPThhul5MJTVI2Kh+dqpPjVECysqyCrOgGGwYGPLEZ7WlfCq3QXZvx wo0rKYB1OGCtcRZK5VU+pTWTkHa1nxkXf2B5dW+yIE6l+l0YGhsTtBG3+LSwEfU5RYXnpm+WKmV LVze0hd9tmZHEjhSlHrQIG845/g/fqHuIEw3KqwtwjDIS5iaSyvXe6OyVOSHvCPka49/jerHR5r eviC3mHeHFIqa9aiKOmWw5Q8YEUs9ddHpL62WOlr3M9tXyrD9xoNCDrBObg9lySBTiQgHALhwOV mlm1YPTxJcNBs+DAE/AgGZ X-Google-Smtp-Source: AGHT+IFyM1iqMXt+qSrwno3qrNX4RPHWfEVVmVOUeAMA6kfv6cT+uLIoklBexS5RYMXJgxPECC8Iuw== X-Received: by 2002:a05:7300:e916:b0:2a4:5a26:25e1 with SMTP id 5a478bee46e88-2abc720560emr74735eec.30.1764959816568; Fri, 05 Dec 2025 10:36:56 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2aba8395d99sm23933342eec.1.2025.12.05.10.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Dec 2025 10:36:56 -0800 (PST) From: Deepak Gupta Date: Fri, 05 Dec 2025 10:36:49 -0800 Subject: [PATCH v25 03/28] riscv: zicfiss / zicfilp enumeration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251205-v5_user_cfi_series-v25-3-8a3570c3e145@rivosinc.com> References: <20251205-v5_user_cfi_series-v25-0-8a3570c3e145@rivosinc.com> In-Reply-To: <20251205-v5_user_cfi_series-v25-0-8a3570c3e145@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?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Benno Lossin 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 , Andreas Korb , Valentin Haudiquet , Deepak Gupta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1764959808; l=3702; i=debug@rivosinc.com; s=20251023; h=from:subject:message-id; bh=ZNC9a/En39m8CKIDJtxwHFeTcpc9wzeOUsHgDemdXXU=; b=CKnG5DfBkhW3eeubJ0rh/DdIBdxV1q/U+YHdRfoYgzWhJJIPEPPX9RsQ4SKbZaD16hCGQTrkw Ly4EGhODA2TBk6N0k+rFvqtbSJeUjXlZqiTKuE/5YDUsrnziMdkP0MK X-Developer-Key: i=debug@rivosinc.com; a=ed25519; pk=O37GQv1thBhZToXyQKdecPDhtWVbEDRQ0RIndijvpjk= 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 Tested-by: Andreas Korb Tested-by: Valentin Haudiquet Signed-off-by: Deepak Gupta --- arch/riscv/include/asm/cpufeature.h | 12 ++++++++++++ arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/kernel/cpufeature.c | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/c= pufeature.h index fbd0e4306c93..481f483ebf15 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -150,4 +150,16 @@ static __always_inline bool riscv_cpu_has_extension_un= likely(int cpu, const unsi return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); } =20 +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 affd63e11b0a..7c4619a6d70d 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -106,6 +106,8 @@ #define RISCV_ISA_EXT_ZAAMO 97 #define RISCV_ISA_EXT_ZALRSC 98 #define RISCV_ISA_EXT_ZICBOP 99 +#define RISCV_ISA_EXT_ZICFILP 100 +#define RISCV_ISA_EXT_ZICFISS 101 =20 #define RISCV_ISA_EXT_XLINUXENVCFG 127 =20 diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 67b59699357d..17b9e77bafc3 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -274,6 +274,24 @@ static int riscv_ext_svadu_validate(const struct riscv= _isa_ext_data *data, return 0; } =20 +static int riscv_cfilp_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 int riscv_cfiss_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_a_exts[] =3D { RISCV_ISA_EXT_ZAAMO, RISCV_ISA_EXT_ZALRSC, @@ -461,6 +479,10 @@ const struct riscv_isa_ext_data riscv_isa_ext[] =3D { __RISCV_ISA_EXT_DATA_VALIDATE(zicbop, RISCV_ISA_EXT_ZICBOP, riscv_ext_zic= bop_validate), __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xli= nuxenvcfg_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_x= linuxenvcfg_exts, + riscv_cfilp_validate), + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicfiss, RISCV_ISA_EXT_ZICFISS, riscv_x= linuxenvcfg_exts, + riscv_cfiss_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), --=20 2.45.0