dm: Reset virtio device before release

With virtio polling mode enabled, a timer is running in the virtio
backend service. And the timer will also be triggered if its frondend
driver didn't do the device reset in shutdown. A freed virtio device
will be accessed in the polling timer handler.

Do the virtio reset() callback specifically to clear the polling timer
before the free.

Tracked-On: #6147
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
This commit is contained in:
Yonghua Huang 2021-07-01 16:42:44 +08:00 committed by wenlingz
parent 65a957dff8
commit 2b91780b4e
12 changed files with 15 additions and 1 deletions

View File

@ -372,6 +372,7 @@ virtio_audio_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
close(virt_audio->vbs_k.audio_fd); close(virt_audio->vbs_k.audio_fd);
virt_audio->vbs_k.audio_fd = -1; virt_audio->vbs_k.audio_fd = -1;
} }
virtio_audio_reset(virt_audio);
pthread_mutex_destroy(&virt_audio->mtx); pthread_mutex_destroy(&virt_audio->mtx);
DPRINTF(("%s: free struct virtio_audio!\n", __func__)); DPRINTF(("%s: free struct virtio_audio!\n", __func__));
free((struct virtio_audio *)dev->arg); free((struct virtio_audio *)dev->arg);

View File

@ -482,6 +482,7 @@ virtio_blk_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
WPRINTF(("vrito_blk:" WPRINTF(("vrito_blk:"
"Failed to flush before close\n")); "Failed to flush before close\n"));
blockif_close(bctxt); blockif_close(bctxt);
virtio_reset_dev(&blk->base);
free(blk); free(blk);
} }
} }

View File

@ -740,6 +740,7 @@ static void
virtio_console_destroy(struct virtio_console *console) virtio_console_destroy(struct virtio_console *console)
{ {
if (console) { if (console) {
virtio_console_reset(console);
if (console->config) if (console->config)
free(console->config); free(console->config);
free(console); free(console);

View File

@ -341,6 +341,7 @@ virtio_coreu_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
pthread_cond_destroy(&vcoreu->rx_cond); pthread_cond_destroy(&vcoreu->rx_cond);
pthread_join(vcoreu->rx_tid, NULL); pthread_join(vcoreu->rx_tid, NULL);
virtio_coreu_reset(vcoreu);
free(vcoreu); free(vcoreu);
} }

View File

@ -466,6 +466,7 @@ virtio_hdcp_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
if (vhdcp) { if (vhdcp) {
DPRINTF(("free struct virtio_hdcp\n")); DPRINTF(("free struct virtio_hdcp\n"));
virtio_hdcp_reset(vhdcp);
free(vhdcp); free(vhdcp);
} }
} }

View File

@ -348,8 +348,10 @@ virtio_hyper_dmabuf_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
vbs_k_hyper_dmabuf_fd = -1; vbs_k_hyper_dmabuf_fd = -1;
} }
if (dev->arg) if (dev->arg) {
virtio_hyper_dmabuf_reset(dev->arg);
free((struct virtio_hyper_dmabuf *)dev->arg); free((struct virtio_hyper_dmabuf *)dev->arg);
}
} }
struct pci_vdev_ops pci_ops_virtio_hyper_dmabuf = { struct pci_vdev_ops pci_ops_virtio_hyper_dmabuf = {

View File

@ -559,6 +559,8 @@ virtio_input_teardown(void *param)
free(vi->evdev); free(vi->evdev);
if (vi->serial) if (vi->serial)
free(vi->serial); free(vi->serial);
virtio_input_reset(vi);
free(vi); free(vi);
vi = NULL; vi = NULL;
} }

View File

@ -379,6 +379,7 @@ virtio_ipu_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
close(ipu->vbs_k.ipu_fd); close(ipu->vbs_k.ipu_fd);
ipu->vbs_k.ipu_fd = -1; ipu->vbs_k.ipu_fd = -1;
} }
virtio_ipu_reset(ipu);
pthread_mutex_destroy(&ipu->mtx); pthread_mutex_destroy(&ipu->mtx);
free(ipu); free(ipu);
} }

View File

@ -976,6 +976,7 @@ vmei_reset_teardown(void *param)
vmei->reset_mevp = NULL; vmei->reset_mevp = NULL;
pthread_mutex_destroy(&vmei->mutex); pthread_mutex_destroy(&vmei->mutex);
virtio_reset_dev(&vmei->base);
free(vmei->config); free(vmei->config);
free(vmei); free(vmei);
} }

View File

@ -975,6 +975,7 @@ virtio_net_teardown(void *param)
} else } else
fprintf(stderr, "net->tapfd is -1!\n"); fprintf(stderr, "net->tapfd is -1!\n");
virtio_reset_dev(&net->base);
free(net); free(net);
} }

View File

@ -492,6 +492,7 @@ virtio_rnd_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
assert(rnd->fd >= 0); assert(rnd->fd >= 0);
close(rnd->fd); close(rnd->fd);
DPRINTF(("%s: free struct virtio_rnd!\n", __func__)); DPRINTF(("%s: free struct virtio_rnd!\n", __func__));
virtio_rnd_reset(rnd);
free(rnd); free(rnd);
} }

View File

@ -777,6 +777,7 @@ virtio_rpmb_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
{ {
if (dev->arg) { if (dev->arg) {
DPRINTF(("virtio_rpmb_be_deinit: free struct virtio_rpmb!\n")); DPRINTF(("virtio_rpmb_be_deinit: free struct virtio_rpmb!\n"));
virtio_rpmb_reset(dev->arg);
free((struct virtio_rpmb *)dev->arg); free((struct virtio_rpmb *)dev->arg);
} }
} }