Skip to content

Commit 4c4c125

Browse files
Shuo Liugregkh
authored andcommitted
virt: acrn: Do hcall_destroy_vm() before resource release
The ACRN hypervisor has scenarios which could run a real-time guest VM. The real-time guest VM occupies dedicated CPU cores, be assigned with dedicated PCI devices. It can run without the Service VM after boot up. hcall_destroy_vm() returns failure when a real-time guest VM refuses. The clearing of flag ACRN_VM_FLAG_DESTROYED causes some kernel resource double-freed in a later acrn_vm_destroy(). Do hcall_destroy_vm() before resource release to drop this chance to destroy the VM if hypercall fails. Fixes: 9c5137a ("virt: acrn: Introduce VM management interfaces") Cc: stable <[email protected]> Signed-off-by: Shuo Liu <[email protected]> Signed-off-by: Fei Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff11764 commit 4c4c125

File tree

1 file changed

+8
-8
lines changed
  • drivers/virt/acrn

1 file changed

+8
-8
lines changed

drivers/virt/acrn/vm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ int acrn_vm_destroy(struct acrn_vm *vm)
6464
test_and_set_bit(ACRN_VM_FLAG_DESTROYED, &vm->flags))
6565
return 0;
6666

67+
ret = hcall_destroy_vm(vm->vmid);
68+
if (ret < 0) {
69+
dev_err(acrn_dev.this_device,
70+
"Failed to destroy VM %u\n", vm->vmid);
71+
clear_bit(ACRN_VM_FLAG_DESTROYED, &vm->flags);
72+
return ret;
73+
}
74+
6775
/* Remove from global VM list */
6876
write_lock_bh(&acrn_vm_list_lock);
6977
list_del_init(&vm->list);
@@ -78,14 +86,6 @@ int acrn_vm_destroy(struct acrn_vm *vm)
7886
vm->monitor_page = NULL;
7987
}
8088

81-
ret = hcall_destroy_vm(vm->vmid);
82-
if (ret < 0) {
83-
dev_err(acrn_dev.this_device,
84-
"Failed to destroy VM %u\n", vm->vmid);
85-
clear_bit(ACRN_VM_FLAG_DESTROYED, &vm->flags);
86-
return ret;
87-
}
88-
8989
acrn_vm_all_ram_unmap(vm);
9090

9191
dev_dbg(acrn_dev.this_device, "VM %u destroyed.\n", vm->vmid);

0 commit comments

Comments
 (0)