From: Dapeng Mi <dapeng1.mi@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andi Kleen <ak@linux.intel.com>,
Eranian Stephane <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Dapeng Mi <dapeng1.mi@intel.com>, Zide Chen <zide.chen@intel.com>,
Falcon Thomas <thomas.falcon@intel.com>,
Xudong Hao <xudong.hao@intel.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Gennady Kupava <gennady.kupava@gmail.com>,
Ravi Bangoria <ravi.bangoria@amd.com>
Subject: [PATCH 2/2] perf/x86: Disable precise sampling for PERF_SAMPLE_STACK_USER
Date: Tue, 8 Sep 2026 15:51:02 +0800 [thread overview]
Message-ID: <20260908075102.540715-2-dapeng1.mi@linux.intel.com> (raw)
In-Reply-To: <20260908075102.540715-1-dapeng1.mi@linux.intel.com>
PERF_SAMPLE_STACK_USER needs to return the user stack and user registers
to user space when the PMI exits. Since the skid from the PEBS/IBS sample
and PMI delivery, the PEBS/IBS register snapshot (especially IP/SP/BP)
can diverge from the user stack at PMI return. That mismatch breaks DWARF
unwinding.
Precise sampling provides no benefit in this case, so disable PEBS/IBS
precise sampling and allow only PMI-based sampling when
PERF_SAMPLE_STACK_USER is requested.
Reported-by: Gennady Kupava <gennady.kupava@gmail.com>
Closes: https://lore.kernel.org/all/CAPu-DQqF0aF6=GS8Z6KKWeeX_V5LiXeKU_rJQZC+uGg8zuTPNw@mail.gmail.com/
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Fixes: c5ebcedb566e ("perf: Add ability to attach user stack dump to sample")
Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
---
arch/x86/events/amd/ibs.c | 3 +++
arch/x86/events/core.c | 3 +++
arch/x86/events/perf_event.h | 19 +++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index 3531f9c23b8c..c67b659d64e2 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -327,6 +327,9 @@ static int perf_ibs_init(struct perf_event *event)
if (has_branch_stack(event))
return -EOPNOTSUPP;
+ if (!x86_pmu_allow_sample_user_stack(event, true))
+ return -EINVAL;
+
/* handle exclude_{user,kernel} in the IRQ handler */
if (event->attr.exclude_host || event->attr.exclude_guest ||
event->attr.exclude_idle)
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 8b3ea0adb965..ceb5038d7565 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -594,6 +594,9 @@ int x86_pmu_hw_config(struct perf_event *event)
/* There's no sense in having PEBS for non sampling events: */
if (!is_sampling_event(event))
return -EINVAL;
+
+ if (!x86_pmu_allow_sample_user_stack(event, false))
+ return -EINVAL;
}
/*
* check that PEBS LBR correction does not conflict with
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 71ed5b2acea2..9fbcf2bcef51 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -1274,6 +1274,25 @@ static inline bool is_counter_pair(struct hw_perf_event *hwc)
return hwc->flags & PERF_X86_EVENT_PAIR;
}
+static inline bool
+x86_pmu_allow_sample_user_stack(struct perf_event *event, bool ibs)
+{
+ if (!(event->attr.sample_type & PERF_SAMPLE_STACK_USER))
+ return true;
+
+ /*
+ * PERF_SAMPLE_STACK_USER needs to return the user stack and
+ * user registers to user space when the PMI exits. Since the skid
+ * from the PEBS/IBS sample and PMI delivery, the PEBS/IBS register
+ * snapshot (especially IP/SP/BP) can diverge from the user stack
+ * at PMI return. That mismatch breaks DWARF unwinding.
+ *
+ * Therefore, disable precise sampling for PERF_SAMPLE_STACK_USER
+ * and permit only PMI-based sampling for this case.
+ */
+ return !(event->attr.precise_ip || ibs);
+}
+
static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc,
u64 enable_mask)
{
--
2.34.1
next prev parent reply other threads:[~2026-09-08 7:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 7:51 [PATCH 1/2] perf/x86/intel: Correct pt_regs->flags update for PEBS path Dapeng Mi
2026-09-08 7:51 ` Dapeng Mi [this message]
2026-09-08 8:49 ` [PATCH 2/2] perf/x86: Disable precise sampling for PERF_SAMPLE_STACK_USER Peter Zijlstra
2026-09-08 8:56 ` Mi, Dapeng
2026-09-08 10:19 ` Peter Zijlstra
2026-09-08 15:10 ` Andi Kleen
2026-09-08 20:56 ` Ian Rogers
2026-09-09 0:59 ` Mi, Dapeng
2026-09-09 1:28 ` Ravi Bangoria
2026-09-09 1:59 ` Mi, Dapeng
2026-09-09 8:11 ` Peter Zijlstra
2026-09-09 9:36 ` Mi, Dapeng
2026-09-09 19:30 ` Namhyung Kim
2026-09-10 0:12 ` Mi, Dapeng
2026-09-09 14:14 ` Namhyung Kim
2026-09-09 1:20 ` Mi, Dapeng
2026-09-08 8:49 ` Mi, Dapeng
2026-09-10 9:01 ` [tip: perf/urgent] perf/x86/intel: Correct pt_regs->flags update for PEBS path tip-bot2 for Dapeng Mi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908075102.540715-2-dapeng1.mi@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=dapeng1.mi@intel.com \
--cc=eranian@google.com \
--cc=gennady.kupava@gmail.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=thomas.falcon@intel.com \
--cc=xudong.hao@intel.com \
--cc=zide.chen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®