Skip to content

Commit 11c98fa

Browse files
iorlov-devsean-jc
authored andcommitted
KVM: x86: Add function for vectoring error generation
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: clarify that the INVALID_GPA logic is new] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 871ac33 commit 11c98fa

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,8 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
20752075
u64 *data, u8 ndata);
20762076
void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
20772077

2078+
void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
2079+
20782080
void kvm_enable_efer_bits(u64);
20792081
bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
20802082
int kvm_get_msr_with_filter(struct kvm_vcpu *vcpu, u32 index, u64 *data);

arch/x86/kvm/vmx/vmx.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6554,19 +6554,12 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
65546554
exit_reason.basic != EXIT_REASON_APIC_ACCESS &&
65556555
exit_reason.basic != EXIT_REASON_TASK_SWITCH &&
65566556
exit_reason.basic != EXIT_REASON_NOTIFY)) {
6557-
int ndata = 3;
6557+
gpa_t gpa = INVALID_GPA;
65586558

6559-
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
6560-
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV;
6561-
vcpu->run->internal.data[0] = vectoring_info;
6562-
vcpu->run->internal.data[1] = exit_reason.full;
6563-
vcpu->run->internal.data[2] = vmx_get_exit_qual(vcpu);
6564-
if (exit_reason.basic == EXIT_REASON_EPT_MISCONFIG) {
6565-
vcpu->run->internal.data[ndata++] =
6566-
vmcs_read64(GUEST_PHYSICAL_ADDRESS);
6567-
}
6568-
vcpu->run->internal.data[ndata++] = vcpu->arch.last_vmentry_cpu;
6569-
vcpu->run->internal.ndata = ndata;
6559+
if (exit_reason.basic == EXIT_REASON_EPT_MISCONFIG)
6560+
gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
6561+
6562+
kvm_prepare_event_vectoring_exit(vcpu, gpa);
65706563
return 0;
65716564
}
65726565

arch/x86/kvm/x86.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8804,6 +8804,28 @@ void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu)
88048804
}
88058805
EXPORT_SYMBOL_GPL(kvm_prepare_emulation_failure_exit);
88068806

8807+
void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
8808+
{
8809+
u32 reason, intr_info, error_code;
8810+
struct kvm_run *run = vcpu->run;
8811+
u64 info1, info2;
8812+
int ndata = 0;
8813+
8814+
kvm_x86_call(get_exit_info)(vcpu, &reason, &info1, &info2,
8815+
&intr_info, &error_code);
8816+
8817+
run->internal.data[ndata++] = info2;
8818+
run->internal.data[ndata++] = reason;
8819+
run->internal.data[ndata++] = info1;
8820+
run->internal.data[ndata++] = gpa;
8821+
run->internal.data[ndata++] = vcpu->arch.last_vmentry_cpu;
8822+
8823+
run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
8824+
run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV;
8825+
run->internal.ndata = ndata;
8826+
}
8827+
EXPORT_SYMBOL_GPL(kvm_prepare_event_vectoring_exit);
8828+
88078829
static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
88088830
{
88098831
struct kvm *kvm = vcpu->kvm;

0 commit comments

Comments
 (0)