Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Nov 2012 16:00:30 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r242828 - head/sys/amd64/amd64
Message-ID:  <201211091600.qA9G0Umd005041@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Nov  9 16:00:30 2012
New Revision: 242828
URL: http://svnweb.freebsd.org/changeset/base/242828

Log:
  Do not try to enable new features in the %cr4 if running under
  hypervisor.  Apparently, hypervisors failed to filter out 'Standard
  Extended Features' report from CPUID, but deliver #gp when
  corresponding bit in %cr4 is toggled.
  
  This shall be reconsidered later, after hypervisors correct the bug.
  
  Reported and tested by:	joel
  Reviewed by:	avg
  MFC after:	2 weeks

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

Modified: head/sys/amd64/amd64/identcpu.c
==============================================================================
--- head/sys/amd64/amd64/identcpu.c	Fri Nov  9 15:29:52 2012	(r242827)
+++ head/sys/amd64/amd64/identcpu.c	Fri Nov  9 16:00:30 2012	(r242828)
@@ -481,7 +481,7 @@ SYSINIT(hook_tsc_freq, SI_SUB_CONFIGURE,
 void
 identify_cpu(void)
 {
-	u_int regs[4];
+	u_int regs[4], cpu_stdext_disable;
 
 	do_cpuid(0, regs);
 	cpu_high = regs[0];
@@ -516,6 +516,20 @@ identify_cpu(void)
 	if (cpu_high >= 7) {
 		cpuid_count(7, 0, regs);
 		cpu_stdext_feature = regs[1];
+
+		/*
+		 * Some hypervisors fail to filter out unsupported
+		 * extended features.  For now, disable the
+		 * extensions, activation of which requires setting a
+		 * bit in CR4, and which VM monitors do not support.
+		 */
+		if (cpu_feature2 & CPUID2_HV) {
+			cpu_stdext_disable = CPUID_STDEXT_FSGSBASE |
+			    CPUID_STDEXT_SMEP;
+		} else
+			cpu_stdext_disable = 0;
+		TUNABLE_INT_FETCH("hw.cpu_stdext_disable", &cpu_stdext_disable);
+		cpu_stdext_feature &= ~cpu_stdext_disable;
 	}
 
 	if (cpu_vendor_id == CPU_VENDOR_INTEL ||



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211091600.qA9G0Umd005041>