Skip to content

Commit 08e3d89

Browse files
committed
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>
1 parent f43f7a2 commit 08e3d89

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
@@ -8007,12 +8007,11 @@ static __init void vmx_set_cpu_caps(void)
80078007
kvm_cpu_cap_check_and_set(X86_FEATURE_WAITPKG);
80088008
}
80098009

8010-
static int vmx_check_intercept_io(struct kvm_vcpu *vcpu,
8010+
static bool vmx_is_io_intercepted(struct kvm_vcpu *vcpu,
80118011
struct x86_instruction_info *info)
80128012
{
80138013
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
80148014
unsigned short port;
8015-
bool intercept;
80168015
int size;
80178016

80188017
if (info->intercept == x86_intercept_in ||
@@ -8032,13 +8031,9 @@ static int vmx_check_intercept_io(struct kvm_vcpu *vcpu,
80328031
* Otherwise, IO instruction VM-exits are controlled by the IO bitmaps.
80338032
*/
80348033
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
8035-
intercept = nested_cpu_has(vmcs12,
8036-
CPU_BASED_UNCOND_IO_EXITING);
8037-
else
8038-
intercept = nested_vmx_check_io_bitmaps(vcpu, port, size);
8034+
return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING);
80398035

8040-
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
8041-
return intercept ? X86EMUL_UNHANDLEABLE : X86EMUL_CONTINUE;
8036+
return nested_vmx_check_io_bitmaps(vcpu, port, size);
80428037
}
80438038

80448039
int vmx_check_intercept(struct kvm_vcpu *vcpu,
@@ -8067,7 +8062,9 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
80678062
case x86_intercept_ins:
80688063
case x86_intercept_out:
80698064
case x86_intercept_outs:
8070-
return vmx_check_intercept_io(vcpu, info);
8065+
if (!vmx_is_io_intercepted(vcpu, info))
8066+
return X86EMUL_CONTINUE;
8067+
break;
80718068

80728069
case x86_intercept_lgdt:
80738070
case x86_intercept_lidt:
@@ -8079,8 +8076,6 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
80798076
case x86_intercept_str:
80808077
if (!nested_cpu_has2(vmcs12, SECONDARY_EXEC_DESC))
80818078
return X86EMUL_CONTINUE;
8082-
8083-
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
80848079
break;
80858080

80868081
case x86_intercept_hlt:
@@ -8108,6 +8103,7 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
81088103
break;
81098104
}
81108105

8106+
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
81118107
return X86EMUL_UNHANDLEABLE;
81128108
}
81138109

0 commit comments

Comments
 (0)