From nobody Thu Sep 11 22:43:02 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36FDC275AEB; Wed, 20 Aug 2025 19:06:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755716797; cv=none; b=kyklt4bDfknCcz3xJD5iio2wSDpQUFvmAkS0SIiJYBbr5Or18yFm18rzPZuVOTOD3/qVCjpntlMkeJ11Dacyk5u2HlNHjbO6IDiGnHo4dTUIf/7YXWYV+PjnE9rf+61FbJb1ZjdafaTanwA3RikrEc+O9clQEztNdMhMYPzWgoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755716797; c=relaxed/simple; bh=nLJGoGeuqPkpzEuh03+jK8eWmMrjjG2N95dLqjOBEos=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=j1oDQywVD6M7YGN07hWlPuidNrOregqH98dbCqc7Xz5z9RJpidEDE6tJTl4tPGfB+FiPI3lYd50nw9Ck17KYKpxfZvmJdLqAmU3l9aIF1fyDoI11a/FUD622+vAHqa3i6qIKBwlEPeYE7+XjiXncTxn+OyIjDdO8lB+Y5eJA+VQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OZrXLEd7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OZrXLEd7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C965FC113D0; Wed, 20 Aug 2025 19:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755716796; bh=nLJGoGeuqPkpzEuh03+jK8eWmMrjjG2N95dLqjOBEos=; h=Date:From:To:Cc:Subject:References:From; b=OZrXLEd7XzCFcqMBGb928PUq3hxO2MjCNNOFVsd667EUAwcxddJcIUQqS+VIF6VlI wYo+ooA8movVa2KF1TglArkFLnD3F0Sl0c63KsJmhsrGzhChi96IrDTyKAQ9qSbsVE 6bWCff1u6v2eHvCWOiwfBK4KQxpg2ghZsHDNYxionrdq5chrHAhz+gcr7/UXbmA7LF j4F7BZbnQOihcwLd8FWf+6YIjB/FgChypDohUCE9pO4roXKZ3maQc4zwtbjs2CyuBy jFYPeY8Mj+eOyeP1bmmfEz79VISFsej6VVt1ULY3OCzRCpD5ql0/xaVVxtVT9sy1ZK HC8qaXYK9njAA== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uoo8t-00000000tEv-3SFu; Wed, 20 Aug 2025 15:06:39 -0400 Message-ID: <20250820190639.676050639@kernel.org> User-Agent: quilt/0.68 Date: Wed, 20 Aug 2025 15:05:47 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Peter Zijlstra , Linus Torvalds , Josh Poimboeuf Subject: [PATCH 1/2] unwind_user/x86: Enable frame pointer unwinding on x86 References: <20250820190546.172023727@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Josh Poimboeuf Use ARCH_INIT_USER_FP_FRAME to describe how frame pointers are unwound on x86, and enable CONFIG_HAVE_UNWIND_USER_FP accordingly so the unwind_user interfaces can be used. Signed-off-by: Josh Poimboeuf Signed-off-by: Steven Rostedt (Google) --- arch/x86/Kconfig | 1 + arch/x86/include/asm/unwind_user.h | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 arch/x86/include/asm/unwind_user.h diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 58d890fe2100..8f94c58d4de8 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -299,6 +299,7 @@ config X86 select HAVE_SYSCALL_TRACEPOINTS select HAVE_UACCESS_VALIDATION if HAVE_OBJTOOL select HAVE_UNSTABLE_SCHED_CLOCK + select HAVE_UNWIND_USER_FP if X86_64 select HAVE_USER_RETURN_NOTIFIER select HAVE_GENERIC_VDSO select VDSO_GETRANDOM if X86_64 diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwi= nd_user.h new file mode 100644 index 000000000000..8597857bf896 --- /dev/null +++ b/arch/x86/include/asm/unwind_user.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_UNWIND_USER_H +#define _ASM_X86_UNWIND_USER_H + +#define ARCH_INIT_USER_FP_FRAME \ + .cfa_off =3D (s32)sizeof(long) * 2, \ + .ra_off =3D (s32)sizeof(long) * -1, \ + .fp_off =3D (s32)sizeof(long) * -2, \ + .use_fp =3D true, + +#endif /* _ASM_X86_UNWIND_USER_H */ --=20 2.50.1 From nobody Thu Sep 11 22:43:02 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FF8C281530; Wed, 20 Aug 2025 19:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755716797; cv=none; b=LBC/QNX0gjxF0RTSn5Z+FMxQtEAt+Ce4iVq2Gl/sy8SAvwlsaskuv8jHkgpj8SXVqenS02v3tJqgpPBt2NYEdDW8rXUmsweiYlsKzSQ6eEgUU4Q/c9ukWiSggeeqoAb2Bsz5w975EKfJELfFrdxOMkbLChGUZAUgcefxD3iLvhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755716797; c=relaxed/simple; bh=gFyS+4phEZAJBQPEgmZZT7FNcIkNb7GGQjLxE06/dZQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VbPpVqP3vsvSUhrR38lOBaUylPOj0gPkeUbP6bfeRDeV4qCUWpY8CvwAnd6I9gGJ/oeAXykU6UG9dK1CamRqidWTBf91nMlFBfeRfFPIm9/xKhgsyJ9TA55N5qn/u4/LN50HqVYRlCA6W1s1C/FedUlpLOorzjZN0lXMcw2LZpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XRv04Rr3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XRv04Rr3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB4E2C116D0; Wed, 20 Aug 2025 19:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755716797; bh=gFyS+4phEZAJBQPEgmZZT7FNcIkNb7GGQjLxE06/dZQ=; h=Date:From:To:Cc:Subject:References:From; b=XRv04Rr3yZ/naw5p9gclt8nvPimId3AZXxTyKau7Fx/JPcRyLqMF8nK2Hv1RiJQqL d/bvT8geCAY+DdDdD8sUsQhWDRK16KXoQkMPfzEpXjdQ/ztD+GqBJFoulknoucCl2S 45MyRRzO5h/9r82URGEKdO2VJGV7BCnFSwRA0gG0+LIZZCyhNGH1YC916Vz4QubL6I Kihi8MAaCwLrdN9sIcBbXhE+w151jGkSBjIaiKqYnM5TXbO6qlcWKcbVK4jmSVAD3W T5oDvpOmwvcwAJyIONKOoLuLNhVkznVGFIxfXhziH2HHDP17zN6Sh10a/a5SQZZP1R SQi2/uozOxBag== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1uoo8t-00000000tFP-49xA; Wed, 20 Aug 2025 15:06:39 -0400 Message-ID: <20250820190639.843442474@kernel.org> User-Agent: quilt/0.68 Date: Wed, 20 Aug 2025 15:05:48 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Peter Zijlstra , Linus Torvalds , Josh Poimboeuf Subject: [PATCH 2/2] unwind deferred/x86: Do not defer stack tracing for compat tasks References: <20250820190546.172023727@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt Currently compat tasks are not supported. If a deferred user space stack trace is requested on a compat task, it should fail and return an error so that the profiler can use an alternative approach (whatever it uses today). Add a arch_unwind_can_defer() macro that is called in unwind_deferred_request(). Have x86 define it to a function that makes sure that the current task is running in 64bit mode, and if it is not, it returns false. This will cause unwind_deferred_request() to error out and the caller can use the current method of user space stack tracing. Signed-off-by: Steven Rostedt (Google) --- arch/x86/include/asm/unwind_user.h | 11 +++++++++++ include/linux/unwind_deferred.h | 5 +++++ kernel/unwind/deferred.c | 3 +++ 3 files changed, 19 insertions(+) diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwi= nd_user.h index 8597857bf896..220fd0a6e175 100644 --- a/arch/x86/include/asm/unwind_user.h +++ b/arch/x86/include/asm/unwind_user.h @@ -2,6 +2,17 @@ #ifndef _ASM_X86_UNWIND_USER_H #define _ASM_X86_UNWIND_USER_H =20 +#ifdef CONFIG_IA32_EMULATION +/* Currently compat mode is not supported for deferred stack trace */ +static inline bool arch_unwind_can_defer(void) +{ + struct pt_regs *regs =3D task_pt_regs(current); + + return user_64bit_mode(regs); +} +# define arch_unwind_can_defer arch_unwind_can_defer +#endif /* CONFIG_IA32_EMULATION */ + #define ARCH_INIT_USER_FP_FRAME \ .cfa_off =3D (s32)sizeof(long) * 2, \ .ra_off =3D (s32)sizeof(long) * -1, \ diff --git a/include/linux/unwind_deferred.h b/include/linux/unwind_deferre= d.h index 26122d00708a..0124865aaab4 100644 --- a/include/linux/unwind_deferred.h +++ b/include/linux/unwind_deferred.h @@ -16,6 +16,11 @@ struct unwind_work { int bit; }; =20 +/* Architectures can add a test to not defer unwinding */ +#ifndef arch_unwind_can_defer +# define arch_unwind_can_defer() (true) +#endif + #ifdef CONFIG_UNWIND_USER =20 enum { diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c index dc6040aae3ee..3601b2efe48d 100644 --- a/kernel/unwind/deferred.c +++ b/kernel/unwind/deferred.c @@ -237,6 +237,9 @@ int unwind_deferred_request(struct unwind_work *work, u= 64 *cookie) =20 *cookie =3D 0; =20 + if (!arch_unwind_can_defer()) + return -EINVAL; + if ((current->flags & (PF_KTHREAD | PF_EXITING)) || !user_mode(task_pt_regs(current))) return -EINVAL; --=20 2.50.1