Skip to content

Commit

Permalink
openvmm: support more devices with a VTL0 paravisor (microsoft#246)
Browse files Browse the repository at this point in the history
Offer vmbus serial ports to VTL0 when VTL2 is disabled. Support
paravisor storage and networking configuration without VTL2. Allow the
UEFI console mode to be set when booting via IGVM.
  • Loading branch information
jstarks authored Nov 5, 2024
1 parent 2e7ddc3 commit e33c6d4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
4 changes: 2 additions & 2 deletions openvmm/hvlite_entry/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ flags:
pub internal_worker: Option<Option<String>>,

/// redirect the VTL 0 vmbus control plane to a proxy in VTL 2.
#[clap(long)]
#[clap(long, requires("vtl2"))]
pub vmbus_redirect: bool,

/// limit the maximum protocol version allowed by vmbus; used for testing purposes
Expand Down Expand Up @@ -511,7 +511,7 @@ flags:
pub battery: bool,

/// set the uefi console mode
#[clap(long, requires("uefi"))]
#[clap(long)]
pub uefi_console_mode: Option<UefiConsoleModeCli>,
}

Expand Down
24 changes: 13 additions & 11 deletions openvmm/hvlite_entry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ fn vm_config_from_command_line(
.spawn(|| serial_pool.run())
.unwrap();

let openhcl_vtl = if opt.vtl2 {
DeviceVtl::Vtl2
} else {
DeviceVtl::Vtl0
};

let console_state: RefCell<Option<ConsoleState<'_>>> = RefCell::new(None);
let setup_serial = |name: &str, cli_cfg, device| -> anyhow::Result<_> {
Ok(match cli_cfg {
Expand Down Expand Up @@ -357,7 +363,7 @@ fn vm_config_from_command_line(
"vmbus_com1",
)? {
vmbus_devices.push((
DeviceVtl::Vtl2,
openhcl_vtl,
VmbusSerialDeviceHandle {
port: VmbusSerialPort::Com1,
backend: vmbus_com1_cfg,
Expand All @@ -376,7 +382,7 @@ fn vm_config_from_command_line(
"vmbus_com2",
)? {
vmbus_devices.push((
DeviceVtl::Vtl2,
openhcl_vtl,
VmbusSerialDeviceHandle {
port: VmbusSerialPort::Com2,
backend: vmbus_com2_cfg,
Expand Down Expand Up @@ -415,7 +421,9 @@ fn vm_config_from_command_line(
);
}

let mut storage = storage_builder::StorageBuilder::new();
let with_get = opt.get || opt.vtl2;

let mut storage = storage_builder::StorageBuilder::new(with_get.then_some(openhcl_vtl));
for &cli_args::DiskCli {
vtl,
ref kind,
Expand Down Expand Up @@ -496,7 +504,7 @@ fn vm_config_from_command_line(
if !opt.no_alias_map {
anyhow::bail!("must specify --no-alias-map to offer NICs to VTL2");
}
let mana = mana_nics[2].get_or_insert_with(|| {
let mana = mana_nics[openhcl_vtl as usize].get_or_insert_with(|| {
let vpci_instance_id = Guid::new_random();
underhill_nics.push(vtl2_settings_proto::NicDeviceLegacy {
instance_id: vpci_instance_id.to_string(),
Expand Down Expand Up @@ -801,13 +809,7 @@ fn vm_config_from_command_line(
};
}

let openhcl_vtl = if opt.vtl2 {
DeviceVtl::Vtl2
} else {
DeviceVtl::Vtl0
};

if (opt.vtl2 || opt.get) && with_hv {
if with_get && with_hv {
let vtl2_settings = vtl2_settings_proto::Vtl2Settings {
version: vtl2_settings_proto::vtl2_settings_base::Version::V1.into(),
fixed: Some(Default::default()),
Expand Down
30 changes: 24 additions & 6 deletions openvmm/hvlite_entry/src/storage_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use vtl2_settings_proto::storage_controller;
use vtl2_settings_proto::Lun;
use vtl2_settings_proto::StorageController;

#[derive(Default)]
pub(super) struct StorageBuilder {
vtl0_ide_disks: Vec<IdeDeviceConfig>,
vtl0_scsi_devices: Vec<ScsiDeviceAndPath>,
Expand All @@ -37,6 +36,7 @@ pub(super) struct StorageBuilder {
vtl2_nvme_namespaces: Vec<NamespaceDefinition>,
underhill_scsi_luns: Vec<Lun>,
underhill_nvme_luns: Vec<Lun>,
openhcl_vtl: Option<DeviceVtl>,
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -67,8 +67,17 @@ const UNDERHILL_VTL0_NVME_INSTANCE: Guid =
Guid::from_static_str("09a59b81-2bf6-4164-81d7-3a0dc977ba65");

impl StorageBuilder {
pub fn new() -> Self {
Self::default()
pub fn new(openhcl_vtl: Option<DeviceVtl>) -> Self {
Self {
vtl0_ide_disks: Vec::new(),
vtl0_scsi_devices: Vec::new(),
vtl2_scsi_devices: Vec::new(),
vtl0_nvme_namespaces: Vec::new(),
vtl2_nvme_namespaces: Vec::new(),
underhill_scsi_luns: Vec::new(),
underhill_nvme_luns: Vec::new(),
openhcl_vtl,
}
}

pub fn has_vtl0_nvme(&self) -> bool {
Expand Down Expand Up @@ -210,19 +219,28 @@ impl StorageBuilder {
is_dvd: bool,
read_only: bool,
) -> anyhow::Result<()> {
let vtl = self.openhcl_vtl.context("openhcl not configured")?;
let sub_device_path = self
.add_inner(DeviceVtl::Vtl2, source, kind, is_dvd, read_only)?
.add_inner(vtl, source, kind, is_dvd, read_only)?
.context("source device not supported by underhill")?;

let (device_type, device_path) = match source {
DiskLocation::Ide(_, _) => anyhow::bail!("ide source not supported for Underhill"),
DiskLocation::Scsi(_) => (
vtl2_settings_proto::physical_device::DeviceType::Vscsi,
SCSI_VTL2_INSTANCE_ID,
if vtl == DeviceVtl::Vtl2 {
SCSI_VTL2_INSTANCE_ID
} else {
SCSI_VTL0_INSTANCE_ID
},
),
DiskLocation::Nvme(_) => (
vtl2_settings_proto::physical_device::DeviceType::Nvme,
NVME_VTL2_INSTANCE_ID,
if vtl == DeviceVtl::Vtl2 {
NVME_VTL2_INSTANCE_ID
} else {
NVME_VTL0_INSTANCE_ID
},
),
};

Expand Down

0 comments on commit e33c6d4

Please sign in to comment.