Skip to content

Commit 2eee50c

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: nVMX: Allow the caller to provide instruction length on nested VM-Exit
JIRA: https://issues.redhat.com/browse/RHEL-95318 commit fbd1e0f Author: Sean Christopherson <seanjc@google.com> Date: Fri Jan 31 17:55:16 2025 -0800 KVM: nVMX: Allow the caller to provide instruction length on nested VM-Exit Rework the nested VM-Exit helper to take the instruction length as a parameter, and convert nested_vmx_vmexit() into a "default" wrapper that grabs the length from vmcs02 as appropriate. This will allow KVM to set the correct instruction length when synthesizing a nested VM-Exit when emulating an instruction that L1 wants to intercept. No functional change intended, as the path to prepare_vmcs12()'s reading of vmcs02.VM_EXIT_INSTRUCTION_LEN is gated on the same set of conditions as the VMREAD in the new nested_vmx_vmexit(). Link: https://lore.kernel.org/r/20250201015518.689704-10-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 0f6a37d commit 2eee50c

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,7 +4515,7 @@ static void sync_vmcs02_to_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
45154515
*/
45164516
static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
45174517
u32 vm_exit_reason, u32 exit_intr_info,
4518-
unsigned long exit_qualification)
4518+
unsigned long exit_qualification, u32 exit_insn_len)
45194519
{
45204520
/* update exit information fields: */
45214521
vmcs12->vm_exit_reason = vm_exit_reason;
@@ -4543,7 +4543,7 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
45434543
vm_exit_reason, exit_intr_info);
45444544

45454545
vmcs12->vm_exit_intr_info = exit_intr_info;
4546-
vmcs12->vm_exit_instruction_len = vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
4546+
vmcs12->vm_exit_instruction_len = exit_insn_len;
45474547
vmcs12->vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
45484548

45494549
/*
@@ -4827,8 +4827,9 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu)
48274827
* and modify vmcs12 to make it see what it would expect to see there if
48284828
* L2 was its real guest. Must only be called when in L2 (is_guest_mode())
48294829
*/
4830-
void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
4831-
u32 exit_intr_info, unsigned long exit_qualification)
4830+
void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
4831+
u32 exit_intr_info, unsigned long exit_qualification,
4832+
u32 exit_insn_len)
48324833
{
48334834
struct vcpu_vmx *vmx = to_vmx(vcpu);
48344835
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
@@ -4878,7 +4879,8 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
48784879

48794880
if (vm_exit_reason != -1)
48804881
prepare_vmcs12(vcpu, vmcs12, vm_exit_reason,
4881-
exit_intr_info, exit_qualification);
4882+
exit_intr_info, exit_qualification,
4883+
exit_insn_len);
48824884

48834885
/*
48844886
* Must happen outside of sync_vmcs02_to_vmcs12() as it will

arch/x86/kvm/vmx/nested.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,26 @@ void nested_vmx_free_vcpu(struct kvm_vcpu *vcpu);
2626
enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
2727
bool from_vmentry);
2828
bool nested_vmx_reflect_vmexit(struct kvm_vcpu *vcpu);
29-
void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
30-
u32 exit_intr_info, unsigned long exit_qualification);
29+
void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
30+
u32 exit_intr_info, unsigned long exit_qualification,
31+
u32 exit_insn_len);
32+
33+
static inline void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
34+
u32 exit_intr_info,
35+
unsigned long exit_qualification)
36+
{
37+
u32 exit_insn_len;
38+
39+
if (to_vmx(vcpu)->fail || vm_exit_reason == -1 ||
40+
(vm_exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY))
41+
exit_insn_len = 0;
42+
else
43+
exit_insn_len = vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
44+
45+
__nested_vmx_vmexit(vcpu, vm_exit_reason, exit_intr_info,
46+
exit_qualification, exit_insn_len);
47+
}
48+
3149
void nested_sync_vmcs12_to_shadow(struct kvm_vcpu *vcpu);
3250
int vmx_set_vmx_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
3351
int vmx_get_vmx_msr(struct nested_vmx_msrs *msrs, u32 msr_index, u64 *pdata);

0 commit comments

Comments
 (0)