* Re: [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask
2023-05-29 20:31 ` Kirill A. Shutemov
@ 2023-05-30 0:54 ` Kirill A. Shutemov
2023-05-30 9:26 ` Thomas Gleixner
2023-05-30 9:26 ` [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask Thomas Gleixner
2023-05-30 10:46 ` [patch] x86/realmode: Make stack lock work in trampoline_compat() Thomas Gleixner
2 siblings, 1 reply; 29+ messages in thread
From: Kirill A. Shutemov @ 2023-05-30 0:54 UTC (permalink / raw)
To: Thomas Gleixner
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Mon, May 29, 2023 at 11:31:29PM +0300, Kirill A. Shutemov wrote:
> On Mon, May 29, 2023 at 09:27:13PM +0200, Thomas Gleixner wrote:
> > On Mon, May 29 2023 at 05:39, Kirill A. Shutemov wrote:
> > > On Sat, May 27, 2023 at 03:40:02PM +0200, Thomas Gleixner wrote:
> > > But it gets broken again on "x86/smpboot: Implement a bit spinlock to
> > > protect the realmode stack" with
> > >
> > > [ 0.554079] .... node #0, CPUs: #1 #2
> > > [ 0.738071] Callback from call_rcu_tasks() invoked.
> > > [ 10.562065] CPU2 failed to report alive state
> > > [ 10.566337] #3
> > > [ 20.570066] CPU3 failed to report alive state
> > > [ 20.574268] #4
> > > ...
> > >
> > > Notably CPU1 is missing from "failed to report" list. So CPU1 takes the
> > > lock fine, but seems never unlocks it.
> > >
> > > Maybe trampoline_lock(%rip) in head_64.S somehow is not the same as
> > > &tr_lock in trampoline_64.S. I donno.
> >
> > It's definitely the same in the regular startup (16bit mode), but TDX
> > starts up via:
> >
> > trampoline_start64
> > trampoline_compat
> > LOAD_REALMODE_ESP <- lock
> >
> > That place cannot work with that LOAD_REALMODE_ESP macro. The untested
> > below should cure it.
>
> Yep, works for me.
>
> Aaand the next patch that breaks TDX boot is... <drum roll>
>
> x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it
>
> Disabling parallel bringup helps. I didn't look closer yet. If you have
> an idea let me know.
Okay, it crashes around .Lread_apicid due to touching MSRs that trigger #VE.
Looks like the patch had no intention to enable parallel bringup on TDX.
+ * Intel-TDX has a secure RDMSR hypercall, but that needs to be
+ * implemented seperately in the low level startup ASM code.
But CC_ATTR_GUEST_STATE_ENCRYPT that used to filter it out is
SEV-ES-specific thingy and doesn't cover TDX. I don't think we have an
attribute that fits nicely here.
--
Kiryl Shutsemau / Kirill A. Shutemov
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask
2023-05-30 0:54 ` Kirill A. Shutemov
@ 2023-05-30 9:26 ` Thomas Gleixner
2023-05-30 10:34 ` Thomas Gleixner
0 siblings, 1 reply; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 9:26 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30 2023 at 03:54, Kirill A. Shutemov wrote:
> On Mon, May 29, 2023 at 11:31:29PM +0300, Kirill A. Shutemov wrote:
>> Disabling parallel bringup helps. I didn't look closer yet. If you have
>> an idea let me know.
>
> Okay, it crashes around .Lread_apicid due to touching MSRs that trigger #VE.
>
> Looks like the patch had no intention to enable parallel bringup on TDX.
>
> + * Intel-TDX has a secure RDMSR hypercall, but that needs to be
> + * implemented seperately in the low level startup ASM code.
>
> But CC_ATTR_GUEST_STATE_ENCRYPT that used to filter it out is
> SEV-ES-specific thingy and doesn't cover TDX. I don't think we have an
> attribute that fits nicely here.
Bah. That sucks.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask
2023-05-30 9:26 ` Thomas Gleixner
@ 2023-05-30 10:34 ` Thomas Gleixner
2023-05-30 11:37 ` Kirill A. Shutemov
2023-05-30 12:09 ` [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE Thomas Gleixner
0 siblings, 2 replies; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 10:34 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30 2023 at 11:26, Thomas Gleixner wrote:
> On Tue, May 30 2023 at 03:54, Kirill A. Shutemov wrote:
>> On Mon, May 29, 2023 at 11:31:29PM +0300, Kirill A. Shutemov wrote:
>>> Disabling parallel bringup helps. I didn't look closer yet. If you have
>>> an idea let me know.
>>
>> Okay, it crashes around .Lread_apicid due to touching MSRs that trigger #VE.
>>
>> Looks like the patch had no intention to enable parallel bringup on TDX.
>>
>> + * Intel-TDX has a secure RDMSR hypercall, but that needs to be
>> + * implemented seperately in the low level startup ASM code.
>>
>> But CC_ATTR_GUEST_STATE_ENCRYPT that used to filter it out is
>> SEV-ES-specific thingy and doesn't cover TDX. I don't think we have an
>> attribute that fits nicely here.
>
> Bah. That sucks.
Can we have something consistent in this CC space or needs everything to
be extra magic per CC variant?
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask
2023-05-30 10:34 ` Thomas Gleixner
@ 2023-05-30 11:37 ` Kirill A. Shutemov
2023-05-30 12:09 ` [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE Thomas Gleixner
1 sibling, 0 replies; 29+ messages in thread
From: Kirill A. Shutemov @ 2023-05-30 11:37 UTC (permalink / raw)
To: Thomas Gleixner
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30, 2023 at 12:34:45PM +0200, Thomas Gleixner wrote:
> On Tue, May 30 2023 at 11:26, Thomas Gleixner wrote:
> > On Tue, May 30 2023 at 03:54, Kirill A. Shutemov wrote:
> >> On Mon, May 29, 2023 at 11:31:29PM +0300, Kirill A. Shutemov wrote:
> >>> Disabling parallel bringup helps. I didn't look closer yet. If you have
> >>> an idea let me know.
> >>
> >> Okay, it crashes around .Lread_apicid due to touching MSRs that trigger #VE.
> >>
> >> Looks like the patch had no intention to enable parallel bringup on TDX.
> >>
> >> + * Intel-TDX has a secure RDMSR hypercall, but that needs to be
> >> + * implemented seperately in the low level startup ASM code.
> >>
> >> But CC_ATTR_GUEST_STATE_ENCRYPT that used to filter it out is
> >> SEV-ES-specific thingy and doesn't cover TDX. I don't think we have an
> >> attribute that fits nicely here.
> >
> > Bah. That sucks.
>
> Can we have something consistent in this CC space or needs everything to
> be extra magic per CC variant?
IIUC, CC_ATTR_GUEST_MEM_ENCRYPT should cover all AMD SEV flavours and
Intel TDX. But the name is confusing in this context: memory encryption
has nothing to do with the APIC.
--
Kiryl Shutsemau / Kirill A. Shutemov
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 10:34 ` Thomas Gleixner
2023-05-30 11:37 ` Kirill A. Shutemov
@ 2023-05-30 12:09 ` Thomas Gleixner
2023-05-30 12:29 ` Kirill A. Shutemov
1 sibling, 1 reply; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 12:09 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
The decision to allow parallel bringup of secondary CPUs checks
CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
parallel bootup because accessing the local APIC is intercepted and raises
a #VC or #VE, which cannot be handled at that point.
The check works correctly, but only for AMD encrypted guests. TDX does not
set that flag.
Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
definitely works for both AMD and Intel.
Fixes: 0c7ffa32dbd6 ("x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it")
Reported-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/kernel/smpboot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1282,7 +1282,7 @@ bool __init arch_cpuhp_init_parallel_bri
* Intel-TDX has a secure RDMSR hypercall, but that needs to be
* implemented seperately in the low level startup ASM code.
*/
- if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) {
+ if (cc_get_vendor() != CC_VENDOR_NONE) {
pr_info("Parallel CPU startup disabled due to guest state encryption\n");
return false;
}
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 12:09 ` [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE Thomas Gleixner
@ 2023-05-30 12:29 ` Kirill A. Shutemov
2023-05-30 16:00 ` Thomas Gleixner
0 siblings, 1 reply; 29+ messages in thread
From: Kirill A. Shutemov @ 2023-05-30 12:29 UTC (permalink / raw)
To: Thomas Gleixner, Tom Lendacky
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
> The decision to allow parallel bringup of secondary CPUs checks
> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
> parallel bootup because accessing the local APIC is intercepted and raises
> a #VC or #VE, which cannot be handled at that point.
>
> The check works correctly, but only for AMD encrypted guests. TDX does not
> set that flag.
>
> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
> definitely works for both AMD and Intel.
It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
we want it.
--
Kiryl Shutsemau / Kirill A. Shutemov
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 12:29 ` Kirill A. Shutemov
@ 2023-05-30 16:00 ` Thomas Gleixner
2023-05-30 16:56 ` Sean Christopherson
2023-05-30 17:02 ` [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE Kirill A. Shutemov
0 siblings, 2 replies; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 16:00 UTC (permalink / raw)
To: Kirill A. Shutemov, Tom Lendacky
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30 2023 at 15:29, Kirill A. Shutemov wrote:
> On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
>> The decision to allow parallel bringup of secondary CPUs checks
>> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
>> parallel bootup because accessing the local APIC is intercepted and raises
>> a #VC or #VE, which cannot be handled at that point.
>>
>> The check works correctly, but only for AMD encrypted guests. TDX does not
>> set that flag.
>>
>> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
>> definitely works for both AMD and Intel.
>
> It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
> report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
> we want it.
Right. Did not think about that.
But the same way is CC_ATTR_GUEST_MEM_ENCRYPT overbroad for AMD. Only
SEV-ES traps RDMSR if I'm understandig that maze correctly.
Thanks,
tglx
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 16:00 ` Thomas Gleixner
@ 2023-05-30 16:56 ` Sean Christopherson
2023-05-30 19:51 ` Thomas Gleixner
2023-05-30 17:02 ` [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE Kirill A. Shutemov
1 sibling, 1 reply; 29+ messages in thread
From: Sean Christopherson @ 2023-05-30 16:56 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Kirill A. Shutemov, Tom Lendacky, LKML, x86, David Woodhouse,
Andrew Cooper, Brian Gerst, Arjan van de Veen, Paolo Bonzini,
Paul McKenney, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30, 2023, Thomas Gleixner wrote:
> On Tue, May 30 2023 at 15:29, Kirill A. Shutemov wrote:
> > On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
> >> The decision to allow parallel bringup of secondary CPUs checks
> >> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
> >> parallel bootup because accessing the local APIC is intercepted and raises
> >> a #VC or #VE, which cannot be handled at that point.
> >>
> >> The check works correctly, but only for AMD encrypted guests. TDX does not
> >> set that flag.
> >>
> >> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
> >> definitely works for both AMD and Intel.
> >
> > It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
> > report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
> > we want it.
>
> Right. Did not think about that.
>
> But the same way is CC_ATTR_GUEST_MEM_ENCRYPT overbroad for AMD. Only
> SEV-ES traps RDMSR if I'm understandig that maze correctly.
Ya, regular SEV doesn't encrypt register state.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 16:56 ` Sean Christopherson
@ 2023-05-30 19:51 ` Thomas Gleixner
2023-05-30 20:03 ` Tom Lendacky
0 siblings, 1 reply; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 19:51 UTC (permalink / raw)
To: Sean Christopherson
Cc: Kirill A. Shutemov, Tom Lendacky, LKML, x86, David Woodhouse,
Andrew Cooper, Brian Gerst, Arjan van de Veen, Paolo Bonzini,
Paul McKenney, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30 2023 at 09:56, Sean Christopherson wrote:
> On Tue, May 30, 2023, Thomas Gleixner wrote:
>> On Tue, May 30 2023 at 15:29, Kirill A. Shutemov wrote:
>> > On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
>> >> The decision to allow parallel bringup of secondary CPUs checks
>> >> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
>> >> parallel bootup because accessing the local APIC is intercepted and raises
>> >> a #VC or #VE, which cannot be handled at that point.
>> >>
>> >> The check works correctly, but only for AMD encrypted guests. TDX does not
>> >> set that flag.
>> >>
>> >> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
>> >> definitely works for both AMD and Intel.
>> >
>> > It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
>> > report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
>> > we want it.
>>
>> Right. Did not think about that.
>>
>> But the same way is CC_ATTR_GUEST_MEM_ENCRYPT overbroad for AMD. Only
>> SEV-ES traps RDMSR if I'm understandig that maze correctly.
>
> Ya, regular SEV doesn't encrypt register state.
That aside. From a semantical POV making this decision about parallel
bootup based on some magic CC encryption attribute is questionable.
I'm tending to just do the below and make this CC agnostic (except that
I couldn't find the right spot for SEV-ES to clear that flag.)
Thanks,
tglx
---
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -871,5 +871,7 @@ void __init tdx_early_init(void)
x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required;
x86_platform.guest.enc_status_change_finish = tdx_enc_status_changed;
+ x86_cpuinit.parallel_bringup = false;
+
pr_info("Guest detected\n");
}
--- a/arch/x86/include/asm/x86_init.h
+++ b/arch/x86/include/asm/x86_init.h
@@ -2,6 +2,7 @@
#ifndef _ASM_X86_PLATFORM_H
#define _ASM_X86_PLATFORM_H
+#include <linux/bits.h>
#include <asm/bootparam.h>
struct ghcb;
@@ -177,11 +178,14 @@ struct x86_init_ops {
* struct x86_cpuinit_ops - platform specific cpu hotplug setups
* @setup_percpu_clockev: set up the per cpu clock event device
* @early_percpu_clock_init: early init of the per cpu clock event device
+ * @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id
+ * @parallel_bringup: Parallel bringup control
*/
struct x86_cpuinit_ops {
void (*setup_percpu_clockev)(void);
void (*early_percpu_clock_init)(void);
void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
+ bool parallel_bringup;
};
struct timespec64;
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1287,6 +1287,11 @@ bool __init arch_cpuhp_init_parallel_bri
return false;
}
+ if (!x86_cpuinit.parallel_bringup) {
+ pr_info("Parallel CPU startup disabled by the platform\n");
+ return false;
+ }
+
smpboot_control = STARTUP_READ_APICID;
pr_debug("Parallel CPU startup enabled: 0x%08x\n", smpboot_control);
return true;
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -126,6 +126,7 @@ struct x86_init_ops x86_init __initdata
struct x86_cpuinit_ops x86_cpuinit = {
.early_percpu_clock_init = x86_init_noop,
.setup_percpu_clockev = setup_secondary_APIC_clock,
+ .parallel_bringup = true,
};
static void default_nmi_init(void) { };
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 19:51 ` Thomas Gleixner
@ 2023-05-30 20:03 ` Tom Lendacky
2023-05-30 20:39 ` Thomas Gleixner
0 siblings, 1 reply; 29+ messages in thread
From: Tom Lendacky @ 2023-05-30 20:03 UTC (permalink / raw)
To: Thomas Gleixner, Sean Christopherson
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Andrew Cooper,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Oleksandr Natalenko, Paul Menzel, Guilherme G. Piccoli,
Piotr Gorski, Usama Arif, Juergen Gross, Boris Ostrovsky,
xen-devel, Russell King, Arnd Bergmann, linux-arm-kernel,
Catalin Marinas, Will Deacon, Guo Ren, linux-csky,
Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On 5/30/23 14:51, Thomas Gleixner wrote:
> On Tue, May 30 2023 at 09:56, Sean Christopherson wrote:
>> On Tue, May 30, 2023, Thomas Gleixner wrote:
>>> On Tue, May 30 2023 at 15:29, Kirill A. Shutemov wrote:
>>>> On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
>>>>> The decision to allow parallel bringup of secondary CPUs checks
>>>>> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
>>>>> parallel bootup because accessing the local APIC is intercepted and raises
>>>>> a #VC or #VE, which cannot be handled at that point.
>>>>>
>>>>> The check works correctly, but only for AMD encrypted guests. TDX does not
>>>>> set that flag.
>>>>>
>>>>> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
>>>>> definitely works for both AMD and Intel.
>>>>
>>>> It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
>>>> report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
>>>> we want it.
>>>
>>> Right. Did not think about that.
>>>
>>> But the same way is CC_ATTR_GUEST_MEM_ENCRYPT overbroad for AMD. Only
>>> SEV-ES traps RDMSR if I'm understandig that maze correctly.
>>
>> Ya, regular SEV doesn't encrypt register state.
>
> That aside. From a semantical POV making this decision about parallel
> bootup based on some magic CC encryption attribute is questionable.
>
> I'm tending to just do the below and make this CC agnostic (except that
> I couldn't find the right spot for SEV-ES to clear that flag.)
Maybe in sme_sev_setup_real_mode() in arch/x86/realmode/init.c? You could
clear the flag within the CC_ATTR_GUEST_STATE_ENCRYPT check.
Thanks,
Tom
>
> Thanks,
>
> tglx
> ---
> --- a/arch/x86/coco/tdx/tdx.c
> +++ b/arch/x86/coco/tdx/tdx.c
> @@ -871,5 +871,7 @@ void __init tdx_early_init(void)
> x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required;
> x86_platform.guest.enc_status_change_finish = tdx_enc_status_changed;
>
> + x86_cpuinit.parallel_bringup = false;
> +
> pr_info("Guest detected\n");
> }
> --- a/arch/x86/include/asm/x86_init.h
> +++ b/arch/x86/include/asm/x86_init.h
> @@ -2,6 +2,7 @@
> #ifndef _ASM_X86_PLATFORM_H
> #define _ASM_X86_PLATFORM_H
>
> +#include <linux/bits.h>
> #include <asm/bootparam.h>
>
> struct ghcb;
> @@ -177,11 +178,14 @@ struct x86_init_ops {
> * struct x86_cpuinit_ops - platform specific cpu hotplug setups
> * @setup_percpu_clockev: set up the per cpu clock event device
> * @early_percpu_clock_init: early init of the per cpu clock event device
> + * @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id
> + * @parallel_bringup: Parallel bringup control
> */
> struct x86_cpuinit_ops {
> void (*setup_percpu_clockev)(void);
> void (*early_percpu_clock_init)(void);
> void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
> + bool parallel_bringup;
> };
>
> struct timespec64;
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -1287,6 +1287,11 @@ bool __init arch_cpuhp_init_parallel_bri
> return false;
> }
>
> + if (!x86_cpuinit.parallel_bringup) {
> + pr_info("Parallel CPU startup disabled by the platform\n");
> + return false;
> + }
> +
> smpboot_control = STARTUP_READ_APICID;
> pr_debug("Parallel CPU startup enabled: 0x%08x\n", smpboot_control);
> return true;
> --- a/arch/x86/kernel/x86_init.c
> +++ b/arch/x86/kernel/x86_init.c
> @@ -126,6 +126,7 @@ struct x86_init_ops x86_init __initdata
> struct x86_cpuinit_ops x86_cpuinit = {
> .early_percpu_clock_init = x86_init_noop,
> .setup_percpu_clockev = setup_secondary_APIC_clock,
> + .parallel_bringup = true,
> };
>
> static void default_nmi_init(void) { };
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 20:03 ` Tom Lendacky
@ 2023-05-30 20:39 ` Thomas Gleixner
2023-05-30 21:13 ` Tom Lendacky
0 siblings, 1 reply; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 20:39 UTC (permalink / raw)
To: Tom Lendacky, Sean Christopherson
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Andrew Cooper,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Oleksandr Natalenko, Paul Menzel, Guilherme G. Piccoli,
Piotr Gorski, Usama Arif, Juergen Gross, Boris Ostrovsky,
xen-devel, Russell King, Arnd Bergmann, linux-arm-kernel,
Catalin Marinas, Will Deacon, Guo Ren, linux-csky,
Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30 2023 at 15:03, Tom Lendacky wrote:
> On 5/30/23 14:51, Thomas Gleixner wrote:
>> That aside. From a semantical POV making this decision about parallel
>> bootup based on some magic CC encryption attribute is questionable.
>>
>> I'm tending to just do the below and make this CC agnostic (except that
>> I couldn't find the right spot for SEV-ES to clear that flag.)
>
> Maybe in sme_sev_setup_real_mode() in arch/x86/realmode/init.c? You could
> clear the flag within the CC_ATTR_GUEST_STATE_ENCRYPT check.
Eeew.
Can we please have a AMD SEV-ES init specific place and not hijack some
random code which has to check CC_ATTR_GUEST_STATE_ENCRYPT?
Thanks,
tglx
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 20:39 ` Thomas Gleixner
@ 2023-05-30 21:13 ` Tom Lendacky
2023-05-31 7:44 ` [patch] x86/smpboot: Fix the parallel bringup decision Thomas Gleixner
0 siblings, 1 reply; 29+ messages in thread
From: Tom Lendacky @ 2023-05-30 21:13 UTC (permalink / raw)
To: Thomas Gleixner, Sean Christopherson
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Andrew Cooper,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Oleksandr Natalenko, Paul Menzel, Guilherme G. Piccoli,
Piotr Gorski, Usama Arif, Juergen Gross, Boris Ostrovsky,
xen-devel, Russell King, Arnd Bergmann, linux-arm-kernel,
Catalin Marinas, Will Deacon, Guo Ren, linux-csky,
Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On 5/30/23 15:39, Thomas Gleixner wrote:
> On Tue, May 30 2023 at 15:03, Tom Lendacky wrote:
>> On 5/30/23 14:51, Thomas Gleixner wrote:
>>> That aside. From a semantical POV making this decision about parallel
>>> bootup based on some magic CC encryption attribute is questionable.
>>>
>>> I'm tending to just do the below and make this CC agnostic (except that
>>> I couldn't find the right spot for SEV-ES to clear that flag.)
>>
>> Maybe in sme_sev_setup_real_mode() in arch/x86/realmode/init.c? You could
>> clear the flag within the CC_ATTR_GUEST_STATE_ENCRYPT check.
>
> Eeew.
>
> Can we please have a AMD SEV-ES init specific place and not hijack some
> random code which has to check CC_ATTR_GUEST_STATE_ENCRYPT?
As long as it's not too early, you could try sme_early_init() in
arch/x86/mm/mem_encrypt_amd.c. Add a check for sev_status &
MSR_AMD64_SEV_ES_ENABLED and clear the flag.
Thanks,
Tom
>
> Thanks,
>
> tglx
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* [patch] x86/smpboot: Fix the parallel bringup decision
2023-05-30 21:13 ` Tom Lendacky
@ 2023-05-31 7:44 ` Thomas Gleixner
2023-05-31 11:07 ` Kirill A. Shutemov
2023-05-31 13:58 ` Tom Lendacky
0 siblings, 2 replies; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-31 7:44 UTC (permalink / raw)
To: Tom Lendacky, Sean Christopherson
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Andrew Cooper,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Oleksandr Natalenko, Paul Menzel, Guilherme G. Piccoli,
Piotr Gorski, Usama Arif, Juergen Gross, Boris Ostrovsky,
xen-devel, Russell King, Arnd Bergmann, linux-arm-kernel,
Catalin Marinas, Will Deacon, Guo Ren, linux-csky,
Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
The decision to allow parallel bringup of secondary CPUs checks
CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
parallel bootup because accessing the local APIC is intercepted and raises
a #VC or #VE, which cannot be handled at that point.
The check works correctly, but only for AMD encrypted guests. TDX does not
set that flag.
As there is no real connection between CC attributes and the inability to
support parallel bringup, replace this with a generic control flag in
x86_cpuinit and let SEV-ES and TDX init code disable it.
Fixes: 0c7ffa32dbd6 ("x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it")
Reported-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/coco/tdx/tdx.c | 11 +++++++++++
arch/x86/include/asm/x86_init.h | 3 +++
arch/x86/kernel/smpboot.c | 19 ++-----------------
arch/x86/kernel/x86_init.c | 1 +
arch/x86/mm/mem_encrypt_amd.c | 15 +++++++++++++++
5 files changed, 32 insertions(+), 17 deletions(-)
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -871,5 +871,16 @@ void __init tdx_early_init(void)
x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required;
x86_platform.guest.enc_status_change_finish = tdx_enc_status_changed;
+ /*
+ * TDX intercepts the RDMSR to read the X2APIC ID in the parallel
+ * bringup low level code. That raises #VE which cannot be handled
+ * there.
+ *
+ * Intel-TDX has a secure RDMSR hypercall, but that needs to be
+ * implemented seperately in the low level startup ASM code.
+ * Until that is in place, disable parallel bringup for TDX.
+ */
+ x86_cpuinit.parallel_bringup = false;
+
pr_info("Guest detected\n");
}
--- a/arch/x86/include/asm/x86_init.h
+++ b/arch/x86/include/asm/x86_init.h
@@ -177,11 +177,14 @@ struct x86_init_ops {
* struct x86_cpuinit_ops - platform specific cpu hotplug setups
* @setup_percpu_clockev: set up the per cpu clock event device
* @early_percpu_clock_init: early init of the per cpu clock event device
+ * @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id
+ * @parallel_bringup: Parallel bringup control
*/
struct x86_cpuinit_ops {
void (*setup_percpu_clockev)(void);
void (*early_percpu_clock_init)(void);
void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
+ bool parallel_bringup;
};
struct timespec64;
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1267,23 +1267,8 @@ void __init smp_prepare_cpus_common(void
/* Establish whether parallel bringup can be supported. */
bool __init arch_cpuhp_init_parallel_bringup(void)
{
- /*
- * Encrypted guests require special handling. They enforce X2APIC
- * mode but the RDMSR to read the APIC ID is intercepted and raises
- * #VC or #VE which cannot be handled in the early startup code.
- *
- * AMD-SEV does not provide a RDMSR GHCB protocol so the early
- * startup code cannot directly communicate with the secure
- * firmware. The alternative solution to retrieve the APIC ID via
- * CPUID(0xb), which is covered by the GHCB protocol, is not viable
- * either because there is no enforcement of the CPUID(0xb)
- * provided "initial" APIC ID to be the same as the real APIC ID.
- *
- * Intel-TDX has a secure RDMSR hypercall, but that needs to be
- * implemented seperately in the low level startup ASM code.
- */
- if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) {
- pr_info("Parallel CPU startup disabled due to guest state encryption\n");
+ if (!x86_cpuinit.parallel_bringup) {
+ pr_info("Parallel CPU startup disabled by the platform\n");
return false;
}
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -126,6 +126,7 @@ struct x86_init_ops x86_init __initdata
struct x86_cpuinit_ops x86_cpuinit = {
.early_percpu_clock_init = x86_init_noop,
.setup_percpu_clockev = setup_secondary_APIC_clock,
+ .parallel_bringup = true,
};
static void default_nmi_init(void) { };
--- a/arch/x86/mm/mem_encrypt_amd.c
+++ b/arch/x86/mm/mem_encrypt_amd.c
@@ -501,6 +501,21 @@ void __init sme_early_init(void)
x86_platform.guest.enc_status_change_finish = amd_enc_status_change_finish;
x86_platform.guest.enc_tlb_flush_required = amd_enc_tlb_flush_required;
x86_platform.guest.enc_cache_flush_required = amd_enc_cache_flush_required;
+
+ /*
+ * AMD-SEV-ES intercepts the RDMSR to read the X2APIC ID in the
+ * parallel bringup low level code. That raises #VC which cannot be
+ * handled there.
+ * It does not provide a RDMSR GHCB protocol so the early startup
+ * code cannot directly communicate with the secure firmware. The
+ * alternative solution to retrieve the APIC ID via CPUID(0xb),
+ * which is covered by the GHCB protocol, is not viable either
+ * because there is no enforcement of the CPUID(0xb) provided
+ * "initial" APIC ID to be the same as the real APIC ID.
+ * Disable parallel bootup.
+ */
+ if (sev_status & MSR_AMD64_SEV_ES_ENABLED)
+ x86_cpuinit.parallel_bringup = false;
}
void __init mem_encrypt_free_decrypted_mem(void)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Fix the parallel bringup decision
2023-05-31 7:44 ` [patch] x86/smpboot: Fix the parallel bringup decision Thomas Gleixner
@ 2023-05-31 11:07 ` Kirill A. Shutemov
2023-05-31 13:58 ` Tom Lendacky
1 sibling, 0 replies; 29+ messages in thread
From: Kirill A. Shutemov @ 2023-05-31 11:07 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Tom Lendacky, Sean Christopherson, LKML, x86, David Woodhouse,
Andrew Cooper, Brian Gerst, Arjan van de Veen, Paolo Bonzini,
Paul McKenney, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Wed, May 31, 2023 at 09:44:26AM +0200, Thomas Gleixner wrote:
> The decision to allow parallel bringup of secondary CPUs checks
> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
> parallel bootup because accessing the local APIC is intercepted and raises
> a #VC or #VE, which cannot be handled at that point.
>
> The check works correctly, but only for AMD encrypted guests. TDX does not
> set that flag.
>
> As there is no real connection between CC attributes and the inability to
> support parallel bringup, replace this with a generic control flag in
> x86_cpuinit and let SEV-ES and TDX init code disable it.
>
> Fixes: 0c7ffa32dbd6 ("x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it")
> Reported-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
--
Kiryl Shutsemau / Kirill A. Shutemov
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/smpboot: Fix the parallel bringup decision
2023-05-31 7:44 ` [patch] x86/smpboot: Fix the parallel bringup decision Thomas Gleixner
2023-05-31 11:07 ` Kirill A. Shutemov
@ 2023-05-31 13:58 ` Tom Lendacky
1 sibling, 0 replies; 29+ messages in thread
From: Tom Lendacky @ 2023-05-31 13:58 UTC (permalink / raw)
To: Thomas Gleixner, Sean Christopherson
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Andrew Cooper,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Oleksandr Natalenko, Paul Menzel, Guilherme G. Piccoli,
Piotr Gorski, Usama Arif, Juergen Gross, Boris Ostrovsky,
xen-devel, Russell King, Arnd Bergmann, linux-arm-kernel,
Catalin Marinas, Will Deacon, Guo Ren, linux-csky,
Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On 5/31/23 02:44, Thomas Gleixner wrote:
> The decision to allow parallel bringup of secondary CPUs checks
> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
> parallel bootup because accessing the local APIC is intercepted and raises
> a #VC or #VE, which cannot be handled at that point.
>
> The check works correctly, but only for AMD encrypted guests. TDX does not
> set that flag.
>
> As there is no real connection between CC attributes and the inability to
> support parallel bringup, replace this with a generic control flag in
> x86_cpuinit and let SEV-ES and TDX init code disable it.
>
> Fixes: 0c7ffa32dbd6 ("x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it")
> Reported-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Still works for SEV-ES/SEV-SNP with parallel boot properly disabled.
Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> arch/x86/coco/tdx/tdx.c | 11 +++++++++++
> arch/x86/include/asm/x86_init.h | 3 +++
> arch/x86/kernel/smpboot.c | 19 ++-----------------
> arch/x86/kernel/x86_init.c | 1 +
> arch/x86/mm/mem_encrypt_amd.c | 15 +++++++++++++++
> 5 files changed, 32 insertions(+), 17 deletions(-)
>
> --- a/arch/x86/coco/tdx/tdx.c
> +++ b/arch/x86/coco/tdx/tdx.c
> @@ -871,5 +871,16 @@ void __init tdx_early_init(void)
> x86_platform.guest.enc_tlb_flush_required = tdx_tlb_flush_required;
> x86_platform.guest.enc_status_change_finish = tdx_enc_status_changed;
>
> + /*
> + * TDX intercepts the RDMSR to read the X2APIC ID in the parallel
> + * bringup low level code. That raises #VE which cannot be handled
> + * there.
> + *
> + * Intel-TDX has a secure RDMSR hypercall, but that needs to be
> + * implemented seperately in the low level startup ASM code.
> + * Until that is in place, disable parallel bringup for TDX.
> + */
> + x86_cpuinit.parallel_bringup = false;
> +
> pr_info("Guest detected\n");
> }
> --- a/arch/x86/include/asm/x86_init.h
> +++ b/arch/x86/include/asm/x86_init.h
> @@ -177,11 +177,14 @@ struct x86_init_ops {
> * struct x86_cpuinit_ops - platform specific cpu hotplug setups
> * @setup_percpu_clockev: set up the per cpu clock event device
> * @early_percpu_clock_init: early init of the per cpu clock event device
> + * @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id
> + * @parallel_bringup: Parallel bringup control
> */
> struct x86_cpuinit_ops {
> void (*setup_percpu_clockev)(void);
> void (*early_percpu_clock_init)(void);
> void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
> + bool parallel_bringup;
> };
>
> struct timespec64;
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -1267,23 +1267,8 @@ void __init smp_prepare_cpus_common(void
> /* Establish whether parallel bringup can be supported. */
> bool __init arch_cpuhp_init_parallel_bringup(void)
> {
> - /*
> - * Encrypted guests require special handling. They enforce X2APIC
> - * mode but the RDMSR to read the APIC ID is intercepted and raises
> - * #VC or #VE which cannot be handled in the early startup code.
> - *
> - * AMD-SEV does not provide a RDMSR GHCB protocol so the early
> - * startup code cannot directly communicate with the secure
> - * firmware. The alternative solution to retrieve the APIC ID via
> - * CPUID(0xb), which is covered by the GHCB protocol, is not viable
> - * either because there is no enforcement of the CPUID(0xb)
> - * provided "initial" APIC ID to be the same as the real APIC ID.
> - *
> - * Intel-TDX has a secure RDMSR hypercall, but that needs to be
> - * implemented seperately in the low level startup ASM code.
> - */
> - if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) {
> - pr_info("Parallel CPU startup disabled due to guest state encryption\n");
> + if (!x86_cpuinit.parallel_bringup) {
> + pr_info("Parallel CPU startup disabled by the platform\n");
> return false;
> }
>
> --- a/arch/x86/kernel/x86_init.c
> +++ b/arch/x86/kernel/x86_init.c
> @@ -126,6 +126,7 @@ struct x86_init_ops x86_init __initdata
> struct x86_cpuinit_ops x86_cpuinit = {
> .early_percpu_clock_init = x86_init_noop,
> .setup_percpu_clockev = setup_secondary_APIC_clock,
> + .parallel_bringup = true,
> };
>
> static void default_nmi_init(void) { };
> --- a/arch/x86/mm/mem_encrypt_amd.c
> +++ b/arch/x86/mm/mem_encrypt_amd.c
> @@ -501,6 +501,21 @@ void __init sme_early_init(void)
> x86_platform.guest.enc_status_change_finish = amd_enc_status_change_finish;
> x86_platform.guest.enc_tlb_flush_required = amd_enc_tlb_flush_required;
> x86_platform.guest.enc_cache_flush_required = amd_enc_cache_flush_required;
> +
> + /*
> + * AMD-SEV-ES intercepts the RDMSR to read the X2APIC ID in the
> + * parallel bringup low level code. That raises #VC which cannot be
> + * handled there.
> + * It does not provide a RDMSR GHCB protocol so the early startup
> + * code cannot directly communicate with the secure firmware. The
> + * alternative solution to retrieve the APIC ID via CPUID(0xb),
> + * which is covered by the GHCB protocol, is not viable either
> + * because there is no enforcement of the CPUID(0xb) provided
> + * "initial" APIC ID to be the same as the real APIC ID.
> + * Disable parallel bootup.
> + */
> + if (sev_status & MSR_AMD64_SEV_ES_ENABLED)
> + x86_cpuinit.parallel_bringup = false;
> }
>
> void __init mem_encrypt_free_decrypted_mem(void)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 16:00 ` Thomas Gleixner
2023-05-30 16:56 ` Sean Christopherson
@ 2023-05-30 17:02 ` Kirill A. Shutemov
2023-05-30 17:31 ` Sean Christopherson
1 sibling, 1 reply; 29+ messages in thread
From: Kirill A. Shutemov @ 2023-05-30 17:02 UTC (permalink / raw)
To: Thomas Gleixner, Tom Lendacky
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30, 2023 at 06:00:46PM +0200, Thomas Gleixner wrote:
> On Tue, May 30 2023 at 15:29, Kirill A. Shutemov wrote:
> > On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
> >> The decision to allow parallel bringup of secondary CPUs checks
> >> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
> >> parallel bootup because accessing the local APIC is intercepted and raises
> >> a #VC or #VE, which cannot be handled at that point.
> >>
> >> The check works correctly, but only for AMD encrypted guests. TDX does not
> >> set that flag.
> >>
> >> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
> >> definitely works for both AMD and Intel.
> >
> > It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
> > report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
> > we want it.
>
> Right. Did not think about that.
>
> But the same way is CC_ATTR_GUEST_MEM_ENCRYPT overbroad for AMD. Only
> SEV-ES traps RDMSR if I'm understandig that maze correctly.
I don't know difference between SEV flavours that well.
I see there's that on SEV-SNP access to x2APIC MSR range (MSR 0x800-0x8FF)
is intercepted regardless if MSR_AMD64_SNP_ALT_INJ feature is present. But
I'm not sure what the state on SEV or SEV-ES.
Tom?
--
Kiryl Shutsemau / Kirill A. Shutemov
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE
2023-05-30 17:02 ` [patch] x86/smpboot: Disable parallel bootup if cc_vendor != NONE Kirill A. Shutemov
@ 2023-05-30 17:31 ` Sean Christopherson
0 siblings, 0 replies; 29+ messages in thread
From: Sean Christopherson @ 2023-05-30 17:31 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: Thomas Gleixner, Tom Lendacky, LKML, x86, David Woodhouse,
Andrew Cooper, Brian Gerst, Arjan van de Veen, Paolo Bonzini,
Paul McKenney, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30, 2023, Kirill A. Shutemov wrote:
> On Tue, May 30, 2023 at 06:00:46PM +0200, Thomas Gleixner wrote:
> > On Tue, May 30 2023 at 15:29, Kirill A. Shutemov wrote:
> > > On Tue, May 30, 2023 at 02:09:17PM +0200, Thomas Gleixner wrote:
> > >> The decision to allow parallel bringup of secondary CPUs checks
> > >> CC_ATTR_GUEST_STATE_ENCRYPT to detect encrypted guests. Those cannot use
> > >> parallel bootup because accessing the local APIC is intercepted and raises
> > >> a #VC or #VE, which cannot be handled at that point.
> > >>
> > >> The check works correctly, but only for AMD encrypted guests. TDX does not
> > >> set that flag.
> > >>
> > >> Check for cc_vendor != CC_VENDOR_NONE instead. That might be overbroad, but
> > >> definitely works for both AMD and Intel.
> > >
> > > It boots fine with TDX, but I think it is wrong. cc_get_vendor() will
> > > report CC_VENDOR_AMD even on bare metal if SME is enabled. I don't think
> > > we want it.
> >
> > Right. Did not think about that.
> >
> > But the same way is CC_ATTR_GUEST_MEM_ENCRYPT overbroad for AMD. Only
> > SEV-ES traps RDMSR if I'm understandig that maze correctly.
>
> I don't know difference between SEV flavours that well.
>
> I see there's that on SEV-SNP access to x2APIC MSR range (MSR 0x800-0x8FF)
> is intercepted regardless if MSR_AMD64_SNP_ALT_INJ feature is present. But
> I'm not sure what the state on SEV or SEV-ES.
With SEV-ES, if the hypervisor intercepts an MSR access, the VM-Exit is instead
morphed to a #VC (except for EFER). The guest needs to do an explicit VMGEXIT
(i.e. a hypercall) to explicitly request MSR emulation (this *can* be done in the
#VC handler, but the guest can also do VMGEXIT directly, e.g. in lieu of a RDMSR).
With regular SEV, VM-Exits aren't reflected into the guest. Register state isn't
encrypted so the hypervisor can emulate MSR accesses (and other instructions)
without needing an explicit hypercall from the guest.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask
2023-05-29 20:31 ` Kirill A. Shutemov
2023-05-30 0:54 ` Kirill A. Shutemov
@ 2023-05-30 9:26 ` Thomas Gleixner
2023-05-30 10:46 ` [patch] x86/realmode: Make stack lock work in trampoline_compat() Thomas Gleixner
2 siblings, 0 replies; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 9:26 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Mon, May 29 2023 at 23:31, Kirill A. Shutemov wrote:
> Aaand the next patch that breaks TDX boot is... <drum roll>
>
> x86/smpboot/64: Implement arch_cpuhp_init_parallel_bringup() and enable it
>
> Disabling parallel bringup helps. I didn't look closer yet. If you have
> an idea let me know.
So how does TDX end up with actual parallel bringup?
if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) {
pr_info("Parallel CPU startup disabled due to guest state encryption\n");
return false;
}
It should take that path, no?
Thanks,
tglx
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* [patch] x86/realmode: Make stack lock work in trampoline_compat()
2023-05-29 20:31 ` Kirill A. Shutemov
2023-05-30 0:54 ` Kirill A. Shutemov
2023-05-30 9:26 ` [patch v3 31/36] x86/apic: Provide cpu_primary_thread mask Thomas Gleixner
@ 2023-05-30 10:46 ` Thomas Gleixner
2023-05-30 11:12 ` Kirill A. Shutemov
2023-06-08 23:34 ` Yunhong Jiang
2 siblings, 2 replies; 29+ messages in thread
From: Thomas Gleixner @ 2023-05-30 10:46 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
The stack locking and stack assignment macro LOAD_REALMODE_ESP fails to
work when invoked from the 64bit trampoline entry point:
trampoline_start64
trampoline_compat
LOAD_REALMODE_ESP <- lock
Accessing tr_lock is only possible from 16bit mode. For the compat entry
point this needs to be pa_tr_lock so that the required relocation entry is
generated. Otherwise it locks the non-relocated address which is
aside of being wrong never cleared in secondary_startup_64() causing all
but the first CPU to get stuck on the lock.
Make the macro take an argument lock_pa which defaults to 0 and rename it
to LOCK_AND_LOAD_REALMODE_ESP to make it clear what this is about.
Fixes: f6f1ae9128d2 ("x86/smpboot: Implement a bit spinlock to protect the realmode stack")
Reported-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/realmode/rm/trampoline_64.S | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
--- a/arch/x86/realmode/rm/trampoline_64.S
+++ b/arch/x86/realmode/rm/trampoline_64.S
@@ -37,12 +37,16 @@
.text
.code16
-.macro LOAD_REALMODE_ESP
+.macro LOCK_AND_LOAD_REALMODE_ESP lock_pa=0
/*
* Make sure only one CPU fiddles with the realmode stack
*/
.Llock_rm\@:
+ .if \lock_pa
+ lock btsl $0, pa_tr_lock
+ .else
lock btsl $0, tr_lock
+ .endif
jnc 2f
pause
jmp .Llock_rm\@
@@ -63,7 +67,7 @@ SYM_CODE_START(trampoline_start)
mov %ax, %es
mov %ax, %ss
- LOAD_REALMODE_ESP
+ LOCK_AND_LOAD_REALMODE_ESP
call verify_cpu # Verify the cpu supports long mode
testl %eax, %eax # Check for return code
@@ -106,7 +110,7 @@ SYM_CODE_START(sev_es_trampoline_start)
mov %ax, %es
mov %ax, %ss
- LOAD_REALMODE_ESP
+ LOCK_AND_LOAD_REALMODE_ESP
jmp .Lswitch_to_protected
SYM_CODE_END(sev_es_trampoline_start)
@@ -189,7 +193,7 @@ SYM_CODE_START(pa_trampoline_compat)
* In compatibility mode. Prep ESP and DX for startup_32, then disable
* paging and complete the switch to legacy 32-bit mode.
*/
- LOAD_REALMODE_ESP
+ LOCK_AND_LOAD_REALMODE_ESP lock_pa=1
movw $__KERNEL_DS, %dx
movl $(CR0_STATE & ~X86_CR0_PG), %eax
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/realmode: Make stack lock work in trampoline_compat()
2023-05-30 10:46 ` [patch] x86/realmode: Make stack lock work in trampoline_compat() Thomas Gleixner
@ 2023-05-30 11:12 ` Kirill A. Shutemov
2023-06-08 23:34 ` Yunhong Jiang
1 sibling, 0 replies; 29+ messages in thread
From: Kirill A. Shutemov @ 2023-05-30 11:12 UTC (permalink / raw)
To: Thomas Gleixner
Cc: LKML, x86, David Woodhouse, Andrew Cooper, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On Tue, May 30, 2023 at 12:46:22PM +0200, Thomas Gleixner wrote:
> The stack locking and stack assignment macro LOAD_REALMODE_ESP fails to
> work when invoked from the 64bit trampoline entry point:
>
> trampoline_start64
> trampoline_compat
> LOAD_REALMODE_ESP <- lock
>
> Accessing tr_lock is only possible from 16bit mode. For the compat entry
> point this needs to be pa_tr_lock so that the required relocation entry is
> generated. Otherwise it locks the non-relocated address which is
> aside of being wrong never cleared in secondary_startup_64() causing all
> but the first CPU to get stuck on the lock.
>
> Make the macro take an argument lock_pa which defaults to 0 and rename it
> to LOCK_AND_LOAD_REALMODE_ESP to make it clear what this is about.
>
> Fixes: f6f1ae9128d2 ("x86/smpboot: Implement a bit spinlock to protect the realmode stack")
> Reported-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
--
Kiryl Shutsemau / Kirill A. Shutemov
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread* Re: [patch] x86/realmode: Make stack lock work in trampoline_compat()
2023-05-30 10:46 ` [patch] x86/realmode: Make stack lock work in trampoline_compat() Thomas Gleixner
2023-05-30 11:12 ` Kirill A. Shutemov
@ 2023-06-08 23:34 ` Yunhong Jiang
2023-06-08 23:57 ` Andrew Cooper
1 sibling, 1 reply; 29+ messages in thread
From: Yunhong Jiang @ 2023-06-08 23:34 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Andrew Cooper,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Tom Lendacky, Sean Christopherson, Oleksandr Natalenko,
Paul Menzel, Guilherme G. Piccoli, Piotr Gorski, Usama Arif,
Juergen Gross, Boris Ostrovsky, xen-devel, Russell King,
Arnd Bergmann, linux-arm-kernel, Catalin Marinas, Will Deacon,
Guo Ren, linux-csky, Thomas Bogendoerfer, linux-mips,
James E.J. Bottomley, Helge Deller, linux-parisc, Paul Walmsley,
Palmer Dabbelt, linux-riscv, Mark Rutland, Sabin Rapan,
Michael Kelley (LINUX), Dave Hansen
On Tue, May 30, 2023 at 12:46:22PM +0200, Thomas Gleixner wrote:
> The stack locking and stack assignment macro LOAD_REALMODE_ESP fails to
> work when invoked from the 64bit trampoline entry point:
>
> trampoline_start64
> trampoline_compat
> LOAD_REALMODE_ESP <- lock
One possibly dumb question and hope get some hints. The LOAD_REALMODE_ESP is
defined under .code16 directive and will be used by 32-bit mode caller also. Is
it ok because the instructions there will be same for both 16-bit and 32-bit? I
checked
https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_16.html#SEC205 and
don't find much information there.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch] x86/realmode: Make stack lock work in trampoline_compat()
2023-06-08 23:34 ` Yunhong Jiang
@ 2023-06-08 23:57 ` Andrew Cooper
2023-06-09 0:22 ` Yunhong Jiang
0 siblings, 1 reply; 29+ messages in thread
From: Andrew Cooper @ 2023-06-08 23:57 UTC (permalink / raw)
To: Yunhong Jiang, Thomas Gleixner
Cc: Kirill A. Shutemov, LKML, x86, David Woodhouse, Brian Gerst,
Arjan van de Veen, Paolo Bonzini, Paul McKenney, Tom Lendacky,
Sean Christopherson, Oleksandr Natalenko, Paul Menzel,
Guilherme G. Piccoli, Piotr Gorski, Usama Arif, Juergen Gross,
Boris Ostrovsky, xen-devel, Russell King, Arnd Bergmann,
linux-arm-kernel, Catalin Marinas, Will Deacon, Guo Ren,
linux-csky, Thomas Bogendoerfer, linux-mips, James E.J. Bottomley,
Helge Deller, linux-parisc, Paul Walmsley, Palmer Dabbelt,
linux-riscv, Mark Rutland, Sabin Rapan, Michael Kelley (LINUX),
Dave Hansen
On 09/06/2023 12:34 am, Yunhong Jiang wrote:
> On Tue, May 30, 2023 at 12:46:22PM +0200, Thomas Gleixner wrote:
>> The stack locking and stack assignment macro LOAD_REALMODE_ESP fails to
>> work when invoked from the 64bit trampoline entry point:
>>
>> trampoline_start64
>> trampoline_compat
>> LOAD_REALMODE_ESP <- lock
> One possibly dumb question and hope get some hints.
There's a phrase. "The only dumb question is the one not asked".
If you have this question, there's an excellent chance that someone else
reading this thread has the same question.
> The LOAD_REALMODE_ESP is
> defined under .code16 directive and will be used by 32-bit mode caller also. Is
> it ok because the instructions there will be same for both 16-bit and 32-bit? I
> checked
> https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_16.html#SEC205 and
> don't find much information there.
The position of the LOAD_REALMODE_ESP .macro itself doesn't matter.
It's just some text which gets pasted elsewhere. Imagine it just the
same as running the C preprocessor on a file before compiling it.
As you note, some expansions of the macro are in .code16, and some are
not. This does result in different bytes being emitted. The default
operands size flips between .code16 and .code32, so there will be some
0x66 prefixes in one mode, and not in others.
The important point is the l suffix on btsl, which forces it to be long
(32bit) irrespective of the default operand size.
So yes, it will work, but that's because gas is handling the differing
encodings automatically based on the default operand size where the
LOAD_REALMODE_ESP gets expanded.
Hope this helps,
~Andrew
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [patch] x86/realmode: Make stack lock work in trampoline_compat()
2023-06-08 23:57 ` Andrew Cooper
@ 2023-06-09 0:22 ` Yunhong Jiang
0 siblings, 0 replies; 29+ messages in thread
From: Yunhong Jiang @ 2023-06-09 0:22 UTC (permalink / raw)
To: Andrew Cooper
Cc: Thomas Gleixner, Kirill A. Shutemov, LKML, x86, David Woodhouse,
Brian Gerst, Arjan van de Veen, Paolo Bonzini, Paul McKenney,
Tom Lendacky, Sean Christopherson, Oleksandr Natalenko,
Paul Menzel, Guilherme G. Piccoli, Piotr Gorski, Usama Arif,
Juergen Gross, Boris Ostrovsky, xen-devel, Russell King,
Arnd Bergmann, linux-arm-kernel, Catalin Marinas, Will Deacon,
Guo Ren, linux-csky, Thomas Bogendoerfer, linux-mips,
James E.J. Bottomley, Helge Deller, linux-parisc, Paul Walmsley,
Palmer Dabbelt, linux-riscv, Mark Rutland, Sabin Rapan,
Michael Kelley (LINUX), Dave Hansen
On Fri, Jun 09, 2023 at 12:57:46AM +0100, Andrew Cooper wrote:
> On 09/06/2023 12:34 am, Yunhong Jiang wrote:
> > On Tue, May 30, 2023 at 12:46:22PM +0200, Thomas Gleixner wrote:
> >> The stack locking and stack assignment macro LOAD_REALMODE_ESP fails to
> >> work when invoked from the 64bit trampoline entry point:
> >>
> >> trampoline_start64
> >> trampoline_compat
> >> LOAD_REALMODE_ESP <- lock
> > One possibly dumb question and hope get some hints.
>
> There's a phrase. "The only dumb question is the one not asked".
>
> If you have this question, there's an excellent chance that someone else
> reading this thread has the same question.
>
> > The LOAD_REALMODE_ESP is
> > defined under .code16 directive and will be used by 32-bit mode caller also. Is
> > it ok because the instructions there will be same for both 16-bit and 32-bit? I
> > checked
> > https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_16.html#SEC205 and
> > don't find much information there.
>
> The position of the LOAD_REALMODE_ESP .macro itself doesn't matter.
> It's just some text which gets pasted elsewhere. Imagine it just the
> same as running the C preprocessor on a file before compiling it.
>
> As you note, some expansions of the macro are in .code16, and some are
> not. This does result in different bytes being emitted. The default
> operands size flips between .code16 and .code32, so there will be some
> 0x66 prefixes in one mode, and not in others.
>
> The important point is the l suffix on btsl, which forces it to be long
> (32bit) irrespective of the default operand size.
>
> So yes, it will work, but that's because gas is handling the differing
> encodings automatically based on the default operand size where the
> LOAD_REALMODE_ESP gets expanded.
>
> Hope this helps,
Thank you for the explaination, it's quite clear now.
>
> ~Andrew
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 29+ messages in thread