• Nicholas Piggin's avatar
    KVM: PPC: Book3S HV P9: Fix "lost kick" race · c7fa848f
    Nicholas Piggin authored
    When new work is created that requires attention from the hypervisor
    (e.g., to inject an interrupt into the guest), fast_vcpu_kick is used to
    pull the target vcpu out of the guest if it may have been running.
    
    Therefore the work creation side looks like this:
    
      vcpu->arch.doorbell_request = 1;
      kvmppc_fast_vcpu_kick_hv(vcpu) {
        smp_mb();
        cpu = vcpu->cpu;
        if (cpu != -1)
            send_ipi(cpu);
      }
    
    And the guest entry side *should* look like this:
    
      vcpu->cpu = smp_processor_id();
      smp_mb();
      if (vcpu->arch.doorbell_request) {
        // do something (abort entry or inject doorbell etc)
      }
    
    But currently the store and load are flipped, so it is possible for the
    entry to see no doorbell pending, and the doorbell creation misses the
    store to set cpu, resulting lost work (or at least delayed until the
    next guest exit).
    
    Fix this by reordering the entry operations and adding a smp_mb
    between them. The P8 path appears to have a similar race which is
    commented but not addressed yet.
    Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/20220303053315.1056880-2-npiggin@gmail.com
    c7fa848f
book3s_hv.c 159 KB