[PATCH v7 5/5] HV: Reset physical core of lapic_pt vm when shutdown


Kaige Fu
 

The physical core of lapic_pt vm should be reset for security and
correctness when shutdown the vm.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
hypervisor/arch/x86/guest/vm.c | 20 +++++++++++++++++++-
hypervisor/include/lib/errno.h | 2 ++
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c
index cebbc9cc..8a66973c 100644
--- a/hypervisor/arch/x86/guest/vm.c
+++ b/hypervisor/arch/x86/guest/vm.c
@@ -446,9 +446,10 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
int32_t shutdown_vm(struct acrn_vm *vm)
{
uint16_t i;
+ uint64_t mask = 0UL;
struct acrn_vcpu *vcpu = NULL;
struct acrn_vm_config *vm_config = NULL;
- int32_t ret;
+ int32_t ret = 0;

pause_vm(vm);

@@ -459,6 +460,23 @@ int32_t shutdown_vm(struct acrn_vm *vm)
foreach_vcpu(i, vm, vcpu) {
reset_vcpu(vcpu);
offline_vcpu(vcpu);
+
+ if (is_lapic_pt(vm)) {
+ bitmap_set_nolock(vcpu->pcpu_id, &mask);
+ }
+ }
+
+ if (is_lapic_pt(vm) && !stop_cpus(mask)) {
+ pr_fatal("Failed to stop all cpus in mask(0x%llx)", mask);
+ }
+
+ /*
+ * No matter whether there are cpus failed to offline, try to start all
+ * cpus in mask anyway.
+ */
+ if (is_lapic_pt(vm) && !start_cpus(mask)) {
+ pr_fatal("Failed to start all cpus in mask(0x%llx)", mask);
+ ret = -ETIMEDOUT;
}

vm_config = get_vm_config(vm->vm_id);
diff --git a/hypervisor/include/lib/errno.h b/hypervisor/include/lib/errno.h
index b97112f5..bc8c0db7 100644
--- a/hypervisor/include/lib/errno.h
+++ b/hypervisor/include/lib/errno.h
@@ -23,5 +23,7 @@
#define ENODEV 19
/** Indicates that argument is not valid. */
#define EINVAL 22
+/** Indicates that timeout occurs. */
+#define ETIMEDOUT 110

#endif /* ERRNO_H */
--
2.20.0

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.