Skip to contentSkip to conversation

x86: don't destroy %rbp on kernel-mode faults

PATCH RESEND Applied Vegard Nossum 3 participants 3 messages Jun 27, 2008 x86

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 x86: don't destroy %rbp on kernel-mode faults

Hi,

I sent this patch earlier, but it was never queued. It has been acked by Arjan and acked informally by Andi. I hope this can make it for 2.6.27.

(It's been tested on two x86_64s.)

Vegard

From: Vegard Nossum <[email protected]>
Date: Thu, 26 Jun 2008 13:26:50 +0200
Subject: [PATCH] x86: don't destroy %rbp on kernel-mode faults

Quoted 1 line

From the code:

"B stepping K8s sometimes report an truncated RIP for IRET exceptions returning to compat mode. Check for these here too."

The code then proceeds to truncate the upper 32 bits of %rbp. This means that when do_page_fault() is finally called, its prologue,

do_page_fault:
push %rbp
movl %rsp, %rbp

will put the truncated base pointer on the stack. This means that the stack tracer will not be able to follow the base-pointer changes and will see all subsequent stack frames as unreliable.

This patch changes the code to use a different register (%rcx) for the checking and leaves %rbp untouched.

---
 arch/x86/kernel/entry_64.S |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/entry_64.S +4 -4
index 556a8df..fa1c9eb 100644
@@ -926,11 +926,11 @@ error_kernelspace:
 	   iret run with kernel gs again, so don't set the user space flag.
 	   B stepping K8s sometimes report an truncated RIP for IRET 
 	   exceptions returning to compat mode. Check for these here too. */
-	leaq irq_return(%rip),%rbp
-	cmpq %rbp,RIP(%rsp) 
+	leaq irq_return(%rip),%rcx
+	cmpq %rcx,RIP(%rsp)
 	je   error_swapgs
-	movl %ebp,%ebp	/* zero extend */
-	cmpq %rbp,RIP(%rsp) 
+	movl %ecx,%ecx	/* zero extend */
+	cmpq %rcx,RIP(%rsp)
 	je   error_swapgs
 	cmpq $gs_change,RIP(%rsp)
         je   error_swapgs
Signature · 1 line
1.5.4.1
Applied
#1 lore raw
Quoted 12 lines · Vegard Nossum
Quoted 1 line

From the code:

"B stepping K8s sometimes report an truncated RIP for IRET exceptions returning to compat mode. Check for these here too."

The code then proceeds to truncate the upper 32 bits of %rbp. This means that when do_page_fault() is finally called, its prologue,

do_page_fault:
push %rbp
movl %rsp, %rbp

Quoted 6 lines

will put the truncated base pointer on the stack. This means that the stack tracer will not be able to follow the base-pointer changes and will see all subsequent stack frames as unreliable.

This patch changes the code to use a different register (%rcx) for the checking and leaves %rbp untouched.

applied to tip/x86/debug - thanks Vegard!

Ingo

#2 lore raw
In reply to Vegard Nossum
Quoted 4 lines · Vegard Nossum

Hi,

I sent this patch earlier, but it was never queued. It has been acked by Arjan and acked informally by Andi. I hope this can make it for 2.6.27.

Just to clarify the "informal ack" was (paraphrased):

All the .S code was always designed to support dwarf2 unwinding and not frame pointers and there are a lot more places that don't care about frame pointers. So even if you fix it here it'll still break in other places.

-Andi