Skip to content

Commit 8ad0fd9

Browse files
ZideChen0wenlingz
authored andcommitted
hv: implement NEED_SHUTDOWN_VM request to idle thread
For pre-launched VMs and SOS, VM shutdown should not be executed in the current VM context. - implement NEED_SHUTDOWN_VM request so that the BSP of the target VM can shut down the guest in idle thread. - implement shutdown_vm_from_idle() to shut down target VM. Tracked-On: #2700 Signed-off-by: Zide Chen <zide.chen@intel.com> Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent db95231 commit 8ad0fd9

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ C_SRCS += arch/x86/guest/vmcs.c
213213
C_SRCS += arch/x86/guest/vmexit.c
214214
S_SRCS += arch/x86/guest/vmx_asm.S
215215
C_SRCS += arch/x86/guest/trusty.c
216+
C_SRCS += arch/x86/guest/vm_reset.c
216217
C_SRCS += arch/x86/cat.c
217218
C_SRCS += arch/x86/lib/memory.c
218219
C_SRCS += lib/string.c

hypervisor/arch/x86/guest/vm_reset.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <vm.h>
8+
#include <vm_reset.h>
9+
#include <per_cpu.h>
10+
11+
void shutdown_vm_from_idle(uint16_t pcpu_id)
12+
{
13+
struct acrn_vm *vm = get_vm_from_vmid(per_cpu(shutdown_vm_id, pcpu_id));
14+
const struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID);
15+
16+
if (vcpu->pcpu_id == pcpu_id) {
17+
(void)shutdown_vm(vm);
18+
}
19+
}

hypervisor/common/hv_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <vm.h>
8+
#include <vm_reset.h>
89
#include <vmcs.h>
910
#include <vmexit.h>
1011
#include <irq.h>
@@ -88,6 +89,8 @@ void default_idle(__unused struct sched_object *obj)
8889
schedule();
8990
} else if (need_offline(pcpu_id) != 0) {
9091
cpu_dead();
92+
} else if (need_shutdown_vm(pcpu_id)) {
93+
shutdown_vm_from_idle(pcpu_id);
9194
} else {
9295
CPU_IRQ_ENABLE();
9396
cpu_do_idle();

hypervisor/common/schedule.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ int32_t need_offline(uint16_t pcpu_id)
152152
return bitmap_test_and_clear_lock(NEED_OFFLINE, &ctx->flags);
153153
}
154154

155+
void make_shutdown_vm_request(uint16_t pcpu_id)
156+
{
157+
struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id);
158+
159+
bitmap_set_lock(NEED_SHUTDOWN_VM, &ctx->flags);
160+
if (get_pcpu_id() != pcpu_id) {
161+
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU);
162+
}
163+
}
164+
165+
bool need_shutdown_vm(uint16_t pcpu_id)
166+
{
167+
struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id);
168+
169+
return bitmap_test_and_clear_lock(NEED_SHUTDOWN_VM, &ctx->flags);
170+
}
171+
155172
static void prepare_switch(struct sched_object *prev, struct sched_object *next)
156173
{
157174
if ((prev != NULL) && (prev->prepare_switch_out != NULL)) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef VM_RESET_H_
8+
#define VM_RESET_H_
9+
10+
void shutdown_vm_from_idle(uint16_t pcpu_id);
11+
12+
#endif /* VM_RESET_H_ */

hypervisor/include/arch/x86/per_cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <gdt.h>
1919
#include <schedule.h>
2020
#include <security.h>
21+
#include <vm_config.h>
2122

2223
struct per_cpu_region {
2324
/* vmxon_region MUST be 4KB-aligned */
@@ -52,6 +53,7 @@ struct per_cpu_region {
5253
#ifdef PROFILING_ON
5354
struct profiling_info_wrapper profiling_info;
5455
#endif
56+
uint16_t shutdown_vm_id;
5557
} __aligned(PAGE_SIZE); /* per_cpu_region size aligned with PAGE_SIZE */
5658

5759
extern struct per_cpu_region per_cpu_data[CONFIG_MAX_PCPU_NUM];

hypervisor/include/common/schedule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#define NEED_RESCHEDULE (1U)
1212
#define NEED_OFFLINE (2U)
13+
#define NEED_SHUTDOWN_VM (3U)
1314

1415
#define DEL_MODE_INIT (1U)
1516
#define DEL_MODE_IPI (2U)
@@ -50,6 +51,8 @@ void make_reschedule_request(uint16_t pcpu_id, uint16_t delmode);
5051
bool need_reschedule(uint16_t pcpu_id);
5152
void make_pcpu_offline(uint16_t pcpu_id);
5253
int32_t need_offline(uint16_t pcpu_id);
54+
void make_shutdown_vm_request(uint16_t pcpu_id);
55+
bool need_shutdown_vm(uint16_t pcpu_id);
5356

5457
void schedule(void);
5558
void run_sched_thread(struct sched_object *obj);

0 commit comments

Comments
 (0)