perf updates
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/core
Soeren reported some time ago that callchains were broken on x86_64 with cpu-clock/task-clock events. After some time I finally found the problem was in the irq low level arg saving. It touches fragile code though, I hope some people can have a look over the fix.
Thanks,
Frederic
---
Frederic Weisbecker (2):
x86: Fix rbp saving in pt_regs on irq entry
perf: Build tools with frame pointer
arch/x86/kernel/entry_64.S | 31 +++++++++++++++++++------------ tools/perf/Makefile | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-)
PATCH 2/2 perf: Build tools with frame pointer
It seems that some gcc versions build by default with frame pointers and some others omit them.
Just build the tools with frame pointers as the callchains can be an important part of the perf workflow.
--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -1
@@ -227,7 +227,7 @@ ifndef PERF_DEBUG CFLAGS_OPTIMIZE = -O6 endif -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) EXTLIBS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 ALL_LDFLAGS = $(LDFLAGS)
Signature · 1 line
1.7.3.2
[tip:perf/core] perf tools: Build with frame pointer
Commit-ID: 6b01f2c4f6188da50d8fe094e369a9c0390424ab Gitweb: http://git.kernel.org/tip/6b01f2c4f6188da50d8fe094e369a9c0390424ab Author: Frederic Weisbecker <[email protected]> AuthorDate: Thu, 6 Jan 2011 15:51:53 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 6 Jan 2011 18:04:54 -0200
perf tools: Build with frame pointer
It seems that some gcc versions build by default with frame pointers and some others omit them.
Just build the tools with frame pointers as the callchains can be an important part of the perf workflow.
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
LKML-Reference: <[email protected]>
--- tools/perf/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/Makefile +1 -1
@@ -227,7 +227,7 @@ ifndef PERF_DEBUG CFLAGS_OPTIMIZE = -O6 endif -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) +CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) EXTLIBS = -lpthread -lrt -lelf -lm ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 ALL_LDFLAGS = $(LDFLAGS)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
From the
x86_64low level interrupt handlers, the frame pointer is saved inpt_regsin the wrong place, in the offset of rbx.rbx is not part of the irq partial saved registers, so it's not critical, but later code that uses
get_irq_regs()to get the interrupted frame pointer instead get a stale rbx value, causing unwinding code to fail miserably.
Code using get_irq_regs() can't rely on the not explicitly saved registers' fields of pt_regs anyway; you now fix this for %rbp, but someone else might look at a different register and want that to be saved too. You just shouldn't, and the fact that %rbp happens to be saved at all shouldn't be taken to mean you can access it via the provided pt_regs pointer. This saving of %rbp could go away or be done in a different way at any point.
Review ret_from_intr: · line 820
Quoted 9 lines
(quoted diff) +2
-0@@ -808,6 +813,8 @@ ret_from_intr: TRACE_IRQS_OFF decl PER_CPU_VAR(irq_count) leaveq + /* we did not save rbx, restore only from ARGOFFSET */ + addq $8, %rsp CFI_RESTORE rbp CFI_DEF_CFA_REGISTER rsp CFI_ADJUST_CFA_OFFSET -8
*If* the patch was to be taken anyway, I would strongly suggest getting this mis-insertion fixed first: CFI annotations belong to the immediately preceding instruction, and hence you must not insert new instructions between an existing one and its annotation.
Furthermore, an adjustment to %rsp (when it serves as the frame pointer as is the case here, though would be better visible if the added instruction was at the right place) needs to be annotated itself.
Jan
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
From the
x86_64low level interrupt handlers, the frame pointer is saved inpt_regsin the wrong place, in the offset of rbx.rbx is not part of the irq partial saved registers, so it's not critical, but later code that uses
get_irq_regs()to get the interrupted frame pointer instead get a stale rbx value, causing unwinding code to fail miserably.
Quoted 8 lines
Code using
get_irq_regs()can't rely on the not explicitly saved registers' fields ofpt_regsanyway; you now fix this for %rbp, but someone else might look at a different register and want that to be saved too. You just shouldn't, and the fact that %rbp happens to be saved at all shouldn't be taken to mean you can access it via the providedpt_regspointer. This saving of %rbp could go away or be done in a different way at any point.
Right. That was something I was wondering about: is rbp saved here as the beginning of the proc stack, or was is supposed to be part of the pt_regs although mistakenly recorded in rbp?
So given what you are explaining me, it rather seem it wasn't supposed to be of part pt_regs and it's there because it begins the frame of the irq handler.
I agree that in the case of common irqs, rbp is not supposed to be part of saved regs. I think may be we can change that semantic though as it requires very few changes. In fact the only added overhead is that addq below.
I'm waiting for opinions though.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +2
-0@@ -808,6 +813,8 @@ ret_from_intr: TRACE_IRQS_OFF decl PER_CPU_VAR(irq_count) leaveq + /* we did not save rbx, restore only from ARGOFFSET */ + addq $8, %rsp
Quoted 8 lines
Review ret_from_intr: · line 820
Quoted 3 lines
(quoted diff) +0
-0CFI_RESTORE rbp CFI_DEF_CFA_REGISTER rsp CFI_ADJUST_CFA_OFFSET -8*If* the patch was to be taken anyway, I would strongly suggest getting this mis-insertion fixed first: CFI annotations belong to the immediately preceding instruction, and hence you must not insert new instructions between an existing one and its annotation.
Good to know, will fix.
Quoted 4 lines
Furthermore, an adjustment to %rsp (when it serves as the frame pointer as is the case here, though would be better visible if the added instruction was at the right place) needs to be annotated itself.
Hmm, I'm not familiar with those CFI adjustments.
Before we had:
leaveq
CFI_RESTORE rbp
CFI_DEF_CFA_REGISTER rsp
CFI_ADJUST_CFA_OFFSET -8
So CFI_RESTORE means rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?
And what follows means that rsp-8 points to the return address? But it doesn't seem to be the case, the return address here beeing rip stored in pt_regs...
I'm confused.
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?
No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA = cfa_register + cfa_offset
with CFA being what all locations on the stack are expressed relative to.
Jan
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
So here rsp points to pt_regs::r11
I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 31 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Quoted 6 lines
Ok.
So here rsp points to
pt_regs::r11I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Jan
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
Quoted 8 lines
Quoted 4 lines
So here rsp points to
pt_regs::r11I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Ah! So CFA acts like a virtual frame base pointer right?
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 35 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
So here rsp points to
pt_regs::r11
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Ah! So CFA acts like a virtual frame base pointer right?
Correct.
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 38 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
So here rsp points to
pt_regs::r11I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Ah! So CFA acts like a virtual frame base pointer right?
Correct.
Ah great. I was starting to prepare for the case you come to stab me :)
So what do you think about that:
leaveq
CFI_RESTORE rbp
CFI_DEF_CFA_REGISTER rsp
CFI_ADJUST_CFA_OFFSET -8
/* we did not save rbx, restore only from ARGOFFSET */
addq $8, %rsp
CFI_ADJUST_CFA_OFFSET -16Does that look correct to you? We increased rsp to start recovering the regs from the right place, but the frame pointer of the current proc must stay what it was.
Now I don't understand how this is all useful as this is not a normal proc but an interruption. We can't get back the return address from the CFA. Or am I missing something?
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 53 lines · Frederic Weisbecker
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 38 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
So here rsp points to
pt_regs::r11I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Ah! So CFA acts like a virtual frame base pointer right?
Correct.
Ah great. I was starting to prepare for the case you come to stab me :)
So what do you think about that:
Quoted 9 lines
leaveq
CFI_RESTORE rbp
CFI_DEF_CFA_REGISTER rsp
CFI_ADJUST_CFA_OFFSET -8
/* we did not save rbx, restore only from ARGOFFSET */
addq $8, %rsp
CFI_ADJUST_CFA_OFFSET -16Or if CFI_ADJUST_CFA_OFFSET is already relative to its previous value, it should be CFI_ADJUST_CFA_OFFSET -8
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
In reply to Frederic WeisbeckerQuoted 65 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 38 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
So here rsp points to
pt_regs::r11I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Ah! So CFA acts like a virtual frame base pointer right?
Correct.
Ah great. I was starting to prepare for the case you come to stab me :)
So what do you think about that:
leaveq CFI_RESTORE rbp CFI_DEF_CFA_REGISTER rsp CFI_ADJUST_CFA_OFFSET -8 /* we did not save rbx, restore only from ARGOFFSET */ addq $8, %rsp CFI_ADJUST_CFA_OFFSET -16
Quoted 3 lines
Does that look correct to you? We increased rsp to start recovering the regs from the right place, but the frame pointer of the current proc must stay what it was.
As you hinted in your subsequent reply - it's -8 here (that's why the directive is named *adjust*; there are other directives allowing to *set* an offset).
Quoted 3 lines
Now I don't understand how this is all useful as this is not a normal proc but an interruption. We can't get back the return address from the CFA. Or am I missing something?
Unwind annotations, when written correctly, allow unwinding through all kinds of execution flows, including interrupts or exceptions as well as including stack switches.
Jan
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Now I don't understand how this is all useful as this is not a normal proc but an interruption. We can't get back the return address from the CFA. Or am I missing something?
Unwind annotations, when written correctly, allow unwinding through all kinds of execution flows, including interrupts or exceptions as well as including stack switches.
Yeah and that's rather useful, as exception contexts can nest in very weird ways, especially with NMIs involved. For example a 7-context combination is possible:
user-space -> syscall -> pagefault -> softirq -> hardirq -> debug trap -> NMI
And the call frame walking logic needs to be able to get all the way back to user-space ...
For that every transition needs to work flawlessly, for debugging (and CFI based profiling) to work fine.
Most of those transitions can happen at any instruction boundary that a given context executes, so the total number of possible combinations is virtually endless.
Unfortunately we dont seem to have a good way to test any of this automatically. Putting a perf probe on every assembly instruction perhaps, and checking whether the frame manages to go back all the way to user-space?
Thanks,
Ingo
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 22 lines · Ingo Molnar
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Now I don't understand how this is all useful as this is not a normal proc but an interruption. We can't get back the return address from the CFA. Or am I missing something?
Unwind annotations, when written correctly, allow unwinding through all kinds of execution flows, including interrupts or exceptions as well as including stack switches.
Yeah and that's rather useful, as exception contexts can nest in very weird ways, especially with NMIs involved. For example a 7-context combination is possible:
user-space -> syscall -> pagefault -> softirq -> hardirq -> debug trap -> NMI
And the call frame walking logic needs to be able to get all the way back to user-space ...
For that every transition needs to work flawlessly, for debugging (and CFI based profiling) to work fine.
Quoted 6 lines
Most of those transitions can happen at any instruction boundary that a given context executes, so the total number of possible combinations is virtually endless.
Unfortunately we dont seem to have a good way to test any of this automatically. Putting a perf probe on every assembly instruction perhaps, and checking whether the frame manages to go back all the way to user-space?
May be.
Once I'll have perf callchain based on CFI ready, we'll perhaps find some issues there. Although I guess there are already tools that can make use of that.
Quoted 4 lines
Thanks,
Ingo
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Once I'll have perf callchain based on CFI ready, we'll perhaps find some issues
there. Although I guess there are already tools that can make use of that.
Is this to read that you're planning to do a re-spin of the CFI unwinding code (which I'm not allowed to submit another time, but which we've been using for years in SuSE distros) then?
Jan
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Once I'll have perf callchain based on CFI ready, we'll perhaps find some issues
there. Although I guess there are already tools that can make use of that.Is this to read that you're planning to do a re-spin of the CFI unwinding code (which I'm not allowed to submit another time, but which we've been using for years in SuSE distros) then?
An in-kernel CFI unwinder?
No the intended CFI unwinding that I'm working on for perf is made on post-processing, on top of partial stack and regs snapshots.
The true unwinding is computed in userspace.
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 10 lines · Frederic Weisbecker
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Once I'll have perf callchain based on CFI ready, we'll perhaps find some issues
there. Although I guess there are already tools that can make use of that.Is this to read that you're planning to do a re-spin of the CFI unwinding code (which I'm not allowed to submit another time, but which we've been using for years in SuSE distros) then?
Quoted 6 lines
An in-kernel CFI unwinder?
No the intended CFI unwinding that I'm working on for perf is made on post-processing, on top of partial stack and regs snapshots.
The true unwinding is computed in userspace.
I think that design will be fundamentally more robust and more flexible than an in-kernel unwinder.
Thanks,
Ingo
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
Quoted 15 lines · Ingo Molnar
Quoted 12 lines · Frederic Weisbecker
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Once I'll have perf callchain based on CFI ready, we'll perhaps find some issues
there. Although I guess there are already tools that can make use of that.Is this to read that you're planning to do a re-spin of the CFI unwinding code (which I'm not allowed to submit another time, but which we've been using for years in SuSE distros) then?
An in-kernel CFI unwinder?
Quoted 7 lines
Quoted 4 lines
No the intended CFI unwinding that I'm working on for perf is made on post-processing, on top of partial stack and regs snapshots.
The true unwinding is computed in userspace.
I think that design will be fundamentally more robust and more flexible than an in-kernel unwinder.
But in fact for the kernel unwinding it still uses frame pointers which is certainly the fastest and lightest way to unwind a stack. Very nice for our profiling.
Now one may argue about the loss of a register and its associated overhead, not sure it's always noticeable though...
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
In reply to Jan BeulichQuoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Once I'll have perf callchain based on CFI ready, we'll perhaps find some issues
there. Although I guess there are already tools that can make use of that.Is this to read that you're planning to do a re-spin of the CFI unwinding code (which I'm not allowed to submit another time, but which we've been using for years in SuSE distros) then?
Actually I couldn't test kernel CFI annotations with perf as we keep the kernel unwinding under frame pointer style.
The CFI unwinding we'll do is only for userspace.
Re: [RFC PATCH 1/2] x86: Fix rbp saving in pt_regs on irq entry
In reply to Jan BeulichQuoted 65 lines · Jan Beulich
Quoted 65 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 38 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Quoted 20 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Frederic Weisbecker
Before we had:
Quoted 8 lines
leaveq
CFI_RESTORErbp
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET-8So
CFI_RESTOREmeans rbp has now the value of the base frame of the calling frame (the base frame pointer of the interrupted proc) ?No - all it means is that %rbp now has its original (caller or interrupted procedure) value again (i.e. an unwinder should not try to read it from the stack [or other previously recorded location] anymore).
Quoted 1 line
And what follows means that rsp-8 points to the return address?
Quoted 8 lines
No - .cfi_def_cfa_register says which register serves as the frame pointer, and .cfi_adjust_cfa_offset says to adjust the offset from the frame pointer to the top [or bottom] of frame. At any time
CFA =
cfa_register+cfa_offsetwith CFA being what all locations on the stack are expressed relative to.
Ok.
So here rsp points to
pt_regs::r11I don't understand why locations relative to the stack must be expressed here by taking rsp - 8 as a base.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Nothing says rsp-8. The annotations merely say to set the base register to rsp and to *adjust* the offset by -8 (after all, that's what the leaveq instruction does).
Ah! So CFA acts like a virtual frame base pointer right?
Correct.
Ah great. I was starting to prepare for the case you come to stab me :)
So what do you think about that:
leaveq CFI_RESTORE rbp CFI_DEF_CFA_REGISTER rsp CFI_ADJUST_CFA_OFFSET -8 /* we did not save rbx, restore only from ARGOFFSET */ addq $8, %rsp CFI_ADJUST_CFA_OFFSET -16
Quoted 7 lines
Quoted 3 lines
Does that look correct to you? We increased rsp to start recovering the regs from the right place, but the frame pointer of the current proc must stay what it was.
As you hinted in your subsequent reply - it's -8 here (that's why the directive is named *adjust*; there are other directives allowing to *set* an offset).
Ok, I'll respin with a proper patch then.
Quoted 7 lines
Quoted 3 lines
Now I don't understand how this is all useful as this is not a normal proc but an interruption. We can't get back the return address from the CFA. Or am I missing something?
Unwind annotations, when written correctly, allow unwinding through all kinds of execution flows, including interrupts or exceptions as well as including stack switches.
Hmm I see, I guess this is handled through the movq_cfi things we have, so that the unwinder can ignore the whole part with the saved registers after which we can find the instruction pointer (considered as the return address) saved by the hardware.
Fine, thanks for your explanations!
Quoted 13 lines · Frederic Weisbecker
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/coreSoeren reported some time ago that callchains were broken on
x86_64with cpu-clock/task-clock events. After some time I finally found the problem was in the irq low level arg saving. It touches fragile code though, I hope some people can have a look over the fix.
Quoted 7 lines
Thanks,
Frederic
---Frederic Weisbecker (2):
x86: Fix rbp saving inpt_regson irq entry
perf: Build tools with frame pointer
Is this variant fine with Jan too?
Thanks,
Ingo
Quoted 20 lines · Ingo Molnar
Quoted 17 lines · Frederic Weisbecker
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/coreSoeren reported some time ago that callchains were broken on
x86_64with cpu-clock/task-clock events. After some time I finally found the problem was in the irq low level arg saving. It touches fragile code though, I hope some people can have a look over the fix.Thanks,
Frederic
---
Quoted 5 lines
Quoted 3 lines
Frederic Weisbecker (2):
x86: Fix rbp saving inpt_regson irq entry
perf: Build tools with frame pointerIs this variant fine with Jan too?
So, Arnaldo has picked up the second patch.
For the first I need to resend with a fix on CFI annotations.
Quoted 25 lines · Frederic Weisbecker
Quoted 24 lines · Ingo Molnar
Quoted 20 lines · Frederic Weisbecker
Ingo,
Please pull the perf/core branch that can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
perf/coreSoeren reported some time ago that callchains were broken on
x86_64with cpu-clock/task-clock events. After some time I finally found the problem was in the irq low level arg saving. It touches fragile code though, I hope some people can have a look over the fix.Thanks,
Frederic
---Frederic Weisbecker (2):
x86: Fix rbp saving inpt_regson irq entry
perf: Build tools with frame pointer
Quoted 5 lines
Quoted 1 line
Is this variant fine with Jan too?
So, Arnaldo has picked up the second patch.
For the first I need to resend with a fix on CFI annotations.
ok, i'll wait with pulling then.
Thanks,
Ingo