-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server/lib: add generic hypervisor enlightenment interface (#846)
Implement some basic infrastructure to support hypervisor enlightenments. The general idea is as follows: - propolis-lib defines `Enlightenment` and `EnlightenmentDevice` traits that are implemented by components that provide a particular guest-hypervisor interface. - Library users instantiate their chosen enlightenment stack and pass the resulting `Arc<dyn EnlightenmentDevice>` to the lib's `machine::Builder`. The resulting `Machine` contains vCPU objects that hold a reference to the selected `Enlightenment`. This allows them to forward RDMSR/WRMSR exits to the enlightenment stack for (possible) processing. - Library users can call `Enlightenment::add_cpuid` to allow hypervisor interfaces to inject CPUID identifiers into the `CpuidSet`s that are used to configure the VM's vCPUs. - Finally, library users can upcast an `EnlightenmentDevice` to an `Arc<dyn Lifecycle>` and use that reference to dispatch lifecycle and migration notifications to the active enlightenment stack. Implement a `BhyveGuestInterface` enlightenment stack that implements these interfaces but does nothing beyond exposing its vendor string in CPUID leaf 0x4000_0000. This matches the hypervisor-related CPUID and MSR behavior guests would have gotten before this change. More interesting hypervisor interfaces are left for future PRs. Add an instance spec field to allow propolis-server clients to select an enlightenment stack. If not specified this defaults to the bhyve interface; this provides compatibility when migrating to/from servers built without this code.
- Loading branch information
Showing
17 changed files
with
505 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Provides a bhyve-compatible guest-hypervisor interface. | ||
//! | ||
//! This interface supplies no special enlightenments; it merely identifies | ||
//! itself as a bhyve hypervisor in CPUID leaf 0x4000_0000. | ||
use cpuid_utils::{ | ||
bits::HYPERVISOR_BASE_LEAF, CpuidIdent, CpuidSet, CpuidValues, | ||
}; | ||
|
||
use crate::{ | ||
accessors::MemAccessor, | ||
common::{Lifecycle, VcpuId}, | ||
enlightenment::{AddCpuidError, Enlightenment}, | ||
msr::{MsrId, RdmsrOutcome, WrmsrOutcome}, | ||
}; | ||
|
||
/// An implementation of the bhyve guest-hypervisor interface. This interface | ||
/// exposes no special enlightenments; its only purpose is to inject the | ||
/// appropriate hypervisor ID into CPUID leaf 0x4000_0000, since this leaf will | ||
/// not otherwise appear in a propolis-server instance specification's CPUID | ||
/// settings. | ||
pub struct BhyveGuestInterface; | ||
|
||
impl Lifecycle for BhyveGuestInterface { | ||
fn type_name(&self) -> &'static str { | ||
"bhyve-guest-interface" | ||
} | ||
} | ||
|
||
impl Enlightenment for BhyveGuestInterface { | ||
fn add_cpuid(&self, cpuid: &mut CpuidSet) -> Result<(), AddCpuidError> { | ||
let mut to_add = CpuidSet::new(cpuid.vendor()); | ||
to_add | ||
.insert( | ||
CpuidIdent::leaf(HYPERVISOR_BASE_LEAF), | ||
// Leaf 0x4000_0000 is the maximum hypervisor leaf. "bhyve bhyve " | ||
// is the vendor ID, split across ebx/ecx/edx. | ||
CpuidValues { | ||
eax: HYPERVISOR_BASE_LEAF, | ||
ebx: 0x76796862, | ||
ecx: 0x68622065, | ||
edx: 0x20657679, | ||
}, | ||
) | ||
.expect("the map was previously empty"); | ||
|
||
super::add_cpuid(cpuid, to_add) | ||
} | ||
|
||
fn rdmsr(&self, _vcpu: VcpuId, _msr: MsrId) -> RdmsrOutcome { | ||
RdmsrOutcome::NotHandled | ||
} | ||
|
||
fn wrmsr(&self, _vcpu: VcpuId, _msr: MsrId, _value: u64) -> WrmsrOutcome { | ||
WrmsrOutcome::NotHandled | ||
} | ||
|
||
fn attach(&self, _parent: &MemAccessor) {} | ||
} |
Oops, something went wrong.