From patchwork Wed Apr 3 23:34:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13616769 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 8E7EACD1288 for ; Wed, 3 Apr 2024 23:41:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3F136B00A1; Wed, 3 Apr 2024 19:41:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEC606B00A2; Wed, 3 Apr 2024 19:41:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B80BC6B00A3; Wed, 3 Apr 2024 19:41:46 -0400 (EDT) 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 92F836B00A1 for ; Wed, 3 Apr 2024 19:41:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4F0C4C03C4 for ; Wed, 3 Apr 2024 23:41:46 +0000 (UTC) X-FDA: 81969845412.07.18E2655 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf09.hostedemail.com (Postfix) with ESMTP id 98AA4140010 for ; Wed, 3 Apr 2024 23:41:44 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tuVyeevz; spf=pass (imf09.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.173 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=1712187704; 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=htkBMuDJ5iEzOh5mmiAVjKhgj30cv1A8JpdqcqJ1q2g=; b=Mhn0f6nhxJnv9MAMtiS8yvQvTWJOJb3XyjsCaOqAqiisMFgpTPWTYdJRwOjpny0W/CwCyt bdYcyUIG4q7MersqLi0TMgZa13c1sx3y4ZPVDktZxIiLckxqW6Uzt6IzNvpiqpK3o67oRx AmV72yBIcfyCDaKPgQQEtLvI4oCFaLc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712187704; a=rsa-sha256; cv=none; b=8FVHfPPCuommVXIT0dpOkF+4WgMT3B2U009EXZFcUx2DtKBHFpvmE0kT/pRSiLoU0D+1n4 WAyeTPoHAlWkL7yBJ3lZiHkpdN+1w69AcmzIMBE7mDigUR0Y6R8Qt/3s1uJ7j+ZP68n/wB /nShGnU1Z6H9DRtQ1if9lclKhlAB5ZE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tuVyeevz; spf=pass (imf09.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e220e40998so3080165ad.1 for ; Wed, 03 Apr 2024 16:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712187703; x=1712792503; 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=htkBMuDJ5iEzOh5mmiAVjKhgj30cv1A8JpdqcqJ1q2g=; b=tuVyeevzjRyyFyjX/9uvEf22x4S5iUvIYmEIdSIMgb/DfkPcV209TGC8TD6zl7e9bP WUKs2Edrty9G939/pJJrwVtX3bzkqPmcrrqYogAQiNec/atz6T3R00obmy2y5Ws0UCHn g7xTAawC703+P+utoFz2oa1Bh0PzC8EbETUcyVk7PrqTRWh3KJr2HZaHUQlE1YrWqmsl VKzypkcjerU6lXH2o4DbnfIyN5YylekIEmTJ2ercDtnZT+gfJUFWrgpNG41hsTF0rKTX yeUZBWhnhqMxmrn8BVxjJaVQ5nn0KURUOK5TSTvJ3Y8xFxhy6QsXnvdd+bpK7ssRMAIV ryiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712187703; x=1712792503; 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=htkBMuDJ5iEzOh5mmiAVjKhgj30cv1A8JpdqcqJ1q2g=; b=GOfHNuikcbZgOPtglsV006B0BiAZ2PG/ng9yo0+grTpbDoeOKDeIuY42pCrFLbKhsf fvdqWtyOpopAYn2YYEj0nm3nTpC7r4oR83DkQ4+g9sGj6Xa26Tu2MxVRedsf1jpc+3l2 0Bz8oc14lJ4nMejRScmqsL1EqzxHVmR2YtaQj0SLnOTJHGTy1ZTHltlg8YZBYuSPCFXd cGO8dBj9Ul1aKfj00FFu01rj9wiQWPJzhlyjJ/jJMT2l7FpQbY9mj3/Dm3ybcw2LD86u Hqsg9sjbHj7VkzoDs4R8d0TS9jm+Z0zVaYFAZoAvZCFLfNVxu55kiO6P9qwh4zc75lH7 8Acg== X-Forwarded-Encrypted: i=1; AJvYcCWE1OlTkTobsO2e71nc74bok2BDjgrAQCtQMg+4q5/BfDVN1hiDpx6oSmPXk7n7QBXJYS1Kd1QP2L3VVpAcct6tDjY= X-Gm-Message-State: AOJu0YwrCtqe3WWorjZRUHI95BLHd1+eSu+C0EJqPP/0qbHrH7ChD/Vr /S23Uor8F/zqPt2nq/6BAhqG5b7zUvsra613D6OevZo0SCxl/MRR8azLKmssGQI= X-Google-Smtp-Source: AGHT+IH7W+PqbZqQgLqe7/1okN5ltEP1rpCUpt8LdmXzCJjFoz54mr5WWDJ+p0nFbKNWmMer9ORIlw== X-Received: by 2002:a17:902:e0d2:b0:1e0:c3b5:1c5 with SMTP id e18-20020a170902e0d200b001e0c3b501c5mr748168pla.24.1712187703505; Wed, 03 Apr 2024 16:41:43 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id b18-20020a170902d51200b001deeac592absm13899117plg.180.2024.04.03.16.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:41:43 -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, conor@kernel.org Cc: 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, corbet@lwn.net, 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 v3 05/29] riscv: zicfiss / zicfilp enumeration Date: Wed, 3 Apr 2024 16:34:53 -0700 Message-ID: <20240403234054.2020347-6-debug@rivosinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240403234054.2020347-1-debug@rivosinc.com> References: <20240403234054.2020347-1-debug@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 98AA4140010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dz7k1m6owk7k3eef5yfxt3dgpaww9kbm X-HE-Tag: 1712187704-720393 X-HE-Meta: U2FsdGVkX19h81L2PbQYlUkQaKaYG8nAwlb3ABqyMRLBD1VVLuHTxlkl/GVu1ZN4SmYX+3xYoTPGEnbxll71YNQoraezL4+7KK4OeFCF95UIiZi7VMiMWBxBcft0ekyDtwI4JWKUOsvkYFHL8LvpSYMQslfQizT4fLIGxerzAW8hzlQTFTLt4SOs5CO3EcTYd0i1Xv0sE3TTUWJ2UKCTaI/DTOotrPa5wbP8pPyXqmj6sEJj15z70R/d6aaftRnzVtuo42T7HeEJKPiOoAKy1GxWSEHijJYQCpfQT7JUfirs3MbpknvlJMTRnIGwXOoYdYEUxLjElFRhuG5f4H4EmzG4PFvEXTUxrOEjti4Dnk+hbmFvGQLIDq59HugGjZH0mmGOgFPcxIDBwG42f8qzkV6b6rO8SMEJUFovwMx/c9+cmp0gt2GW6Wx4AwPZtTydHEEE+mCOZY7XJcyh3NBZVLdRs851etWHU3UQ6JkovJDRH3551u+Huo6Mp9Uvu4YMZi2t0RSNlfMUoz2ppLaA1FdqEkqVWNC4eyYoJLRNRedECWTR11io0OKhSYBKFeyVTtKiVJ/jBld8gWlqfgzdYl/3UkFBKfU5vfi7jsga8w7wipJFJ9EdpNM66sbd3F/x0lTRWv0xPRBmit3GmeDth9yoDI9hFbBjubkk8q2MSjJuqClLpPD+KWuWYGKREcC17auOOW5GWg6NOpR0COVggCus+HW27T/d7QLUU1Cgjz2xleyi/V7ckC4318ulwUqSWu/MDQGIj4EOaJwiU7LYAWB3zIpDR2j9NwC+mVDuMJ0sYfpkGzCR/PAamgMD2XY6y1z84OvWG43aU5aF8FULtnXYpzGdxdZF3FzCTgNR6FkriS40Bv6IhZE9p1WLapr6bCExTCY6SORhB0g2yjuO5JC7dyx9gGxCb5KrDm25hrmpSqpSxwYr5qJVr222mhpwKzB0mapynfpE6B52t5t mc/+PUTj lwqnG+qksc2PYE9ChIlR6hCUh/pN3S+rERFz0dcIsYAeEaO6VrkPNOXefO6wDZc2q3KOX3Qmy3N8J3QUm3/x9wv58TzQhch6z4WUtPrEyxvzl5jYPm0DlIC9GvRyCIGajfn0R/ISMq9PgY8iNQ0YAkCIfJaDfSVFyVN4R09pTjOG+wyelNWBY2Z3Kjj6KQ/0AZ787NN4ajJCTHqBPI7b5wop+vPoE0+2AWg4wXnHGbKIHEktjvLEHg3Gnxg== 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 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),