From mboxrd@z Thu Jan 1 00:00:00 1970 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 7A3C1C3ABA5 for ; Wed, 30 Apr 2025 00:24:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D87AA6B00A2; Tue, 29 Apr 2025 20:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D38036B00A3; Tue, 29 Apr 2025 20:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3AC46B00A4; Tue, 29 Apr 2025 20:24:44 -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 87D6F6B00A2 for ; Tue, 29 Apr 2025 20:24:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3C6FCC1579 for ; Wed, 30 Apr 2025 00:17:42 +0000 (UTC) X-FDA: 83388796764.09.93A8CD7 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf01.hostedemail.com (Postfix) with ESMTP id 777A640004 for ; Wed, 30 Apr 2025 00:17:40 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=fID2MTtK; dmarc=none; spf=pass (imf01.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745972260; a=rsa-sha256; cv=none; b=dku4gr4m04jXzTf8zFAsOQnY4IpiAYaop7L/ykFgKAQhBPV7wKSGCfnvEfmrSsTIs8LUm+ kLtraMBhj4mN0ZSjDKZwS8yv3ZkA0vvJwaFyuXwZcFZBp0Fy5wjblYpYZAhokF0sNQgobe ctNrA8+x2EV+yT3Cls2htEYl10NwP6s= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=fID2MTtK; dmarc=none; spf=pass (imf01.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745972260; 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=C5ZEZwH3aQrzLfVWdE9j1t2G3YTj0WprbxNkrWh/BaE=; b=7JPXnae+CCftkG6XaBZYhB0YqdH9ZloL/sK/n/NAHn27pCf4xGvvnEE925Fgd5cAlCtasB Kvxw2+JTIsg0yQZ+Zya/XQSMiOEAtXmGoc6+aV3CCKuZ/v9f9ooYk5+naQSPI3B/0/KE1Q Zigkd1C8WvKHpjTcWNJjUeixm4Bi1kY= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-b1396171fb1so4296244a12.2 for ; Tue, 29 Apr 2025 17:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745972259; x=1746577059; 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=C5ZEZwH3aQrzLfVWdE9j1t2G3YTj0WprbxNkrWh/BaE=; b=fID2MTtK/ACrkZiTDTF/5CrOMmUGrHWcIYvtTS4bpTKWHjP2VMwLlkDpd2nA54PCjv i4kl7iphTaiMzdLRDRPJOg+cAdCVSFG8BImFs6PjpkymYpjtKQGPaaIoiLQjCUSYjZAr KF6sXne/3JRM4N3JqzrZKMoUDuJkH2eX6r81aXB1WTlTmYOLnjgr+Hhc9lnwaRSy1Tui t4ijHE5zZFbnkc4Z+uCNwMSLk4vZ4bauGa7LKUh039x5Cf6O3U5/xcCoDwSdWxTKkdkQ NV6qsaBRXP2am3p/JiuTlJhYV5rA/VV/e0rXKSNcszA+BBFdIOddk3JpVBNOjBFoC/W+ uOsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745972259; x=1746577059; 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=C5ZEZwH3aQrzLfVWdE9j1t2G3YTj0WprbxNkrWh/BaE=; b=FSki4Cs5uvIblpp4kRNi2AxHXKnFbNTok61whtEWrjkgTZ2a7Pd4cnS1X617kQg+hf eaX8oFagZ+2gcTg/hlPW/IscoDeGuPnh7rflykCjnpOBYtZYjhYXXYVtl3Ymy1//YQCH +MrDmAEpZYForzP/yxN2eH4sLrdnWENsEOUGZ2seuHqx2m5+Z9IiQ6GS6c8Br4lK4NZo w1SqCnY1VqFDCrwRtf/y9OHc+GS8/IViooADEJ7Efa53tCxiKwau694vCNB+VKhnuNCi CKudUHYEFLZuqs5ofRHDPTRpiv6wGVkaalKYssPWt6gF88NTaW1hkc68hgYIKzoVAWge hwcw== X-Forwarded-Encrypted: i=1; AJvYcCU/4ypiYHqgNh+Y5wmKHAvZ3hhVQM83lzvnUhZtdtHgRRNhk8ae65M6UgegHkwzAT/J9CeIbdmq7Q==@kvack.org X-Gm-Message-State: AOJu0YwtATcOSAs4oF29Y2LbfNRrbD7Yn1zSNbsrAHY85M3vKwjhcLxb rCUtfltpD/9LsBHTIrkI3YECTUCwKxOTOuaiYBzlfmkxgBWw08F2hgJTv08etik= X-Gm-Gg: ASbGncsHc+JUic1wi9y1KJPlMQktomTecFtQ0CIYSHye0anjkCxWprxX1r5AXa6ALap NtVMM/A/Wwb6fwLJWih+SxMK07Z4TRBS6U95pzcMMHn8zEYTDuv/JjYkqXxo6jIMNKQVZmZKEnG pIbKlbVWd+oTO5u6GlnLMbO99QS5nMrvupfucdzhHSxCh9B3jAxJ75JE6ZPyYfflMBscomht8ZY Mslf0xkptLKmGdfviyMoIK8KZk4RWc9KOwk8o4qSog0IoO44AV+CeLriT2XUN/lGZ3VXXR5d2HY gsVOKxrvBeTtfoqJH+MjTPMvDUWCEiN1jlVwlsqrbvAUfWQAw84= X-Google-Smtp-Source: AGHT+IFAMLIyLPT3Vyub7NbksFuJzHx0Dg3VrKlspZ+PnLCueluan8OlRjrHsN8k6+RcRQ9h1pRZQA== X-Received: by 2002:a17:90b:5824:b0:2ff:618c:a1e0 with SMTP id 98e67ed59e1d1-30a333608d8mr1421802a91.29.1745972259317; Tue, 29 Apr 2025 17:17:39 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db4d770d6sm109386035ad.17.2025.04.29.17.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 17:17:38 -0700 (PDT) From: Deepak Gupta Date: Tue, 29 Apr 2025 17:16:40 -0700 Subject: [PATCH v14 23/27] arch/riscv: compile vdso with landing pad MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250429-v5_user_cfi_series-v14-23-5239410d012a@rivosinc.com> References: <20250429-v5_user_cfi_series-v14-0-5239410d012a@rivosinc.com> In-Reply-To: <20250429-v5_user_cfi_series-v14-0-5239410d012a@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 , Jann Horn , Conor Dooley , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross 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, rust-for-linux@vger.kernel.org, Zong Li , Deepak Gupta X-Mailer: b4 0.13.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 777A640004 X-Stat-Signature: jzaan7wg88wr4d9us3kn5whc1k4ripat X-HE-Tag: 1745972260-545001 X-HE-Meta: U2FsdGVkX19uOYnCPx0p+okhr/h09bN/JP6aSlOKLCK0Mep0r7UJNniKrW3e7bsmimGM5wTP9kv/AKMWB6ADg0WKxJ1MCAXyDAP44jbj15jEv5uow/18BX2X4lGWaSJL2yp0ngpe09X06BrFkaaeTQN7anck/8e2dhZa3wyOCa6eKV//ANVqFgH7VqcLNrhBSq8STXJ9aB4piLNB3eFwFELPom2I0SPu6ye7TOXNBh1Rk5jW6DpSFDPGZNTL7uDuBmG7WN1SZDZD9nKVZOE0QxdZoQBy4tv39OwTeTD1lNGS/klt5Ip5DmD/Ytggg3v82kX9C0/sw+jYEEqrPl0MQw4flYmTvQ0nGc1K2QeXynNS6YXGiZhKiXzT8tzybnBJSmGRygbu4i6fty3X2sZ+Q8M/Mek+BBfjvMyA3LssVxifLQTwTqhKSX4r40MKglvnf0wAfZ5GIQF2HFYCUmWwO32wMUwTUf45Q3fTkGR/g+s7N1HNP7js/L7PAKP04auf1iWETSWBVLed81gRyO+fTFa3q2uwXO3IcbxagcRowgi1hrwaJejCg4kqEnRSRLPZ5aqSFRy+G5qRRFsXI+esp6I5+SG0vAYaLPMxONh39Wsar3s9X28ZGSzd4S2evsIqGzyxF1PnsKlwtvUS9BadMNiyhcamxXDe0USXWSXQQ4iPqE7rcD2tR7AAEvaZA0wJBY0u3OiVNSM6VIVQQLHDs1LJ8jMIHKXOWEAyfoeoT1QqbMcIZolZFdkNBVTPhhinW8z/UXQAJ7ApSYUiljl1NoIeCct2tg2FL0199LizX9H/FkSRq7Ebbg0wkzGGHPwNRE8rNn87CDQjWF4TlnY00+67ltzsEzy+8+05c2xlbFnzHF+7eqeGLa1pU90tvv5tAEaTQ9Oh9ynaW+UIAZbTjaQTizIJmdqd2P8AWnyakUjLdIoiLKlKz/5N5W1KyEUGzVPhMmn70CE4FSSuynv vZZ9NuPf 3sp09Bnfukmk8PEfLI2rmZzzYlP8DI1o9GW1qCQEw0xnweHgaYIQ5E8FYh3JQCpW1IaNNH01EtWcqMy3ZwPWf9VL6mEfFUkvgQfmZIz0ormvlnpM= 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: From: Jim Shu user mode tasks compiled with zicfilp may call indirectly into vdso (like hwprobe indirect calls). Add landing pad compile support in vdso. vdso with landing pad in it will be nop for tasks which have not enabled landing pad. This patch allows to run user mode tasks with cfi eanbled and do no harm. Future work can be done on this to do below - labeled landing pad on vdso functions (whenever labeling support shows up in gnu-toolchain) - emit shadow stack instructions only in vdso compiled objects as part of kernel compile. Signed-off-by: Jim Shu Reviewed-by: Zong Li Signed-off-by: Deepak Gupta --- arch/riscv/Makefile | 5 +++- arch/riscv/include/asm/assembler.h | 44 +++++++++++++++++++++++++++++++++++ arch/riscv/kernel/vdso/Makefile | 6 +++++ arch/riscv/kernel/vdso/flush_icache.S | 4 ++++ arch/riscv/kernel/vdso/getcpu.S | 4 ++++ arch/riscv/kernel/vdso/rt_sigreturn.S | 4 ++++ arch/riscv/kernel/vdso/sys_hwprobe.S | 4 ++++ 7 files changed, 70 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 539d2aef5cab..c2dd09bb9db3 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -88,9 +88,12 @@ riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZACAS) := $(riscv-march-y)_zacas # Check if the toolchain supports Zabha riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZABHA) := $(riscv-march-y)_zabha +KBUILD_BASE_ISA = -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/') +export KBUILD_BASE_ISA + # Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by # matching non-v and non-multi-letter extensions out with the filter ([^v_]*) -KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/') +KBUILD_CFLAGS += $(KBUILD_BASE_ISA) KBUILD_AFLAGS += -march=$(riscv-march-y) diff --git a/arch/riscv/include/asm/assembler.h b/arch/riscv/include/asm/assembler.h index 44b1457d3e95..a058ea5e9c58 100644 --- a/arch/riscv/include/asm/assembler.h +++ b/arch/riscv/include/asm/assembler.h @@ -80,3 +80,47 @@ .endm #endif /* __ASM_ASSEMBLER_H */ + +#if defined(CONFIG_RISCV_USER_CFI) && (__riscv_xlen == 64) +.macro vdso_lpad +lpad 0 +.endm +#else +.macro vdso_lpad +.endm +#endif + +/* + * This macro emits a program property note section identifying + * architecture features which require special handling, mainly for + * use in assembly files included in the VDSO. + */ +#define NT_GNU_PROPERTY_TYPE_0 5 +#define GNU_PROPERTY_RISCV_FEATURE_1_AND 0xc0000000 + +#define GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP (1U << 0) +#define GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS (1U << 1) + +#if defined(CONFIG_RISCV_USER_CFI) && (__riscv_xlen == 64) +#define GNU_PROPERTY_RISCV_FEATURE_1_DEFAULT \ + (GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP) +#endif + +#ifdef GNU_PROPERTY_RISCV_FEATURE_1_DEFAULT +.macro emit_riscv_feature_1_and, feat = GNU_PROPERTY_RISCV_FEATURE_1_DEFAULT + .pushsection .note.gnu.property, "a" + .p2align 3 + .word 4 + .word 16 + .word NT_GNU_PROPERTY_TYPE_0 + .asciz "GNU" + .word GNU_PROPERTY_RISCV_FEATURE_1_AND + .word 4 + .word \feat + .word 0 + .popsection +.endm +#else +.macro emit_riscv_feature_1_and, feat = 0 +.endm +#endif diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile index ad73607abc28..8e771d316938 100644 --- a/arch/riscv/kernel/vdso/Makefile +++ b/arch/riscv/kernel/vdso/Makefile @@ -13,12 +13,18 @@ vdso-syms += flush_icache vdso-syms += hwprobe vdso-syms += sys_hwprobe +ifdef CONFIG_RISCV_USER_CFI +LPAD_MARCH = _zicfilp +endif + # Files to link into the vdso obj-vdso = $(patsubst %, %.o, $(vdso-syms)) note.o ccflags-y := -fno-stack-protector ccflags-y += -DDISABLE_BRANCH_PROFILING ccflags-y += -fno-builtin +ccflags-y += $(KBUILD_BASE_ISA)$(LPAD_MARCH) +asflags-y += $(KBUILD_BASE_ISA)$(LPAD_MARCH) ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y) diff --git a/arch/riscv/kernel/vdso/flush_icache.S b/arch/riscv/kernel/vdso/flush_icache.S index 8f884227e8bc..e4c56970905e 100644 --- a/arch/riscv/kernel/vdso/flush_icache.S +++ b/arch/riscv/kernel/vdso/flush_icache.S @@ -5,11 +5,13 @@ #include #include +#include .text /* int __vdso_flush_icache(void *start, void *end, unsigned long flags); */ SYM_FUNC_START(__vdso_flush_icache) .cfi_startproc + vdso_lpad #ifdef CONFIG_SMP li a7, __NR_riscv_flush_icache ecall @@ -20,3 +22,5 @@ SYM_FUNC_START(__vdso_flush_icache) ret .cfi_endproc SYM_FUNC_END(__vdso_flush_icache) + +emit_riscv_feature_1_and diff --git a/arch/riscv/kernel/vdso/getcpu.S b/arch/riscv/kernel/vdso/getcpu.S index 9c1bd531907f..5c1ecc4e1465 100644 --- a/arch/riscv/kernel/vdso/getcpu.S +++ b/arch/riscv/kernel/vdso/getcpu.S @@ -5,14 +5,18 @@ #include #include +#include .text /* int __vdso_getcpu(unsigned *cpu, unsigned *node, void *unused); */ SYM_FUNC_START(__vdso_getcpu) .cfi_startproc + vdso_lpad /* For now, just do the syscall. */ li a7, __NR_getcpu ecall ret .cfi_endproc SYM_FUNC_END(__vdso_getcpu) + +emit_riscv_feature_1_and diff --git a/arch/riscv/kernel/vdso/rt_sigreturn.S b/arch/riscv/kernel/vdso/rt_sigreturn.S index 3dc022aa8931..e82987dc3739 100644 --- a/arch/riscv/kernel/vdso/rt_sigreturn.S +++ b/arch/riscv/kernel/vdso/rt_sigreturn.S @@ -5,12 +5,16 @@ #include #include +#include .text SYM_FUNC_START(__vdso_rt_sigreturn) .cfi_startproc .cfi_signal_frame + vdso_lpad li a7, __NR_rt_sigreturn ecall .cfi_endproc SYM_FUNC_END(__vdso_rt_sigreturn) + +emit_riscv_feature_1_and diff --git a/arch/riscv/kernel/vdso/sys_hwprobe.S b/arch/riscv/kernel/vdso/sys_hwprobe.S index 77e57f830521..f1694451a60c 100644 --- a/arch/riscv/kernel/vdso/sys_hwprobe.S +++ b/arch/riscv/kernel/vdso/sys_hwprobe.S @@ -3,13 +3,17 @@ #include #include +#include .text SYM_FUNC_START(riscv_hwprobe) .cfi_startproc + vdso_lpad li a7, __NR_riscv_hwprobe ecall ret .cfi_endproc SYM_FUNC_END(riscv_hwprobe) + +emit_riscv_feature_1_and -- 2.43.0