KVM: arm64: Eagerly init vgic dist/redist on vgic creation
Marc Zyngier
maintainerPATCH 1/1 KVM: arm64: Eagerly init vgic dist/redist on vgic creation
If vgic_allocate_private_irqs_locked() fails for any odd reason, we exit kvm_vgic_create() early, leaving dist->rd_regions uninitialised.
kvm_vgic_dist_destroy() then comes along and walks into the weeds trying to free the RDs. Got to love this stuff.
Solve it by moving all the static initialisation early, and make sure that if we fail halfway, we're in a reasonable shape to perform the rest of the teardown. While at it, reset the vgic model on failure, just in case...
--- arch/arm64/kvm/vgic/vgic-init.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
arch/arm64/kvm/vgic/vgic-init.c +16 -16
@@ -143,6 +143,21 @@ int kvm_vgic_create(struct kvm *kvm, u32 type) kvm->arch.vgic.in_kernel = true; kvm->arch.vgic.vgic_model = type; kvm->arch.vgic.implementation_rev =KVM_VGIC_IMP_REV_LATEST ; + kvm->arch.vgic.vgic_dist_base =VGIC_ADDR_UNDEF ; + + aa64pfr0 =kvm_read_vm_id_reg (kvm,SYS_ID_AA64PFR0_EL1 ) & ~ID_AA64PFR0_EL1_GIC ; + pfr1 =kvm_read_vm_id_reg (kvm,SYS_ID_PFR1_EL1 ) & ~ID_PFR1_EL1_GIC ; + +if (type ==KVM_DEV_TYPE_ARM_VGIC_V2 ) { + kvm->arch.vgic.vgic_cpu_base =VGIC_ADDR_UNDEF ; + }else { +INIT_LIST_HEAD (&kvm->arch.vgic.rd_regions); + aa64pfr0 |=SYS_FIELD_PREP_ENUM (ID_AA64PFR0_EL1 ,GIC ,IMP ); + pfr1 |=SYS_FIELD_PREP_ENUM (ID_PFR1_EL1 ,GIC , GICv3); + } + +kvm_set_vm_id_reg (kvm,SYS_ID_AA64PFR0_EL1 , aa64pfr0); +kvm_set_vm_id_reg (kvm,SYS_ID_PFR1_EL1 , pfr1);kvm_for_each_vcpu (i, vcpu, kvm) { ret =vgic_allocate_private_irqs_locked (vcpu, type);
@@ -157,25 +172,10 @@ int kvm_vgic_create(struct kvm *kvm, u32 type) vgic_cpu->private_irqs =NULL ; } + kvm->arch.vgic.vgic_model =0 ; goto out_unlock; } - kvm->arch.vgic.vgic_dist_base =VGIC_ADDR_UNDEF ; - - aa64pfr0 =kvm_read_vm_id_reg (kvm,SYS_ID_AA64PFR0_EL1 ) & ~ID_AA64PFR0_EL1_GIC ; - pfr1 =kvm_read_vm_id_reg (kvm,SYS_ID_PFR1_EL1 ) & ~ID_PFR1_EL1_GIC ; - -if (type ==KVM_DEV_TYPE_ARM_VGIC_V2 ) { - kvm->arch.vgic.vgic_cpu_base =VGIC_ADDR_UNDEF ; - }else { -INIT_LIST_HEAD (&kvm->arch.vgic.rd_regions); - aa64pfr0 |=SYS_FIELD_PREP_ENUM (ID_AA64PFR0_EL1 ,GIC ,IMP ); - pfr1 |=SYS_FIELD_PREP_ENUM (ID_PFR1_EL1 ,GIC , GICv3); - } - -kvm_set_vm_id_reg (kvm,SYS_ID_AA64PFR0_EL1 , aa64pfr0); -kvm_set_vm_id_reg (kvm,SYS_ID_PFR1_EL1 , pfr1); -if (type ==KVM_DEV_TYPE_ARM_VGIC_V3 ) kvm->arch.vgic.nassgicap =system_supports_direct_sgis ();
Signature · 1 line
2.47.3
Quoted 6 lines · Marc Zyngier
If
vgic_allocate_private_irqs_locked()fails for any odd reason, we exitkvm_vgic_create()early, leavingdist->rd_regionsuninitialised.
kvm_vgic_dist_destroy()then comes along and walks into the weeds trying to free the RDs. Got to love this stuff.
Quoted 6 lines
Solve it by moving all the static initialisation early, and make sure that if we fail halfway, we're in a reasonable shape to perform the rest of the teardown. While at it, reset the vgic model on failure, just in case...
[...]
Applied to fixes, thanks!
[1/1] KVM: arm64: Eagerly init vgic dist/redist on vgic creation
commit: ac6769c8f948dff33265c50e524aebf9aa6f1be0
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.