Skip to content

Commit b045ae9

Browse files
ouptonbonzini
authored andcommitted
kvm: nVMX: reflect MTF VM-exits if injected by L1
According to SDM 26.6.2, it is possible to inject an MTF VM-exit via the VM-entry interruption-information field regardless of the 'monitor trap flag' VM-execution control. KVM appropriately copies the VM-entry interruption-information field from vmcs12 to vmcs02. However, if L1 has not set the 'monitor trap flag' VM-execution control, KVM fails to reflect the subsequent MTF VM-exit into L1. Fix this by consulting the VM-entry interruption-information field of vmcs12 to determine if L1 has injected the MTF VM-exit. If so, reflect the exit, regardless of the 'monitor trap flag' VM-execution control. Fixes: 5f3d45e ("kvm/x86: add support for MONITOR_TRAP_FLAG") Signed-off-by: Oliver Upton <[email protected]> Reviewed-by: Peter Shier <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 97daa02 commit b045ae9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5533,6 +5533,23 @@ static bool nested_vmx_exit_handled_vmcs_access(struct kvm_vcpu *vcpu,
55335533
return 1 & (b >> (field & 7));
55345534
}
55355535

5536+
static bool nested_vmx_exit_handled_mtf(struct vmcs12 *vmcs12)
5537+
{
5538+
u32 entry_intr_info = vmcs12->vm_entry_intr_info_field;
5539+
5540+
if (nested_cpu_has_mtf(vmcs12))
5541+
return true;
5542+
5543+
/*
5544+
* An MTF VM-exit may be injected into the guest by setting the
5545+
* interruption-type to 7 (other event) and the vector field to 0. Such
5546+
* is the case regardless of the 'monitor trap flag' VM-execution
5547+
* control.
5548+
*/
5549+
return entry_intr_info == (INTR_INFO_VALID_MASK
5550+
| INTR_TYPE_OTHER_EVENT);
5551+
}
5552+
55365553
/*
55375554
* Return 1 if we should exit from L2 to L1 to handle an exit, or 0 if we
55385555
* should handle it ourselves in L0 (and then continue L2). Only call this
@@ -5633,7 +5650,7 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
56335650
case EXIT_REASON_MWAIT_INSTRUCTION:
56345651
return nested_cpu_has(vmcs12, CPU_BASED_MWAIT_EXITING);
56355652
case EXIT_REASON_MONITOR_TRAP_FLAG:
5636-
return nested_cpu_has_mtf(vmcs12);
5653+
return nested_vmx_exit_handled_mtf(vmcs12);
56375654
case EXIT_REASON_MONITOR_INSTRUCTION:
56385655
return nested_cpu_has(vmcs12, CPU_BASED_MONITOR_EXITING);
56395656
case EXIT_REASON_PAUSE_INSTRUCTION:

0 commit comments

Comments
 (0)