Skip to contentSkip to conversation

x86: guest: rely on leaf 0x40000001 to detect Hyper-V

PATCH In review Paolo Bonzini 4 participants 5 messages Oct 2, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: guest: rely on leaf 0x40000001 to detect Hyper-V

The specification says that "Microsoft Hv" is actually a vendor ID field that is only used for reporting and diagnostic purposes. The actual field that you need to check is the interface ID that you get in eax when querying the HYPERV_CPUID_INTERFACE.

Change ms_hyperv_platform to actually do what the specification suggests. This roughy matches what Windows looks for, though Windows actually ignores HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS completely.

---
 arch/x86/kernel/cpu/mshyperv.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +6 -8
index 381c8b9b3a33..7910e7fd705b 100644
@@ -116,18 +116,16 @@ static void hv_machine_crash_shutdown(struct pt_regs *regs)
 static uint32_t  __init ms_hyperv_platform(void)
 {
 	u32 eax;
-	u32 hyp_signature[3];
 
 	if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
 		return 0;
 
-	cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS,
-	      &eax, &hyp_signature[0], &hyp_signature[1], &hyp_signature[2]);
-
-	if (eax >= HYPERV_CPUID_MIN &&
-	    eax <= HYPERV_CPUID_MAX &&
-	    !memcmp("Microsoft Hv", hyp_signature, 12))
-		return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
+	eax = cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS);
+	if (eax >= HYPERV_CPUID_MIN && eax <= HYPERV_CPUID_MAX) {
+		eax = cpuid_eax(HYPERV_CPUID_INTERFACE);
+		if (!memcmp(&eax, "Hv#1", sizeof(eax)))
+			return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
+	}
 
 	return 0;
 }
Signature · 1 line
2.5.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paolo Bonzini

The specification says that "Microsoft Hv" is actually a vendor ID field that is only used for reporting and diagnostic purposes. The actual field that you need to check is the interface ID that you get in eax when querying the HYPERV_CPUID_INTERFACE.

Change ms_hyperv_platform to actually do what the specification suggests. This roughy matches what Windows looks for, though Windows actually ignores HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS completely.

(and it seems K. Y. is missing on the CC: list, fixed).

Quoted 33 lines
---
 arch/x86/kernel/cpu/mshyperv.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +6 -8
index 381c8b9b3a33..7910e7fd705b 100644
@@ -116,18 +116,16 @@ static void hv_machine_crash_shutdown(struct pt_regs *regs)
 static uint32_t  __init ms_hyperv_platform(void)
 {
 	u32 eax;
-	u32 hyp_signature[3];
 
 	if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
 		return 0;
 
-	cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS,
-	      &eax, &hyp_signature[0], &hyp_signature[1], &hyp_signature[2]);
-
-	if (eax >= HYPERV_CPUID_MIN &&
-	    eax <= HYPERV_CPUID_MAX &&
-	    !memcmp("Microsoft Hv", hyp_signature, 12))
-		return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
+	eax = cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS);
+	if (eax >= HYPERV_CPUID_MIN && eax <= HYPERV_CPUID_MAX) {
+		eax = cpuid_eax(HYPERV_CPUID_INTERFACE);
+		if (!memcmp(&eax, "Hv#1", sizeof(eax)))
+			return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
+	}
 
 	return 0;
 }
Signature · 1 line
  Vitaly
#2 lore raw
In reply to Paolo Bonzini
Quoted 17 lines

-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]] On Behalf Of Paolo Bonzini
Sent: Friday, October 2, 2015 2:27 AM
To: [email protected]
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] x86: guest: rely on leaf 0x40000001 to detect Hyper-V

The specification says that "Microsoft Hv" is actually a vendor ID field that is only used for reporting and diagnostic purposes. The actual field that you need to check is the interface ID that you get in eax when querying the HYPERV_CPUID_INTERFACE.

Quoted 5 lines

Change ms_hyperv_platform to actually do what the specification suggests. This roughy matches what Windows looks for, though Windows actually ignores HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS completely.

Thanks Paolo.

Quoted 40 lines
---
 arch/x86/kernel/cpu/mshyperv.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +5 -8
index 381c8b9b3a33..7910e7fd705b 100644
@@ -116,18 +116,16 @@ static void hv_machine_crash_shutdown(struct
 pt_regs *regs)
 static uint32_t  __init ms_hyperv_platform(void)
 {
 	u32 eax;
-	u32 hyp_signature[3];
 
 	if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
 		return 0;
 
-	cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS,
-	      &eax, &hyp_signature[0], &hyp_signature[1],
 &hyp_signature[2]);
-
-	if (eax >= HYPERV_CPUID_MIN &&
-	    eax <= HYPERV_CPUID_MAX &&
-	    !memcmp("Microsoft Hv", hyp_signature, 12))
-		return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
+	eax =
 cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS);
+	if (eax >= HYPERV_CPUID_MIN && eax <= HYPERV_CPUID_MAX) {
+		eax = cpuid_eax(HYPERV_CPUID_INTERFACE);
+		if (!memcmp(&eax, "Hv#1", sizeof(eax)))
+			return

HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;

arch/x86/kernel/cpu/mshyperv.c +1 -1
+	}
 
 	return 0;
 }
--

2.5.0

#3 lore raw
Quoted 9 lines · KY Srinivasan
Quoted 5 lines

Change ms_hyperv_platform to actually do what the specification suggests. This roughy matches what Windows looks for, though Windows actually ignores HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS completely.

Thanks Paolo.

Does that mean Acked-by or Reviewed-by? SOB certainly does not apply here.

Thanks,

tglx

#4 lore raw
Quoted 17 lines

-----Original Message-----
From: Thomas Gleixner [mailto:[email protected]]
Sent: Friday, October 2, 2015 1:07 PM
To: KY Srinivasan <[email protected]>
Cc: Paolo Bonzini <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] x86: guest: rely on leaf 0x40000001 to detect Hyper-V

Quoted 1 line · KY Srinivasan
Quoted 1 line

Change ms_hyperv_platform to actually do what the specification

suggests.

Quoted 3 lines
Quoted 3 lines

This roughy matches what Windows looks for, though Windows actually ignores HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS completely.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks Paolo.

Does that mean Acked-by or Reviewed-by? SOB certainly does not apply here.

Thomas,

I have reviewed the patch and am acking this change.

Regards,

K. Y

Quoted 4 lines

Thanks,

tglx