x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
Subsystems (2)
PATCH 1/1 x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
From: Lai Jiangshan <[email protected]>
In idtentry_vc(), the real frame is changed after it switches to new stack, ENCODE_FRAME_POINTER should be called in case for unwinder.
--- arch/x86/entry/entry_64.S | 1 + 1 file changed, 1 insertion(+)
arch/x86/entry/entry_64.S +1 -0
@@ -540,6 +540,7 @@ SYM_CODE_START(\asmsym) call vc_switch_off_ist movq %rax, %rsp /* Switch to new stack */ + ENCODE_FRAME_POINTER UNWIND_HINT_REGS /* Update pt_regs */
Signature · 1 line
2.19.1.6.gb485710b
Quoted 17 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
In
idtentry_vc(), the real frame is changed after it switches to new stack,ENCODE_FRAME_POINTERshould be called in case for unwinder.Cc Joerg Roedel <[email protected]>Cc Josh Poimboeuf <[email protected]>Signed-off-by Lai Jiangshan <[email protected]>--- arch/x86/entry/entry_64.S | 1 + 1 file changed, 1 insertion(+)arch/x86/entry/entry_64.S +0
-0
arch/x86/entry/entry_64.S SYM_CODE_START(\asmsym) · line 546
Quoted 7 lines
arch/x86/entry/entry_64.S +1
-0@@ -540,6 +540,7 @@ SYM_CODE_START(\asmsym) call vc_switch_off_ist movq %rax, %rsp /* Switch to new stack */ + ENCODE_FRAME_POINTER UNWIND_HINT_REGS /* Update pt_regs */
Looks right to me. Any chance you have the ability to test this scenario by unwinding from #VC with CONFIG_FRAME_POINTER?
Signature · 1 line
Josh
Quoted 22 lines · Josh Poimboeuf
Quoted 20 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
In
idtentry_vc(), the real frame is changed after it switches to new stack,ENCODE_FRAME_POINTERshould be called in case for unwinder.Cc Joerg Roedel <[email protected]>Cc Josh Poimboeuf <[email protected]>Signed-off-by Lai Jiangshan <[email protected]>--- arch/x86/entry/entry_64.S | 1 + 1 file changed, 1 insertion(+)arch/x86/entry/entry_64.S +0
-0@@ -540,6 +540,7 @@ SYM_CODE_START(\asmsym) call vc_switch_off_ist movq %rax, %rsp /* Switch to new stack */
Quoted 8 lines
arch/x86/entry/entry_64.S SYM_CODE_START(\asmsym) · line 546
Quoted 4 lines
arch/x86/entry/entry_64.S +1
-0+ ENCODE_FRAME_POINTER UNWIND_HINT_REGS /* Update pt_regs */Looks right to me. Any chance you have the ability to test this scenario by unwinding from #VC with
CONFIG_FRAME_POINTER?
I don't have the hardware to test it. Actually, it was you to inspire me to find this in the conversation of my patchset when I tried to search all the code of switching of %rsp to see how ENCODE_FRAME_POINTER and UNWIND_HINT_REGS are used once more.
Quoted 3 lines
--
Josh
Josh Poimboeuf
Acked-byQuoted 32 lines · Lai Jiangshan
Quoted 22 lines · Josh Poimboeuf
Quoted 20 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
In
idtentry_vc(), the real frame is changed after it switches to new stack,ENCODE_FRAME_POINTERshould be called in case for unwinder.Cc Joerg Roedel <[email protected]>Cc Josh Poimboeuf <[email protected]>Signed-off-by Lai Jiangshan <[email protected]>--- arch/x86/entry/entry_64.S | 1 + 1 file changed, 1 insertion(+)arch/x86/entry/entry_64.S +0
-0@@ -540,6 +540,7 @@ SYM_CODE_START(\asmsym) call vc_switch_off_ist movq %rax, %rsp /* Switch to new stack */Quoted 8 lines
arch/x86/entry/entry_64.S SYM_CODE_START(\asmsym) · line 546
Quoted 4 lines
arch/x86/entry/entry_64.S +1
-0+ ENCODE_FRAME_POINTER UNWIND_HINT_REGS /* Update pt_regs */Looks right to me. Any chance you have the ability to test this scenario by unwinding from #VC with
CONFIG_FRAME_POINTER?
Quoted 4 lines
I don't have the hardware to test it. Actually, it was you to inspire me to find this in the conversation of my patchset when I tried to search all the code of switching of %rsp to see how
ENCODE_FRAME_POINTERandUNWIND_HINT_REGSare used once more.
Ok, maybe Joerg can test it. It looks obviously right to me though. Since it fixes a real frame pointer unwinding bug, it probably needs:
Signature · 1 line
Josh
Quoted 1 line · Josh Poimboeuf
Ok, maybe Joerg can test it. It looks obviously right to me though.
It looks also obviously right to me.
Hello, Joerg
Any feedback?
Quoted 5 lines
Since it fixes a real frame pointer unwinding bug, it probably needs:
Fixes a13644f3a53d ("x86/entry/64: Add entry code for #VC handler")Acked-by Josh Poimboeuf <[email protected]>
Hello, Borislav
Can you have a look at the patch, please?
Thanks
Lai
Quoted 15 lines · Lai Jiangshan
Quoted 1 line · Josh Poimboeuf
Ok, maybe Joerg can test it. It looks obviously right to me though.
It looks also obviously right to me.
Hello, Joerg
Any feedback?
Quoted 4 lines
Since it fixes a real frame pointer unwinding bug, it probably needs:
Fixes a13644f3a53d ("x86/entry/64: Add entry code for #VC handler")
Quoted 8 lines
Quoted 1 line
Acked-by Josh Poimboeuf <[email protected]>Hello, Borislav
Can you have a look at the patch, please?
Thanks
Lai
Hello
Ping.
Thanks
Lai
+ Brijesh
+ Tom
Quoted 27 lines · Lai Jiangshan
Quoted 15 lines · Lai Jiangshan
Quoted 1 line · Josh Poimboeuf
Ok, maybe Joerg can test it. It looks obviously right to me though.
It looks also obviously right to me.
Hello, Joerg
Any feedback?
Quoted 4 lines
Since it fixes a real frame pointer unwinding bug, it probably needs:
Fixes a13644f3a53d ("x86/entry/64: Add entry code for #VC handler")Quoted 8 lines
Quoted 1 line
Acked-by Josh Poimboeuf <[email protected]>Hello, Borislav
Can you have a look at the patch, please?
Thanks
Lai
Quoted 6 lines
Hello
Ping.
Thanks
Lai
Hello, Joerg, Brijesh, Tom
Ping.
Thanks
Lai
[tip: x86/sev] x86/sev: Annotate stack change in the #VC handler
In reply to Lai JiangshanThe following commit has been merged into the x86/sev branch of tip:
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: c42b145181aafd59ed31ccd879493389e3ea5a08 Gitweb: https://git.kernel.org/tip/c42b145181aafd59ed31ccd879493389e3ea5a08 Author: Lai Jiangshan <[email protected]> AuthorDate: Wed, 16 Mar 2022 12:16:12 +08:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Wed, 18 May 2022 20:36:03 +02:00
x86/sev: Annotate stack change in the #VC handler
In idtentry_vc(), vc_switch_off_ist() determines a safe stack to switch to, off of the IST stack. Annotate the new stack switch with ENCODE_FRAME_POINTER in case UNWINDER_FRAME_POINTER is used.
A stack walk before looks like this:
CPU: 0 PID: 0 Comm: swapper Not tainted 5.18.0-rc7+ #2 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 Call Trace: <TASK> dump_stack_lvl dump_stack kernel_exc_vmm_communication asm_exc_vmm_communication ? native_read_msr ? __x2apic_disable.part.0 ? x2apic_setup ? cpu_init ? trap_init ? start_kernel ? x86_64_start_reservations ? x86_64_start_kernel ? secondary_startup_64_no_verify </TASK>
and with the fix, the stack dump is exact:
CPU: 0 PID: 0 Comm: swapper Not tainted 5.18.0-rc7+ #3 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 Call Trace: <TASK> dump_stack_lvl dump_stack kernel_exc_vmm_communication asm_exc_vmm_communication RIP: 0010:native_read_msr Code: ... < snipped regs > ? __x2apic_disable.part.0 x2apic_setup cpu_init trap_init start_kernel x86_64_start_reservations x86_64_start_kernel secondary_startup_64_no_verify </TASK>
[ bp: Test in a SEV-ES guest and rewrite the commit message to
explain what exactly this does. ]
--- arch/x86/entry/entry_64.S | 1 + 1 file changed, 1 insertion(+)
arch/x86/entry/entry_64.S +1 -0
@@ -505,6 +505,7 @@ SYM_CODE_START(\asmsym) call vc_switch_off_ist movq %rax, %rsp /* Switch to new stack */ + ENCODE_FRAME_POINTER UNWIND_HINT_REGS /* Update pt_regs */