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.
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(+)
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index e20eabaa56b8..f99f2881ed83 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -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 */
--
2.19.1.6.gb485710b
On Wed, Mar 16, 2022 at 12:16:12PM +0800, Lai Jiangshan wrote:
> 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.
>
> 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(+)
>
> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> index e20eabaa56b8..f99f2881ed83 100644
> --- a/arch/x86/entry/entry_64.S
> +++ b/arch/x86/entry/entry_64.S
> @@ -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?
--
Josh
On Fri, Mar 18, 2022 at 6:19 AM Josh Poimboeuf <[email protected]> wrote:
>
> On Wed, Mar 16, 2022 at 12:16:12PM +0800, Lai Jiangshan wrote:
> > 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.
> >
> > 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(+)
> >
> > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> > index e20eabaa56b8..f99f2881ed83 100644
> > --- a/arch/x86/entry/entry_64.S
> > +++ b/arch/x86/entry/entry_64.S
> > @@ -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?
>
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.
> --
> Josh
>
On Fri, Mar 18, 2022 at 09:14:09AM +0800, Lai Jiangshan wrote:
> On Fri, Mar 18, 2022 at 6:19 AM Josh Poimboeuf <[email protected]> wrote:
> >
> > On Wed, Mar 16, 2022 at 12:16:12PM +0800, Lai Jiangshan wrote:
> > > 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.
> > >
> > > 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(+)
> > >
> > > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> > > index e20eabaa56b8..f99f2881ed83 100644
> > > --- a/arch/x86/entry/entry_64.S
> > > +++ b/arch/x86/entry/entry_64.S
> > > @@ -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?
> >
>
> 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.
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:
Fixes: a13644f3a53d ("x86/entry/64: Add entry code for #VC handler")
Acked-by: Josh Poimboeuf <[email protected]>
--
Josh
On Sat, Mar 19, 2022 at 1:03 AM Josh Poimboeuf <[email protected]> wrote:
> Ok, maybe Joerg can test it. It looks obviously right to me though.
It looks also obviously right to me.
Hello, Joerg
Any feedback?
> 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
On Tue, Apr 12, 2022 at 8:24 PM Lai Jiangshan <[email protected]> wrote:
>
> On Sat, Mar 19, 2022 at 1:03 AM Josh Poimboeuf <[email protected]> wrote:
>
> > Ok, maybe Joerg can test it. It looks obviously right to me though.
>
> It looks also obviously right to me.
>
> Hello, Joerg
>
> Any feedback?
>
> > 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
Hello
Ping.
Thanks
Lai
+ Brijesh
+ Tom
On Wed, Apr 27, 2022 at 4:26 PM Lai Jiangshan <[email protected]> wrote:
>
> On Tue, Apr 12, 2022 at 8:24 PM Lai Jiangshan <[email protected]> wrote:
> >
> > On Sat, Mar 19, 2022 at 1:03 AM Josh Poimboeuf <[email protected]> wrote:
> >
> > > Ok, maybe Joerg can test it. It looks obviously right to me though.
> >
> > It looks also obviously right to me.
> >
> > Hello, Joerg
> >
> > Any feedback?
> >
> > > 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
>
>
> Hello
>
> Ping.
>
> Thanks
> Lai
Hello, Joerg, Brijesh, Tom
Ping.
Thanks
Lai
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. ]
Fixes: a13644f3a53d ("x86/entry/64: Add entry code for #VC handler")
Signed-off-by: Lai Jiangshan <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
arch/x86/entry/entry_64.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 4faac48..f7bd800 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -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 */