From patchwork Tue Oct 1 16:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13818411 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 EECE4CEACE5 for ; Tue, 1 Oct 2024 16:07:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DF752800A3; Tue, 1 Oct 2024 12:07:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 48FCF280068; Tue, 1 Oct 2024 12:07:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BD6E2800A3; Tue, 1 Oct 2024 12:07:24 -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 09A30280068 for ; Tue, 1 Oct 2024 12:07:24 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8E07D1C4603 for ; Tue, 1 Oct 2024 16:07:23 +0000 (UTC) X-FDA: 82625513166.17.6DB8839 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf14.hostedemail.com (Postfix) with ESMTP id 9D7AA100029 for ; Tue, 1 Oct 2024 16:07:21 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="nmm/6xlK"; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.51 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=1727798777; 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=E+5BUiXk0qE5fwdGMgQslVF9cwH/K3wvmujTMdEKiHU=; b=FPRWze8W/A/JdahRqho6Qjc2iGQWy8DdZi2/IU8Xpw5ZDfyQhkGnVVSg+sB/QzURcpwH12 TTtMb4xSjHiZBg/7S5QACHt0r+ioHN5/CgVYqZW82WOWJ5buyZnhn3i3+exuDyz6hnAGUB WZIyR/A8/UxcWCbNK9tlrJM7yiB0nWY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="nmm/6xlK"; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727798777; a=rsa-sha256; cv=none; b=tJGGkhwLSQz506NxNyGKYYGMPFzxf//W3aZTNPyK2bKPrC/D2UQjmknfEbpk0IUbclvxpc ZPofxjnkIYxtgFqsl4VLt1wpntaTg4+kQvv89eqdZukbtMryCPwdlu5+VzHmGKzhsBShHJ GD/xdVH72Z2bVcj3CUQenSS5YkmOkhw= Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2e0946f9a8eso4041078a91.1 for ; Tue, 01 Oct 2024 09:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1727798840; x=1728403640; 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=E+5BUiXk0qE5fwdGMgQslVF9cwH/K3wvmujTMdEKiHU=; b=nmm/6xlKFhCQ065mBh2F5ap6zRWKexqz3SzXBBbyJkAFaGZXLP9IsV2n8hGScp1Qii vCQB5Lxk4phVMg67NILUSLAjvQe2A7xeNurUyWVozvASLe+XvCFkJNnBabTMBMMW/3WP RBmrKOUSmbPrx3JA3QEe8AS3wMW/Jp7dn9UYhOWMtLbTPz1dbzipIoVb8Pt+QNpJFGu5 1AOoltgOoYves+ADOghhCzocLpl6ONlfLcHKQGZj9LjahS4ESn+AWzzt4m1RAjlzWKZI Pe9cBboYAHePTFKDzEUP3zj3CGCuK62NGLzSkBI9dTFSWwMFOd2RWZjmhk0Uj8jIR/r5 HV4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727798840; x=1728403640; 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=E+5BUiXk0qE5fwdGMgQslVF9cwH/K3wvmujTMdEKiHU=; b=KGQqe0Vme4F3jQSclkxO/HaWeBLHuiHUO6CMRsxfLmbAI10w9uKD04s+kwWp8Ni4HM Chk+Fw9I8QFjfpUF1HuxG8bljiIKKygcSFhSWecUiregbZGyD+0pwCyi7ZWK+DwFUbR/ IZHolzh0WytQ69dTiX6kPBiXVdR7z9lUTDa4FC3A2bLdDZkgfh18SKaWI3HYQeFlOswf c4oBTMiuHuzOgEoocvgJZdfq0NgnVXO1hXQmeIdWut9K5Gz8zCYAymR5kgVcXTBWRrtN saJse3YulFj3g18dYcDVqHEUu6emx8mv7a1mqjzwaZechLiXvV7ofraw4RhYgSkIA6GF ssKg== X-Forwarded-Encrypted: i=1; AJvYcCU552TKabWmtU0Yz9FGJo6wrS5AiTxPkTHZuF6sJJR1VHZgki2PW7XbAlz1wMjNddRTDkTRu9XCPA==@kvack.org X-Gm-Message-State: AOJu0Yz0O/xkGdcsZmHLz+2rn6HWVsPFWhNRrEtYq+NUgwkUvwZu4CKJ kU52xvQu0gkvl4y/klyWuuR7MVJeV3ht2ebWGj8hlDIOsdp73eVQhvUbITODiJA= X-Google-Smtp-Source: AGHT+IErQf5YjbMNwa+at3UP7ZmCJwrLyizTuL84rtWHL68ki3hQqLuCxkKzW7aSkks+lwT0RS+2sw== X-Received: by 2002:a17:90b:4b0c:b0:2e0:808f:ef9e with SMTP id 98e67ed59e1d1-2e1848e3633mr179913a91.26.1727798840354; Tue, 01 Oct 2024 09:07:20 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e1d7d47sm13843973a91.28.2024.10.01.09.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:07:20 -0700 (PDT) From: Deepak Gupta Date: Tue, 01 Oct 2024 09:06:13 -0700 Subject: [PATCH 08/33] riscv: zicfiss / zicfilp enumeration MIME-Version: 1.0 Message-Id: <20241001-v5_user_cfi_series-v1-8-3ba65b6e550f@rivosinc.com> References: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@rivosinc.com> In-Reply-To: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@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: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 9D7AA100029 X-Stat-Signature: 6hr76u591nj73h7kediqipi5eyy487gj X-HE-Tag: 1727798841-156536 X-HE-Meta: U2FsdGVkX1+Z2OEBFG013lJIIkcSL2u8E36jln4ut9r2lQbKjoDLZ9BbCfd/mqzujzNFFGJ3bNuyGhBJXQWh7vx86T+UOExvVT6+bTco8XklJVcZJbWW6ajL/tfMs4jZWnDFaLfWq5aMgiCyE7B3pq7bTNRNckXTPimw9sMwTZCuZib6oIrdi4UhzQcDWyoL1eHHcROPMkgPTfWD34pZQsxJzuB/AHY1pwL0jHi1fJlNnvshYazEKrMhYHFNrzcEr/cH+0CQUOkNxIjMsV/ocfm/5GqVhRckNAbhnrC3b4vXxILi6zWslBtM4j2O0qhEaEaNgQPpMCk7xgfKctHlbYEzVxhyceSUYVuU/+7P7adQIuhi12hf90WP85pYwnLv/PsstBKDt06NhN54RnlPzD2Hpq9CX3aslYWF7ABDN1dHBba0xoQq6VVePaEONzQrcyrYk4lgTdaNq/AD03NcxqqHxIuAWtVrjxRCQez6gdnYsO+qqsMrJTVCeHYgWpIX052KF3NLvVYq9c2tF6wUtEdAcrnnkLUq4TqnFvK3n6EaNz9Q41I1A0r0T6Yfy4wdzfBubnHNjd2/cmkknb80Y0M/Qx8iamZtmVmJ5QYNVot/BhrE9xbgQ+KMUbm0Ag8UUtjRFbA47Ld18ducj1jLjVVpXRDY0d1fb0eT9v2nKZsWmeZSOUVDhIlQNFdDw8vJDmnKA0Q59ErwJsL7Q2xmDSaj+Cc8uu4bVwQ6+MtMTfdyN5dac+8fOicEirEsOWjBXqLrJ6P0usp+BoVpke8zflbo61Z6FXnMcaGEFg02ycxCIYBE++qfNgcv9Gdt3cWjMSKUe47V1UpdCbmRTmHMer4oHC9lNk4RlKTg2rWqYndS3TG1O4eRUcjJsj0beGTh+w6J6GFGgKVMDldv+ZbO5/6s8jsifLX6NnEd7kqRnSZ4+TL38ntVJkkPRv4BOlihJuwsCoT64gaAFLSGduj LynlD5w4 cjy0NoWtrRtFXf7BDbuecrv3KM1bNvLIf4QFfTR453uev/qnlGLkfmJb0yAmeGt3M0o1PeziX8+txmCZV8Hyb0c9fq+gqg4KfC2XmtwUCfdK/Pq97pZZ2IRgbQ1F8Nb6DHgOS6sAsQGr7mqTcONjkY1FNKNCUj7AqmV/LqxbWlfkQe+qXZQ0oIfVFJP9V1dB0F7u1zBm9phqJoYq4RfxgT2PbSz7yRCencjK1fK8JI4ucnNz30+lH4e5c0r6WQTA5BAahjXEwDzjvefIpnnpKa+b2FlsbgbjId3L71Z2g59OCxipuJ/ILEvXOpYBjjPG4WS1t2Pk4aia1w9Vu0BISFxuAC/EmGVNJYj5nTIqOZOFFHhXnT92w1A5QAKrW2657L0a0hm2uvcxCPBtSZWgRKprQLxmTQmTSuutMs5P5sCaS+VEPhVdDla6kJd2fne8Xp3XxkaFF5I7u8GURMZ32hbeKztuaKKurC10kx4ISUvhiFIHrI3fd3IS5Mg== 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 ce9a995730c1..344b8e8cd3e8 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -180,4 +181,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 46d9de54179e..10d315a6ef0e 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -93,6 +93,8 @@ #define RISCV_ISA_EXT_ZCMOP 84 #define RISCV_ISA_EXT_ZAWRS 85 #define RISCV_ISA_EXT_SVVPTC 86 +#define RISCV_ISA_EXT_ZICFILP 87 +#define RISCV_ISA_EXT_ZICFISS 88 #define RISCV_ISA_EXT_XLINUXENVCFG 127 diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index efa1b3519b23..9ea0021a1a75 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 7117366d80db..96a1375d7171 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -317,6 +317,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { riscv_ext_zicbom_validate), __RISCV_ISA_EXT_SUPERSET_VALIDATE(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts, riscv_ext_zicboz_validate), + __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),