From patchwork Fri Mar 29 04:44:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13610048 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 94FBECD1283 for ; Fri, 29 Mar 2024 04:46:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 224046B0098; Fri, 29 Mar 2024 00:46:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D5876B0099; Fri, 29 Mar 2024 00:46:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 026BF6B009A; Fri, 29 Mar 2024 00:46:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D92FB6B0098 for ; Fri, 29 Mar 2024 00:46:02 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5666681136 for ; Fri, 29 Mar 2024 04:46:02 +0000 (UTC) X-FDA: 81948839364.19.76D82F8 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by imf13.hostedemail.com (Postfix) with ESMTP id 85C132000C for ; Fri, 29 Mar 2024 04:46:00 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=XosRXdBz; spf=pass (imf13.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.46 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711687560; a=rsa-sha256; cv=none; b=Ew9ZXTxCGbONHV6ZeX5pFoHP6XnOznBlcvpKazYAnuBcBwu5lx9iriD0NmQakQ4TZ4AgYj o8aa5TpUOzj+rS0qJf7eGrL5eSPjlfEjRLKMAqSec7kTvmWixBgQGFROzOWlpwSYBuYUSG m9cndmLqYjcJcHVuvbXkFg4n4GofiDE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=XosRXdBz; spf=pass (imf13.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.46 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=1711687560; 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=BgqTcRj2U8Se9b0MFn8iBZ1MBZsdImVYllpKzi7FoF0=; b=kTJyo/QRriLaqmiKgJXhfdGRPVtF1rzpLSN+ksHVVqKrocOM57rn3CQzThCWX5/4P3JPVc TgqDRBTD/eiiCRmpxDsK7dDixmYHtcVlXP4k1r8xTPXMDfixQxpeBOD3AV0AuLKF0bWK7y T0ZWCvw42mkvrUCamm7XCLPqGneUXXg= Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6e6d063e88bso1053382a34.3 for ; Thu, 28 Mar 2024 21:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711687559; x=1712292359; 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=BgqTcRj2U8Se9b0MFn8iBZ1MBZsdImVYllpKzi7FoF0=; b=XosRXdBz7GLaZJC6446cqWjr00suO+6Dso7Hs7XfCgiQR7JJdUF0tDkmu/ngQcjd/J b2qY6q+7c/5v1cpDYUixBB+KEUlADw0dergl7gqMzFVlh8BmX9OjPLcwMcfqSDiH+CL3 QnpG8FEIlRWI+WFAlXYZf0WT4ATXEbJFB3z9hhYPUyyppXFNo/ufayRxgCV1nSV67AKS OoOivbQw4pnQXav0DK4j0L1AaFeiOkpQugHUZ0K+2EgP7etDVauMgr5FM4F0A2TcmQEy 2yiXWa0bBhbbxBm98tbCx3EdokBw9OzGkUAWUxtsXP/MZcGuBZeQ/Bm1ZhlqjVNjPU0U JdMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711687559; x=1712292359; 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=BgqTcRj2U8Se9b0MFn8iBZ1MBZsdImVYllpKzi7FoF0=; b=tKtSvn9R/4rdrnDixPzB+n9V53ZZ4srVvG666k2X7H78qkOhmxyTeUN98aX2x+iSxd Z+UW5OcjM57PKfizzWy2q5JnNRPceRmP7AnA3jJ60ZLK5LmRRNFBBVxgaccohc2FiFu0 oWfk6EJFcgxXAZ+5YkR6qXRP+Xct7c4EhFMwGhDR7LrH9wA3l7qZaiuEvMF4TVbIYhLZ oR87z0vwDq72I5GpWtYN50BG3eZNfBE/8gbU5nc3KGXbwWETw+E5gEib2Hdz9Uj8Atwj jdUr4Z2JKCr4qxrZqfFmX2udjNjGxt09nWM79LQyMpAF4Bzl/5VjEfjcm+Sg/vftyg9+ Q7sA== X-Forwarded-Encrypted: i=1; AJvYcCX1cFJrSdWOA6a7CNzHkT0vWOZ87LrBoct7GzEUhpYkEQYnm2UrAOoaIbSihMWA/ZwelH30ZCIEEy/GMgCCEK6caQs= X-Gm-Message-State: AOJu0Yzk7lVQ321l+Oh8pH0K7xEiLOSn5T2h/wPU+wpULc59Up/nodzX 1EAbNxYoUEcVIXaAsmnxip/fbthqQ32kx9Up7yNCJo0ptZSaaxtBUN2r5eFbNPg= X-Google-Smtp-Source: AGHT+IF8V+3oImQuk/A4crk7sPM/VnCwTyQ17ZYhfUB3qy96qUK1l2ScpaHLIegUvWCFYCKqh7Y5ZQ== X-Received: by 2002:a05:6808:1a05:b0:3c3:d477:62d3 with SMTP id bk5-20020a0568081a0500b003c3d47762d3mr1372369oib.44.1711687559607; Thu, 28 Mar 2024 21:45:59 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id i18-20020aa78b52000000b006ea7e972947sm2217120pfd.130.2024.03.28.21.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:45:59 -0700 (PDT) From: Deepak Gupta To: paul.walmsley@sifive.com, rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, kito.cheng@sifive.com, keescook@chromium.org, ajones@ventanamicro.com, conor.dooley@microchip.com, cleger@rivosinc.com, atishp@atishpatra.org, alex@ghiti.fr, bjorn@rivosinc.com, alexghiti@rivosinc.com, samuel.holland@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-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, tech-j-ext@lists.risc-v.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, Liam.Howlett@oracle.com, vbabka@suse.cz, lstoakes@gmail.com, shuah@kernel.org, brauner@kernel.org, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, hankuan.chen@sifive.com, greentime.hu@sifive.com, evan@rivosinc.com, xiao.w.wang@intel.com, charlie@rivosinc.com, apatel@ventanamicro.com, mchitale@ventanamicro.com, dbarboza@ventanamicro.com, sameo@rivosinc.com, shikemeng@huaweicloud.com, willy@infradead.org, vincent.chen@sifive.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, gerg@kernel.org, heiko@sntech.de, bhe@redhat.com, jeeheng.sia@starfivetech.com, cyy@cyyself.name, maskray@google.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bgray@linux.ibm.com, mpe@ellerman.id.au, baruch@tkos.co.il, alx@kernel.org, david@redhat.com, catalin.marinas@arm.com, revest@chromium.org, josh@joshtriplett.org, shr@devkernel.io, deller@gmx.de, omosnace@redhat.com, ojeda@kernel.org, jhubbard@nvidia.com Subject: [PATCH v2 04/27] riscv: zicfiss/zicfilp enumeration Date: Thu, 28 Mar 2024 21:44:36 -0700 Message-Id: <20240329044459.3990638-5-debug@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240329044459.3990638-1-debug@rivosinc.com> References: <20240329044459.3990638-1-debug@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 85C132000C X-Stat-Signature: 8e8emmeof31zh7i31fq4iprh1hzabi6k X-Rspam-User: X-HE-Tag: 1711687560-224292 X-HE-Meta: U2FsdGVkX180JQ2qXvGTXxf/R1TqrJDji9TXK2BixJIDMwRapul9AaQ+i6tEIK9Di66JgMBjvT8sIUQNQXFo8aQS3ZTdbExrwmTKEdSlPrYvOXRLzymB/P6JPBccLfGEUDIaTa6HNopHF/D59G7Zjtwx2oRtW3ZtJ4KX5eMA2lG+YzWUmzXzRXIBM+tPMH5QtLlnjsoDFjxyfWrIp7fJ/uHx3g3JvSOXdhLFhkeCZjZKIDAqIbyAihNya3CgTZ0Wi4c6SqfIC2OBzhv7BO0nK+3viwgWQvMOro2fKmVatLnB0fhpIwhp+1khBPBmayasS0EYHJyoRZUNnKupaXLs93Zj9Rj5WTEBgJdCf61kOY8peOv0d30lIaNH2NEAomWBth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6ItpZ80nQxkcm2+JOuUW8Nz/yLzoDN/eKO5V0dEugLAVxtR83VSiO3fjkkY4= 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: Adds description in dt-bindings (extensions.yaml) 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 --- .../devicetree/bindings/riscv/extensions.yaml | 10 ++++++++++ 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 ++ 5 files changed, 28 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Documentation/devicetree/bindings/riscv/extensions.yaml index 63d81dc895e5..f8d78bf7400b 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -317,6 +317,16 @@ properties: The standard Zicboz extension for cache-block zeroing as ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs. + - const: zicfilp + description: + The standard Zicfilp extension for enforcing forward edge control-flow + integrity as ratified in commit 0036ff2 of riscv-cfi. + + - const: zicfiss + description: + The standard Zicfiss extension for enforcing backward edge control-flow + integrity as ratified in commit 0036ff2 of riscv-cfi. + - const: zicntr description: The standard Zicntr extension for base counters and timers, as diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 0bd11862b760..f0fb8d8ae273 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 @@ -137,4 +138,16 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi DECLARE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key); +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 1f2d2599c655..74b6c727f545 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -80,6 +80,8 @@ #define RISCV_ISA_EXT_ZFA 71 #define RISCV_ISA_EXT_ZTSO 72 #define RISCV_ISA_EXT_ZACAS 73 +#define RISCV_ISA_EXT_ZICFILP 74 +#define RISCV_ISA_EXT_ZICFISS 75 #define RISCV_ISA_EXT_XLINUXENVCFG 127 diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index a8509cc31ab2..6c5b3d928b12 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -13,6 +13,7 @@ #include #include +#include #ifdef CONFIG_64BIT #define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 79a5a35fab96..d052cad5b82f 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -263,6 +263,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(h, RISCV_ISA_EXT_h), __RISCV_ISA_EXT_SUPERSET(zicbom, RISCV_ISA_EXT_ZICBOM, riscv_xlinuxenvcfg_exts), __RISCV_ISA_EXT_SUPERSET(zicboz, RISCV_ISA_EXT_ZICBOZ, riscv_xlinuxenvcfg_exts), + __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),