From owner-svn-src-projects@FreeBSD.ORG Wed Dec 31 07:00:39 2014 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 403FB51F; Wed, 31 Dec 2014 07:00:39 +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 20C483797; Wed, 31 Dec 2014 07:00:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBV70doM061476; Wed, 31 Dec 2014 07:00:39 GMT (envelope-from bryanv@FreeBSD.org) Received: (from bryanv@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBV70bWw061467; Wed, 31 Dec 2014 07:00:37 GMT (envelope-from bryanv@FreeBSD.org) Message-Id: <201412310700.sBV70bWw061467@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bryanv set sender to bryanv@FreeBSD.org using -f From: Bryan Venteicher Date: Wed, 31 Dec 2014 07:00:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r276455 - in projects/paravirt/sys: conf kern sys x86/x86 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: Wed, 31 Dec 2014 07:00:39 -0000 Author: bryanv Date: Wed Dec 31 07:00:36 2014 New Revision: 276455 URL: https://svnweb.freebsd.org/changeset/base/276455 Log: Add basic bhyve guest detection Added: projects/paravirt/sys/x86/x86/bhyve.c (contents, props changed) Modified: projects/paravirt/sys/conf/files.amd64 projects/paravirt/sys/conf/files.i386 projects/paravirt/sys/kern/subr_param.c projects/paravirt/sys/sys/systm.h projects/paravirt/sys/x86/x86/hypervisor.c Modified: projects/paravirt/sys/conf/files.amd64 ============================================================================== --- projects/paravirt/sys/conf/files.amd64 Wed Dec 31 06:59:22 2014 (r276454) +++ projects/paravirt/sys/conf/files.amd64 Wed Dec 31 07:00:36 2014 (r276455) @@ -555,6 +555,7 @@ x86/isa/nmi.c standard x86/isa/orm.c optional isa x86/pci/pci_bus.c optional pci x86/pci/qpi.c optional pci +x86/x86/bhyve.c standard x86/x86/busdma_bounce.c standard x86/x86/busdma_machdep.c standard x86/x86/dump_machdep.c standard Modified: projects/paravirt/sys/conf/files.i386 ============================================================================== --- projects/paravirt/sys/conf/files.i386 Wed Dec 31 06:59:22 2014 (r276454) +++ projects/paravirt/sys/conf/files.i386 Wed Dec 31 07:00:36 2014 (r276455) @@ -573,6 +573,7 @@ x86/isa/nmi.c standard x86/isa/orm.c optional isa x86/pci/pci_bus.c optional pci x86/pci/qpi.c optional pci +x86/x86/bhyve.c standard x86/x86/busdma_bounce.c standard x86/x86/busdma_machdep.c standard x86/x86/dump_machdep.c standard Modified: projects/paravirt/sys/kern/subr_param.c ============================================================================== --- projects/paravirt/sys/kern/subr_param.c Wed Dec 31 06:59:22 2014 (r276454) +++ projects/paravirt/sys/kern/subr_param.c Wed Dec 31 07:00:36 2014 (r276455) @@ -160,6 +160,7 @@ static const char *const vm_guest_sysctl "hv", "vmware", "kvm", + "bhyve", NULL }; CTASSERT(nitems(vm_guest_sysctl_names) - 1 == VM_LAST); Modified: projects/paravirt/sys/sys/systm.h ============================================================================== --- projects/paravirt/sys/sys/systm.h Wed Dec 31 06:59:22 2014 (r276454) +++ projects/paravirt/sys/sys/systm.h Wed Dec 31 07:00:36 2014 (r276455) @@ -73,7 +73,7 @@ extern int vm_guest; /* Running as virt * Keep in sync with vm_guest_sysctl_names[]. */ enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV, - VM_GUEST_VMWARE, VM_GUEST_KVM, VM_LAST }; + VM_GUEST_VMWARE, VM_GUEST_KVM, VM_GUEST_BHYVE, VM_LAST }; #if defined(WITNESS) || defined(INVARIANTS) void kassert_panic(const char *fmt, ...) __printflike(1, 2); Added: projects/paravirt/sys/x86/x86/bhyve.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/paravirt/sys/x86/x86/bhyve.c Wed Dec 31 07:00:36 2014 (r276455) @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 2014 Bryan Venteicher + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include + +static int bhyve_identify(void); + +const struct hypervisor_info bhyve_hypervisor_info = { + .hvi_name = "bhyve", + .hvi_signature = "bhyve bhyve", + .hvi_type = VM_GUEST_BHYVE, + .hvi_identify = bhyve_identify, +}; + +static uint32_t bhyve_cpuid_base = -1; +static uint32_t bhyve_cpuid_high = -1; + +static uint32_t +bhyve_cpuid_identify(void) +{ + + if (bhyve_cpuid_base == -1) { + hypervisor_cpuid_base(bhyve_hypervisor_info.hvi_signature, + 0, &bhyve_cpuid_base, &bhyve_cpuid_high); + } + + return (bhyve_cpuid_base); +} + +static int +bhyve_identify(void) +{ + + return (bhyve_cpuid_identify() != 0); +} Modified: projects/paravirt/sys/x86/x86/hypervisor.c ============================================================================== --- projects/paravirt/sys/x86/x86/hypervisor.c Wed Dec 31 06:59:22 2014 (r276454) +++ projects/paravirt/sys/x86/x86/hypervisor.c Wed Dec 31 07:00:36 2014 (r276455) @@ -40,10 +40,12 @@ char hv_vendor[16]; SYSCTL_STRING(_hw, OID_AUTO, hv_vendor, CTLFLAG_RD, hv_vendor, 0, "Hypervisor vendor"); +extern const struct hypervisor_info bhyve_hypervisor_info; extern const struct hypervisor_info kvm_hypervisor_info; extern const struct hypervisor_info vmware_hypervisor_info; static const struct hypervisor_info *hypervisor_infos[] = { + &bhyve_hypervisor_info, &kvm_hypervisor_info, &vmware_hypervisor_info, };