Align RSP to a 16-byte boundary in the IPI handler for SMP function calls before calling into C code, as required by the x86-64 ABI. Failure to ensure the stack is properly aligned leads to obscure failures if a struct (or any other object) tagged with __attribute__((aligned(16))) (or any alignment greater than 16) is place on the stack. E.g. VM-Enter will fail on VMX if a vmx_msr_entry structure is placed on the stack. Signed-off-by: Sean Christopherson --- lib/x86/smp.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/x86/smp.c b/lib/x86/smp.c index 366e184c..0cd44cdc 100644 --- a/lib/x86/smp.c +++ b/lib/x86/smp.c @@ -58,12 +58,23 @@ static __attribute__((used)) void ipi(void) } asm ( - "ipi_entry: \n" - " call ipi \n" -#ifndef __x86_64__ - " iret" + "ipi_entry: \n" +#ifdef __x86_64__ + /* + * Align the stack on a 16-byte boundary (as per x86_64 ABI) before + * calling into C code. Make sure not to clobber any regs! + */ + " push %rbp\n" + " mov %rsp, %rbp\n" + " and $-0x10, %rsp\n" +#endif + " call ipi\n" +#ifdef __x86_64__ + " mov %rbp, %rsp\n" + " pop %rbp\n" + " iretq" #else - " iretq" + " iret" #endif ); -- 2.54.0.563.g4f69b47b94-goog