Skip to content

Commit 5a23f7b

Browse files
ZideChen0acrnsi
authored andcommitted
hv: initial host reset implementation
- add the GUEST_FLAG_HIGHEST_SEVERITY flag to indicate that the guest has privilege to reboot the host system. - this flag is statically assigned to guest(s) in vm_configurations.c in different scenarios. - implement reset_host() function to reset the host. First try the ACPI reset register if available, then try the 0xcf9 PIO. Tracked-On: #3145 Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 321e4f1 commit 5a23f7b

File tree

6 files changed

+67
-3
lines changed

6 files changed

+67
-3
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ bool is_rt_vm(const struct acrn_vm *vm)
111111
return ((vm_config->guest_flags & GUEST_FLAG_RT) != 0U);
112112
}
113113

114+
/**
115+
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
116+
*/
117+
bool is_highest_severity_vm(const struct acrn_vm *vm)
118+
{
119+
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
120+
121+
return ((vm_config->guest_flags & GUEST_FLAG_HIGHEST_SEVERITY) != 0U);
122+
}
123+
114124
/**
115125
* @pre vm != NULL && vm_config != NULL && vm->vmid < CONFIG_MAX_VM_NUM
116126
*/

hypervisor/arch/x86/guest/vm_reset.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,45 @@ void triple_fault_shutdown_vm(struct acrn_vm *vm)
7878
}
7979
}
8080

81+
static void reset_host(void)
82+
{
83+
struct acpi_generic_address *gas = &(host_reset_reg.reg);
84+
85+
86+
/* TODO: gracefully shut down all guests before doing host reset. */
87+
88+
/*
89+
* UEFI more likely sets the reset value as 0x6 (not 0xe) for 0xcf9 port.
90+
* This asserts PLTRST# to reset devices on the platform, but not the
91+
* SLP_S3#/4#/5# signals, which power down the systems. This might not be
92+
* enough for us.
93+
*/
94+
if ((gas->space_id == SPACE_SYSTEM_IO) &&
95+
(gas->bit_width == 8U) && (gas->bit_offset == 0U) &&
96+
(gas->address != 0U) && (gas->address != 0xcf9U)) {
97+
pio_write8(host_reset_reg.val, (uint16_t)host_reset_reg.reg.address);
98+
}
99+
100+
/*
101+
* Fall back
102+
* making sure bit 2 (RST_CPU) is '0', when the reset command is issued.
103+
*/
104+
pio_write8(0x2U, 0xcf9U);
105+
pio_write8(0xeU, 0xcf9U);
106+
107+
/*
108+
* Fall back
109+
* keyboard controller might cause the INIT# being asserted,
110+
* and not power cycle the system.
111+
*/
112+
pio_write8(0xfeU, 0x64U);
113+
114+
pr_fatal("%s(): can't reset host.", __func__);
115+
while (1) {
116+
asm_pause();
117+
}
118+
}
119+
81120
/**
82121
* @pre vcpu != NULL && vm != NULL
83122
*/
@@ -108,7 +147,11 @@ static bool handle_common_reset_reg_write(struct acrn_vm *vm, bool reset)
108147
{
109148
bool ret = true;
110149

111-
if (is_postlaunched_vm(vm)) {
150+
if (is_highest_severity_vm(vm)) {
151+
if (reset) {
152+
reset_host();
153+
}
154+
} else if (is_postlaunched_vm(vm)) {
112155
/* re-inject to DM */
113156
ret = false;
114157

@@ -155,7 +198,11 @@ static bool handle_reset_reg_write(__unused struct acrn_vm *vm, uint16_t addr, s
155198
{
156199
if (bytes == 1U) {
157200
if (val == host_reset_reg.val) {
158-
/* ignore reset request */
201+
if (is_highest_severity_vm(vm)) {
202+
reset_host();
203+
} else {
204+
/* ignore reset request */
205+
}
159206
} else {
160207
/*
161208
* ACPI defines the reset value but doesn't specify the meaning of other values.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void vrtc_init(struct acrn_vm *vm);
218218

219219
bool is_lapic_pt_configured(const struct acrn_vm *vm);
220220
bool is_rt_vm(const struct acrn_vm *vm);
221+
bool is_highest_severity_vm(const struct acrn_vm *vm);
221222
bool vm_hide_mtrr(const struct acrn_vm *vm);
222223

223224
#endif /* !ASSEMBLER */

hypervisor/include/public/acrn_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#define GUEST_FLAG_CLOS_REQUIRED (1UL << 3U) /* Whether CLOS is required */
5454
#define GUEST_FLAG_HIDE_MTRR (1UL << 4U) /* Whether hide MTRR from VM */
5555
#define GUEST_FLAG_RT (1UL << 5U) /* Whether the vm is RT-VM */
56+
#define GUEST_FLAG_HIGHEST_SEVERITY (1UL << 6U) /* Whether has the highest severity */
5657

5758
/* TODO: We may need to get this addr from guest ACPI instead of hardcode here */
5859
#define VIRTUAL_PM1A_CNT_ADDR 0x404U

hypervisor/scenarios/industry/vm_configurations.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
5353
.uuid = {0x49U, 0x5aU, 0xe2U, 0xe5U, 0x26U, 0x03U, 0x4dU, 0x64U, \
5454
0xafU, 0x76U, 0xd4U, 0xbcU, 0x5aU, 0x8eU, 0xc0U, 0xe5U},
5555
/* 495ae2e5-2603-4d64-af76-d4bc5a8ec0e5 */
56+
57+
/* The hard RTVM must be launched as VM2 */
58+
.guest_flags = GUEST_FLAG_HIGHEST_SEVERITY,
5659
.vuart[0] = {
5760
.type = VUART_LEGACY_PIO,
5861
.addr.port_base = INVALID_COM_BASE,

hypervisor/scenarios/sdc/vm_configurations.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
1414
.uuid = {0xdbU, 0xbbU, 0xd4U, 0x34U, 0x7aU, 0x57U, 0x42U, 0x16U, \
1515
0xa1U, 0x2cU, 0x22U, 0x01U, 0xf1U, 0xabU, 0x02U, 0x40U},
1616
/* dbbbd434-7a57-4216-a12c-2201f1ab0240 */
17-
.guest_flags = 0UL,
17+
18+
/* Allow SOS to reboot the host since there is supposed to be the highest severity guest */
19+
.guest_flags = GUEST_FLAG_HIGHEST_SEVERITY,
1820
.clos = 0U,
1921
.memory = {
2022
.start_hpa = 0UL,

0 commit comments

Comments
 (0)