Skip to content

Commit e71237d

Browse files
ouptonbonzini
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]>
1 parent 07721fe commit e71237d

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
@@ -5312,24 +5312,17 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu)
53125312
return 1;
53135313
}
53145314

5315-
5316-
static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
5317-
struct vmcs12 *vmcs12)
5315+
/*
5316+
* Return true if an IO instruction with the specified port and size should cause
5317+
* a VM-exit into L1.
5318+
*/
5319+
bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port,
5320+
int size)
53185321
{
5319-
unsigned long exit_qualification;
5322+
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
53205323
gpa_t bitmap, last_bitmap;
5321-
unsigned int port;
5322-
int size;
53235324
u8 b;
53245325

5325-
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
5326-
return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING);
5327-
5328-
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
5329-
5330-
port = exit_qualification >> 16;
5331-
size = (exit_qualification & 7) + 1;
5332-
53335326
last_bitmap = (gpa_t)-1;
53345327
b = -1;
53355328

@@ -5356,6 +5349,24 @@ static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
53565349
return false;
53575350
}
53585351

5352+
static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
5353+
struct vmcs12 *vmcs12)
5354+
{
5355+
unsigned long exit_qualification;
5356+
unsigned int port;
5357+
int size;
5358+
5359+
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
5360+
return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING);
5361+
5362+
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
5363+
5364+
port = exit_qualification >> 16;
5365+
size = (exit_qualification & 7) + 1;
5366+
5367+
return nested_vmx_check_io_bitmaps(vcpu, port, size);
5368+
}
5369+
53595370
/*
53605371
* Return 1 if we should exit from L2 to L1 to handle an MSR access,
53615372
* 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_get_vmx_msr(struct nested_vmx_msrs *msrs, u32 msr_index, u64 *pdata);
3333
int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
3434
u32 vmx_instruction_info, bool wr, int len, gva_t *ret);
3535
void nested_vmx_pmu_entry_exit_ctls_update(struct kvm_vcpu *vcpu);
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)