From owner-svn-src-projects@FreeBSD.ORG Thu Oct 16 18:13:11 2014 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6B155671; Thu, 16 Oct 2014 18:13:11 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3DAB7A48; Thu, 16 Oct 2014 18:13:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9GIDBoe097046; Thu, 16 Oct 2014 18:13:11 GMT (envelope-from neel@FreeBSD.org) Received: (from neel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9GIDBto097044; Thu, 16 Oct 2014 18:13:11 GMT (envelope-from neel@FreeBSD.org) Message-Id: <201410161813.s9GIDBto097044@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: neel set sender to neel@FreeBSD.org using -f From: Neel Natu Date: Thu, 16 Oct 2014 18:13:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r273175 - projects/bhyve_svm/sys/amd64/vmm X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Oct 2014 18:13:11 -0000 Author: neel Date: Thu Oct 16 18:13:10 2014 New Revision: 273175 URL: https://svnweb.freebsd.org/changeset/base/273175 Log: Fix topology enumeration issues exposed by AMD Bulldozer Family 15h processor. Initialize CPUID.80000008H:ECX[7:0] with the number of logical processors in the package. This fixes a panic during early boot in NetBSD 7.0 BETA. Clear the Topology Extension feature bit from CPUID.80000001H:ECX since we don't emulate leaves 0x8000001D and 0x8000001E. This fixes a divide by zero panic in early boot in Centos 6.4. Tested on an "AMD Opteron 6320" courtesy of Ben Perrault. Reviewed by: grehan Modified: projects/bhyve_svm/sys/amd64/vmm/x86.c Modified: projects/bhyve_svm/sys/amd64/vmm/x86.c ============================================================================== --- projects/bhyve_svm/sys/amd64/vmm/x86.c Thu Oct 16 18:04:43 2014 (r273174) +++ projects/bhyve_svm/sys/amd64/vmm/x86.c Thu Oct 16 18:13:10 2014 (r273175) @@ -44,6 +44,8 @@ __FBSDID("$FreeBSD$"); #include #include "vmm_host.h" +#include "vmm_ktr.h" +#include "vmm_util.h" #include "x86.h" SYSCTL_DECL(_hw_vmm); @@ -54,6 +56,8 @@ static SYSCTL_NODE(_hw_vmm, OID_AUTO, to static const char bhyve_id[12] = "bhyve bhyve "; static uint64_t bhyve_xcpuids; +SYSCTL_ULONG(_hw_vmm, OID_AUTO, bhyve_xcpuids, CTLFLAG_RW, &bhyve_xcpuids, 0, + "Number of times an unknown cpuid leaf was accessed"); /* * The default CPU topology is a single thread per package. @@ -91,6 +95,8 @@ x86_emulate_cpuid(struct vm *vm, int vcp unsigned int func, regs[4], logical_cpus; enum x2apic_state x2apic_state; + VCPU_CTR2(vm, vcpu_id, "cpuid %#x,%#x", *eax, *ecx); + /* * Requests for invalid CPUID levels should map to the highest * available level instead. @@ -124,17 +130,33 @@ x86_emulate_cpuid(struct vm *vm, int vcp case CPUID_8000_0003: case CPUID_8000_0004: case CPUID_8000_0006: + cpuid_count(*eax, *ecx, regs); + break; case CPUID_8000_0008: cpuid_count(*eax, *ecx, regs); + if (vmm_is_amd()) { + /* + * XXX this might appear silly because AMD + * cpus don't have threads. + * + * However this matches the logical cpus as + * advertised by leaf 0x1 and will work even + * if the 'threads_per_core' tunable is set + * incorrectly on an AMD host. + */ + logical_cpus = threads_per_core * + cores_per_package; + regs[2] = logical_cpus - 1; + } break; case CPUID_8000_0001: cpuid_count(*eax, *ecx, regs); /* - * Hide SVM capability from guest. + * Hide SVM and Topology Extension features from guest. */ - regs[2] &= ~AMDID2_SVM; + regs[2] &= ~(AMDID2_SVM | AMDID2_TOPOLOGY); /* * Hide rdtscp/ia32_tsc_aux until we know how