FAILED: patch "[PATCH] KVM: arm64: vgic-v3: Undo assignment on iodev registration failure" failed to apply to 5.15-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 8a88a46b86ca3dbbd24522760d29edfb3f24ac2a
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 8a88a46b86ca3dbbd24522760d29edfb3f24ac2a Mon Sep 17 00:00:00 2001
From: Karl Mehltretter <[email protected]>
Date: Mon, 31 Aug 2026 10:10:01 +0200
Subject: [PATCH] KVM: arm64: vgic-v3: Undo assignment on iodev registration
failure
vgic_register_redist_iodev() assigns a redistributor region and base address to the vCPU before adding its iodev to the MMIO bus. However, the region's free_index is advanced only after registration succeeds.
If kvm_io_bus_register_dev() fails, the vCPU retains the assignment while free_index still identifies the same slot as free. A later registration can therefore reuse a slot that remains assigned to the vCPU.
Reserve the slot before registering its iodev. The caller holds slots_lock, so a registration failure cannot race with a later assignment. Undo the reservation and clear the cached assignment on failure.
--- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm64/kvm/vgic/vgic-mmio-v3.c +10 -5
@@ -818,16 +818,21 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu) rd_dev->nr_regions =ARRAY_SIZE (vgic_v3_rd_registers); rd_dev->redist_vcpu = vcpu; +/* Protected by slots_lock */ + rdreg->free_index++; +mutex_unlock (&kvm->arch.config_lock); ret =kvm_io_bus_register_dev (kvm,KVM_MMIO_BUS , rd_base,2 *SZ_64K , &rd_dev->dev); -if (ret) -return ret; +if (ret) { +guard (mutex)(&vcpu->kvm->arch.config_lock); + vgic_cpu->rdreg->free_index--; + vgic_cpu->rdreg =NULL ; + vgic_cpu->rd_iodev.base_addr =VGIC_ADDR_UNDEF ; + } -/* Protected by slots_lock */ - rdreg->free_index++; -return 0 ; +return ret; out_unlock:mutex_unlock (&kvm->arch.config_lock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 KVM: arm64: vgic-v3: Undo assignment on iodev registration failure
From: Karl Mehltretter <[email protected]>
[ Upstream commit 8a88a46b86ca3dbbd24522760d29edfb3f24ac2a ]
vgic_register_redist_iodev() assigns a redistributor region and base address to the vCPU before adding its iodev to the MMIO bus. However, the region's free_index is advanced only after registration succeeds.
If kvm_io_bus_register_dev() fails, the vCPU retains the assignment while free_index still identifies the same slot as free. A later registration can therefore reuse a slot that remains assigned to the vCPU.
Reserve the slot before registering its iodev. The caller holds slots_lock, so a registration failure cannot race with a later assignment. Undo the reservation and clear the cached assignment on failure.
--- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/arm64/kvm/vgic/vgic-mmio-v3.c +9 -4
@@ -739,16 +739,21 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu) rd_dev->nr_regions =ARRAY_SIZE (vgic_v3_rd_registers); rd_dev->redist_vcpu = vcpu; +/* Protected by kvm->lock */ + rdreg->free_index++; +mutex_lock (&kvm->slots_lock); ret =kvm_io_bus_register_dev (kvm,KVM_MMIO_BUS , rd_base,2 *SZ_64K , &rd_dev->dev);mutex_unlock (&kvm->slots_lock); -if (ret) -return ret; +if (ret) { + vgic_cpu->rdreg->free_index--; + vgic_cpu->rdreg =NULL ; + vgic_cpu->rd_iodev.base_addr =VGIC_ADDR_UNDEF ; + } - rdreg->free_index++; -return 0 ; +return ret; }void vgic_unregister_redist_iodev (struct kvm_vcpu *vcpu)
Signature · 1 line
2.53.0