Skip to content

Commit 02e3858

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: vgic: Force vcpu vgic teardown on vcpu destroy
When failing to create a vcpu because (for example) it has a duplicate vcpu_id, we destroy the vcpu. Amusingly, this leaves the redistributor registered with the KVM_MMIO bus. This is no good, and we should properly clean the mess. Force a teardown of the vgic vcpu interface, including the RD device before returning to the caller. Cc: [email protected] Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent d26b9cb commit 02e3858

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
410410
kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache);
411411
kvm_timer_vcpu_terminate(vcpu);
412412
kvm_pmu_vcpu_destroy(vcpu);
413-
413+
kvm_vgic_vcpu_destroy(vcpu);
414414
kvm_arm_vcpu_destroy(vcpu);
415415
}
416416

arch/arm64/kvm/vgic/vgic-init.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ static void __kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
379379
vgic_flush_pending_lpis(vcpu);
380380

381381
INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
382-
vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF;
382+
if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
383+
vgic_unregister_redist_iodev(vcpu);
384+
vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF;
385+
}
383386
}
384387

385388
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)

arch/arm64/kvm/vgic/vgic-mmio-v3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu)
820820
return ret;
821821
}
822822

823-
static void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
823+
void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
824824
{
825825
struct vgic_io_device *rd_dev = &vcpu->arch.vgic_cpu.rd_iodev;
826826

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq);
241241
int vgic_v3_save_pending_tables(struct kvm *kvm);
242242
int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count);
243243
int vgic_register_redist_iodev(struct kvm_vcpu *vcpu);
244+
void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu);
244245
bool vgic_v3_check_base(struct kvm *kvm);
245246

246247
void vgic_v3_load(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)