Skip to content

Commit 329bd56

Browse files
shvipinbonzini
authored andcommitted
KVM: VMX: Add a helper function to retrieve the GPR index for INVPCID, INVVPID, and INVEPT
handle_invept(), handle_invvpid(), handle_invpcid() read the same reg2 field in vmcs.VMX_INSTRUCTION_INFO to get the index of the GPR that holds the invalidation type. Add a helper to retrieve reg2 from VMX instruction info to consolidate and document the shift+mask magic. 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 a5e0c25 commit 329bd56

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5343,7 +5343,7 @@ static int handle_invept(struct kvm_vcpu *vcpu)
53435343
struct {
53445344
u64 eptp, gpa;
53455345
} operand;
5346-
int i, r;
5346+
int i, r, gpr_index;
53475347

53485348
if (!(vmx->nested.msrs.secondary_ctls_high &
53495349
SECONDARY_EXEC_ENABLE_EPT) ||
@@ -5356,7 +5356,8 @@ static int handle_invept(struct kvm_vcpu *vcpu)
53565356
return 1;
53575357

53585358
vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
5359-
type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf);
5359+
gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info);
5360+
type = kvm_register_read(vcpu, gpr_index);
53605361

53615362
types = (vmx->nested.msrs.ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6;
53625363

@@ -5423,7 +5424,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
54235424
u64 gla;
54245425
} operand;
54255426
u16 vpid02;
5426-
int r;
5427+
int r, gpr_index;
54275428

54285429
if (!(vmx->nested.msrs.secondary_ctls_high &
54295430
SECONDARY_EXEC_ENABLE_VPID) ||
@@ -5436,7 +5437,8 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
54365437
return 1;
54375438

54385439
vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
5439-
type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf);
5440+
gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info);
5441+
type = kvm_register_read(vcpu, gpr_index);
54405442

54415443
types = (vmx->nested.msrs.vpid_caps &
54425444
VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8;

arch/x86/kvm/vmx/vmx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5443,14 +5443,16 @@ static int handle_invpcid(struct kvm_vcpu *vcpu)
54435443
u64 pcid;
54445444
u64 gla;
54455445
} operand;
5446+
int gpr_index;
54465447

54475448
if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID)) {
54485449
kvm_queue_exception(vcpu, UD_VECTOR);
54495450
return 1;
54505451
}
54515452

54525453
vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
5453-
type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf);
5454+
gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info);
5455+
type = kvm_register_read(vcpu, gpr_index);
54545456

54555457
if (type > 3) {
54565458
kvm_inject_gp(vcpu, 0);

arch/x86/kvm/vmx/vmx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,9 @@ static inline bool vmx_guest_state_valid(struct kvm_vcpu *vcpu)
550550

551551
void dump_vmcs(struct kvm_vcpu *vcpu);
552552

553+
static inline int vmx_get_instr_info_reg2(u32 vmx_instr_info)
554+
{
555+
return (vmx_instr_info >> 28) & 0xf;
556+
}
557+
553558
#endif /* __KVM_X86_VMX_H */

0 commit comments

Comments
 (0)