When the vCPU is destroyed, we must free the space allocated to the dirty quota context for the vCPU. Co-developed-by: Anurag Madnawat <anurag.madnawat@xxxxxxxxxxx> Signed-off-by: Anurag Madnawat <anurag.madnawat@xxxxxxxxxxx> Signed-off-by: Shivam Kumar <shivam.kumar1@xxxxxxxxxxx> Signed-off-by: Shaju Abraham <shaju.abraham@xxxxxxxxxxx> Signed-off-by: Manish Mishra <manish.mishra@xxxxxxxxxxx> --- include/linux/dirty_quota_migration.h | 1 + virt/kvm/dirty_quota_migration.c | 6 ++++++ virt/kvm/kvm_main.c | 2 ++ 3 files changed, 9 insertions(+) diff --git a/include/linux/dirty_quota_migration.h b/include/linux/dirty_quota_migration.h index f343c073f38d..d3ccab153d44 100644 --- a/include/linux/dirty_quota_migration.h +++ b/include/linux/dirty_quota_migration.h @@ -16,5 +16,6 @@ int kvm_vcpu_dirty_quota_alloc(struct vCPUDirtyQuotaContext **vCPUdqctx); struct page *kvm_dirty_quota_context_get_page( struct vCPUDirtyQuotaContext *vCPUdqctx, u32 offset); bool is_dirty_quota_full(struct vCPUDirtyQuotaContext *vCPUdqctx); +void kvm_vcpu_dirty_quota_free(struct vCPUDirtyQuotaContext **vCPUdqctx); #endif /* DIRTY_QUOTA_MIGRATION_H */ diff --git a/virt/kvm/dirty_quota_migration.c b/virt/kvm/dirty_quota_migration.c index eeef19347af4..3f74af2ccab9 100644 --- a/virt/kvm/dirty_quota_migration.c +++ b/virt/kvm/dirty_quota_migration.c @@ -23,3 +23,9 @@ bool is_dirty_quota_full(struct vCPUDirtyQuotaContext *vCPUdqctx) { return (vCPUdqctx->dirty_counter >= vCPUdqctx->dirty_quota); } + +void kvm_vcpu_dirty_quota_free(struct vCPUDirtyQuotaContext **vCPUdqctx) +{ + vfree(*vCPUdqctx); + *vCPUdqctx = NULL; +} diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c41b85af8682..30fce3f93ce0 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -430,6 +430,7 @@ static void kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id) void kvm_vcpu_destroy(struct kvm_vcpu *vcpu) { + kvm_vcpu_dirty_quota_free(&vcpu->vCPUdqctx); kvm_dirty_ring_free(&vcpu->dirty_ring); kvm_arch_vcpu_destroy(vcpu); @@ -3683,6 +3684,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) unlock_vcpu_destroy: mutex_unlock(&kvm->lock); + kvm_vcpu_dirty_quota_free(&vcpu->vCPUdqctx); kvm_dirty_ring_free(&vcpu->dirty_ring); arch_vcpu_destroy: kvm_arch_vcpu_destroy(vcpu); -- 2.22.3