Skip to content

Commit 684766f

Browse files
Shuo A Liuwenlingz
authored andcommitted
hv: Save/restore MSR_IA32_CSTAR during context switch
Both Windows guest and Linux guest use the MSR MSR_IA32_CSTAR, while Linux uses it rarely. Now vcpu context switch doesn't save/restore it. Windows detects the change of the MSR and rises a exception. Do the save/resotre MSR_IA32_CSTAR during context switch. Tracked-On: #5899 Signed-off-by: Shuo A Liu <[email protected]>
1 parent 9e4fd1f commit 684766f

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ static void context_switch_out(struct thread_object *prev)
837837

838838
/* We don't flush TLB as we assume each vcpu has different vpid */
839839
ectx->ia32_star = msr_read(MSR_IA32_STAR);
840+
ectx->ia32_cstar = msr_read(MSR_IA32_CSTAR);
840841
ectx->ia32_lstar = msr_read(MSR_IA32_LSTAR);
841842
ectx->ia32_fmask = msr_read(MSR_IA32_FMASK);
842843
ectx->ia32_kernel_gs_base = msr_read(MSR_IA32_KERNEL_GS_BASE);
@@ -852,6 +853,7 @@ static void context_switch_in(struct thread_object *next)
852853
load_vmcs(vcpu);
853854

854855
msr_write(MSR_IA32_STAR, ectx->ia32_star);
856+
msr_write(MSR_IA32_CSTAR, ectx->ia32_cstar);
855857
msr_write(MSR_IA32_LSTAR, ectx->ia32_lstar);
856858
msr_write(MSR_IA32_FMASK, ectx->ia32_fmask);
857859
msr_write(MSR_IA32_KERNEL_GS_BASE, ectx->ia32_kernel_gs_base);

hypervisor/include/arch/x86/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ struct ext_context {
392392
struct segment_sel gs;
393393

394394
uint64_t ia32_star;
395+
uint64_t ia32_cstar;
395396
uint64_t ia32_lstar;
396397
uint64_t ia32_fmask;
397398
uint64_t ia32_kernel_gs_base;

0 commit comments

Comments
 (0)