From 611944c018b27938efb9821ad04fb56b1e7e481e Mon Sep 17 00:00:00 2001 From: Shuo Liu Date: Mon, 19 Nov 2018 14:31:25 +0800 Subject: [PATCH] dm: Fix race between ioreq client destroy and access vcpu thread need to exit when doing VM full reset and VM shutdown. Change the code to align the logic. This also can fix race condition between ioreq client destruction and accessing. Tracked-On: #1857 Signed-off-by: Fengwei Yin Signed-off-by: Shuo Liu Acked-by: Yu Wang --- devicemodel/core/main.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 83a3d6012..6d6700d31 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -96,8 +96,6 @@ static cpuset_t cpumask; static void vm_loop(struct vmctx *ctx); -static int quit_vm_loop; - static char vhm_request_page[4096] __attribute__ ((aligned(4096))); static struct vhm_request *vhm_req_buf = @@ -286,11 +284,8 @@ delete_cpu(struct vmctx *ctx, int vcpu) exit(1); } - /* wait for vm_loop cleanup */ - quit_vm_loop = 1; + pthread_join(mt_vmm_info[0].mt_thr, NULL); vm_destroy_ioreq_client(ctx); - while (quit_vm_loop) - usleep(10000); CPU_CLR_ATOMIC(vcpu, &cpumask); return CPU_EMPTY(&cpumask); @@ -666,6 +661,11 @@ vm_loop(struct vmctx *ctx) handle_vmexit(ctx, vhm_req, vcpu_id); } + if (VM_SUSPEND_FULL_RESET == vm_get_suspend_mode() || + VM_SUSPEND_POWEROFF == vm_get_suspend_mode()) { + break; + } + if (VM_SUSPEND_SYSTEM_RESET == vm_get_suspend_mode()) { vm_system_reset(ctx); } @@ -674,7 +674,6 @@ vm_loop(struct vmctx *ctx) vm_suspend_resume(ctx); } } - quit_vm_loop = 0; printf("VM loop exit\n"); } @@ -756,7 +755,6 @@ dm_run(int argc, char *argv[]) guest_ncpus = 1; memsize = 256 * MB; mptgen = 1; - quit_vm_loop = 0; if (signal(SIGHUP, sig_handler_term) == SIG_ERR) fprintf(stderr, "cannot register handler for SIGHUP\n");