Skip to content

Commit 8ad5adc

Browse files
KaigeFuacrnsi
authored andcommitted
HV: Set vm state as with VM_POWERING_OFF when RTVM poweroff by itself
We set the vm state as VM_POWERING_OFF when RTVM is trying to poweroff by itself. We will check it when trying to pause vCPUs of RTVM. Only if vm state equal to VM_POWERING_OFF, we take action to pause the vCPUs of RTVM. Otherwise, we will reject the pause request. Tracked-On: #2865 Signed-off-by: Kaige Fu <kaige.fu@intel.com>
1 parent 83d11bb commit 8ad5adc

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

hypervisor/arch/x86/guest/pm.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,16 @@ static bool rt_vm_pm1a_io_read(__unused struct acrn_vm *vm, __unused struct acrn
220220
return false;
221221
}
222222

223-
static bool rt_vm_pm1a_io_write(__unused struct acrn_vm *vm, __unused uint16_t addr,
224-
__unused size_t width, __unused uint32_t v)
223+
static bool rt_vm_pm1a_io_write(struct acrn_vm *vm, uint16_t addr, size_t width, uint32_t v)
225224
{
226-
/* TODO: Check if the vm is trying to powering off itself */
225+
if ((addr != RT_VM_PM1A_CNT_ADDR) || (width != 2U)) {
226+
pr_dbg("Invalid address (0x%x) or width (0x%x)", addr, width);
227+
} else {
228+
if (((v & RT_VM_PM1A_SLP_EN) && (((v & RT_VM_PM1A_SLP_TYP) >> 10U) == 5U)) != 0U) {
229+
vm->state = VM_POWERING_OFF;
230+
}
231+
}
232+
227233
return false;
228234
}
229235

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ enum vm_state {
8888
VM_STATE_INVALID = 0,
8989
VM_CREATED, /* VM created / awaiting start (boot) */
9090
VM_STARTED, /* VM started (booted) */
91+
VM_POWERING_OFF, /* RTVM only, it is trying to poweroff by itself */
9192
VM_PAUSED, /* VM paused */
9293
};
9394

hypervisor/include/public/acrn_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
/* TODO: We may need to get this addr from guest ACPI instead of hardcode here */
5858
#define RT_VM_PM1A_CNT_ADDR 0x404U
59+
#define RT_VM_PM1A_SLP_TYP 0x1c00U
60+
#define RT_VM_PM1A_SLP_EN 0x2000U
5961

6062
/**
6163
* @brief Hypercall

0 commit comments

Comments
 (0)