From: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx> Current IPI handler may corrupt cpu context, it's not an big issue as AP only enable interrupt in idle loop. But in TD-guest, hlt instruction is simulated though tdvmcall in #VE handler. IPI will corrupt #VE context. Save and restore cpu context in IPI handler to avoid crash. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxx> Reviewed-by: Yu Zhang <yu.c.zhang@xxxxxxxxx> Link: https://lore.kernel.org/r/20220303071907.650203-12-zhenzhong.duan@xxxxxxxxx Signed-off-by: Qian Wen <qian.wen@xxxxxxxxx> --- lib/x86/smp.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/x86/smp.c b/lib/x86/smp.c index 7147cf6b..171c5939 100644 --- a/lib/x86/smp.c +++ b/lib/x86/smp.c @@ -60,12 +60,20 @@ static __attribute__((used)) void ipi(void) asm ( "ipi_entry: \n" - " call ipi \n" -#ifndef __x86_64__ - " iret" -#else - " iretq" +#ifdef __x86_64__ + "push %r15; push %r14; push %r13; push %r12 \n\t" + "push %r11; push %r10; push %r9; push %r8 \n\t" #endif + "push %"R "di; push %"R "si; push %"R "bp; \n\t" + "push %"R "bx; push %"R "dx; push %"R "cx; push %"R "ax \n\t" + "call ipi \n\t" + "pop %"R "ax; pop %"R "cx; pop %"R "dx; pop %"R "bx \n\t" + "pop %"R "bp; pop %"R "si; pop %"R "di \n\t" +#ifdef __x86_64__ + "pop %r8; pop %r9; pop %r10; pop %r11 \n\t" + "pop %r12; pop %r13; pop %r14; pop %r15 \n\t" +#endif + "iret"W" \n\t" ); int cpu_count(void) -- 2.25.1