]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Add function for vectoring error generation
authorIvan Orlov <iorlov@amazon.com>
Tue, 17 Dec 2024 18:14:52 +0000 (18:14 +0000)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 23:14:41 +0000 (15:14 -0800)
Extract VMX code for unhandleable VM-Exit during vectoring into
vendor-agnostic function so that boiler-plate code can be shared by SVM.

To avoid unnecessarily complexity in the helper, unconditionally report a
GPA to userspace instead of having a conditional entry.  For exits that
don't report a GPA, i.e. everything except EPT Misconfig, simply report
KVM's "invalid GPA".

Signed-off-by: Ivan Orlov <iorlov@amazon.com>
Link: https://lore.kernel.org/r/20241217181458.68690-2-iorlov@amazon.com
[sean: clarify that the INVALID_GPA logic is new]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c

index 81ce8cd5814ac2c6ac7a3a8ed0e91482264db64f..cbfd1fdb514ad68c854dbbe683c5e2478c9b2e1a 100644 (file)
@@ -2075,6 +2075,8 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
                                          u64 *data, u8 ndata);
 void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
 
+void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
+
 void kvm_enable_efer_bits(u64);
 bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
 int kvm_get_msr_with_filter(struct kvm_vcpu *vcpu, u32 index, u64 *data);
index cf872d8691b5019e345de09c7fbe9c9941f941e7..b6ce17bf74d775b989c9cbdca0766f0d16db1140 100644 (file)
@@ -6554,19 +6554,12 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
             exit_reason.basic != EXIT_REASON_APIC_ACCESS &&
             exit_reason.basic != EXIT_REASON_TASK_SWITCH &&
             exit_reason.basic != EXIT_REASON_NOTIFY)) {
-               int ndata = 3;
+               gpa_t gpa = INVALID_GPA;
 
-               vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
-               vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV;
-               vcpu->run->internal.data[0] = vectoring_info;
-               vcpu->run->internal.data[1] = exit_reason.full;
-               vcpu->run->internal.data[2] = vmx_get_exit_qual(vcpu);
-               if (exit_reason.basic == EXIT_REASON_EPT_MISCONFIG) {
-                       vcpu->run->internal.data[ndata++] =
-                               vmcs_read64(GUEST_PHYSICAL_ADDRESS);
-               }
-               vcpu->run->internal.data[ndata++] = vcpu->arch.last_vmentry_cpu;
-               vcpu->run->internal.ndata = ndata;
+               if (exit_reason.basic == EXIT_REASON_EPT_MISCONFIG)
+                       gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
+
+               kvm_prepare_event_vectoring_exit(vcpu, gpa);
                return 0;
        }
 
index 320764e5f798854d63c1c23844f7054c95e8c798..7fcdfafb25a24cda3fa65879bb2e162904fdcbe2 100644 (file)
@@ -8804,6 +8804,28 @@ void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvm_prepare_emulation_failure_exit);
 
+void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
+{
+       u32 reason, intr_info, error_code;
+       struct kvm_run *run = vcpu->run;
+       u64 info1, info2;
+       int ndata = 0;
+
+       kvm_x86_call(get_exit_info)(vcpu, &reason, &info1, &info2,
+                                   &intr_info, &error_code);
+
+       run->internal.data[ndata++] = info2;
+       run->internal.data[ndata++] = reason;
+       run->internal.data[ndata++] = info1;
+       run->internal.data[ndata++] = gpa;
+       run->internal.data[ndata++] = vcpu->arch.last_vmentry_cpu;
+
+       run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+       run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV;
+       run->internal.ndata = ndata;
+}
+EXPORT_SYMBOL_GPL(kvm_prepare_event_vectoring_exit);
+
 static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
 {
        struct kvm *kvm = vcpu->kvm;