Commit 4efd805f authored by Radim Krčmář's avatar Radim Krčmář Committed by Paolo Bonzini

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: 6228a0da ("KVM: x86: Add lowest-priority support for vt-d posted-interrupts")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 78db6a50
...@@ -685,6 +685,15 @@ int kvm_vector_to_index(u32 vector, u32 dest_vcpus, ...@@ -685,6 +685,15 @@ int kvm_vector_to_index(u32 vector, u32 dest_vcpus,
return idx; 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, 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) 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, ...@@ -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, idx = kvm_vector_to_index(irq->vector,
dest_vcpus, &bitmap, 16); dest_vcpus, &bitmap, 16);
/* if (!dst[idx]) {
* We may find a hardware disabled LAPIC here, if that kvm_apic_disabled_lapic_found(kvm);
* 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");
goto out; goto out;
} }
...@@ -859,16 +861,9 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq, ...@@ -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, idx = kvm_vector_to_index(irq->vector, dest_vcpus,
&bitmap, 16); &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]; dst = map->logical_map[cid][idx];
if (!dst && !kvm->arch.disabled_lapic_found) { if (!dst) {
kvm->arch.disabled_lapic_found = true; kvm_apic_disabled_lapic_found(kvm);
printk(KERN_INFO
"Disabled LAPIC found during irq injection\n");
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment