Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jul 2016 11:03:06 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r302834 - head/sys/amd64/amd64
Message-ID:  <201607141103.u6EB36we065234@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Thu Jul 14 11:03:05 2016
New Revision: 302834
URL: https://svnweb.freebsd.org/changeset/base/302834

Log:
  fix-up for configuration of AMD Family 10h processors borrowed from Linux
  
  http://lxr.free-electrons.com/source/arch/x86/kernel/cpu/amd.c#L643
  BIOS may configure Family 10h processors to convert WC+ cache type
  to CD.  That can hurt performance of guest VMs using nested paging.
  
  Reviewed by:	kib
  MFC after:	3 weeks
  Differential Revision: https://reviews.freebsd.org/D6059

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

Modified: head/sys/amd64/amd64/initcpu.c
==============================================================================
--- head/sys/amd64/amd64/initcpu.c	Thu Jul 14 09:47:49 2016	(r302833)
+++ head/sys/amd64/amd64/initcpu.c	Thu Jul 14 11:03:05 2016	(r302834)
@@ -94,6 +94,20 @@ init_amd(void)
 			wrmsr(MSR_NB_CFG1, msr);
 		}
 	}
+
+	/*
+	 * BIOS may configure Family 10h processors to convert WC+ cache type
+	 * to CD.  That can hurt performance of guest VMs using nested paging.
+	 * The relevant MSR bit is not documented in the BKDG,
+	 * the fix is borrowed from Linux.
+	 */
+	if (CPUID_TO_FAMILY(cpu_id) == 0x10) {
+		if ((cpu_feature2 & CPUID2_HV) == 0) {
+			msr = rdmsr(0xc001102a);
+			msr &= ~((uint64_t)1 << 24);
+			wrmsr(0xc001102a, msr);
+		}
+	}
 }
 
 /*
@@ -179,6 +193,7 @@ initializecpu(void)
 void
 initializecpucache(void)
 {
+	uint64_t msr;
 
 	/*
 	 * CPUID with %eax = 1, %ebx returns



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