Skip to content

Commit

Permalink
OS-6400 want HVM exclusion lock
Browse files Browse the repository at this point in the history
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
  • Loading branch information
pfmooney committed Oct 17, 2017
1 parent 3e8f2de commit 8359acf
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions usr/src/uts/i86pc/Makefile.files
Expand Up @@ -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 \
Expand Down
57 changes: 57 additions & 0 deletions 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);
}
35 changes: 35 additions & 0 deletions 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 */

0 comments on commit 8359acf

Please sign in to comment.