Skip to content

Commit e5117bf

Browse files
fyin1wenlingz
authored andcommitted
vm: add severity for vm_config
Add severity definitions for different scenarios. The static guest severity is defined according to guest configurations. Also add sanity check to make sure the severity for all guests are correct. Tracked-On: #4270 Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
1 parent f7df43e commit e5117bf

File tree

6 files changed

+81
-12
lines changed

6 files changed

+81
-12
lines changed

hypervisor/arch/x86/configs/vm_config.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <cat.h>
1111
#include <pgtable.h>
1212

13+
static uint8_t rtvm_uuid1[16] = RTVM_UUID1;
14+
static uint8_t safety_vm_uuid1[16] = SAFETY_VM_UUID1;
15+
1316
/*
1417
* @pre vm_id < CONFIG_MAX_VM_NUM
1518
* @post return != NULL
@@ -40,6 +43,27 @@ bool vm_has_matched_uuid(uint16_t vmid, const uint8_t *uuid)
4043

4144
return (uuid_is_equal(vm_config->uuid, uuid));
4245
}
46+
/**
47+
* return true if the input uuid is for RTVM
48+
*
49+
* @pre vmid < CONFIG_MAX_VM_NUM
50+
*/
51+
static bool is_safety_vm_uuid(const uint8_t *uuid)
52+
{
53+
/* TODO: Extend to check more safety VM uuid if we have more than one safety VM. */
54+
return uuid_is_equal(uuid, safety_vm_uuid1);
55+
}
56+
57+
/**
58+
* return true if the input uuid is for RTVM
59+
*
60+
* @pre vmid < CONFIG_MAX_VM_NUM
61+
*/
62+
static bool is_rtvm_uuid(const uint8_t *uuid)
63+
{
64+
/* TODO: Extend to check more rtvm uuid if we have more than one RTVM. */
65+
return uuid_is_equal(uuid, rtvm_uuid1);
66+
}
4367

4468
/**
4569
* return true if no UUID collision is found in vm configs array start from vm_configs[vm_id]
@@ -108,7 +132,9 @@ bool sanitize_vm_config(void)
108132
} else if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)
109133
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0U)) {
110134
ret = false;
111-
}else if (vm_config->epc.size != 0UL) {
135+
} else if (vm_config->epc.size != 0UL) {
136+
ret = false;
137+
} else if (is_safety_vm_uuid(vm_config->uuid) && (vm_config->severity != (uint8_t)SEVERITY_SAFETY_VM)) {
112138
ret = false;
113139
} else {
114140
pre_launch_pcpu_bitmap |= vm_pcpu_bitmap;
@@ -119,6 +145,8 @@ bool sanitize_vm_config(void)
119145
sos_pcpu_bitmap ^= pre_launch_pcpu_bitmap;
120146
if ((sos_pcpu_bitmap == 0U) || ((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)) {
121147
ret = false;
148+
} else if (vm_config->severity != (uint8_t)SEVERITY_SOS) {
149+
ret = false;
122150
} else {
123151
vm_config->vcpu_num = bitmap_weight(sos_pcpu_bitmap);
124152
for (vcpu_id = 0U; vcpu_id < vm_config->vcpu_num; vcpu_id++) {
@@ -133,6 +161,22 @@ bool sanitize_vm_config(void)
133161
pr_err("%s: Post-launch VM has no pcpus or share pcpu with Pre-launch VM!", __func__);
134162
ret = false;
135163
}
164+
165+
if ((vm_config->severity == (uint8_t)SEVERITY_SAFETY_VM) ||
166+
(vm_config->severity == (uint8_t)SEVERITY_SOS)) {
167+
ret = false;
168+
}
169+
170+
/* VM with RTVM uuid must have RTVM severity */
171+
if (is_rtvm_uuid(vm_config->uuid) && (vm_config->severity != (uint8_t)SEVERITY_RTVM)) {
172+
ret = false;
173+
}
174+
175+
/* VM WITHOUT RTVM uuid must NOT have RTVM severity */
176+
if (!is_rtvm_uuid(vm_config->uuid) && (vm_config->severity == (uint8_t)SEVERITY_RTVM)) {
177+
ret = false;
178+
}
179+
136180
break;
137181
default:
138182
/* Nothing to do for a unknown VM, break directly. */

hypervisor/include/arch/x86/vm_config.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#define PCI_DEV_TYPE_HVEMUL (1U << 1U)
2525
#define PCI_DEV_TYPE_SOSEMUL (1U << 2U)
2626

27+
#define RTVM_UUID1 {0x49U, 0x5aU, 0xe2U, 0xe5U, 0x26U, 0x03U, 0x4dU, 0x64U, \
28+
0xafU, 0x76U, 0xd4U, 0xbcU, 0x5aU, 0x8eU, 0xc0U, 0xe5U}
29+
30+
#define SAFETY_VM_UUID1 {0xfcU, 0x83U, 0x69U, 0x01U, 0x86U, 0x85U, 0x4bU, 0xc0U, \
31+
0x8bU, 0x71U, 0x6eU, 0x31U, 0xdcU, 0x36U, 0xfaU, 0x47U}
32+
2733
/*
2834
* PRE_LAUNCHED_VM is launched by ACRN hypervisor, with LAPIC_PT;
2935
* SOS_VM is launched by ACRN hypervisor, without LAPIC_PT;
@@ -35,6 +41,14 @@ enum acrn_vm_load_order {
3541
POST_LAUNCHED_VM /* Launched by Devicemodel in SOS_VM */
3642
};
3743

44+
/* ACRN guest severity */
45+
enum acrn_vm_severity {
46+
SEVERITY_SAFETY_VM = 0x40U,
47+
SEVERITY_RTVM = 0x30U,
48+
SEVERITY_SOS = 0x20U,
49+
SEVERITY_STANDARD_VM = 0x10U,
50+
};
51+
3852
struct acrn_vm_mem_config {
3953
uint64_t start_hpa; /* the start HPA of VM memory configuration, for pre-launched VMs only */
4054
uint64_t size; /* VM memory size configuration */
@@ -99,6 +113,7 @@ struct acrn_vm_config {
99113
char name[MAX_VM_OS_NAME_LEN]; /* VM name identifier, useful for debug. */
100114
const uint8_t uuid[16]; /* UUID of the VM */
101115
uint16_t vcpu_num; /* Number of vCPUs for the VM */
116+
uint8_t severity; /* severity of the VM */
102117

103118
uint64_t vcpu_affinity[MAX_VCPUS_PER_VM];/* bitmaps for vCPUs' affinity */
104119
uint64_t guest_flags; /* VM flags that we want to configure for guest

hypervisor/scenarios/hybrid/vm_configurations.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
1212
{ /* VM0 */
1313
.load_order = PRE_LAUNCHED_VM,
1414
.name = "ACRN PRE-LAUNCHED VM0",
15-
.uuid = {0xfcU, 0x83U, 0x69U, 0x01U, 0x86U, 0x85U, 0x4bU, 0xc0U, \
16-
0x8bU, 0x71U, 0x6eU, 0x31U, 0xdcU, 0x36U, 0xfaU, 0x47U},
17-
/* fc836901-8685-4bc0-8b71-6e31dc36fa47 */
18-
.guest_flags = GUEST_FLAG_HIGHEST_SEVERITY,
15+
/* fc836901-8685-4bc0-8b71-6e31dc36fa47 */
16+
.uuid = SAFETY_VM_UUID1,
17+
.guest_flags = 0UL,
1918
.vcpu_num = 1U,
2019
.vcpu_affinity = VM0_CONFIG_VCPU_AFFINITY,
2120
.clos = 0U,
21+
.severity = SEVERITY_SAFETY_VM,
2222
.memory = {
2323
.start_hpa = VM0_CONFIG_MEM_START_HPA,
2424
.size = VM0_CONFIG_MEM_SIZE,
@@ -53,6 +53,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
5353

5454
.guest_flags = 0UL,
5555
.clos = 0U,
56+
.severity = SEVERITY_SOS,
5657
.memory = {
5758
.start_hpa = 0UL,
5859
.size = CONFIG_SOS_RAM_SIZE,
@@ -85,6 +86,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
8586
/* d2795438-25d6-11e8-864e-cb7a18b34643 */
8687
.vcpu_num = 1U,
8788
.vcpu_affinity = VM2_CONFIG_VCPU_AFFINITY,
89+
.severity = SEVERITY_STANDARD_VM,
8890
.vuart[0] = {
8991
.type = VUART_LEGACY_PIO,
9092
.addr.port_base = COM1_BASE,

hypervisor/scenarios/industry/vm_configurations.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
1717
/* dbbbd434-7a57-4216-a12c-2201f1ab0240 */
1818
.guest_flags = 0UL,
1919
.clos = 0U,
20+
.severity = SEVERITY_SOS,
2021
.memory = {
2122
.start_hpa = 0UL,
2223
.size = CONFIG_SOS_RAM_SIZE,
@@ -49,6 +50,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
4950
/* d2795438-25d6-11e8-864e-cb7a18b34643 */
5051
.vcpu_num = 1U,
5152
.vcpu_affinity = VM1_CONFIG_VCPU_AFFINITY,
53+
.severity = SEVERITY_STANDARD_VM,
5254
.vuart[0] = {
5355
.type = VUART_LEGACY_PIO,
5456
.addr.port_base = COM1_BASE,
@@ -62,14 +64,13 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
6264
},
6365
{
6466
.load_order = POST_LAUNCHED_VM,
65-
.uuid = {0x49U, 0x5aU, 0xe2U, 0xe5U, 0x26U, 0x03U, 0x4dU, 0x64U, \
66-
0xafU, 0x76U, 0xd4U, 0xbcU, 0x5aU, 0x8eU, 0xc0U, 0xe5U},
67-
/* 495ae2e5-2603-4d64-af76-d4bc5a8ec0e5 */
68-
67+
/* 495ae2e5-2603-4d64-af76-d4bc5a8ec0e5 */
68+
.uuid = RTVM_UUID1,
6969
/* The hard RTVM must be launched as VM2 */
70-
.guest_flags = GUEST_FLAG_HIGHEST_SEVERITY,
70+
.guest_flags = 0UL,
7171
.vcpu_num = 2U,
7272
.vcpu_affinity = VM2_CONFIG_VCPU_AFFINITY,
73+
.severity = SEVERITY_RTVM,
7374
.vuart[0] = {
7475
.type = VUART_LEGACY_PIO,
7576
.addr.port_base = COM1_BASE,

hypervisor/scenarios/sdc/vm_configurations.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
1717
/* dbbbd434-7a57-4216-a12c-2201f1ab0240 */
1818

1919
/* Allow SOS to reboot the host since there is supposed to be the highest severity guest */
20-
.guest_flags = GUEST_FLAG_HIGHEST_SEVERITY,
20+
.guest_flags = 0UL,
2121
.clos = 0U,
22+
.severity = SEVERITY_SOS,
2223
.memory = {
2324
.start_hpa = 0UL,
2425
.size = CONFIG_SOS_RAM_SIZE,
@@ -48,6 +49,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
4849
/* d2795438-25d6-11e8-864e-cb7a18b34643 */
4950
.vcpu_num = MAX_PCPU_NUM - CONFIG_MAX_KATA_VM_NUM - 1U,
5051
.vcpu_affinity = VM1_CONFIG_VCPU_AFFINITY,
52+
.severity = SEVERITY_STANDARD_VM,
5153
.vuart[0] = {
5254
.type = VUART_LEGACY_PIO,
5355
.addr.port_base = INVALID_COM_BASE,
@@ -66,6 +68,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
6668
/* a7ada506-1ab0-4b6b-a0da-e513ca9b8c2f */
6769
.vcpu_num = 1U,
6870
.vcpu_affinity = VM2_CONFIG_VCPU_AFFINITY,
71+
.severity = SEVERITY_STANDARD_VM,
6972
.vuart[0] = {
7073
.type = VUART_LEGACY_PIO,
7174
.addr.port_base = INVALID_COM_BASE,

hypervisor/scenarios/sdc2/vm_configurations.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
1717
/* dbbbd434-7a57-4216-a12c-2201f1ab0240 */
1818

1919
/* Allow SOS to reboot the host since there is supposed to be the highest severity guest */
20-
.guest_flags = GUEST_FLAG_HIGHEST_SEVERITY,
20+
.guest_flags = 0UL,
2121
.clos = 0U,
22+
.severity = SEVERITY_SOS,
2223
.memory = {
2324
.start_hpa = 0UL,
2425
.size = CONFIG_SOS_RAM_SIZE,
@@ -48,6 +49,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
4849
/* d2795438-25d6-11e8-864e-cb7a18b34643 */
4950
.vcpu_num = 1U,
5051
.vcpu_affinity = VM1_CONFIG_VCPU_AFFINITY,
52+
.severity = SEVERITY_STANDARD_VM,
5153
.vuart[0] = {
5254
.type = VUART_LEGACY_PIO,
5355
.addr.port_base = INVALID_COM_BASE,
@@ -65,6 +67,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
6567
/* 495ae2e5-2603-4d64-af76-d4bc5a8ec0e5 */
6668
.vcpu_num = 1U,
6769
.vcpu_affinity = VM2_CONFIG_VCPU_AFFINITY,
70+
.severity = SEVERITY_STANDARD_VM,
6871
.vuart[0] = {
6972
.type = VUART_LEGACY_PIO,
7073
.addr.port_base = INVALID_COM_BASE,
@@ -82,6 +85,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
8285
/* 38158821-5208-4005-b72a-8a609e4190d0 */
8386
.vcpu_num = 1U,
8487
.vcpu_affinity = VM3_CONFIG_VCPU_AFFINITY,
88+
.severity = SEVERITY_STANDARD_VM,
8589
.vuart[0] = {
8690
.type = VUART_LEGACY_PIO,
8791
.addr.port_base = INVALID_COM_BASE,

0 commit comments

Comments
 (0)