summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Mooney <pmooney@pfmooney.com>2017-10-13 22:24:22 +0000
committerPatrick Mooney <pmooney@pfmooney.com>2017-10-17 17:50:58 +0000
commit8359acfb8fd4655b7437bff72bed36033caf5420 (patch)
tree7c0428d920117bea5ef78125f62769c85cfbedf5
parent3e8f2de8060a6dc6b5940f6a15c3b444fd288b58 (diff)
downloadillumos-joyent-8359acfb8fd4655b7437bff72bed36033caf5420.tar.gz
OS-6400 want HVM exclusion lock
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Robert Mustacchi <rm@joyent.com>
-rw-r--r--usr/src/uts/i86pc/Makefile.files1
-rw-r--r--usr/src/uts/i86pc/os/pc_hvm.c57
-rw-r--r--usr/src/uts/i86pc/sys/pc_hvm.h35
3 files changed, 93 insertions, 0 deletions
diff --git a/usr/src/uts/i86pc/Makefile.files b/usr/src/uts/i86pc/Makefile.files
index 26d7f3f039..4993cc682b 100644
--- a/usr/src/uts/i86pc/Makefile.files
+++ b/usr/src/uts/i86pc/Makefile.files
@@ -99,6 +99,7 @@ CORE_OBJS += \
memscrub.o \
mpcore.o \
notes.o \
+ pc_hvm.o \
pci_bios.o \
pci_cfgacc.o \
pci_cfgacc_x86.o \
diff --git a/usr/src/uts/i86pc/os/pc_hvm.c b/usr/src/uts/i86pc/os/pc_hvm.c
new file mode 100644
index 0000000000..b74ceb17bf
--- /dev/null
+++ b/usr/src/uts/i86pc/os/pc_hvm.c
@@ -0,0 +1,57 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/mutex.h>
+#include <sys/debug.h>
+
+static kmutex_t hvm_excl_lock;
+static const char *hvm_excl_holder = NULL;
+
+/*
+ * HVM Exclusion Interface
+ *
+ * To avoid VMX/SVM conflicts from arising when multiple hypervisor providers
+ * (eg. KVM, bhyve) are shipped with the system, this simple advisory locking
+ * system is presented for their use. Until a proper hypervisor API, like the
+ * one in OSX, is shipped in illumos, this will serve as opt-in regulation to
+ * dictate that only a single hypervisor be allowed to configure the system and
+ * run at any given time.
+ */
+
+boolean_t
+hvm_excl_hold(const char *consumer)
+{
+ boolean_t res = B_FALSE;
+
+ mutex_enter(&hvm_excl_lock);
+ if (hvm_excl_holder == NULL) {
+ hvm_excl_holder = consumer;
+ res = B_TRUE;
+ }
+ mutex_exit(&hvm_excl_lock);
+
+ return (res);
+}
+
+void
+hvm_excl_rele(const char *consumer)
+{
+ mutex_enter(&hvm_excl_lock);
+ VERIFY(consumer == hvm_excl_holder);
+ hvm_excl_holder = NULL;
+ mutex_exit(&hvm_excl_lock);
+}
diff --git a/usr/src/uts/i86pc/sys/pc_hvm.h b/usr/src/uts/i86pc/sys/pc_hvm.h
new file mode 100644
index 0000000000..38acf052e4
--- /dev/null
+++ b/usr/src/uts/i86pc/sys/pc_hvm.h
@@ -0,0 +1,35 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
+
+#ifndef _PC_HVM_H
+#define _PC_HVM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(_KERNEL)
+
+extern boolean_t hvm_excl_hold(const char *);
+extern void hvm_excl_rele(const char *);
+
+#endif /* defined(_KERNEL) */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PC_HVM_H */