Skip to content

Commit 796c83c

Browse files
shvipinbonzini
authored andcommitted
KVM: Move INVPCID type check from vmx and svm to the common kvm_handle_invpcid()
Handle #GP on INVPCID due to an invalid type in the common switch statement instead of relying on the callers (VMX and SVM) to manually validate the type. Unlike INVVPID and INVEPT, INVPCID is not explicitly documented to check the type before reading the operand from memory, so deferring the type validity check until after that point is architecturally allowed. Signed-off-by: Vipin Sharma <[email protected]> Reviewed-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 329bd56 commit 796c83c

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,11 +3119,6 @@ static int invpcid_interception(struct kvm_vcpu *vcpu)
31193119
type = svm->vmcb->control.exit_info_2;
31203120
gva = svm->vmcb->control.exit_info_1;
31213121

3122-
if (type > 3) {
3123-
kvm_inject_gp(vcpu, 0);
3124-
return 1;
3125-
}
3126-
31273122
return kvm_handle_invpcid(vcpu, type, gva);
31283123
}
31293124

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5454,11 +5454,6 @@ static int handle_invpcid(struct kvm_vcpu *vcpu)
54545454
gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info);
54555455
type = kvm_register_read(vcpu, gpr_index);
54565456

5457-
if (type > 3) {
5458-
kvm_inject_gp(vcpu, 0);
5459-
return 1;
5460-
}
5461-
54625457
/* According to the Intel instruction reference, the memory operand
54635458
* is read even if it isn't needed (e.g., for type==all)
54645459
*/

arch/x86/kvm/x86.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12510,7 +12510,8 @@ int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva)
1251012510
return kvm_skip_emulated_instruction(vcpu);
1251112511

1251212512
default:
12513-
BUG(); /* We have already checked above that type <= 3 */
12513+
kvm_inject_gp(vcpu, 0);
12514+
return 1;
1251412515
}
1251512516
}
1251612517
EXPORT_SYMBOL_GPL(kvm_handle_invpcid);

0 commit comments

Comments
 (0)