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 45944C369AB for ; Thu, 24 Apr 2025 07:21:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB6526B00A0; Thu, 24 Apr 2025 03:21:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3E836B00A1; Thu, 24 Apr 2025 03:21:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A95D56B00A2; Thu, 24 Apr 2025 03:21:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 80C6D6B00A0 for ; Thu, 24 Apr 2025 03:21:43 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C995E140A45 for ; Thu, 24 Apr 2025 07:21:44 +0000 (UTC) X-FDA: 83368092528.28.FAD90B0 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf03.hostedemail.com (Postfix) with ESMTP id DB68E20002 for ; Thu, 24 Apr 2025 07:21:42 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EvfSa9vm; dmarc=none; spf=pass (imf03.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745479302; a=rsa-sha256; cv=none; b=Lq0RyQTMsbdtE43Ltttp6idpb/5nWawoE8F8/hFY3a8VdMOLTmNLWNW0p0jU0bMPBrGEm9 YA7MeGvJ9wZRboQgRWv1Cvo4IFPJ9Rda5nhKO4lNpTtbEq/fDKGUTxdWeslan0I50cDL9w yIdM2K6ULer+lsQq/SRV+RieboCOptY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=EvfSa9vm; dmarc=none; spf=pass (imf03.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.181 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=1745479302; 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=3bZAForidndaJiph8x07kePNvG7PVWj8ECIIwcjlznY=; b=iaWD3PpavPHDv6HlPiqXuy2/ppuzXPkWgEDs0pQJ+VZwjw3GGXz9I6Zx8683GnZt2auwJb w3EozlueS3HRNgi/8i9agVcj3oFJU7wfp9mgIBT6NVX/QJE8/HAf1XhkWVAOUXl6Ic6s42 pN6KyhhnvASSg1Bb+D2cUPGX2xe613Q= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-22928d629faso6403235ad.3 for ; Thu, 24 Apr 2025 00:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745479302; x=1746084102; 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=3bZAForidndaJiph8x07kePNvG7PVWj8ECIIwcjlznY=; b=EvfSa9vmAh4Yo9i1xit4LvwVP3GfIX3/Wywhjx3AZUB0/iCH4RKsG59PXfMgtM24Qz s6i7gwMMIe+NPK5X4isQrdVdWauRjLFZc4y+atGv9MUeQx2/Fndy6wvuecj7Sk9chFeq aJOtCshJbK+1LIfEv/eqxxT9BCdIMyt56qd4eiMgBAsQY0M3R00q6ggoMJcGEQIyyP+8 7ZACGunK936fBP1OxcRMfT6ucSDJyS1hA9ewm9iKx51Yms4W9+/VfMQpKRupME/QmpSI M8j6JXBNJjMuEimEc5VxR7iTvKhHc8yCaaWgmgXdrdugutXy/xTIdKABp7aiZwlt3Fz6 IFgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745479302; x=1746084102; 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=3bZAForidndaJiph8x07kePNvG7PVWj8ECIIwcjlznY=; b=fMXsSt6LV7F+MV5TVDL7r/wEN4X4XuTvLr9KmkCTQoGrxOeTbIqzyovyn4PgFf7F6o QDbuUlBMxqqGlwvnYU05bHtoTglPYaOQm3Z45FM5CJStza8EthL0aqmhMur7X9ZZzYcX PE2MQGXV4A217sX1ISQRcxr0UTrTjtHBUqwOvgqUJxfSlrBFv4ReUeaKpVlIldQfJGcy y9oiwSpfmZRpgWzPSAFq7JQ/jy/K9eg1vGOJkXZj0ls8Jgg5avWOApytHkScJ8SfyjIM 9fQF6GvGNmFrkCSVdZvAZo1pS0rZp/xcU18MirkCgeMVJSqoXtBJcTnF/YqcHL5/gbFN 6Y8g== X-Forwarded-Encrypted: i=1; AJvYcCUh9qJaNg/hGsHZ5q5XLfw0OHeWCA7vkepvm+j0s8dWmLwaop+PzQo9HWQ70njI1u5dNM/lNIs+tQ==@kvack.org X-Gm-Message-State: AOJu0YzymCFq8QU/wrlWLG7SrBerdzlgndkVoDjzR8KlNITdMRuW95EU 8DJEYh1bYIS69PQdn59VQn4J0u9HYmDbFp3c5pJ+Krbyk0H/O29ZsPFGuiDW+c0= X-Gm-Gg: ASbGncvgp1SYkbg/EdXPX1yKcCP9mTxfPzSdIfZ2UZPhJ0cJBOObzGiZ9pvZQ+y6xPq mqi05SMNzyI4yD0EkQ4NhT0wnBPpj06G/wERhG8d0E7YMSaquQ+l37jGmCdgAWguU+pPPvyiyos ePvfT9HUQ/PO9FihM5FZ7/NSCx51u0LptuBr1E+J030Xz4DtJ9w6Yg1Ns6OMoRC0KlOtgAm1qlS E+BCLZHcWa9V3Lmcfk3myB933ootwAoNXug8cLvtjYPXbzyjxxRDKa4Cl6iK6jOT6hfX8gB8SNM OOpXdIK4BGXeeio3JB6Zw8CaXORa+Va3APPOI8eFbqAuslKeEdk= X-Google-Smtp-Source: AGHT+IH5wBtqkkeJYu8+cHUtzMx+3KSdfBGDdvgu1hIkxYh7ovgwECUuPKTN+h0Qjbdot/cYo03Pew== X-Received: by 2002:a17:903:2ca:b0:224:26f2:97d7 with SMTP id d9443c01a7336-22db3bbb020mr18690825ad.8.1745479301658; Thu, 24 Apr 2025 00:21:41 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db52163d6sm6240765ad.214.2025.04.24.00.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 00:21:41 -0700 (PDT) From: Deepak Gupta Date: Thu, 24 Apr 2025 00:20:39 -0700 Subject: [PATCH v13 24/28] arch/riscv: compile vdso with landing pad MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250424-v5_user_cfi_series-v13-24-971437de586a@rivosinc.com> References: <20250424-v5_user_cfi_series-v13-0-971437de586a@rivosinc.com> In-Reply-To: <20250424-v5_user_cfi_series-v13-0-971437de586a@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-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: DB68E20002 X-Stat-Signature: wxmunwhumd77b7io4azbt4qfc9eeaa6c X-Rspam-User: X-HE-Tag: 1745479302-709090 X-HE-Meta: U2FsdGVkX1/AbSt8fdxrO7+Q2KrkpMhyy1dqDEGmmIksXE/VzQaeDQxzzU147fsSGqLcSbBQL1sjVEk7zCLM23Rc6W0xUsJDFW/BUfECWDZcoDSOLlv3chxgxOMcFdG+yf7KhAT+RegIjMMdcYSrpjZR32CCb8x7MwCfiSJBTRDUSlePE9O3UqW7Gy/Qz9ABFd3CsR0I72vJLAXWqZw5YRnXMLA4s9MQZZaoQ1LJVOl5fTp0w7EvU6GUURJzuLWzRkmzFUSKDhPLFY1DjNbf8WzALQybZKewEk5bpIRK7a0a1+iNo10joclpvthvwIY9S/2BVIbWy9jII4GmEtjyvdhBSQwCzq6Y1djWEYwlUxztm8pZiFfRa4BBST0JpenT8Wdz04lgRltn7ZbV/6EdfMbt3blVsV/jIOY7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3GNekqZxdvW76Hy5P8zVCdsFQI= 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 13fbc0f94238..eca94246cda6 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 9a1b555e8733..b8a9417dfd67 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