Skip to content

Commit 3d5bdae

Browse files
Liran Alonbonzini
authored andcommitted
KVM: nVMX: Use correct VPID02 when emulating L1 INVVPID
In case L0 didn't allocate vmx->nested.vpid02 for L2, vmcs02->vpid is set to vmx->vpid. Consider this case when emulating L1 INVVPID in L0. Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com> Reviewed-by: Mark Kanda <mark.kanda@oracle.com> Signed-off-by: Liran Alon <liran.alon@oracle.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 1438921 commit 3d5bdae

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

arch/x86/kvm/vmx.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9003,6 +9003,13 @@ static int handle_invept(struct kvm_vcpu *vcpu)
90039003
return kvm_skip_emulated_instruction(vcpu);
90049004
}
90059005

9006+
static u16 nested_get_vpid02(struct kvm_vcpu *vcpu)
9007+
{
9008+
struct vcpu_vmx *vmx = to_vmx(vcpu);
9009+
9010+
return vmx->nested.vpid02 ? vmx->nested.vpid02 : vmx->vpid;
9011+
}
9012+
90069013
static int handle_invvpid(struct kvm_vcpu *vcpu)
90079014
{
90089015
struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -9014,6 +9021,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
90149021
u64 vpid;
90159022
u64 gla;
90169023
} operand;
9024+
u16 vpid02;
90179025

90189026
if (!(vmx->nested.msrs.secondary_ctls_high &
90199027
SECONDARY_EXEC_ENABLE_VPID) ||
@@ -9053,6 +9061,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
90539061
return kvm_skip_emulated_instruction(vcpu);
90549062
}
90559063

9064+
vpid02 = nested_get_vpid02(vcpu);
90569065
switch (type) {
90579066
case VMX_VPID_EXTENT_INDIVIDUAL_ADDR:
90589067
if (!operand.vpid ||
@@ -9061,12 +9070,11 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
90619070
VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
90629071
return kvm_skip_emulated_instruction(vcpu);
90639072
}
9064-
if (cpu_has_vmx_invvpid_individual_addr() &&
9065-
vmx->nested.vpid02) {
9073+
if (cpu_has_vmx_invvpid_individual_addr()) {
90669074
__invvpid(VMX_VPID_EXTENT_INDIVIDUAL_ADDR,
9067-
vmx->nested.vpid02, operand.gla);
9075+
vpid02, operand.gla);
90689076
} else
9069-
__vmx_flush_tlb(vcpu, vmx->nested.vpid02, true);
9077+
__vmx_flush_tlb(vcpu, vpid02, true);
90709078
break;
90719079
case VMX_VPID_EXTENT_SINGLE_CONTEXT:
90729080
case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL:
@@ -9075,10 +9083,10 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
90759083
VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
90769084
return kvm_skip_emulated_instruction(vcpu);
90779085
}
9078-
__vmx_flush_tlb(vcpu, vmx->nested.vpid02, true);
9086+
__vmx_flush_tlb(vcpu, vpid02, true);
90799087
break;
90809088
case VMX_VPID_EXTENT_ALL_CONTEXT:
9081-
__vmx_flush_tlb(vcpu, vmx->nested.vpid02, true);
9089+
__vmx_flush_tlb(vcpu, vpid02, true);
90829090
break;
90839091
default:
90849092
WARN_ON_ONCE(1);

0 commit comments

Comments
 (0)