Skip to content

Commit a7cde48

Browse files
Liran Alonbonzini
authored andcommitted
KVM: nVMX: Do not forward VMREAD/VMWRITE VMExits to L1 if required so by vmcs12 vmread/vmwrite bitmaps
This is done as a preparation for VMCS shadowing emulation. Signed-off-by: Liran Alon <liran.alon@oracle.com> Signed-off-by: Jim Mattson <jmattson@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6d894f4 commit a7cde48

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

‎arch/x86/kvm/vmx.c‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9107,6 +9107,30 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu,
91079107
return false;
91089108
}
91099109

9110+
static bool nested_vmx_exit_handled_vmcs_access(struct kvm_vcpu *vcpu,
9111+
struct vmcs12 *vmcs12, gpa_t bitmap)
9112+
{
9113+
u32 vmx_instruction_info;
9114+
unsigned long field;
9115+
u8 b;
9116+
9117+
if (!nested_cpu_has_shadow_vmcs(vmcs12))
9118+
return true;
9119+
9120+
/* Decode instruction info and find the field to access */
9121+
vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
9122+
field = kvm_register_read(vcpu, (((vmx_instruction_info) >> 28) & 0xf));
9123+
9124+
/* Out-of-range fields always cause a VM exit from L2 to L1 */
9125+
if (field >> 15)
9126+
return true;
9127+
9128+
if (kvm_vcpu_read_guest(vcpu, bitmap + field/8, &b, 1))
9129+
return true;
9130+
9131+
return 1 & (b >> (field & 7));
9132+
}
9133+
91109134
/*
91119135
* Return 1 if we should exit from L2 to L1 to handle an exit, or 0 if we
91129136
* should handle it ourselves in L0 (and then continue L2). Only call this
@@ -9191,10 +9215,15 @@ static bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
91919215
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_RDSEED_EXITING);
91929216
case EXIT_REASON_RDTSC: case EXIT_REASON_RDTSCP:
91939217
return nested_cpu_has(vmcs12, CPU_BASED_RDTSC_EXITING);
9218+
case EXIT_REASON_VMREAD:
9219+
return nested_vmx_exit_handled_vmcs_access(vcpu, vmcs12,
9220+
vmcs12->vmread_bitmap);
9221+
case EXIT_REASON_VMWRITE:
9222+
return nested_vmx_exit_handled_vmcs_access(vcpu, vmcs12,
9223+
vmcs12->vmwrite_bitmap);
91949224
case EXIT_REASON_VMCALL: case EXIT_REASON_VMCLEAR:
91959225
case EXIT_REASON_VMLAUNCH: case EXIT_REASON_VMPTRLD:
9196-
case EXIT_REASON_VMPTRST: case EXIT_REASON_VMREAD:
9197-
case EXIT_REASON_VMRESUME: case EXIT_REASON_VMWRITE:
9226+
case EXIT_REASON_VMPTRST: case EXIT_REASON_VMRESUME:
91989227
case EXIT_REASON_VMOFF: case EXIT_REASON_VMON:
91999228
case EXIT_REASON_INVEPT: case EXIT_REASON_INVVPID:
92009229
/*

0 commit comments

Comments
 (0)