From patchwork Mon Nov 11 20:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13871341 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 08DE9D3ABF5 for ; Mon, 11 Nov 2024 20:54:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E047E6B00BD; Mon, 11 Nov 2024 15:54:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D667D6B00BE; Mon, 11 Nov 2024 15:54:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB9556B00BF; Mon, 11 Nov 2024 15:54:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 893EB6B00BD for ; Mon, 11 Nov 2024 15:54:08 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3F5B4ADB8C for ; Mon, 11 Nov 2024 20:54:08 +0000 (UTC) X-FDA: 82775015022.25.8258027 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf14.hostedemail.com (Postfix) with ESMTP id E5602100004 for ; Mon, 11 Nov 2024 20:53:20 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=s7ib8dEN; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731358214; 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=kCloQ3kpRaUIw71nS1Yef0RT6Cd+Bh0EPCOA/9JkyG8=; b=Pvrc6rvsYKw0xg1mVzYEbNNjWEd23jEpQsGNuRyB5eUSIS08rAt4kOiY29GTLuOGu2kmjI AKxxH9022rSBVmAc+QhKqp840YlSSIeOIt7VYTPE8WCRMCmyN7lNBZiqBYV5Ng+jLalVZj EVRRdzgrlcEYnNq6FJqF0YGfvA90T40= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=s7ib8dEN; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731358214; a=rsa-sha256; cv=none; b=0WOa12oZF0oZ1gltrpFiiXw8uWTTZj3ZdXpg6BId6DldJlNN5iervxyvdhDvT9xtpMcHh7 2Is0YpfcoOnJiYxK/TnYFjbsHhYqW6wUg+xuJ+AUSo5XqTWt8UDCSvwWIbdHtS4ucgM7zx d4gZHUFHilBVVn9Ptopj2OZ3tetbeoA= Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2e9b4a4182dso2333389a91.0 for ; Mon, 11 Nov 2024 12:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731358445; x=1731963245; 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=kCloQ3kpRaUIw71nS1Yef0RT6Cd+Bh0EPCOA/9JkyG8=; b=s7ib8dENKMp5Ect09ZoyvhgsRCNLBKXGTNn/3JpGMPaJfSrnSTyqtegjmf7MSHaEGU I3UJ+TdFL99o5BufsBh095DcsW81GlO+26Jt8dWyMEv0apRJvsfywKeNxlPRPwiBAwdE +dB1AV5AmnnSPur9TNMiuf2ysiMfxT8puBXUZGJZnFYCkiKD/+ubxozenWecS3u2QnWb 32zdTn/DWMbxHQf57J8FF11N33SSLMTTtgNzCQkPa8xxETojcc30ARkgEpIuGwswSq4j 3So22MYZOlRMUGKEq1ZVzgQIqzzWyZCBJ8KmrjDFiHse6HbVhxaIhmJK4HyVDxQwr8cr fsOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358445; x=1731963245; 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=kCloQ3kpRaUIw71nS1Yef0RT6Cd+Bh0EPCOA/9JkyG8=; b=xUVuEisGXVG/DrNtWpkJgk+OYaFMQ8f9V8Kjz6WKOdVEnXlYsi4gYEQAk/a2PkEVJQ kY4KJTyMu6akRZ1QCreqwQ191ZKa0o36rOzqq880LTi7qgnaAte3RrJQIRw/gvq8IuX6 PVzhVySxMQR+zVSa5qZhGfcc5lMraRA4RNK/iyrACp3Uiu0v/l7sU2Ohw5N9Htb9pwlX 9/zCo2al+R9MYp9MP4xxNzaBPGI0opep3ORAjFXI0tOFMCC/UpnaklMik1klotJMQa57 awhAq3sky1vE19QQYGvEJ7U4EDffgfZO6wTGGONJqBMeE6CvHAFt9cvlTL1GIUzTTOCv OQJA== X-Forwarded-Encrypted: i=1; AJvYcCVA1ge5DQLsXm8r4FXeHttIM4oNtMs3IzbayH1A06JOnCfCAhwBHHJiO4HzxOxyH/fRaTwqu8E9Xg==@kvack.org X-Gm-Message-State: AOJu0Yzw1ujH/xGGo57OSkLi+R2l34ChAmT6bmQjrxzlHOA4SCvgMz+I HkhvT4FVTu0Z1wdS1jivzcrcULAzD9dGNAheVeoBl+i837IAeB2jYuh4sPtH+3E= X-Google-Smtp-Source: AGHT+IEzLgiBrXYk8UpI73d5WjrE2IsuXIp2E2P6Y/oemnmdip5WKObNchwxhppbPh61kx0lDDr4mA== X-Received: by 2002:a17:90b:1bc3:b0:2e0:7b03:1908 with SMTP id 98e67ed59e1d1-2e9b0a57d33mr21146939a91.10.1731358445109; Mon, 11 Nov 2024 12:54:05 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5fd1534sm9059974a91.42.2024.11.11.12.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:54:04 -0800 (PST) From: Deepak Gupta Date: Mon, 11 Nov 2024 12:53:49 -0800 Subject: [PATCH v8 04/29] riscv: zicfiss / zicfilp enumeration MIME-Version: 1.0 Message-Id: <20241111-v5_user_cfi_series-v8-4-dce14aa30207@rivosinc.com> References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> In-Reply-To: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@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 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, Deepak Gupta X-Mailer: b4 0.14.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E5602100004 X-Stat-Signature: cxsq7wtoh18ynbkyje7dxwp5xd1yo488 X-Rspam-User: X-HE-Tag: 1731358400-607875 X-HE-Meta: U2FsdGVkX18o6I/MkQtxjFVRxw407buGdfWNlhmvHgUOhwF2Mv5ixjMIpSRS0tU8/ZkIWe2fmVLKo9+DUfLL1vdDukNwzyw3eOzhdGAUa/UaoC+IRoiSZE0nxuDgINYQXPpybyI8/jrfbXGPsm/V58ohU9t5odwxsUDucpy94ObooOUsGqd5dX2Y0H4lzB0R6ZzFYh2O6FDKZFPfQxq+g+Z30MVzF55wjPmxDg1A3Q59catVCgkrDTulUGR3gNW8bC4l9Zgxp3V766CZSXNHtQybbHP8hp/viiQDW1kYSxGvbsdd/rRnLA4X3dtnMU5B6LEpVleWDH9bC/C6fpDGQVU/P9k5rjZfhwltalIeavUdHL2AS/oM/o8jAr7JPQQymZ9YkjjQPpaaUc3aUI2WygowlV9Scfw0cFN6N4byK3yPWnPAyQvB8LAEiKR4vSl62G03aeUmSz2yFWmo5dnuv4AEaJShgxizPWbTa5C/8vxyffRb/n/G5N4utiTX5rgG554xidoF3puyw662n31pMrXgKPLbFFzRY64g8IaWidEWzBvcrCVnIC4hIlBv3RPKyBnKI+ZVEX5yCOmAuesg13HemuV+KZ//7b5rXmCOhssmOcF6KZEqttEgUapoVt8yzsfWKHQd1t3yPlcxmeZS4YliyomEMYcfKEbC/h+x06t4OXWtrAqyzoaI4EjbufWeH3y8ziMk+7GsPvOWB8pM/Ian3ErdtQFC1CR9T6vS2ay5J1us9Ne6dAxBL7bfxoQG23EDgy/L0gnYnduBAjmgelEZVWG8v6O1tmraU4uB5F7LjX2G55YBzuIM6UVEUnW51SWvw3DgF4iOg/XNkT1LnixERW1ng+qeEfjGQLUMcXaw34wzAAWG1f+GYR3XJuEeOjSwMThzVidXDPtjD6XfEqlh4DmM51DbyAcTROUC2Q5SiqOosNDofozPY+lmrOA+j4qMU61JGxa6J52WT/8 DGzZRClj DUFflyawOoLqtIkUQAFKRd5objR3m5fE51QWgaMBBZFysCDchpGxX8GlyKEsdzEJn0Pfr8UAWBc/YwgdXFETjLjVVOTiKixBhCD6ZJvwctK2EHYMF+5WYJgcFGAfmywR/t6dRgYOdy+oQ4PIffKu+OqPyX3GLcFR3H/Ig//pevgo+AxO4qzU9JgulXhgCvjG6nsAZ6a//83WrNHcIvh+LDp7qwqlnaRvhJVOC/FhVf9GBPADPNyq26Oby3f15E8AZXMhH25xfdPx5g0Y2T9uW8G1CMLUiwqRTIASM2iQmD3GnaGbSJVitdh+zW51L9dNrS2S9+1J0PW96oQw15PBu80jXs1WK1PhNSn29wvfIivw6XpH2vUlC4hwRYOTty6QocoruMtyOIV0N5xsmUZVfG2m01g8EqMGFYmasry6o2B3Cn1RELgL5G0sM2Hkqe7kW8jj8mlxCglfkSgX/Z++8OruEuPDZHKtUX5pyEG2x2GRroYfjoN+FHaXSlg== 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. Signed-off-by: Deepak Gupta --- arch/riscv/include/asm/cpufeature.h | 13 +++++++++++++ arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/include/asm/processor.h | 1 + arch/riscv/kernel/cpufeature.c | 2 ++ 4 files changed, 18 insertions(+) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 4bd054c54c21..8d12dc6c7d44 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -135,4 +136,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_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZICFISS)); +} + +static inline bool cpu_supports_indirect_br_lp_instr(void) +{ + return (IS_ENABLED(CONFIG_RISCV_USER_CFI) && + riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZICFILP)); +} + #endif diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 08d2a5697466..f81f62b32f72 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -98,6 +98,8 @@ #define RISCV_ISA_EXT_SSNPM 89 #define RISCV_ISA_EXT_ZABHA 90 #define RISCV_ISA_EXT_ZICCRSE 91 +#define RISCV_ISA_EXT_ZICFILP 92 +#define RISCV_ISA_EXT_ZICFISS 93 #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 eb904ca64ad0..0f2c466a51ee 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -318,6 +318,8 @@ 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(zicfilp, RISCV_ISA_EXT_ZICFILP, riscv_xlinuxenvcfg_exts), + __RISCV_ISA_EXT_SUPERSET(zicfiss, RISCV_ISA_EXT_ZICFISS, riscv_xlinuxenvcfg_exts), __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),