mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-11-20 03:35:00 +00:00
hv: vcpu: Move offline_vcpu to common vcpu.c and rename to destroy_vcpu
destroy_vcpu: Call arch_deinit_vcpu, and do common deinit. 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:
@@ -756,15 +756,9 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu)
|
|||||||
* @pre vcpu != NULL
|
* @pre vcpu != NULL
|
||||||
* @pre vcpu->state == VCPU_ZOMBIE
|
* @pre vcpu->state == VCPU_ZOMBIE
|
||||||
*/
|
*/
|
||||||
void offline_vcpu(struct acrn_vcpu *vcpu)
|
void arch_deinit_vcpu(struct acrn_vcpu *vcpu)
|
||||||
{
|
{
|
||||||
vlapic_free(vcpu);
|
vlapic_free(vcpu);
|
||||||
per_cpu(ever_run_vcpu, pcpuid_from_vcpu(vcpu)) = NULL;
|
|
||||||
|
|
||||||
/* This operation must be atomic to avoid contention with posted interrupt handler */
|
|
||||||
per_cpu(vcpu_array, pcpuid_from_vcpu(vcpu))[vcpu->vm->vm_id] = NULL;
|
|
||||||
|
|
||||||
vcpu_set_state(vcpu, VCPU_OFFLINE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kick_vcpu(struct acrn_vcpu *vcpu)
|
void kick_vcpu(struct acrn_vcpu *vcpu)
|
||||||
@@ -961,7 +955,7 @@ uint64_t vcpumask2pcpumask(struct acrn_vm *vm, uint64_t vdmask)
|
|||||||
* VT-d PI handler, find the corresponding vCPU for this IRQ,
|
* VT-d PI handler, find the corresponding vCPU for this IRQ,
|
||||||
* if the associated PID's bit ON is set, wake it up.
|
* if the associated PID's bit ON is set, wake it up.
|
||||||
*
|
*
|
||||||
* shutdown_vm would unregister the devices before offline_vcpu is called,
|
* shutdown_vm would unregister the devices before destroy_vcpu is called,
|
||||||
* so spinlock is not needed to protect access to vcpu_array and vcpu.
|
* so spinlock is not needed to protect access to vcpu_array and vcpu.
|
||||||
*
|
*
|
||||||
* @pre (vcpu_index < CONFIG_MAX_VM_NUM) && (get_pi_desc(get_cpu_var(vcpu_array)[vcpu_index]) != NULL)
|
* @pre (vcpu_index < CONFIG_MAX_VM_NUM) && (get_pi_desc(get_cpu_var(vcpu_array)[vcpu_index]) != NULL)
|
||||||
|
|||||||
@@ -955,7 +955,7 @@ int32_t shutdown_vm(struct acrn_vm *vm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach_vcpu(i, vm, vcpu) {
|
foreach_vcpu(i, vm, vcpu) {
|
||||||
offline_vcpu(vcpu);
|
destroy_vcpu(vcpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HYPERV_ENABLED
|
#ifdef CONFIG_HYPERV_ENABLED
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ int32_t hcall_service_vm_offline_cpu(struct acrn_vcpu *vcpu, __unused struct acr
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
zombie_vcpu(target_vcpu, VCPU_ZOMBIE);
|
zombie_vcpu(target_vcpu, VCPU_ZOMBIE);
|
||||||
offline_vcpu(target_vcpu);
|
destroy_vcpu(target_vcpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,3 +130,20 @@ int32_t create_vcpu(struct acrn_vm *vm, uint16_t pcpu_id)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @pre vcpu != NULL
|
||||||
|
* @pre vcpu->state == VCPU_ZOMBIE
|
||||||
|
*/
|
||||||
|
void destroy_vcpu(struct acrn_vcpu *vcpu)
|
||||||
|
{
|
||||||
|
arch_deinit_vcpu(vcpu);
|
||||||
|
|
||||||
|
/* TODO: Move ever_run_vcpu to x86 specific */
|
||||||
|
per_cpu(ever_run_vcpu, pcpuid_from_vcpu(vcpu)) = NULL;
|
||||||
|
|
||||||
|
/* This operation must be atomic to avoid contention with posted interrupt handler */
|
||||||
|
per_cpu(vcpu_array, pcpuid_from_vcpu(vcpu))[vcpu->vm->vm_id] = NULL;
|
||||||
|
|
||||||
|
vcpu_set_state(vcpu, VCPU_OFFLINE);
|
||||||
|
}
|
||||||
|
|||||||
@@ -549,17 +549,6 @@ void load_iwkey(struct acrn_vcpu *vcpu);
|
|||||||
*/
|
*/
|
||||||
int32_t run_vcpu(struct acrn_vcpu *vcpu);
|
int32_t run_vcpu(struct acrn_vcpu *vcpu);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief unmap the vcpu with pcpu and free its vlapic
|
|
||||||
*
|
|
||||||
* Unmap the vcpu with pcpu and free its vlapic, and set the vcpu state to offline
|
|
||||||
*
|
|
||||||
* @param[inout] vcpu pointer to vcpu data structure
|
|
||||||
* @pre vcpu != NULL
|
|
||||||
* @pre vcpu->state == VCPU_ZOMBIE
|
|
||||||
*/
|
|
||||||
void offline_vcpu(struct acrn_vcpu *vcpu);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief reset vcpu state and values
|
* @brief reset vcpu state and values
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ struct per_cpu_arch {
|
|||||||
struct acrn_vcpu *whose_iwkey;
|
struct acrn_vcpu *whose_iwkey;
|
||||||
uint32_t kick_pcpu_mode;
|
uint32_t kick_pcpu_mode;
|
||||||
uint32_t idle_mode;
|
uint32_t idle_mode;
|
||||||
|
|
||||||
} __aligned(PAGE_SIZE); /* per_cpu_region size aligned with PAGE_SIZE */
|
} __aligned(PAGE_SIZE); /* per_cpu_region size aligned with PAGE_SIZE */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ struct per_cpu_region {
|
|||||||
* share same pCPU. So the maximum possible # of vCPUs that can
|
* share same pCPU. So the maximum possible # of vCPUs that can
|
||||||
* run on a pCPU is CONFIG_MAX_VM_NUM.
|
* run on a pCPU is CONFIG_MAX_VM_NUM.
|
||||||
* vcpu_array address must be aligned to 64-bit for atomic access
|
* vcpu_array address must be aligned to 64-bit for atomic access
|
||||||
* to avoid contention between offline_vcpu and posted interrupt handler
|
* to avoid contention between destroy_vcpu and posted interrupt handler
|
||||||
*/
|
*/
|
||||||
struct acrn_vcpu *vcpu_array[CONFIG_MAX_VM_NUM] __aligned(8);
|
struct acrn_vcpu *vcpu_array[CONFIG_MAX_VM_NUM] __aligned(8);
|
||||||
struct shared_buf *sbuf[ACRN_SBUF_PER_PCPU_ID_MAX];
|
struct shared_buf *sbuf[ACRN_SBUF_PER_PCPU_ID_MAX];
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ void vcpu_set_state(struct acrn_vcpu *vcpu, enum vcpu_state new_state);
|
|||||||
|
|
||||||
uint16_t pcpuid_from_vcpu(const struct acrn_vcpu *vcpu);
|
uint16_t pcpuid_from_vcpu(const struct acrn_vcpu *vcpu);
|
||||||
int32_t arch_init_vcpu(struct acrn_vcpu *vcpu);
|
int32_t arch_init_vcpu(struct acrn_vcpu *vcpu);
|
||||||
|
void arch_deinit_vcpu(struct acrn_vcpu *vcpu);
|
||||||
|
|
||||||
void arch_vcpu_thread(struct thread_object *obj);
|
void arch_vcpu_thread(struct thread_object *obj);
|
||||||
void arch_context_switch_out(struct thread_object *prev);
|
void arch_context_switch_out(struct thread_object *prev);
|
||||||
@@ -117,6 +118,17 @@ uint64_t arch_build_stack_frame(struct acrn_vcpu *vcpu);
|
|||||||
*/
|
*/
|
||||||
int32_t create_vcpu(struct acrn_vm *vm, uint16_t pcpu_id);
|
int32_t create_vcpu(struct acrn_vm *vm, uint16_t pcpu_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy a vcpu structure
|
||||||
|
*
|
||||||
|
* Unmap the vcpu with pcpu and deinitialize a vcpu structure
|
||||||
|
*
|
||||||
|
* @param[inout] vcpu pointer to vcpu data structure
|
||||||
|
* @pre vcpu != NULL
|
||||||
|
* @pre vcpu->state == VCPU_ZOMBIE
|
||||||
|
*/
|
||||||
|
void destroy_vcpu(struct acrn_vcpu *vcpu);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user