mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-05 15:06:58 +00:00
dm: release host memory after devices de-init
Devices' de-init process might access some mapped memory space, such as virtio virtqueues. Access after unmap will cause a fault. Release the memory map after de-init processes can avoid it. Reading more code, there are many error handling lost to unmap the memory. Refined the code to do it. Signed-off-by: Liu Shuo <shuo.a.liu@intel.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
parent
cee499f867
commit
ee43f23b0e
@ -92,8 +92,6 @@ static const int BSP;
|
|||||||
|
|
||||||
static cpuset_t cpumask;
|
static cpuset_t cpumask;
|
||||||
|
|
||||||
static void do_close_pre(struct vmctx *ctx);
|
|
||||||
static void do_close_post(struct vmctx *ctx);
|
|
||||||
static void vm_loop(struct vmctx *ctx);
|
static void vm_loop(struct vmctx *ctx);
|
||||||
|
|
||||||
static int quit_vm_loop;
|
static int quit_vm_loop;
|
||||||
@ -531,24 +529,6 @@ do_open(const char *vmname)
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
do_close_pre(struct vmctx *ctx)
|
|
||||||
{
|
|
||||||
vm_destroy(ctx);
|
|
||||||
vm_close(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
do_close_post(struct vmctx *ctx)
|
|
||||||
{
|
|
||||||
pci_irq_deinit(ctx);
|
|
||||||
deinit_pci(ctx);
|
|
||||||
atkbdc_deinit(ctx);
|
|
||||||
vrtc_deinit(ctx);
|
|
||||||
vm_destroy(ctx);
|
|
||||||
vm_close(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sig_handler_term(int signo)
|
sig_handler_term(int signo)
|
||||||
{
|
{
|
||||||
@ -768,30 +748,26 @@ main(int argc, char *argv[])
|
|||||||
/* set IOReq buffer page */
|
/* set IOReq buffer page */
|
||||||
error = vm_set_shared_io_page(ctx, (unsigned long)vhm_req_buf);
|
error = vm_set_shared_io_page(ctx, (unsigned long)vhm_req_buf);
|
||||||
if (error)
|
if (error)
|
||||||
do_close_pre(ctx);
|
goto fail;
|
||||||
assert(error == 0);
|
|
||||||
|
|
||||||
if (guest_ncpus < 1) {
|
if (guest_ncpus < 1) {
|
||||||
fprintf(stderr, "Invalid guest vCPUs (%d)\n",
|
fprintf(stderr, "Invalid guest vCPUs (%d)\n",
|
||||||
guest_ncpus);
|
guest_ncpus);
|
||||||
do_close_pre(ctx);
|
goto fail;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
max_vcpus = num_vcpus_allowed(ctx);
|
max_vcpus = num_vcpus_allowed(ctx);
|
||||||
if (guest_ncpus > max_vcpus) {
|
if (guest_ncpus > max_vcpus) {
|
||||||
fprintf(stderr, "%d vCPUs requested but %d available\n",
|
fprintf(stderr, "%d vCPUs requested but %d available\n",
|
||||||
guest_ncpus, max_vcpus);
|
guest_ncpus, max_vcpus);
|
||||||
do_close_pre(ctx);
|
goto fail;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vm_set_memflags(ctx, memflags);
|
vm_set_memflags(ctx, memflags);
|
||||||
err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);
|
err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL);
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf(stderr, "Unable to setup memory (%d)\n", errno);
|
fprintf(stderr, "Unable to setup memory (%d)\n", errno);
|
||||||
do_close_pre(ctx);
|
goto fail;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_mem();
|
init_mem();
|
||||||
@ -809,8 +785,7 @@ main(int argc, char *argv[])
|
|||||||
* initialization
|
* initialization
|
||||||
*/
|
*/
|
||||||
if (init_pci(ctx) != 0) {
|
if (init_pci(ctx) != 0) {
|
||||||
do_close_pre(ctx);
|
goto pci_fail;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gdb_port != 0)
|
if (gdb_port != 0)
|
||||||
@ -825,27 +800,23 @@ main(int argc, char *argv[])
|
|||||||
if (mptgen) {
|
if (mptgen) {
|
||||||
error = mptable_build(ctx, guest_ncpus);
|
error = mptable_build(ctx, guest_ncpus);
|
||||||
if (error) {
|
if (error) {
|
||||||
do_close_post(ctx);
|
goto vm_fail;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error = smbios_build(ctx);
|
error = smbios_build(ctx);
|
||||||
if (error)
|
if (error)
|
||||||
do_close_post(ctx);
|
goto vm_fail;
|
||||||
assert(error == 0);
|
|
||||||
|
|
||||||
if (acpi) {
|
if (acpi) {
|
||||||
error = acpi_build(ctx, guest_ncpus);
|
error = acpi_build(ctx, guest_ncpus);
|
||||||
if (error)
|
if (error)
|
||||||
do_close_post(ctx);
|
goto vm_fail;
|
||||||
assert(error == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error = acrn_sw_load(ctx);
|
error = acrn_sw_load(ctx);
|
||||||
if (error)
|
if (error)
|
||||||
do_close_post(ctx);
|
goto vm_fail;
|
||||||
assert(error == 0);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Change the proc title to include the VM name.
|
* Change the proc title to include the VM name.
|
||||||
@ -865,16 +836,34 @@ main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
mevent_dispatch();
|
mevent_dispatch();
|
||||||
|
|
||||||
monitor_close();
|
|
||||||
vm_pause(ctx);
|
vm_pause(ctx);
|
||||||
fbsdrun_deletecpu(ctx, BSP);
|
fbsdrun_deletecpu(ctx, BSP);
|
||||||
vm_unsetup_memory(ctx);
|
|
||||||
do_close_post(ctx);
|
|
||||||
_ctx = 0;
|
|
||||||
|
|
||||||
if (vm_get_suspend_mode() != VM_SUSPEND_RESET)
|
if (vm_get_suspend_mode() != VM_SUSPEND_RESET)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
pci_irq_deinit(ctx);
|
||||||
|
deinit_pci(ctx);
|
||||||
|
monitor_close();
|
||||||
|
vrtc_deinit(ctx);
|
||||||
|
atkbdc_deinit(ctx);
|
||||||
|
vm_unsetup_memory(ctx);
|
||||||
|
vm_destroy(ctx);
|
||||||
|
vm_close(ctx);
|
||||||
|
_ctx = 0;
|
||||||
|
|
||||||
vm_set_suspend_mode(VM_SUSPEND_NONE);
|
vm_set_suspend_mode(VM_SUSPEND_NONE);
|
||||||
}
|
}
|
||||||
|
vm_fail:
|
||||||
|
pci_irq_deinit(ctx);
|
||||||
|
deinit_pci(ctx);
|
||||||
|
pci_fail:
|
||||||
|
monitor_close();
|
||||||
|
vrtc_deinit(ctx);
|
||||||
|
atkbdc_deinit(ctx);
|
||||||
|
vm_unsetup_memory(ctx);
|
||||||
|
fail:
|
||||||
|
vm_destroy(ctx);
|
||||||
|
vm_close(ctx);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user