Quellcode durchsuchen

[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 vor 9 Jahren
Ursprung
Commit
b6889eaa1e
2 geänderte Dateien mit 41 neuen und 0 gelöschten Zeilen
  1. 26
    0
      src/arch/x86/drivers/hyperv/hyperv.c
  2. 15
    0
      src/arch/x86/drivers/hyperv/hyperv.h

+ 26
- 0
src/arch/x86/drivers/hyperv/hyperv.c Datei anzeigen

@@ -150,6 +150,8 @@ static int hv_check_hv ( struct hv_hypervisor *hv ) {
150 150
 	uint32_t discard_ebx;
151 151
 	uint32_t discard_ecx;
152 152
 	uint32_t discard_edx;
153
+	uint32_t available;
154
+	uint32_t permissions;
153 155
 
154 156
 	/* Check for presence of a hypervisor (not necessarily Hyper-V) */
155 157
 	x86_features ( &features );
@@ -167,6 +169,30 @@ static int hv_check_hv ( struct hv_hypervisor *hv ) {
167 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 196
 	return 0;
171 197
 }
172 198
 

+ 15
- 0
src/arch/x86/drivers/hyperv/hyperv.h Datei anzeigen

@@ -18,6 +18,21 @@ FILE_LICENCE ( GPL2_OR_LATER );
18 18
 /** Get hypervisor identification */
19 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 36
 /** Guest OS identity MSR */
22 37
 #define HV_X64_MSR_GUEST_OS_ID 0x40000000UL
23 38
 

Laden…
Abbrechen
Speichern