svn commit: r331466 - head/sys/x86/x86

John Baldwin jhb at FreeBSD.org
Fri Mar 23 22:36:25 UTC 2018


Author: jhb
Date: Fri Mar 23 22:36:24 2018
New Revision: 331466
URL: https://svnweb.freebsd.org/changeset/base/331466

Log:
  Add a workaround to the hypervisor detection for older versions of KVM.
  
  Originally KVM set %eax to 0 in the cpuid leaf 0x4000000 rather than
  to the highest supported leaf in the hypervisor "branch".  Detect this
  case and fixup the %eax value so that the hypervisor is still
  detected.
  
  Reported by:	jpaetzel
  Reviewed by:	kib
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D14810

Modified:
  head/sys/x86/x86/identcpu.c

Modified: head/sys/x86/x86/identcpu.c
==============================================================================
--- head/sys/x86/x86/identcpu.c	Fri Mar 23 21:06:06 2018	(r331465)
+++ head/sys/x86/x86/identcpu.c	Fri Mar 23 22:36:24 2018	(r331466)
@@ -1304,6 +1304,18 @@ identify_hypervisor(void)
 	if (cpu_feature2 & CPUID2_HV) {
 		vm_guest = VM_GUEST_VM;
 		do_cpuid(0x40000000, regs);
+
+		/*
+		 * KVM from Linux kernels prior to commit
+		 * 57c22e5f35aa4b9b2fe11f73f3e62bbf9ef36190 set %eax
+		 * to 0 rather than a valid hv_high value.  Check for
+		 * the KVM signature bytes and fixup %eax to the
+		 * highest supported leaf in that case.
+		 */
+		if (regs[0] == 0 && regs[1] == 0x4b4d564b &&
+		    regs[2] == 0x564b4d56 && regs[3] == 0x0000004d)
+			regs[0] = 0x40000001;
+			
 		if (regs[0] >= 0x40000000) {
 			hv_high = regs[0];
 			((u_int *)&hv_vendor)[0] = regs[1];


More information about the svn-src-all mailing list