Skip to contentSkip to conversation

Xen vs Trenchboot: TXT AP bringup

DISCUSSION Andrew Cooper 3 participants 3 messages Oct 27, 2022 – Nov 7, 2022

lore
Share & tools
lore
#0 lore raw

Hello,

Krystian is working on the next bit of the Trenchboot project's plans, specifically getting Xen able to operate with TXT directly (i.e. without tboot in the middle).

The way TXT releases APs back to the BSP is causing some fun.  All APs release simultaneously, at a point of the BSP's choosing.  (SDM Vol2 6.2)

While the APs do release in 32bit flat unpaged mode (so much nicer than 16bit mode), it is still inherently a parallel boot, and the APIC_ID is the only sensible piece of uniquely identifying information.

The simple bodge is probably to have a variable similar to smpboot's booting_cpu, where all APs spin until they find their own APIC_ID.  This serialises the APs around the existing boot sequence.

However, we're also very close to supporting parallel boot.  The serialising point we currently have is __high_start loading %rsp from stack_start, because that's a single pointer adjusted by do_boot_cpu(). Everything else, even the processor's idea of Xen's CPU id is derived from the stack; specifically in the cpu_info block on the top of the stack, which is prepared by the BSP.

All we need to do full parallel boot is an array mapping APIC_ID -> Xen CPU index.  The AP boot path doesn't use the trampoline stack at all. Given some way of transforming APIC_ID into a Xen CPU index, the APs could pull their stack pointer straight out of the stack_bases[] array. This would allow us in the general case to boot APs using an all-but-self INIT-SIPI-SIPI.  (This is how firmware does AP bringup anyway.)

Thoughts?  In particular, is there an obvious option I've missed[1]?

~Andrew

[1] There is another way of doing this with multiple copies of the AP trampoline at different positions, where trampoline_realmode_entry() can derive the Xen CPU ID from %cs, but this is already horrible and isn't a sensible approach to consider.

#1 lore raw
Quoted 15 lines · Andrew Cooper

However, we're also very close to supporting parallel boot.  The serialising point we currently have is __high_start loading %rsp from stack_start, because that's a single pointer adjusted by do_boot_cpu(). Everything else, even the processor's idea of Xen's CPU id is derived from the stack; specifically in the cpu_info block on the top of the stack, which is prepared by the BSP.

All we need to do full parallel boot is an array mapping APIC_ID -> Xen CPU index.  The AP boot path doesn't use the trampoline stack at all. Given some way of transforming APIC_ID into a Xen CPU index, the APs could pull their stack pointer straight out of the stack_bases[] array. This would allow us in the general case to boot APs using an all-but-self INIT-SIPI-SIPI.  (This is how firmware does AP bringup anyway.)

Quoted 1 line

Thoughts?  In particular, is there an obvious option I've missed[1]?

Well, I don't see other options, but I'm not sure we're as close as you describe. I'm pretty sure we have assumptions elsewhere that multiple CPUs won't be starting in parallel. Those places will need finding and adjusting. Plus the generic CPU infrastructure also assumes things are done one by one, with (for example) cpu_up() taking a CPU number, not a CPU mask.

Jan

#2 lore raw
Quoted 18 lines · Jan Beulich' via trenchboot-devel
Quoted 15 lines · Andrew Cooper

However, we're also very close to supporting parallel boot.  The serialising point we currently have is __high_start loading %rsp from stack_start, because that's a single pointer adjusted by do_boot_cpu(). Everything else, even the processor's idea of Xen's CPU id is derived from the stack; specifically in the cpu_info block on the top of the stack, which is prepared by the BSP.

All we need to do full parallel boot is an array mapping APIC_ID -> Xen CPU index.  The AP boot path doesn't use the trampoline stack at all. Given some way of transforming APIC_ID into a Xen CPU index, the APs could pull their stack pointer straight out of the stack_bases[] array. This would allow us in the general case to boot APs using an all-but-self INIT-SIPI-SIPI.  (This is how firmware does AP bringup anyway.)

Quoted 1 line

Thoughts?  In particular, is there an obvious option I've missed[1]?

Quoted 9 lines

Well, I don't see other options, but I'm not sure we're as close as you describe. I'm pretty sure we have assumptions elsewhere that multiple CPUs won't be starting in parallel. Those places will need finding and adjusting. Plus the generic CPU infrastructure also assumes things are done one by one, with (for example) cpu_up() taking a CPU number, not a CPU mask.

Jan

For what it is worth, I can explain what I do for the Linux kernel. After SENTER transfers control to the setup kernel (the MLE), I wake all the APs up, restore their state, disable interrupts and park them (hlt) in a safe area that was setup.

Later in the SMP boot code I detect that it is a Secure Launch. This code is being called per CPU with the APIC IDs. One at a time I bypass the normal boot path (INIT-SIPI-SIPI or direct 64b) and call our SMP function. This function sends an IPI to the particular APIC in question (NMI in this case) and vectors it to the normal SMP startup code that is in the rmpiggy. From there everything else happens as it normally would and the AP jumps through the unchanged startup trampolines. There is actually not very much Secure Launch specific code in the SMP boot code. This is the one patch (well commit where the patch came from):

https://github.com/TrenchBoot/linux/commit/c81d3580bea8f0111e17ad0cdfce15149b46249f

And for anyone not familiar with the rmpiggy, it is a blob of machine code that is fixed up at runtime by the kernel proper and placed at an a location < 1M so INIT-SIPI-SIPI can vector to it in real mode.

Ross