• Paolo Bonzini's avatar
    KVM: LAPIC: ensure APIC map is up to date on concurrent update requests · 44d52717
    Paolo Bonzini authored
    The following race can cause lost map update events:
    
             cpu1                            cpu2
    
                                    apic_map_dirty = true
      ------------------------------------------------------------
                                    kvm_recalculate_apic_map:
                                         pass check
                                             mutex_lock(&kvm->arch.apic_map_lock);
                                             if (!kvm->arch.apic_map_dirty)
                                         and in process of updating map
      -------------------------------------------------------------
        other calls to
           apic_map_dirty = true         might be too late for affected cpu
      -------------------------------------------------------------
                                         apic_map_dirty = false
      -------------------------------------------------------------
        kvm_recalculate_apic_map:
        bail out on
          if (!kvm->arch.apic_map_dirty)
    
    To fix it, record the beginning of an update of the APIC map in
    apic_map_dirty.  If another APIC map change switches apic_map_dirty
    back to DIRTY during the update, kvm_recalculate_apic_map should not
    make it CLEAN, and the other caller will go through the slow path.
    Reported-by: default avatarIgor Mammedov <imammedo@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    44d52717
lapic.c 72.9 KB