Skip to content

Commit

Permalink
KVM: x86: Disable APIC logical map if logical ID covers multiple MDAs
Browse files Browse the repository at this point in the history
Disable the optimized APIC logical map if a logical ID covers multiple
MDAs, i.e. if a vCPU has multiple bits set in its ID.  In logical mode,
events match if "ID & MDA != 0", i.e. creating an entry for only the
first bit can cause interrupts to be missed.

Note, creating an entry for every bit is also wrong as KVM would generate
IPIs for every matching bit.  It would be possible to teach KVM to play
nice with this edge case, but it is very much an edge case and probably
not used in any real world OS, i.e. it's not worth optimizing.

Fixes: 1e08ec4 ("KVM: optimize apic interrupt delivery")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20230106011306.85230-21-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Jan 13, 2023
1 parent 76e5275 commit 2bf934a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions arch/x86/kvm/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,14 @@ void kvm_recalculate_apic_map(struct kvm *kvm)
continue;
}

if (mask)
cluster[ffs(mask) - 1] = apic;
if (!mask)
continue;

if (!is_power_of_2(mask)) {
new->logical_mode = KVM_APIC_MODE_MAP_DISABLED;
continue;
}
cluster[ffs(mask) - 1] = apic;
}
out:
old = rcu_dereference_protected(kvm->arch.apic_map,
Expand Down

0 comments on commit 2bf934a

Please sign in to comment.