]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Merge tag 'kvmarm-fixes-6.16-1' of https://git.kernel.org/pub/scm/linux/kernel/git...
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 2 Jun 2025 07:05:29 +0000 (03:05 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 2 Jun 2025 07:05:29 +0000 (03:05 -0400)
KVM/arm64 fixes for 6.16, take #1

- Make the irqbypass hooks resilient to changes in the GSI<->MSI
  routing, avoiding behind stale vLPI mappings being left behind. The
  fix is to resolve the VGIC IRQ using the host IRQ (which is stable)
  and nuking the vLPI mapping upon a routing change.

- Close another VGIC race where vCPU creation races with VGIC
  creation, leading to in-flight vCPUs entering the kernel w/o private
  IRQs allocated.

- Fix a build issue triggered by the recently added workaround for
  Ampere's AC04_CPU_23 erratum.

- Correctly sign-extend the VA when emulating a TLBI instruction
  potentially targeting a VNCR mapping.

- Avoid dereferencing a NULL pointer in the VGIC debug code, which can
  happen if the device doesn't have any mapping yet.

1  2 
arch/arm64/kvm/arm.c
arch/arm64/kvm/vgic/vgic-init.c
arch/arm64/kvm/vgic/vgic-its.c

Simple merge
index 6a426d403a6b385667358f939b671f332c055d5b,0611a1c2ce8ef7e6739823db72769c70aae627b9..eb1205654ac890709cd1c990077b920f7c9de770
@@@ -84,15 -84,40 +84,40 @@@ int kvm_vgic_create(struct kvm *kvm, u3
                !kvm_vgic_global_state.can_emulate_gicv2)
                return -ENODEV;
  
-       /* Must be held to avoid race with vCPU creation */
+       /*
+        * Ensure mutual exclusion with vCPU creation and any vCPU ioctls by:
+        *
+        *  - Holding kvm->lock to prevent KVM_CREATE_VCPU from reaching
+        *    kvm_arch_vcpu_precreate() and ensuring created_vcpus is stable.
+        *    This alone is insufficient, as kvm_vm_ioctl_create_vcpu() drops
+        *    the kvm->lock before completing the vCPU creation.
+        */
        lockdep_assert_held(&kvm->lock);
  
+       /*
+        *  - Acquiring the vCPU mutex for every *online* vCPU to prevent
+        *    concurrent vCPU ioctls for vCPUs already visible to userspace.
+        */
        ret = -EBUSY;
 -      if (!lock_all_vcpus(kvm))
 +      if (kvm_trylock_all_vcpus(kvm))
                return ret;
  
+       /*
+        *  - Taking the config_lock which protects VGIC data structures such
+        *    as the per-vCPU arrays of private IRQs (SGIs, PPIs).
+        */
        mutex_lock(&kvm->arch.config_lock);
  
+       /*
+        * - Bailing on the entire thing if a vCPU is in the middle of creation,
+        *   dropped the kvm->lock, but hasn't reached kvm_arch_vcpu_create().
+        *
+        * The whole combination of this guarantees that no vCPU can get into
+        * KVM with a VGIC configuration inconsistent with the VM's VGIC.
+        */
+       if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
+               goto out_unlock;
        if (irqchip_in_kernel(kvm)) {
                ret = -EEXIST;
                goto out_unlock;
Simple merge