10
10
#include <cat.h>
11
11
#include <pgtable.h>
12
12
13
+ static uint8_t rtvm_uuid1 [16 ] = RTVM_UUID1 ;
14
+ static uint8_t safety_vm_uuid1 [16 ] = SAFETY_VM_UUID1 ;
15
+
13
16
/*
14
17
* @pre vm_id < CONFIG_MAX_VM_NUM
15
18
* @post return != NULL
@@ -40,6 +43,27 @@ bool vm_has_matched_uuid(uint16_t vmid, const uint8_t *uuid)
40
43
41
44
return (uuid_is_equal (vm_config -> uuid , uuid ));
42
45
}
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
+ }
43
67
44
68
/**
45
69
* 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)
108
132
} else if (((vm_config -> guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH ) != 0U )
109
133
&& ((vm_config -> guest_flags & GUEST_FLAG_RT ) == 0U )) {
110
134
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 )) {
112
138
ret = false;
113
139
} else {
114
140
pre_launch_pcpu_bitmap |= vm_pcpu_bitmap ;
@@ -119,6 +145,8 @@ bool sanitize_vm_config(void)
119
145
sos_pcpu_bitmap ^= pre_launch_pcpu_bitmap ;
120
146
if ((sos_pcpu_bitmap == 0U ) || ((vm_config -> guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH ) != 0U )) {
121
147
ret = false;
148
+ } else if (vm_config -> severity != (uint8_t )SEVERITY_SOS ) {
149
+ ret = false;
122
150
} else {
123
151
vm_config -> vcpu_num = bitmap_weight (sos_pcpu_bitmap );
124
152
for (vcpu_id = 0U ; vcpu_id < vm_config -> vcpu_num ; vcpu_id ++ ) {
@@ -133,6 +161,22 @@ bool sanitize_vm_config(void)
133
161
pr_err ("%s: Post-launch VM has no pcpus or share pcpu with Pre-launch VM!" , __func__ );
134
162
ret = false;
135
163
}
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
+
136
180
break ;
137
181
default :
138
182
/* Nothing to do for a unknown VM, break directly. */
0 commit comments