[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2b3be1da18a8a1895762c2f394aa353f227d6543.1726268190.git.jpoimboe@kernel.org>
Date: Sat, 14 Sep 2024 01:02:12 +0200
From: Josh Poimboeuf <jpoimboe@...nel.org>
To: x86@...nel.org
Cc: Peter Zijlstra <peterz@...radead.org>,
Steven Rostedt <rostedt@...dmis.org>,
Ingo Molnar <mingo@...nel.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
linux-kernel@...r.kernel.org,
Indu Bhagat <indu.bhagat@...cle.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
linux-perf-users@...r.kernel.org,
Mark Brown <broonie@...nel.org>,
linux-toolchains@...r.kernel.org,
Jordan Rome <jordalgo@...a.com>,
Sam James <sam@...too.org>
Subject: [PATCH v2 10/11] perf/x86: Add HAVE_PERF_CALLCHAIN_DEFERRED
Enable deferred user space unwinding on x86. Frame pointers are still
the default for now.
Signed-off-by: Josh Poimboeuf <jpoimboe@...nel.org>
---
arch/x86/Kconfig | 1 +
arch/x86/events/core.c | 52 +++++++++++++++++++++++++++---------------
2 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0b3d7c72b65b..24d9373cc5e6 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -265,6 +265,7 @@ config X86
select HAVE_PERF_EVENTS_NMI
select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI
select HAVE_PCI
+ select HAVE_PERF_CALLCHAIN_DEFERRED
select HAVE_PERF_REGS
select HAVE_PERF_USER_STACK_DUMP
select MMU_GATHER_RCU_TABLE_FREE if PARAVIRT
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index e82aadf99d9b..d6ea265d9aa8 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2821,8 +2821,8 @@ static unsigned long get_segment_base(unsigned int segment)
#include <linux/compat.h>
-static inline int
-perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *entry)
+static int __perf_callchain_user32(struct pt_regs *regs,
+ struct perf_callchain_entry_ctx *entry)
{
/* 32-bit process in 64-bit kernel. */
unsigned long ss_base, cs_base;
@@ -2836,7 +2836,6 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
ss_base = get_segment_base(regs->ss);
fp = compat_ptr(ss_base + regs->bp);
- pagefault_disable();
while (entry->nr < entry->max_stack) {
if (!valid_user_frame(fp, sizeof(frame)))
break;
@@ -2849,19 +2848,18 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
perf_callchain_store(entry, cs_base + frame.return_address);
fp = compat_ptr(ss_base + frame.next_frame);
}
- pagefault_enable();
return 1;
}
-#else
-static inline int
-perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *entry)
+#else /* !CONFIG_IA32_EMULATION */
+static int __perf_callchain_user32(struct pt_regs *regs,
+ struct perf_callchain_entry_ctx *entry)
{
- return 0;
+ return 0;
}
-#endif
+#endif /* CONFIG_IA32_EMULATION */
-void
-perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs)
+static void __perf_callchain_user(struct perf_callchain_entry_ctx *entry,
+ struct pt_regs *regs, bool atomic)
{
struct user_unwind_state state;
@@ -2878,20 +2876,36 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
perf_callchain_store(entry, regs->ip);
- if (!nmi_uaccess_okay())
- return;
+ if (atomic) {
+ if (!nmi_uaccess_okay())
+ return;
+ pagefault_disable();
+ }
- if (perf_callchain_user32(regs, entry))
- return;
-
- pagefault_disable();
+ if (__perf_callchain_user32(regs, entry))
+ goto done;
for_each_user_frame(&state, USER_UNWIND_TYPE_FP) {
if (perf_callchain_store(entry, state.ip))
- break;
+ goto done;
}
- pagefault_enable();
+done:
+ if (atomic)
+ pagefault_enable();
+}
+
+
+void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
+ struct pt_regs *regs)
+{
+ return __perf_callchain_user(entry, regs, true);
+}
+
+void perf_callchain_user_deferred(struct perf_callchain_entry_ctx *entry,
+ struct pt_regs *regs)
+{
+ return __perf_callchain_user(entry, regs, false);
}
/*
--
2.46.0
Powered by blists - more mailing lists