Skip to content

Commit bca06b8

Browse files
sean-jcbonzini
authored andcommitted
Revert "KVM: VMX: Save HOST_CR3 in vmx_set_host_fs_gs()"
Undo a nested VMX fix as a step toward reverting the commit it fixed, 15ad976 ("KVM: VMX: Save HOST_CR3 in vmx_prepare_switch_to_guest()"), as the underlying premise that "host CR3 in the vcpu thread can only be changed when scheduling" is wrong. This reverts commit a9f2705. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e910a53 commit bca06b8

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx,
246246
src = &prev->host_state;
247247
dest = &vmx->loaded_vmcs->host_state;
248248

249-
vmx_set_vmcs_host_state(dest, src->cr3, src->fs_sel, src->gs_sel,
250-
src->fs_base, src->gs_base);
249+
vmx_set_host_fs_gs(dest, src->fs_sel, src->gs_sel, src->fs_base, src->gs_base);
251250
dest->ldt_sel = src->ldt_sel;
252251
#ifdef CONFIG_X86_64
253252
dest->ds_sel = src->ds_sel;

arch/x86/kvm/vmx/vmx.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,14 +1080,9 @@ static void pt_guest_exit(struct vcpu_vmx *vmx)
10801080
wrmsrl(MSR_IA32_RTIT_CTL, vmx->pt_desc.host.ctl);
10811081
}
10821082

1083-
void vmx_set_vmcs_host_state(struct vmcs_host_state *host, unsigned long cr3,
1084-
u16 fs_sel, u16 gs_sel,
1085-
unsigned long fs_base, unsigned long gs_base)
1083+
void vmx_set_host_fs_gs(struct vmcs_host_state *host, u16 fs_sel, u16 gs_sel,
1084+
unsigned long fs_base, unsigned long gs_base)
10861085
{
1087-
if (unlikely(cr3 != host->cr3)) {
1088-
vmcs_writel(HOST_CR3, cr3);
1089-
host->cr3 = cr3;
1090-
}
10911086
if (unlikely(fs_sel != host->fs_sel)) {
10921087
if (!(fs_sel & 7))
10931088
vmcs_write16(HOST_FS_SELECTOR, fs_sel);
@@ -1119,6 +1114,7 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
11191114
#ifdef CONFIG_X86_64
11201115
int cpu = raw_smp_processor_id();
11211116
#endif
1117+
unsigned long cr3;
11221118
unsigned long fs_base, gs_base;
11231119
u16 fs_sel, gs_sel;
11241120
int i;
@@ -1182,8 +1178,14 @@ void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
11821178
gs_base = segment_base(gs_sel);
11831179
#endif
11841180

1185-
vmx_set_vmcs_host_state(host_state, __get_current_cr3_fast(),
1186-
fs_sel, gs_sel, fs_base, gs_base);
1181+
vmx_set_host_fs_gs(host_state, fs_sel, gs_sel, fs_base, gs_base);
1182+
1183+
/* Host CR3 including its PCID is stable when guest state is loaded. */
1184+
cr3 = __get_current_cr3_fast();
1185+
if (unlikely(cr3 != host_state->cr3)) {
1186+
vmcs_writel(HOST_CR3, cr3);
1187+
host_state->cr3 = cr3;
1188+
}
11871189

11881190
vmx->guest_state_loaded = true;
11891191
}

arch/x86/kvm/vmx/vmx.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ int allocate_vpid(void);
374374
void free_vpid(int vpid);
375375
void vmx_set_constant_host_state(struct vcpu_vmx *vmx);
376376
void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu);
377-
void vmx_set_vmcs_host_state(struct vmcs_host_state *host, unsigned long cr3,
378-
u16 fs_sel, u16 gs_sel,
379-
unsigned long fs_base, unsigned long gs_base);
377+
void vmx_set_host_fs_gs(struct vmcs_host_state *host, u16 fs_sel, u16 gs_sel,
378+
unsigned long fs_base, unsigned long gs_base);
380379
int vmx_get_cpl(struct kvm_vcpu *vcpu);
381380
bool vmx_emulation_required(struct kvm_vcpu *vcpu);
382381
unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)