linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
@ 2022-03-16  4:16 Lai Jiangshan
  2022-03-17 22:19 ` Josh Poimboeuf
  2022-05-18 18:44 ` [tip: x86/sev] x86/sev: Annotate stack change in the #VC handler tip-bot2 for Lai Jiangshan
  0 siblings, 2 replies; 8+ messages in thread
From: Lai Jiangshan @ 2022-03-16  4:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: x86, Lai Jiangshan, Joerg Roedel, Josh Poimboeuf,
	Andy Lutomirski, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, H. Peter Anvin

From: Lai Jiangshan <jiangshan.ljs@antgroup.com>

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 <jroedel@suse.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
  2022-03-16  4:16 [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC Lai Jiangshan
@ 2022-03-17 22:19 ` Josh Poimboeuf
  2022-03-18  1:14   ` Lai Jiangshan
  2022-05-18 18:44 ` [tip: x86/sev] x86/sev: Annotate stack change in the #VC handler tip-bot2 for Lai Jiangshan
  1 sibling, 1 reply; 8+ messages in thread
From: Josh Poimboeuf @ 2022-03-17 22:19 UTC (permalink / raw)
  To: Lai Jiangshan
  Cc: linux-kernel, x86, Lai Jiangshan, Joerg Roedel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

On Wed, Mar 16, 2022 at 12:16:12PM +0800, Lai Jiangshan wrote:
> From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> 
> 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 <jroedel@suse.de>
> Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> ---
>  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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
  2022-03-17 22:19 ` Josh Poimboeuf
@ 2022-03-18  1:14   ` Lai Jiangshan
  2022-03-18 17:03     ` Josh Poimboeuf
  0 siblings, 1 reply; 8+ messages in thread
From: Lai Jiangshan @ 2022-03-18  1:14 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: LKML, X86 ML, Lai Jiangshan, Joerg Roedel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

On Fri, Mar 18, 2022 at 6:19 AM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> On Wed, Mar 16, 2022 at 12:16:12PM +0800, Lai Jiangshan wrote:
> > From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> >
> > 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 <jroedel@suse.de>
> > Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> > Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> > ---
> >  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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
  2022-03-18  1:14   ` Lai Jiangshan
@ 2022-03-18 17:03     ` Josh Poimboeuf
  2022-04-12 12:24       ` Lai Jiangshan
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Poimboeuf @ 2022-03-18 17:03 UTC (permalink / raw)
  To: Lai Jiangshan
  Cc: LKML, X86 ML, Lai Jiangshan, Joerg Roedel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

On Fri, Mar 18, 2022 at 09:14:09AM +0800, Lai Jiangshan wrote:
> On Fri, Mar 18, 2022 at 6:19 AM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >
> > On Wed, Mar 16, 2022 at 12:16:12PM +0800, Lai Jiangshan wrote:
> > > From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> > >
> > > 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 <jroedel@suse.de>
> > > Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> > > Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> > > ---
> > >  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 <jpoimboe@redhat.com>

-- 
Josh


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
  2022-03-18 17:03     ` Josh Poimboeuf
@ 2022-04-12 12:24       ` Lai Jiangshan
  2022-04-27  8:26         ` Lai Jiangshan
  0 siblings, 1 reply; 8+ messages in thread
From: Lai Jiangshan @ 2022-04-12 12:24 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: LKML, X86 ML, Lai Jiangshan, Joerg Roedel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

On Sat, Mar 19, 2022 at 1:03 AM Josh Poimboeuf <jpoimboe@redhat.com> 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 <jpoimboe@redhat.com>

Hello, Borislav

Can you have a look at the patch, please?

Thanks
Lai

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
  2022-04-12 12:24       ` Lai Jiangshan
@ 2022-04-27  8:26         ` Lai Jiangshan
  2022-05-13  9:04           ` Lai Jiangshan
  0 siblings, 1 reply; 8+ messages in thread
From: Lai Jiangshan @ 2022-04-27  8:26 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: LKML, X86 ML, Lai Jiangshan, Joerg Roedel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

On Tue, Apr 12, 2022 at 8:24 PM Lai Jiangshan <jiangshanlai@gmail.com> wrote:
>
> On Sat, Mar 19, 2022 at 1:03 AM Josh Poimboeuf <jpoimboe@redhat.com> 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 <jpoimboe@redhat.com>
>
> Hello, Borislav
>
> Can you have a look at the patch, please?
>
> Thanks
> Lai


Hello

Ping.

Thanks
Lai

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC
  2022-04-27  8:26         ` Lai Jiangshan
@ 2022-05-13  9:04           ` Lai Jiangshan
  0 siblings, 0 replies; 8+ messages in thread
From: Lai Jiangshan @ 2022-05-13  9:04 UTC (permalink / raw)
  To: Joerg Roedel, Brijesh Singh, Tom Lendacky
  Cc: LKML, X86 ML, Lai Jiangshan, Josh Poimboeuf, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

+ Brijesh
+ Tom

On Wed, Apr 27, 2022 at 4:26 PM Lai Jiangshan <jiangshanlai@gmail.com> wrote:
>
> On Tue, Apr 12, 2022 at 8:24 PM Lai Jiangshan <jiangshanlai@gmail.com> wrote:
> >
> > On Sat, Mar 19, 2022 at 1:03 AM Josh Poimboeuf <jpoimboe@redhat.com> 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 <jpoimboe@redhat.com>
> >
> > Hello, Borislav
> >
> > Can you have a look at the patch, please?
> >
> > Thanks
> > Lai
>
>
> Hello
>
> Ping.
>
> Thanks
> Lai


Hello, Joerg, Brijesh, Tom

Ping.

Thanks
Lai

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip: x86/sev] x86/sev: Annotate stack change in the #VC handler
  2022-03-16  4:16 [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC Lai Jiangshan
  2022-03-17 22:19 ` Josh Poimboeuf
@ 2022-05-18 18:44 ` tip-bot2 for Lai Jiangshan
  1 sibling, 0 replies; 8+ messages in thread
From: tip-bot2 for Lai Jiangshan @ 2022-05-18 18:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Lai Jiangshan, Borislav Petkov, Josh Poimboeuf, x86, linux-kernel

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 <jiangshan.ljs@antgroup.com>
AuthorDate:    Wed, 16 Mar 2022 12:16:12 +08:00
Committer:     Borislav Petkov <bp@suse.de>
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 <jiangshan.ljs@antgroup.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20220316041612.71357-1-jiangshanlai@gmail.com
---
 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 */

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-18 18:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16  4:16 [PATCH] x86/sev: Add ENCODE_FRAME_POINTER after stack changed for #VC Lai Jiangshan
2022-03-17 22:19 ` Josh Poimboeuf
2022-03-18  1:14   ` Lai Jiangshan
2022-03-18 17:03     ` Josh Poimboeuf
2022-04-12 12:24       ` Lai Jiangshan
2022-04-27  8:26         ` Lai Jiangshan
2022-05-13  9:04           ` Lai Jiangshan
2022-05-18 18:44 ` [tip: x86/sev] x86/sev: Annotate stack change in the #VC handler tip-bot2 for Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).