Ver código fonte

[hyperv] Check for required features

Other hypervisors (e.g. KVM) may provide an unusable subset of the
Hyper-V features, and our attempts to use these non-existent features
cause the guest to reboot.

Fix by explicitly checking for the Hyper-V features that we use.

Reported-by: Ján ONDREJ (SAL) <ondrejj@salstar.sk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 anos atrás
pai
commit
b6889eaa1e

+ 26
- 0
src/arch/x86/drivers/hyperv/hyperv.c Ver arquivo

150
 	uint32_t discard_ebx;
150
 	uint32_t discard_ebx;
151
 	uint32_t discard_ecx;
151
 	uint32_t discard_ecx;
152
 	uint32_t discard_edx;
152
 	uint32_t discard_edx;
153
+	uint32_t available;
154
+	uint32_t permissions;
153
 
155
 
154
 	/* Check for presence of a hypervisor (not necessarily Hyper-V) */
156
 	/* Check for presence of a hypervisor (not necessarily Hyper-V) */
155
 	x86_features ( &features );
157
 	x86_features ( &features );
167
 		return -ENODEV;
169
 		return -ENODEV;
168
 	}
170
 	}
169
 
171
 
172
+	/* Check that required features and privileges are available */
173
+	cpuid ( HV_CPUID_FEATURES, &available, &permissions, &discard_ecx,
174
+		&discard_edx );
175
+	if ( ! ( available & HV_FEATURES_AVAIL_HYPERCALL_MSR ) ) {
176
+		DBGC ( hv, "HV %p has no hypercall MSRs (features %08x:%08x)\n",
177
+		       hv, available, permissions );
178
+		return -ENODEV;
179
+	}
180
+	if ( ! ( available & HV_FEATURES_AVAIL_SYNIC_MSR ) ) {
181
+		DBGC ( hv, "HV %p has no SynIC MSRs (features %08x:%08x)\n",
182
+		       hv, available, permissions );
183
+		return -ENODEV;
184
+	}
185
+	if ( ! ( permissions & HV_FEATURES_PERM_POST_MESSAGES ) ) {
186
+		DBGC ( hv, "HV %p cannot post messages (features %08x:%08x)\n",
187
+		       hv, available, permissions );
188
+		return -EACCES;
189
+	}
190
+	if ( ! ( permissions & HV_FEATURES_PERM_SIGNAL_EVENTS ) ) {
191
+		DBGC ( hv, "HV %p cannot signal events (features %08x:%08x)",
192
+		       hv, available, permissions );
193
+		return -EACCES;
194
+	}
195
+
170
 	return 0;
196
 	return 0;
171
 }
197
 }
172
 
198
 

+ 15
- 0
src/arch/x86/drivers/hyperv/hyperv.h Ver arquivo

18
 /** Get hypervisor identification */
18
 /** Get hypervisor identification */
19
 #define HV_CPUID_HYPERVISOR_ID 0x40000002UL
19
 #define HV_CPUID_HYPERVISOR_ID 0x40000002UL
20
 
20
 
21
+/** Get hypervisor features */
22
+#define HV_CPUID_FEATURES 0x40000003UL
23
+
24
+/** SynIC MSRs are available */
25
+#define HV_FEATURES_AVAIL_SYNIC_MSR 0x00000004UL
26
+
27
+/** Hypercall MSRs are available */
28
+#define HV_FEATURES_AVAIL_HYPERCALL_MSR 0x00000020UL
29
+
30
+/** Guest may post messages */
31
+#define HV_FEATURES_PERM_POST_MESSAGES 0x00000010UL
32
+
33
+/** Guest may signal events */
34
+#define HV_FEATURES_PERM_SIGNAL_EVENTS 0x00000020UL
35
+
21
 /** Guest OS identity MSR */
36
 /** Guest OS identity MSR */
22
 #define HV_X64_MSR_GUEST_OS_ID 0x40000000UL
37
 #define HV_X64_MSR_GUEST_OS_ID 0x40000000UL
23
 
38
 

Carregando…
Cancelar
Salvar