From: Radim Krčmář Date: Fri, 12 Feb 2016 14:00:15 +0000 (+0100) Subject: KVM: x86: fix *NULL on invalid low-prio irq X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4efd805fca5590af181f89ad122b8695c63b5f2c;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git KVM: x86: fix *NULL on invalid low-prio irq Smatch noticed a NULL dereference in kvm_intr_is_single_vcpu_fast that happens if VM already warned about invalid lowest-priority interrupt. Create a function for common code while fixing it. Fixes: 6228a0da8057 ("KVM: x86: Add lowest-priority support for vt-d posted-interrupts") Reported-by: Dan Carpenter Signed-off-by: Radim Krčmář Signed-off-by: Paolo Bonzini --- diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 1482a581a83c..cf74404230ca 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -685,6 +685,15 @@ int kvm_vector_to_index(u32 vector, u32 dest_vcpus, return idx; } +static void kvm_apic_disabled_lapic_found(struct kvm *kvm) +{ + if (!kvm->arch.disabled_lapic_found) { + kvm->arch.disabled_lapic_found = true; + printk(KERN_INFO + "Disabled LAPIC found during irq injection\n"); + } +} + bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, struct kvm_lapic_irq *irq, int *r, unsigned long *dest_map) { @@ -763,15 +772,8 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, idx = kvm_vector_to_index(irq->vector, dest_vcpus, &bitmap, 16); - /* - * We may find a hardware disabled LAPIC here, if that - * is the case, print out a error message once for each - * guest and return. - */ - if (!dst[idx] && !kvm->arch.disabled_lapic_found) { - kvm->arch.disabled_lapic_found = true; - printk(KERN_INFO - "Disabled LAPIC found during irq injection\n"); + if (!dst[idx]) { + kvm_apic_disabled_lapic_found(kvm); goto out; } @@ -859,16 +861,9 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq, idx = kvm_vector_to_index(irq->vector, dest_vcpus, &bitmap, 16); - /* - * We may find a hardware disabled LAPIC here, if that - * is the case, print out a error message once for each - * guest and return - */ dst = map->logical_map[cid][idx]; - if (!dst && !kvm->arch.disabled_lapic_found) { - kvm->arch.disabled_lapic_found = true; - printk(KERN_INFO - "Disabled LAPIC found during irq injection\n"); + if (!dst) { + kvm_apic_disabled_lapic_found(kvm); goto out; }