Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New VMM extension integration mechanism #560

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ project(hypervisor)
# Cmake global properties
# ------------------------------------------------------------------------------

include(ExternalProject)
include(${CMAKE_SOURCE_DIR}/scripts/cmake/global_vars.cmake)
include(${CMAKE_SOURCE_DIR}/scripts/cmake/macros.cmake)
include(${BF_CONFIG_DIR}/default.cmake)
include(${BF_FLAGS_DIR}/flags.cmake)
include(${BF_SCRIPTS_DIR}/cmake/build_rules.cmake)
include(${BF_SCRIPTS_DIR}/cmake/targets.cmake)
include(ExternalProject)

validate_build()

Expand Down Expand Up @@ -224,5 +224,7 @@ if(ENABLE_UNITTESTING)
endif()
endif()


add_vmm_extensions()
print_banner()
print_usage()
27 changes: 8 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ supported platforms and their dependencies:

#### Arch Linux:
```
sudo pacman -S git linux-headers nasm clang cmake
sudo pacman -S git linux-headers nasm clang cmake base-devel
```

#### Ubuntu 17.04 (or Higher):
Expand Down Expand Up @@ -177,30 +177,19 @@ bcdedit.exe /set testsigning ON
```
## Compilation Instructions

To compile, run the following commands:
To compile with default settings for your host environment, run the following commands:

```
git clone -b dev https://github.com/bareflank/hypervisor.git
mkdir hypervisor/build; cd hypervisor/build
cmake ..
mkdir build; cd build
cmake ../hypervisor
make -j<# cores + 1>
```

Also, if your modifying the hypervisor, we highly recommend enabling
unit testing and developer mode. This will enable the various different tools
that are needed to pass all of our CI tests. This also compiles the hypervisor
in debug mode.
- `-DENABLE_UNITTESTING=ON`
- `-DENABLE_DEVELOPER_MODE=ON`

Once this is enabled, you can run the following commands before submitting a
PR:
- `make test`
- `make format`
- `make tidy`

If you wish to enable the extended APIs, you can do so using the following.
- `-DENABLE_EXTENDED_APIS=ON` and/or `-DEXTENDED_APIS_PATH=<path>`
For more detailed build instuctions and configurations, see the
[detailed build instructions](scripts/docs/build_instructions.md).
For instructions on building and creating Bareflank extensions, see the
[extension build instructions](scripts/docs/extension_instructions.md)

## Usage Instructions

Expand Down
5 changes: 5 additions & 0 deletions scripts/cmake/build_rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ add_build_rule(
FAIL_MSG "Extended APIs unit tests require VMM unit tests, please enable UNITTEST_VMM"
)

add_build_rule(
FAIL_ON ${UNITTEST_VMM_EXTENSIONS} AND NOT ${UNITTEST_VMM}
FAIL_MSG "VMM extension unit tests require VMM unit tests, please enable UNITTEST_VMM"
)

# ------------------------------------------------------------------------------
# Developer-mode build rules
# ------------------------------------------------------------------------------
Expand Down
58 changes: 58 additions & 0 deletions scripts/cmake/config/bfconfig_template.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Bareflank Hypervisor
# Copyright (C) 2015 Assured Information Security, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# ------------------------------------------------------------------------------
# README
# ------------------------------------------------------------------------------

# Use this template and the examples below to configure the Bareflank build
# system and add VMM extensions. Remove the '#' symbol to uncomment a line.
#
# For detailed instructions on configuring and building Bareflank, see
# hypervisor/scripts/docs/build_instructions.md.

# For detailed instructions on configuring and adding VMM extensions, see
# hypervisor/scripts/docs/extension_instructions.md

# To view all available build system configuration variables, use ccmake or
# cmake-gui from your build directory:
# cd </path/to>/build; ccmake .

# ------------------------------------------------------------------------------
# Bareflank Build Configurations
# ------------------------------------------------------------------------------

# set(BUILD_TYPE Debug)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should provide documentation in the template so that all you have to do is read and modify the template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much documentation should go in the template? I choose the commented out lines in the template as specific examples of 90% of what you would want to do with this file, namely:

  • Setting a string type config
  • Setting a boolean type config
  • Adding an extension from GitHub
  • Adding an extension from a local directory

What else should be added? Maybe a link or reference to the build instructions readme? One-sentence descriptions of what each section is for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a fan of redundancy, so in this case I would say adding the build instructions, and then a link to all of the options that are available in another doc would be fine so long as each option is documented somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding something like this:

# For instructions on configuring and building Bareflank, see hypervisor/scripts/docs/build_instructions.md

# To view all available configurations, use ccmake or cmake-gui from your build directory:
#      cd </path/to>/build; ccmake .

I've been avoiding creating a file that documents all available build configurations because those things are going to change, get added, and get dropped really fluidly as we continue development. As the build README indicates, the best way to view all of the available configs is to use ccmake or cmake-gui. From those, you can see every available option, the possible values for each, and a description for each. If we go the README route for build configs, we'll have to remember to add/modify two things every time we touch a build config.

# set(BUILD_VMM_STATIC ON)
# set(ENABLE_DEVELOPER_MODE ON)

# ------------------------------------------------------------------------------
# Bareflank Extensions
# ------------------------------------------------------------------------------

# vmm_extension(
# extended_apis
# GIT_REPOSITORY https://github.com/bareflank/extended_apis.git
# GIT_TAG dev
# )

# vmm_extension(
# my_extension
# SOURCE_DIR ~/bareflank/my_extension
# DEPENDS extended_apis
# )
52 changes: 43 additions & 9 deletions scripts/cmake/config/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,36 @@
# using: cmake /path/to/src -DBFCONFIG=/path/to/config.cmake

# ------------------------------------------------------------------------------
# Import user configuration file (if specified)
# Import Bareflank build configuration file
# ------------------------------------------------------------------------------

# -DBFCONFIG=/path/to/bfconfig.cmake takes first precedence
# Search relative to the build directory first, then the source tree defaults
if(BFCONFIG)
find_file(_BFCONFIG_PATH ${BFCONFIG} ${BF_CONFIG_DIR})
set(_BFCONFIG_PATH ${_BFCONFIG_PATH} CACHE INTERNAL "")
if(EXISTS ${_BFCONFIG_PATH})
message(STATUS "Configuring Bareflank using: ${_BFCONFIG_PATH}")
include(${_BFCONFIG_PATH})
# Prevent infinite loop this file is specified
if(${BFCONFIG} STREQUAL default.cmake)
message(STATUS "Building Bareflank with default settings")
else()
message(FATAL_ERROR "Configuration file ${BFCONFIG} not found")
find_file(_BFCONFIG_PATH ${BFCONFIG} PATHS ${BF_BUILD_DIR} ${BF_CONFIG_DIR})
if(EXISTS ${_BFCONFIG_PATH})
message(STATUS "Configuring Bareflank using: ${_BFCONFIG_PATH}")
include(${_BFCONFIG_PATH})
else()
message(FATAL_ERROR "Configuration file ${BFCONFIG} not found")
endif()
endif()
# Next, search the current build directory for "bfconfig.cmake"
elseif(EXISTS ${BF_BUILD_DIR}/bfconfig.cmake)
message(STATUS "Configuring Bareflank using: ${BF_BUILD_DIR}/bfconfig.cmake")
include(${BF_BUILD_DIR}/bfconfig.cmake)
# Otherwise, fall back to the empty bfconfig template file
else()
message(STATUS "No configuration specified, using default settings")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${BF_CONFIG_DIR}/bfconfig_template.cmake
${BF_BUILD_DIR}/bfconfig.cmake
)
message(STATUS "No build configuration specified, using default settings")
endif()

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -140,6 +156,13 @@ add_config(
DESCRIPTION "Path to the Bareflank Extended APIs"
)

add_config(
CONFIG_NAME BUILD_VMM_EXTENSIONS
CONFIG_TYPE BOOL
DEFAULT_VAL ON
DESCRIPTION "Build all configured Bareflank VMM extensions"
)

if(${CMAKE_VERBOSE_MAKEFILE})
set(_BUILD_VERBOSE ON CACHE INTERNAL "")
else()
Expand Down Expand Up @@ -254,7 +277,18 @@ add_config(
CONFIG_NAME UNITTEST_VMM
CONFIG_TYPE BOOL
DEFAULT_VAL ${ENABLE_UNITTESTING}
DESCRIPTION "Build unit tests for the VMM"
DESCRIPTION "Build VMM unit tests"
)

set(_DEFAULT_UNITTEST_VMM_EXTENSIONS OFF CACHE INTERNAL "")
if(${ENABLE_UNITTESTING} AND ${BUILD_VMM_EXTENSIONS} AND ${UNITTEST_VMM})
set(_DEFAULT_UNITTEST_VMM_EXTENSIONS ON)
endif()
add_config(
CONFIG_NAME UNITTEST_VMM_EXTENSIONS
CONFIG_TYPE BOOL
DEFAULT_VAL ${_DEFAULT_UNITTEST_VMM_EXTENSIONS}
DESCRIPTION "Build VMM extension unit tests"
)

set(_DEFAULT_UNITTEST_BFDRIVER OFF CACHE INTERNAL "")
Expand Down
129 changes: 129 additions & 0 deletions scripts/cmake/config/default_extension.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#
# Bareflank Hypervisor
# Copyright (C) 2015 Assured Information Security, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# ------------------------------------------------------------------------------
# README
# ------------------------------------------------------------------------------

# This file defines all configurable cmake variables available to Barefank
# VMM extensions, set to their default value. These configuration are NOT
# available to base Bareflank hypervisor projects. VMM extension projects
# can use both these configurations PLUS the base hypervisor configurations.

# Each configuration here indicates the Bareflank suggested convention as
# a default value. The goal is to encourage a "convention over configuration"
# mindset for extension developers. If extension developers choose not follow
# a suggested convention, they can override a configuration using two methods:
#
# 1) Specify each configuration as CMAKE_ARGS to the vmm_extension() macro. Ex:
#
# vmm_extension(
# extension_name
# CMAKE_ARGS -DVMM_EX_BUILD_RULES=/path/to/build_rules.cmake
# )
#
# 2) Override a configuration in the extension's CMakeLists.txt file BEFORE
# calling include(${VMM_EXTENSION}). Ex:
#
# set(VMM_EX_BUILD_RULES "/path/to/build_rules.cmake")
# set(VMM_EX_UNITTEST_PATH "/path/to/the/unit/tests")
# include(${VMM_EXTENSION})
#

# ------------------------------------------------------------------------------
# Source tree structure
# ------------------------------------------------------------------------------

add_config(
CONFIG_NAME VMM_EX_TOP_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${CMAKE_CURRENT_SOURCE_DIR}
DESCRIPTION "Path to the top directory for this VMM extension"
)

add_config(
CONFIG_NAME VMM_EX_SOURCE_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${VMM_EX_TOP_DIR}/src
DESCRIPTION "Path to the source code directory for this VMM extension"
SKIP_VALIDATION
)

add_config(
CONFIG_NAME VMM_EX_INCLUDE_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${VMM_EX_TOP_DIR}/include
DESCRIPTION "Path to the header include directory for this VMM extension"
SKIP_VALIDATION
)

add_config(
CONFIG_NAME VMM_EX_UNITTEST_DIR
CONFIG_TYPE PATH
DEFAULT_VAL ${VMM_EX_TOP_DIR}/test
DESCRIPTION "Path to the unit test directory for this VMM extension"
SKIP_VALIDATION
)

# ------------------------------------------------------------------------------
# Build system features
# ------------------------------------------------------------------------------

add_config(
CONFIG_NAME VMM_EX_CONFIGS
CONFIG_TYPE FILE
DEFAULT_VAL ${VMM_EX_TOP_DIR}/configs.cmake
DESCRIPTION "Path to extention-specific build configurations to be added "
"for this VMM extension"
SKIP_VALIDATION
)

add_config(
CONFIG_NAME VMM_EX_BUILD_RULES
CONFIG_TYPE FILE
DEFAULT_VAL ${VMM_EX_TOP_DIR}/build_rules.cmake
DESCRIPTION "Path to a build rules file to be validated before building "
"this VMM extension"
SKIP_VALIDATION
)

# ------------------------------------------------------------------------------
# Read-only variables
# ------------------------------------------------------------------------------

add_config(
CONFIG_NAME VMM_EX_IS_UNITTEST_BUILD
CONFIG_TYPE INTERNAL
DEFAULT_VAL OFF
DESCRIPTION "The build system sets this variable to ON if this extension's "
"unit tests are currently being built, rather than it's source"
SKIP_VALIDATION
)

if(VMM_EX_IS_UNTTEST_BUILD)
set(_VMM_EX_SYSROOT_DEFAULT ${BUILD_SYSROOT_TEST})
else()
set(_VMM_EX_SYSROOT_DEFAULT ${BUILD_SYSROOT_VMM})
endif()
add_config(
CONFIG_NAME VMM_EX_SYSROOT
CONFIG_TYPE INTERNAL
DEFAULT_VAL ${_VMM_EX_SYSROOT_DEFAULT}
DESCRIPTION "Path to this VMM extension's sysroot"
SKIP_VALIDATION
)
Loading