Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Apr 2016 08:29:57 +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: r298736 - head/sys/amd64/amd64
Message-ID:  <201604280829.u3S8Tvwl045202@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Thu Apr 28 08:29:57 2016
New Revision: 298736
URL: https://svnweb.freebsd.org/changeset/base/298736

Log:
  ensure that initial local apic id is sane on AMD 10h systems
  
  Summary:
  The Initial Local APIC ID is returned by CPUID function 1 (in EBX).
  On AMD Family 10h systems the way that ID is built is controlled by
  an MSR bit (InitApicIdCpuIdLo).  BKDG instructs BIOS to set it in a
  certain way, but a BIOS can be buggy.  In that case the ID can confuse
  tools that use it, e.g. hwloc.
  For example, on a system that I own real Local APIC IDs are configured
  as 0, 1, 2, 3, but IDs reported via CPUID.1 are 0, 0x40, 0x80, 0xc0.
  See: https://github.com/open-mpi/hwloc/issues/183
  
  Reviewed by:	kib
  MFC after:	2 weeks
  Differential Revision: https://reviews.freebsd.org/D6060

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

Modified: head/sys/amd64/amd64/initcpu.c
==============================================================================
--- head/sys/amd64/amd64/initcpu.c	Thu Apr 28 06:20:43 2016	(r298735)
+++ head/sys/amd64/amd64/initcpu.c	Thu Apr 28 08:29:57 2016	(r298736)
@@ -80,6 +80,19 @@ init_amd(void)
 			wrmsr(0xc0011029, rdmsr(0xc0011029) | 1);
 		break;
 	}
+
+	/*
+	 * BIOS may fail to set InitApicIdCpuIdLo to 1 as it should per BKDG.
+	 * So, do it here or otherwise some tools could be confused by
+	 * Initial Local APIC ID reported with CPUID Function 1 in EBX.
+	 */
+	if (CPUID_TO_FAMILY(cpu_id) == 0x10) {
+		if ((cpu_feature2 & CPUID2_HV) == 0) {
+			msr = rdmsr(MSR_NB_CFG1);
+			msr |= (uint64_t)1 << 54;
+			wrmsr(MSR_NB_CFG1, msr);
+		}
+	}
 }
 
 /*



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