From 1512e5a19866e850d4e192233b1d6bb4abbf9b9e Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Mon, 16 Feb 2026 20:57:02 +0000 Subject: [PATCH] x86/boot: Document the ordering dependency of _svm_cpu_up() Lets just say this took an unreasonable amount of time and effort to track down, when trying to move traps_init() earlier during boot. When the SYSCALL linkage MSRs are not configured ahead of _svm_cpu_up() on the BSP, context switch clobbers the later-set-up linkage with the 0's cached here. Amongst other problems, this causes PV guest to enter at 0 in supervisor mode on the user stack. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich (cherry picked from commit c2f15b0fff94ca71fe32792ea933fcf2a907111d) --- xen/arch/x86/hvm/svm/svm.c | 14 ++++++++++++++ xen/arch/x86/setup.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index b54f9d9af5..f1128a657d 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -1579,6 +1579,20 @@ static int _svm_cpu_up(bool bsp) /* Initialize OSVW bits to be used by guests */ svm_host_osvw_init(); + /* + * VMSAVE writes out the current full FS, GS, LDTR and TR segments, and + * the GS_SHADOW, SYSENTER and SYSCALL linkage MSRs. + * + * The segment data gets modified by the svm_load_segs() optimisation for + * PV context switches, but all values get reloaded at that point, as well + * as during context switch from SVM. + * + * If PV guests are available, it is critical that the SYSCALL linkage + * MSRs been configured at this juncture even in FRED mode. + */ + if ( IS_ENABLED(CONFIG_PV) ) + ASSERT(rdmsr(MSR_STAR) == XEN_MSR_STAR); + svm_vmsave_pa(per_cpu(host_vmcb, cpu)); return 0; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 44da5efa1d..455eac47d6 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2078,7 +2078,7 @@ void asmlinkage __init noreturn __start_xen(void) &this_cpu(stubs).mfn); BUG_ON(!this_cpu(stubs.addr)); - traps_init(); /* Needs stubs allocated. */ + traps_init(); /* Needs stubs allocated, must be before presmp_initcalls. */ cpu_init();