svn commit: r276455 - in projects/paravirt/sys: conf kern sys x86/x86
Bryan Venteicher
bryanv at FreeBSD.org
Wed Dec 31 07:00:39 UTC 2014
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 <bryanv at FreeBSD.org>
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <x86/hypervisor.h>
+
+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,
};
More information about the svn-src-projects
mailing list