Skip to content

Commit 090df0f

Browse files
ouptonjfvogel
authored andcommitted
KVM: nVMX: Refactor IO bitmap checks into helper function
Checks against the IO bitmap are useful for both instruction emulation and VM-exit reflection. Refactor the IO bitmap checks into a helper function. Signed-off-by: Oliver Upton <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit e71237d) Orabug: 30847133 CVE: CVE-2020-2732 Signed-off-by: Boris Ostrovsky <[email protected]> Reviewed-by: Darren Kenny <[email protected]> Conflicts: arch/x86/kvm/vmx/nested.h context: no nested_vmx_pmu_entry_exit_ctls_update
1 parent b4129ce commit 090df0f

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5130,24 +5130,17 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu)
51305130
return 1;
51315131
}
51325132

5133-
5134-
static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
5135-
struct vmcs12 *vmcs12)
5133+
/*
5134+
* Return true if an IO instruction with the specified port and size should cause
5135+
* a VM-exit into L1.
5136+
*/
5137+
bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port,
5138+
int size)
51365139
{
5137-
unsigned long exit_qualification;
5140+
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
51385141
gpa_t bitmap, last_bitmap;
5139-
unsigned int port;
5140-
int size;
51415142
u8 b;
51425143

5143-
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
5144-
return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING);
5145-
5146-
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
5147-
5148-
port = exit_qualification >> 16;
5149-
size = (exit_qualification & 7) + 1;
5150-
51515144
last_bitmap = (gpa_t)-1;
51525145
b = -1;
51535146

@@ -5174,6 +5167,24 @@ static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
51745167
return false;
51755168
}
51765169

5170+
static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
5171+
struct vmcs12 *vmcs12)
5172+
{
5173+
unsigned long exit_qualification;
5174+
unsigned int port;
5175+
int size;
5176+
5177+
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
5178+
return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING);
5179+
5180+
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
5181+
5182+
port = exit_qualification >> 16;
5183+
size = (exit_qualification & 7) + 1;
5184+
5185+
return nested_vmx_check_io_bitmaps(vcpu, port, size);
5186+
}
5187+
51775188
/*
51785189
* Return 1 if we should exit from L2 to L1 to handle an MSR access access,
51795190
* rather than handle it ourselves in L0. I.e., check whether L1 expressed

arch/x86/kvm/vmx/nested.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ int vmx_set_vmx_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
3333
int vmx_get_vmx_msr(struct nested_vmx_msrs *msrs, u32 msr_index, u64 *pdata);
3434
int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
3535
u32 vmx_instruction_info, bool wr, int len, gva_t *ret);
36+
bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port,
37+
int size);
3638

3739
static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu)
3840
{

0 commit comments

Comments
 (0)