Skip to content

Commit c7f0309

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: nVMX: Consolidate missing X86EMUL_INTERCEPTED logic in L2 emulation
JIRA: https://issues.redhat.com/browse/RHEL-95318 commit 08e3d89 Author: Sean Christopherson <seanjc@google.com> Date: Fri Jan 31 17:55:12 2025 -0800 KVM: nVMX: Consolidate missing X86EMUL_INTERCEPTED logic in L2 emulation Refactor the handling of port I/O interception checks when emulating on behalf of L2 in anticipation of synthesizing a nested VM-Exit to L1 instead of injecting a #UD into L2. No functional change intended. Link: https://lore.kernel.org/r/20250201015518.689704-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 271544f commit c7f0309

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7919,12 +7919,11 @@ static __init void vmx_set_cpu_caps(void)
79197919
kvm_cpu_cap_check_and_set(X86_FEATURE_WAITPKG);
79207920
}
79217921

7922-
static int vmx_check_intercept_io(struct kvm_vcpu *vcpu,
7922+
static bool vmx_is_io_intercepted(struct kvm_vcpu *vcpu,
79237923
struct x86_instruction_info *info)
79247924
{
79257925
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
79267926
unsigned short port;
7927-
bool intercept;
79287927
int size;
79297928

79307929
if (info->intercept == x86_intercept_in ||
@@ -7944,13 +7943,9 @@ static int vmx_check_intercept_io(struct kvm_vcpu *vcpu,
79447943
* Otherwise, IO instruction VM-exits are controlled by the IO bitmaps.
79457944
*/
79467945
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
7947-
intercept = nested_cpu_has(vmcs12,
7948-
CPU_BASED_UNCOND_IO_EXITING);
7949-
else
7950-
intercept = nested_vmx_check_io_bitmaps(vcpu, port, size);
7946+
return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING);
79517947

7952-
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
7953-
return intercept ? X86EMUL_UNHANDLEABLE : X86EMUL_CONTINUE;
7948+
return nested_vmx_check_io_bitmaps(vcpu, port, size);
79547949
}
79557950

79567951
int vmx_check_intercept(struct kvm_vcpu *vcpu,
@@ -7979,7 +7974,9 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
79797974
case x86_intercept_ins:
79807975
case x86_intercept_out:
79817976
case x86_intercept_outs:
7982-
return vmx_check_intercept_io(vcpu, info);
7977+
if (!vmx_is_io_intercepted(vcpu, info))
7978+
return X86EMUL_CONTINUE;
7979+
break;
79837980

79847981
case x86_intercept_lgdt:
79857982
case x86_intercept_lidt:
@@ -7991,8 +7988,6 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
79917988
case x86_intercept_str:
79927989
if (!nested_cpu_has2(vmcs12, SECONDARY_EXEC_DESC))
79937990
return X86EMUL_CONTINUE;
7994-
7995-
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
79967991
break;
79977992

79987993
case x86_intercept_hlt:
@@ -8020,6 +8015,7 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
80208015
break;
80218016
}
80228017

8018+
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
80238019
return X86EMUL_UNHANDLEABLE;
80248020
}
80258021

0 commit comments

Comments
 (0)