hv: vm: Move reset_vm to common scope

Move reset_vm to common scope and remove unused reset_mode.

The reset_mode in x86 reset_vm code is simply used as an if condition
on whether the prepare_os_image should be executed. The entire
if body will never be true as we don't support resetting Service VM
without resetting ACRN hypervisor. To reset Service VM, the only
way is through a platform reset. Therefore the prepare_os_image
action will never be called. Delete this action.

Once the if condition and prepare_os_image action is deleted,
the input parameter "mode" is useless. Delete that too. The reset_vm
API in ACRN is simply a "warm reset". It does not need to take
input.

Tracked-On: #8830
Signed-off-by: Yifan Liu <yifan1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang Yu1 <yu1.wang@intel.com>
This commit is contained in:
Yifan Liu
2025-09-13 07:45:28 +00:00
committed by acrnsi-robot
parent e0130295b5
commit a4f136188c
5 changed files with 31 additions and 17 deletions

View File

@@ -98,14 +98,6 @@ bool is_created_vm(const struct acrn_vm *vm)
return (vm->state == VM_CREATED);
}
/**
* @pre vm != NULL
*/
bool is_paused_vm(const struct acrn_vm *vm)
{
return (vm->state == VM_PAUSED);
}
bool is_service_vm(const struct acrn_vm *vm)
{
return (vm != NULL) && (get_vm_config(vm->vm_id)->load_order == SERVICE_VM);
@@ -869,7 +861,7 @@ void arch_vm_prepare_bsp(struct acrn_vcpu *bsp)
* @pre vm != NULL
* @pre vm->state == VM_PAUSED
*/
int32_t reset_vm(struct acrn_vm *vm, enum reset_mode mode)
int32_t arch_reset_vm(struct acrn_vm *vm)
{
uint16_t i;
uint64_t mask;
@@ -890,16 +882,11 @@ int32_t reset_vm(struct acrn_vm *vm, enum reset_mode mode)
*/
vm->arch_vm.vlapic_mode = VM_VLAPIC_XAPIC;
if ((mode == POWER_ON_RESET) && is_service_vm(vm)) {
(void)prepare_os_image(vm);
}
reset_vm_ioreqs(vm);
reset_vioapics(vm);
destroy_secure_world(vm, false);
vm->arch_vm.sworld_control.flag.active = 0UL;
vm->arch_vm.iwkey_backup_status = 0UL;
vm->state = VM_CREATED;
return ret;
}
@@ -933,7 +920,7 @@ void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec)
{
struct acrn_vcpu *bsp = vcpu_from_vid(vm, BSP_CPU_ID);
reset_vm(vm, RESUME_FROM_S3);
reset_vm(vm);
/* When Service VM resume from S3, it will return to real mode
* with entry set to wakeup_vec.

View File

@@ -348,7 +348,7 @@ int32_t hcall_reset_vm(__unused struct acrn_vcpu *vcpu, struct acrn_vm *target_v
if (is_paused_vm(target_vm)) {
/* TODO: check target_vm guest_flags */
ret = reset_vm(target_vm, COLD_RESET);
ret = reset_vm(target_vm);
}
return ret;
}

View File

@@ -15,6 +15,14 @@ static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE);
static struct acrn_vm *service_vm_ptr = NULL;
/**
* @pre vm != NULL
*/
bool is_paused_vm(const struct acrn_vm *vm)
{
return (vm->state == VM_PAUSED);
}
/**
* @pre vm_config != NULL
*/
@@ -243,3 +251,21 @@ int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *v
return status;
}
/**
* "Warm" reset a VM.
* To "Cold" reset a VM, simply destroy and re-create.
*
* @pre vm->state == VM_PAUSED
*/
int32_t reset_vm(struct acrn_vm *vm)
{
int32_t ret = -1;
ret = arch_reset_vm(vm);
if (ret == 0) {
vm->state = VM_CREATED;
}
return ret;
}

View File

@@ -131,7 +131,6 @@ void make_shutdown_vm_request(uint16_t pcpu_id);
bool need_shutdown_vm(uint16_t pcpu_id);
void poweroff_if_rt_vm(struct acrn_vm *vm);
void resume_vm_from_s3(struct acrn_vm *vm, uint32_t wakeup_vec);
int32_t reset_vm(struct acrn_vm *vm, enum reset_mode mode);
bool is_created_vm(const struct acrn_vm *vm);
bool is_service_vm(const struct acrn_vm *vm);
bool is_postlaunched_vm(const struct acrn_vm *vm);

View File

@@ -153,12 +153,14 @@ void arch_trigger_level_intr(__unused struct acrn_vm *vm,
int32_t arch_init_vm(struct acrn_vm *vm, struct acrn_vm_config *vm_config);
int32_t arch_deinit_vm(struct acrn_vm *vm);
void arch_vm_prepare_bsp(struct acrn_vcpu *bsp);
int32_t arch_reset_vm(struct acrn_vm *vm);
int32_t create_vm(uint16_t vm_id, uint64_t pcpu_bitmap, struct acrn_vm_config *vm_config, struct acrn_vm **rtn_vm);
void launch_vms(uint16_t pcpu_id);
void start_vm(struct acrn_vm *vm);
void pause_vm(struct acrn_vm *vm);
int32_t destroy_vm(struct acrn_vm *vm);
int32_t reset_vm(struct acrn_vm *vm);
#endif /* !ASSEMBLER */