Linux Perf Users
 help / color / mirror / Atom feed
From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Ravi Bangoria <ravi.bangoria@amd.com>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Gennady Kupava <gennady.kupava@gmail.com>,
	linux-perf-users@vger.kernel.org
Subject: Re: [DISCUSSION] Three problems behind broken "perf --call-graph dwarf" on AMD: IP and stack dump mismatch, libdw fails on lld's layout, and the unwinder fallback never runs
Date: Mon, 7 Sep 2026 14:23:16 +0800	[thread overview]
Message-ID: <f1d6a335-b1d5-4793-b7c8-6bc9091d98ce@linux.intel.com> (raw)
In-Reply-To: <a5d3798c-7d62-43d0-88c6-eec26bd4f63d@linux.intel.com>


On 9/3/2026 7:59 PM, Mi, Dapeng wrote:
> On 9/3/2026 7:36 PM, Ravi Bangoria wrote:
>>>>> This should resolve the DWARF unwinding issue with IBS PMUs:
>>>>>
>>>>> --- a/arch/x86/events/amd/ibs.c
>>>>> +++ b/arch/x86/events/amd/ibs.c
>>>>> @@ -1523,8 +1523,11 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
>>>>>  			goto out;
>>>>>  		}
>>>>>  
>>>>> -		set_linear_ip(&regs, ibs_data.regs[1]);
>>>>> -		regs.flags |= PERF_EFLAGS_EXACT;
>>>>> +		if (event->attr.sample_type & PERF_SAMPLE_IP) {
>>>>> +			data.ip = ibs_data.regs[1];
>>>>> +			data.sample_flags |= PERF_SAMPLE_IP;
>>> We may not set PERF_SAMPLE_IP here, otherwise the kernel address leakage
>>> check in perf_instruction_pointer() could be bypassed.
>> Yes. I realized this wouldn't be straightforward, since the privilege
>> level might change between when the HW captures the sample and when the
>> NMI is delivered. So, any perf code that depends on user_mode() (e.g.
>> perf_exclude_event(), _REGS_USER, _REGS_INTR, header->misc, etc.) may
>> regress with the above change. In addition, guest entry/exit occurring
>> between sample capture and NMI delivery further complicates the problem.
>>
>>>> Right, that's what I thought.  And I believe we should do similar on
>>>> Intel and not update other registers.
>>> For Intel PEBS, the call-chain would always use the interrupt regs instead
>>> of the PEBS regs, so there would be no issues for Intel PEBS.
>>>
>>>     /*
>>>      * We must however always use iregs for the unwinder to stay sane; the
>>>      * record BP,SP,IP can point into thin air when the record is from a
>>>      * previous PMI context or an (I)RET happened between the record and
>>>      * PMI.
>>>      */
>>>     perf_sample_save_callchain(data, event, iregs);
>> This wouldn't take care of _STACK_USER, right?
> Yes, I just realized this is not fully correct for Intel PEBS after sending
> the comments.
>
> On Intel platforms, for SAMPLE_STACK_USER, the IP/SP/BP is consistent and
> they all comes from PEBS, so the DWARF unwinding has no issues. But for
> SAMPLE_CALLCHAIN, it's not consistent, the IP is overwritten by PEBS while
> the BP/SP are still gotten from PMI. So the kernel call-chain unwinding
> could not work.

The statement about SAMPLE_CALLCHAIN is not correct. Just went though the
code carefully, the kernel has already returned a IP chain to user space
for SAMPLE_CALLCHAIN requirement, which doesn't need to current IP/SP/BP
registers to reconstruct the call chain. So We only need to ensure the PMI
context registers are reported for SAMPLE_STACK_USER requirement. Thanks.


>
> Suppose we need to follow below 2 rules to ensure the correct call-chain
> unwinding and register snapshot consistency.
>
> 1. All registers including IP should come from either PEBS or PMI, must not
> be mixed. This ensures to get an consistent registers snapshot.
>
> 2. Either SAMPLE_CALLCHAIN or SAMPLE_STACK_USER is required, the PMI
> registers snapshot must be used. This proves the correct DWARF unwinding.
>
> How's your idea?
>
> Thanks.
>
>
>> Thanks,
>> Ravi

      parent reply	other threads:[~2026-09-07  6:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 21:49 [DISCUSSION] Three problems behind broken "perf --call-graph dwarf" on AMD: IP and stack dump mismatch, libdw fails on lld's layout, and the unwinder fallback never runs Gennady Kupava
2026-08-24 13:35 ` Ravi Bangoria
2026-08-25 18:05 ` Ian Rogers
2026-08-27 21:55 ` Namhyung Kim
2026-08-28 16:47   ` Namhyung Kim
2026-08-28 16:58   ` Namhyung Kim
2026-08-31  5:05     ` Ravi Bangoria
2026-09-01 15:19       ` Namhyung Kim
2026-09-03  8:39         ` Mi, Dapeng
2026-09-03 11:36           ` Ravi Bangoria
2026-09-03 11:59             ` Mi, Dapeng
2026-09-03 16:02               ` Ravi Bangoria
2026-09-04  0:22                 ` Mi, Dapeng
2026-09-05 10:14                   ` Gennady Kupava
2026-09-07  6:23               ` Mi, Dapeng [this message]

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=f1d6a335-b1d5-4793-b7c8-6bc9091d98ce@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=gennady.kupava@gmail.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=ravi.bangoria@amd.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