ACRN:DM: Fix the memory_leak of vga_context in virtio_gpu_deinit

Otherwise the memory related with vga_context is leaked.

v1->v2: Use the pthread_join instead of usleep to wait for
the termination of vga_thread.

Tracked-On: #7296
Acked-by: Wang Yu1 <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
This commit is contained in:
Zhao Yakui 2022-04-18 10:28:26 +08:00 committed by acrnsi-robot
parent 2e9773ed55
commit a555658484
3 changed files with 44 additions and 0 deletions

View File

@ -1644,6 +1644,20 @@ virtio_gpu_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
gpu = (struct virtio_gpu *)dev->arg;
gpu->vga.enable = false;
pthread_mutex_lock(&gpu->vga_thread_mtx);
if (atomic_load(&gpu->vga_thread_status) != VGA_THREAD_EOL) {
pthread_mutex_unlock(&gpu->vga_thread_mtx);
pthread_join(gpu->vga.tid, NULL);
} else
pthread_mutex_unlock(&gpu->vga_thread_mtx);
if (gpu->vga.dev)
vga_deinit(&gpu->vga);
if (gpu->vga.gc) {
gc_deinit(gpu->vga.gc);
gpu->vga.gc = NULL;
}
pthread_mutex_destroy(&gpu->vga_thread_mtx);
while (LIST_FIRST(&gpu->r2d_list)) {
r2d = LIST_FIRST(&gpu->r2d_list);

View File

@ -1426,3 +1426,32 @@ vga_vbe_read(struct vmctx *ctx, int vcpu, struct vga *vga,
return (value);
}
void vga_deinit(struct vga *vga)
{
struct vga_vdev *vd;
struct inout_port iop;
int port;
vd = (struct vga_vdev *)vga->dev;
for (port = VGA_IOPORT_START; port <= VGA_IOPORT_END; port++) {
iop.port = port;
iop.size = 1;
iop.flags = IOPORT_F_INOUT;
iop.handler = NULL;
iop.arg = NULL;
unregister_inout(&iop);
//error = unregister_inout(&iop);
//assert(error == 0);
}
unregister_mem_fallback(&vd->mr);
free(vd->vga_ram);
vd->vga_ram = NULL;
free(vd);
vga->dev = NULL;
}

View File

@ -199,4 +199,5 @@ void vga_vbe_write(struct vmctx *ctx, int vcpu, struct vga *vga,
uint64_t vga_vbe_read(struct vmctx *ctx, int vcpu, struct vga *vga,
uint64_t offset, int size);
void vga_deinit(struct vga *vga);
#endif /* _VGA_H_ */