KVM: arm/arm64: kvm_arch_destroy_vm cleanups
PATCH 1/1 KVM: arm/arm64: kvm_arch_destroy_vm cleanups
Recently commit b2c9a85dd75a ("KVM: arm/arm64: vgic: Move kvm_vgic_destroy call around") caught my eye. When I looked closer I saw that while it made the code saner, it wasn't changing anything. kvm_for_each_vcpu() checks for NULL kvm->vcpus[i], so there wasn't a NULL dereference being fixed, and because kvm_vgic_vcpu_destroy() was called by kvm_arch_vcpu_free() it was still getting called, just not by kvm_vgic_destroy() as intended. But now the call from kvm_arch_vcpu_free() is redundant, and while currently harmless, it should be removed in case kvm_vgic_vcpu_destroy() were ever to want to reference vgic state, as kvm_vgic_destroy() now comes before kvm_arch_vcpu_free(). Additionally the other architectures set kvm->online_vcpus to zero after freeing them. We might as well do that for ARM too.
--- virt/kvm/arm/arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/arm.c +1 -1
@@ -188,6 +188,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) kvm->vcpus[i] =NULL ; } } +atomic_set (&kvm->online_vcpus,0 ); }int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext)
@@ -296,7 +297,6 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) {kvm_mmu_free_memory_caches (vcpu);kvm_timer_vcpu_terminate (vcpu); -kvm_vgic_vcpu_destroy (vcpu);kvm_pmu_vcpu_destroy (vcpu);kvm_vcpu_uninit (vcpu);kmem_cache_free (kvm_vcpu_cache, vcpu);
Signature · 1 line
2.13.6
Hi Drew,
Quoted 5 lines · Andrew Jones
Recently commit
b2c9a85dd75a("KVM: arm/arm64: vgic: Movekvm_vgic_destroycall around") caught my eye. When I looked closer I saw that while it made the code saner, it wasn't changing anything.kvm_for_each_vcpu()checks for NULL kvm->vcpus[i], so there wasn't a NULL dereference being fixed, and becausekvm_vgic_vcpu_destroy()
Quoted 8 lines
was called by
kvm_arch_vcpu_free()it was still getting called, just not bykvm_vgic_destroy()as intended. But now the call fromkvm_arch_vcpu_free()is redundant, and while currently harmless, it should be removed in casekvm_vgic_vcpu_destroy()were ever to want to reference vgic state, askvm_vgic_destroy()now comes beforekvm_arch_vcpu_free(). Additionally the other architectures setkvm->online_vcpusto zero after freeing them. We might as well do that for ARM too.
Could this commit message be rewritten to:
kvm_vgic_vcpu_destroy already gets called from kvm_vgic_destroy for each vcpu, so we don't have to call it from kvm_arch_vcpu_free.
Additionally the other architectures set kvm->online_vcpus to zero after freeing them. We might as well do that for ARM too.
?
Thanks,
-Christoffer
Quoted 29 lines
Signed-off-by Andrew Jones <[email protected]>--- virt/kvm/arm/arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)virt/kvm/arm/arm.c +1
-1@@ -188,6 +188,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) kvm->vcpus[i] =NULL ; } } +atomic_set (&kvm->online_vcpus,0 ); }int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext)@@ -296,7 +297,6 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) {kvm_mmu_free_memory_caches (vcpu);kvm_timer_vcpu_terminate (vcpu); -kvm_vgic_vcpu_destroy (vcpu);kvm_pmu_vcpu_destroy (vcpu);kvm_vcpu_uninit (vcpu);kmem_cache_free (kvm_vcpu_cache, vcpu);Signature · 1 line
2.13.6
Quoted 17 lines · Christoffer Dall
Hi Drew,
Quoted 5 lines · Andrew Jones
Recently commit
b2c9a85dd75a("KVM: arm/arm64: vgic: Movekvm_vgic_destroycall around") caught my eye. When I looked closer I saw that while it made the code saner, it wasn't changing anything.kvm_for_each_vcpu()checks for NULL kvm->vcpus[i], so there wasn't a NULL dereference being fixed, and becausekvm_vgic_vcpu_destroy()Quoted 8 lines
was called by
kvm_arch_vcpu_free()it was still getting called, just not bykvm_vgic_destroy()as intended. But now the call fromkvm_arch_vcpu_free()is redundant, and while currently harmless, it should be removed in casekvm_vgic_vcpu_destroy()were ever to want to reference vgic state, askvm_vgic_destroy()now comes beforekvm_arch_vcpu_free(). Additionally the other architectures setkvm->online_vcpusto zero after freeing them. We might as well do that for ARM too.
Quoted 7 lines
Could this commit message be rewritten to:
kvm_vgic_vcpu_destroyalready gets called fromkvm_vgic_destroyfor each vcpu, so we don't have to call it fromkvm_arch_vcpu_free.Additionally the other architectures set
kvm->online_vcpusto zero after freeing them. We might as well do that for ARM too.
Sure, I don't mind you removing the '-v' (verbose) from it. Should I respin? Or is that something you don't mind doing while applying?
Thanks,
drew
Quoted 37 lines
?
Thanks,
-ChristofferQuoted 29 lines
Signed-off-by Andrew Jones <[email protected]>--- virt/kvm/arm/arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)virt/kvm/arm/arm.c +1
-1@@ -188,6 +188,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) kvm->vcpus[i] =NULL ; } } +atomic_set (&kvm->online_vcpus,0 ); }int kvm_vm_ioctl_check_extension (struct kvm *kvm,long ext)@@ -296,7 +297,6 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) {kvm_mmu_free_memory_caches (vcpu);kvm_timer_vcpu_terminate (vcpu); -kvm_vgic_vcpu_destroy (vcpu);kvm_pmu_vcpu_destroy (vcpu);kvm_vcpu_uninit (vcpu);kmem_cache_free (kvm_vcpu_cache, vcpu);Signature · 1 line
2.13.6
Quoted 20 lines · Andrew Jones
Quoted 19 lines · Christoffer Dall
Hi Drew,
Quoted 5 lines · Andrew Jones
Recently commit
b2c9a85dd75a("KVM: arm/arm64: vgic: Movekvm_vgic_destroycall around") caught my eye. When I looked closer I saw that while it made the code saner, it wasn't changing anything.kvm_for_each_vcpu()checks for NULL kvm->vcpus[i], so there wasn't a NULL dereference being fixed, and becausekvm_vgic_vcpu_destroy()Quoted 8 lines
was called by
kvm_arch_vcpu_free()it was still getting called, just not bykvm_vgic_destroy()as intended. But now the call fromkvm_arch_vcpu_free()is redundant, and while currently harmless, it should be removed in casekvm_vgic_vcpu_destroy()were ever to want to reference vgic state, askvm_vgic_destroy()now comes beforekvm_arch_vcpu_free(). Additionally the other architectures setkvm->online_vcpusto zero after freeing them. We might as well do that for ARM too.Could this commit message be rewritten to:
Quoted 9 lines
Quoted 5 lines
kvm_vgic_vcpu_destroyalready gets called fromkvm_vgic_destroyfor each vcpu, so we don't have to call it fromkvm_arch_vcpu_free.Additionally the other architectures set
kvm->online_vcpusto zero after freeing them. We might as well do that for ARM too.Sure, I don't mind you removing the '-v' (verbose) from it. Should I respin? Or is that something you don't mind doing while applying?
No need to respin, I already applied your patch with the adjusted commit message.
Thanks,
-Christoffer