From patchwork Thu Sep 12 23:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13802831 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 4792CEEE271 for ; Thu, 12 Sep 2024 23:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCCB36B009F; Thu, 12 Sep 2024 19:17:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7CA86B00A0; Thu, 12 Sep 2024 19:17:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACF396B00A1; Thu, 12 Sep 2024 19:17:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8876F6B009F for ; Thu, 12 Sep 2024 19:17:44 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 506AFA0E3C for ; Thu, 12 Sep 2024 23:17:44 +0000 (UTC) X-FDA: 82557650448.25.59D4D9A Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf03.hostedemail.com (Postfix) with ESMTP id 765E72000C for ; Thu, 12 Sep 2024 23:17:42 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nqdNJ7qb; spf=pass (imf03.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.181 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=1726182957; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TC8HJTmLFTCxnzwVbVDHY5HOw5On7Gme9EHJxcVvh2Y=; b=OeHawfMzFlmsOXf2o+ruO+frcq2/fE2YMA+CydKXeXWOy4xqbYqLnusgDg5tPG0pHmDciJ lOX86UTatvP1YDrkFdBITHbD48qUgmrwGNskrwZgEkbOM5GSRepCoexu29NbZrvPMcNvob 6mLR3GTtOuqYrRRCkV0TCgPWQnoEkY4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726182957; a=rsa-sha256; cv=none; b=L08tRiabgncELtdTx2YAPPS4F7sHWjyOjdWl1pVT3fuZbYVr85UOAYddIAJQ67meiIB6LB 5jpRk0OyIsU4gFG6WoJ57ae0qiSeo2unnzvdQNiae9jnR9taqSD3WwRHv1IHVvpYs9pCiM 6GcUNjGvVvuXHbyRCEJR+58/AYLec3Q= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nqdNJ7qb; spf=pass (imf03.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-205659dc63aso16899535ad.1 for ; Thu, 12 Sep 2024 16:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726183061; x=1726787861; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TC8HJTmLFTCxnzwVbVDHY5HOw5On7Gme9EHJxcVvh2Y=; b=nqdNJ7qbD/ZD5XhzEUIIjrTd8ao1ZuAwCGnK3wEJI7Sd4Jp7kpySUSBlwdYl/TuYjJ wl87VkPjYhTH6mhPAOyX2kTNlLjUn2vnBP/d3uGO61JVzx/e/Fhy78ZPPgZBSlsYg4VI 4wTq0epFr3zzxlzuZkDN/VjnTzqejqzGKG17ERUaGGYpKXZGrbWbsnmfDRQh1G/LDbJ3 BO/kHfU3a2SkYxTWFvPJFhKPJeoM6fiDGDt7f/abQMgtqYq5CD1E/9NBjV3A3o7WU80P kk/wzZj6MS9BbzO9oSC0mLrbASGUzu78mZyqgmUMnlOv+3/LUWCcYEjqjE1frQ7ktjUg fe2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726183061; x=1726787861; h=content-transfer-encoding:mime-version: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=TC8HJTmLFTCxnzwVbVDHY5HOw5On7Gme9EHJxcVvh2Y=; b=KHOUrk2JtYDaN24CQZCmTSO6gbyDoYcbxxFYSUtsreD3muRI6JXkQ819UOxggbL7YQ 8ITLoBlcCI9aLxJXMfsjflzFfOScvinShJDv83y74g3BxhzD2U9RAfFC9rViqHkGiHDr lLo2aDCg9KOBe03JN644x9uHGiyuDbXvTs3gXWs9k3jeMaOMOrqdvHtMw/qsiE/3Ibju YVAoXMcC+Jzm03DZmsghsASiduFi1t3bmpyZg3hINO7pMNGtaBzy+ZlGKkuMvs6Sx+Fq dUkA2dtKulJyqyCDQ/oQNd+iSN+sxlYVsmijmsUlKD4CAFIEnRGAUylOZHnKWWblu96u JacQ== X-Forwarded-Encrypted: i=1; AJvYcCX9rKR+YpsgTj2iklhZBoVcRRsU2pM1hQEoLtcYppHaDpqtHyCPPIyk0BG9yme99uhTZGMSnpYhcQ==@kvack.org X-Gm-Message-State: AOJu0YyVq2IPcb0Uk2rq/+Jvstg3A2sF+ATQMMnBQ2dS+ehkyvfdUyls jBRrlZMceBzgDCOk4tvQ/bKr0lDLXQVn0vcvLln/1XS0w0wxMXY6+VbUusmZZmM= X-Google-Smtp-Source: AGHT+IEpTcNeHZnDkxzsBefZDBG9gwlZQAPff/y8vG/iX+SRyJGFk81Qx5PcE3129Vm1O5X6NKyS+w== X-Received: by 2002:a17:90b:4c41:b0:2c9:3370:56e3 with SMTP id 98e67ed59e1d1-2dba008304amr4873291a91.34.1726183060973; Thu, 12 Sep 2024 16:17:40 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db6c1ac69asm3157591a91.0.2024.09.12.16.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:17:40 -0700 (PDT) From: Deepak Gupta To: paul.walmsley@sifive.com, palmer@sifive.com, conor@kernel.org, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, krzk+dt@kernel.org, oleg@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, kees@kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, lorenzo.stoakes@oracle.com, shuah@kernel.org, brauner@kernel.org, samuel.holland@sifive.com, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, greentime.hu@sifive.com, charlie@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, xiao.w.wang@intel.com, ajones@ventanamicro.com, anup@brainfault.org, mchitale@ventanamicro.com, atishp@rivosinc.com, sameo@rivosinc.com, bjorn@rivosinc.com, alexghiti@rivosinc.com, david@redhat.com, libang.li@antgroup.com, jszhang@kernel.org, leobras@redhat.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, costa.shul@redhat.com, bhe@redhat.com, zong.li@sifive.com, puranjay@kernel.org, namcaov@gmail.com, antonb@tenstorrent.com, sorear@fastmail.com, quic_bjorande@quicinc.com, ancientmodern4@gmail.com, ben.dooks@codethink.co.uk, quic_zhonhan@quicinc.com, cuiyunhui@bytedance.com, yang.lee@linux.alibaba.com, ke.zhao@shingroup.cn, sunilvl@ventanamicro.com, tanzhasanwork@gmail.com, schwab@suse.de, dawei.li@shingroup.cn, rppt@kernel.org, willy@infradead.org, usama.anjum@collabora.com, osalvador@suse.de, ryan.roberts@arm.com, andrii@kernel.org, alx@kernel.org, catalin.marinas@arm.com, broonie@kernel.org, revest@chromium.org, bgray@linux.ibm.com, deller@gmx.de, zev@bewilderbeest.net Subject: [PATCH v4 08/30] riscv: zicfiss / zicfilp enumeration Date: Thu, 12 Sep 2024 16:16:27 -0700 Message-ID: <20240912231650.3740732-9-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912231650.3740732-1-debug@rivosinc.com> References: <20240912231650.3740732-1-debug@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 765E72000C X-Stat-Signature: piwwxc8tai9576hpmbdn476efzwhzwue X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1726183062-173102 X-HE-Meta: U2FsdGVkX1/FmepKYs7DrKEGVREgUYl8UxszmKbtci4yXyxIjjQZQhKNzFJedbVbf07cRS6Npik9fAYjDwfz9r6V4c/lO+qH/D+LZ5ZBDP+ceCxTorbiJCVGeWONbfDc1+E5QDtM4gLZeu3g865pTJTk783FmlEeRGzvL9fkB0IYpQg7f5CVf39dnqNnLtGHfyADL8R8hAn15o5F53t/jwYQUqusweVc5TbwtpkMqnNMQlmVorVxZzH/kzKcjlzaDqkz6hLRtIRQEgU+UmBGu41mOjs//y/gopSJ2ooV4mWvo3b9wB7YsfZFS80qJkj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JzarBS36vuDHxsS5oU1apXaRwrhVWSX9akaaNa3M/XThpTr3QKrvgR8SarUum5wYXVCcdYJM3TVvr2HppkiI+usCj99ytM= 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 5a0bd27fd11a..04425476526a 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -92,6 +92,8 @@ #define RISCV_ISA_EXT_ZCF 83 #define RISCV_ISA_EXT_ZCMOP 84 #define RISCV_ISA_EXT_ZAWRS 85 +#define RISCV_ISA_EXT_ZICFILP 86 +#define RISCV_ISA_EXT_ZICFISS 87 #define RISCV_ISA_EXT_XLINUXENVCFG 127 diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 8702b8721a27..d61587964bd7 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -13,6 +13,7 @@ #include #include +#include /* * addr is a hint to the maximum userspace address that mmap should provide, so diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 41fd0be25bd8..ae6ea2f1d1db 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),