[PATCH v2 10/11] perf/x86: Add HAVE_PERF_CALLCHAIN_DEFERRED
From: Josh Poimboeuf
Date: Fri Sep 13 2024 - 19:05:24 EST
Enable deferred user space unwinding on x86. Frame pointers are still
the default for now.
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
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