Skip to content

Commit 67de8f2

Browse files
author
Lai Jiangshan
committed
pvm: Switch PVCS on updating MSR_GS_BASE
Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
1 parent 1136b3b commit 67de8f2

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

arch/x86/include/asm/pvm_para.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ typedef void (*idtentry_t)(struct pt_regs *regs);
1515
void __init pvm_early_setup(void);
1616
void __init pvm_setup_early_traps(void);
1717
void __init pvm_install_sysvec(unsigned int sysvec, idtentry_t handler);
18-
void __init pvm_switch_pvcs(int cpu);
1918
void pvm_setup_event_handling(void);
2019
bool __init pvm_kernel_layout_relocate(void);
2120

@@ -81,10 +80,6 @@ static inline void pvm_install_sysvec(unsigned int sysvec, idtentry_t handler)
8180
{
8281
}
8382

84-
static inline void pvm_switch_pvcs(int cpu)
85-
{
86-
}
87-
8883
static inline void pvm_setup_event_handling(void)
8984
{
9085
}

arch/x86/kernel/cpu/common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ void __init switch_gdt_and_percpu_base(int cpu)
753753
* per CPU stack canary is 0 in both per CPU areas.
754754
*/
755755
wrmsrl(MSR_GS_BASE, cpu_kernelmode_gs_base(cpu));
756-
pvm_switch_pvcs(cpu);
757756
#else
758757
/*
759758
* %fs is already set to __KERNEL_PERCPU, but after switching GDT

arch/x86/kernel/pvm.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static unsigned long long pvm_read_msr(unsigned int msr)
118118
static int notrace pvm_write_msr_safe(unsigned int msr, u32 low, u32 high)
119119
{
120120
unsigned long base = ((u64)high << 32) | low;
121+
u64 pvcs_pa;
121122

122123
switch (msr) {
123124
case MSR_FS_BASE:
@@ -126,6 +127,18 @@ static int notrace pvm_write_msr_safe(unsigned int msr, u32 low, u32 high)
126127
case MSR_KERNEL_GS_BASE:
127128
this_cpu_write(pvm_vcpu_struct.user_gsbase, base);
128129
return 0;
130+
case MSR_GS_BASE:
131+
pvm_hypercall2(PVM_HC_WRMSR, msr, base);
132+
/*
133+
* During the boot process, the boot CPU will switch GSBASE
134+
* from the .init.data area to the runtime per-CPU area (via
135+
* the PV-awared wrmsr() and reach here), so the architectural
136+
* physical address of PVCS needs to be updated.
137+
*/
138+
pvcs_pa = slow_virt_to_phys(this_cpu_ptr(&pvm_vcpu_struct));
139+
140+
wrmsrl(MSR_PVM_VCPU_STRUCT, pvcs_pa);
141+
return 0;
129142
default:
130143
return pvm_hypercall2(PVM_HC_WRMSR, msr, base);
131144
}
@@ -493,20 +506,6 @@ void __init pvm_early_setup(void)
493506
pvm_early_patch();
494507
}
495508

496-
void __init pvm_switch_pvcs(int cpu)
497-
{
498-
/*
499-
* During the boot process, the boot CPU will switch GSBASE from the
500-
* .init.data area to the runtime per-CPU area, so we need to switch
501-
* the physical address of PVCS after that.
502-
*/
503-
if (boot_cpu_has(X86_FEATURE_KVM_PVM_GUEST) && !cpu) {
504-
u64 xpa = slow_virt_to_phys(this_cpu_ptr(&pvm_vcpu_struct));
505-
506-
wrmsrl(MSR_PVM_VCPU_STRUCT, xpa);
507-
}
508-
}
509-
510509
void pvm_setup_event_handling(void)
511510
{
512511
if (boot_cpu_has(X86_FEATURE_KVM_PVM_GUEST)) {

0 commit comments

Comments
 (0)