openvmm_defs/config.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Configuration for the VM worker.
5
6pub use serial_uart_resources::UartId;
7pub use smbios_defs::SmbiosBiosOverrides;
8pub use smbios_defs::SmbiosConfig;
9pub use smbios_defs::SmbiosSystemOverrides;
10
11use guid::Guid;
12use input_core::InputData;
13use memory_range::MemoryRange;
14use mesh::MeshPayload;
15use mesh::payload::Protobuf;
16use net_backend_resources::mac_address::MacAddress;
17use openvmm_pcat_locator::RomFileLocation;
18use std::fs::File;
19use tpm_resources::TpmVersion;
20use vm_resource::Resource;
21use vm_resource::kind::PciDeviceHandleKind;
22use vm_resource::kind::VirtioDeviceHandle;
23use vm_resource::kind::VmbusDeviceHandleKind;
24use vmgs_resources::VmgsResource;
25use vmotherboard::ChipsetDeviceHandle;
26use vmotherboard::LegacyPciChipsetDeviceHandle;
27use vmotherboard::options::BaseChipsetManifest;
28use vmotherboard::options::VmChipsetCapabilities;
29
30#[derive(MeshPayload, Debug)]
31pub struct Config {
32 pub load_mode: LoadMode,
33 pub floppy_disks: Vec<floppy_resources::FloppyDiskConfig>,
34 pub ide_disks: Vec<ide_resources::IdeDeviceConfig>,
35 pub pcie_root_complexes: Vec<PcieRootComplexConfig>,
36 pub pcie_ecam_below_4gb: bool,
37 pub pcie_devices: Vec<PcieDeviceConfig>,
38 pub pcie_switches: Vec<PcieSwitchConfig>,
39 pub pcie_generic_initiators: Vec<PcieGenericInitiatorConfig>,
40 pub vpci_devices: Vec<VpciDeviceConfig>,
41 pub numa: NumaTopology,
42 /// Disable persistent guest-memory locking while keeping CPU copies available.
43 /// Host-owned I/O buffers are not restricted.
44 pub disable_guest_memory_locking: bool,
45 pub processor_topology: ProcessorTopologyConfig,
46 pub hypervisor: HypervisorConfig,
47 pub chipset: BaseChipsetManifest,
48 pub vmbus: Option<VmbusConfig>,
49 pub vtl2_vmbus: Option<VmbusConfig>,
50 #[cfg(windows)]
51 pub kernel_vmnics: Vec<KernelVmNicConfig>,
52 pub input: mesh::Receiver<InputData>,
53 pub framebuffer: Option<framebuffer::Framebuffer>,
54 pub vga_firmware: Option<RomFileLocation>,
55 pub vtl2_gfx: bool,
56 pub virtio_devices: Vec<(VirtioBus, Resource<VirtioDeviceHandle>)>,
57 #[cfg(windows)]
58 pub vpci_resources: Vec<virt_whp::device::DeviceHandle>,
59 pub vmgs: Option<VmgsResource>,
60 // TODO: move FirmwareEvent somewhere not GED-specific.
61 pub firmware_event_send: Option<mesh::Sender<get_resources::ged::FirmwareEvent>>,
62 pub debugger_rpc: Option<mesh::Receiver<vmm_core_defs::debug_rpc::DebugRequest>>,
63 pub vmbus_devices: Vec<(DeviceVtl, Resource<VmbusDeviceHandleKind>)>,
64 pub chipset_devices: Vec<ChipsetDeviceHandle>,
65 pub pci_chipset_devices: Vec<LegacyPciChipsetDeviceHandle>,
66 pub isa_dma_controller: Option<Resource<vm_resource::kind::IsaDmaControllerHandleKind>>,
67 pub chipset_capabilities: VmChipsetCapabilities,
68 /// Memory layout sizing for the layout engine. Determines chipset MMIO
69 /// range sizes; addresses are allocated dynamically by the resolver.
70 pub layout: vmm_core_defs::LayoutConfig,
71 // This is used for testing. TODO: resourcify, and also store this in VMGS.
72 pub rtc_delta_milliseconds: i64,
73}
74
75pub const DEFAULT_GIC_DISTRIBUTOR_BASE: u64 = 0xFFFF_0000;
76// The KVM in-kernel vGICv3 requires the distributor and redistributor bases be 64KiB aligned.
77pub const DEFAULT_GIC_REDISTRIBUTORS_BASE: u64 = cfg_select! {
78 target_os = "linux" => 0xEFFF_0000,
79 _ => 0xEFFE_E000,
80};
81
82/// Base address of the guest-visible GIC v2m MSI frame (exposed via the MADT
83/// and used by the software v2m SETSPI decoder for emulated devices). This is
84/// OpenVMM-emulated MMIO (one 4 KiB page), not shadowed by the hypervisor, so
85/// it stays at the conventional address.
86pub const DEFAULT_GIC_V2M_MSI_FRAME_BASE: u64 = 0xEFFE_8000;
87/// Size of the v2m MSI frame (one 4KB page is the architectural minimum).
88pub const GIC_V2M_MSI_FRAME_SIZE: u64 = 0x1000;
89
90/// Default device-assignment MSI IOVA reservation for a physical SMMU
91/// implementation that lets the VMM select the range. The base follows the
92/// Hyper-V convention; 1 MiB matches Linux's Arm SMMU reservation size.
93pub const DEFAULT_DEVICE_ASSIGNMENT_MSI_IOVA_RANGE: MemoryRange =
94 MemoryRange::new(0xEFF6_8000..0xF006_8000);
95
96/// Base address of the GICv3 ITS MMIO region. Must be 64 KiB aligned,
97/// below the v2m frame address, and not overlap other devices.
98/// The region extends from this base to base + GIC_ITS_SIZE (128 KiB).
99pub const DEFAULT_GIC_ITS_BASE: u64 = 0xEFFC_0000;
100/// Size of the ITS MMIO region (control frame + translation frame, 2×64 KiB).
101pub const GIC_ITS_SIZE: u64 = 0x2_0000;
102
103/// Default virtual timer PPI (GIC INTID). PPI 4 = INTID 16 + 4 = 20.
104/// This is the EL1 virtual timer interrupt used across Hyper-V, KVM, and HVF.
105pub const DEFAULT_VIRT_TIMER_PPI: u32 = 20;
106
107/// Default total number of GIC interrupts (SGIs + PPIs + SPIs).
108/// Must satisfy KVM constraints: 64 <= n <= 1023, multiple of 32.
109/// 992 = 31 × 32 is the largest valid value.
110pub const DEFAULT_GIC_NR_IRQS: u32 = 992;
111
112/// Default VMBus PPI (GIC INTID). PPI 2 = INTID 16 + 2 = 18.
113pub const DEFAULT_VMBUS_PPI: u32 = 18;
114
115/// Default IOAPIC interrupt for the ACPI power button on x86_64.
116pub const DEFAULT_ACPI_POWER_BUTTON_IRQ_X64: u32 = 10;
117/// Default GIC SPI index (INTID 39) for the ACPI power button on AArch64.
118///
119/// Firmware reserves INTIDs 35-38 for generation ID, battery, PMEM, and
120/// processor-idle events.
121pub const DEFAULT_ACPI_POWER_BUTTON_SPI_AARCH64: u32 = 7;
122
123/// How firmware tables are presented to the guest in Linux direct boot.
124///
125/// On x86, `DeviceTree` is not supported and will be rejected. On aarch64,
126/// this selects between a full device tree or an ACPI boot path.
127#[derive(MeshPayload, Debug, Clone, Copy, PartialEq, Eq)]
128pub enum LinuxDirectBootMode {
129 /// Full device tree with all devices described in DT nodes (aarch64 only).
130 DeviceTree,
131 /// ACPI tables for device discovery. On aarch64, this also synthesizes
132 /// an EFI system table so the kernel enters its ACPI code path. On x86,
133 /// ACPI tables are always provided via the zero page.
134 Acpi,
135}
136
137/// Isolation-specific settings for Linux direct boot.
138#[derive(MeshPayload, Debug, Clone, Copy, PartialEq, Eq)]
139pub enum LinuxIsolationConfig {
140 /// No isolation-specific loader configuration.
141 None,
142 /// AMD SEV-SNP loader configuration.
143 Snp {
144 /// Enables restricted interrupt injection in the SNP VMSA.
145 restricted_injection: bool,
146 },
147}
148
149#[derive(MeshPayload, Debug)]
150pub enum LoadMode {
151 Linux {
152 kernel: File,
153 initrd: Option<File>,
154 cmdline: String,
155 enable_serial: bool,
156 isolation: LinuxIsolationConfig,
157 boot_mode: LinuxDirectBootMode,
158 // Boxed to keep the `Linux` variant from dominating `LoadMode`'s size.
159 smbios: Box<SmbiosConfig>,
160 },
161 Uefi {
162 firmware: File,
163 enable_debugging: bool,
164 enable_memory_protections: bool,
165 disable_frontpage: bool,
166 tpm_version: Option<TpmVersion>,
167 enable_battery: bool,
168 enable_serial: bool,
169 enable_vpci_boot: bool,
170 uefi_console_mode: Option<UefiConsoleMode>,
171 default_boot_always_attempt: bool,
172 // Boxed to keep the `Uefi` variant from dominating `LoadMode`'s size.
173 // The VM's BIOS GUID is sourced from `smbios.system.uuid`, so UEFI and
174 // Linux direct boot share a single UUID origin.
175 smbios: Box<SmbiosConfig>,
176 enable_vmbus: bool,
177 force_dma_bounce: bool,
178 enable_hv: bool,
179 /// Whether the guest firmware should enable hibernation (S4) support.
180 hibernation_enabled: bool,
181 force_firmware_version: bool,
182 },
183 Pcat {
184 firmware: RomFileLocation,
185 boot_order: [PcatBootDevice; 4],
186 /// Whether the guest firmware should enable hibernation (S4) support.
187 hibernation_enabled: bool,
188 // Boxed to keep the `Pcat` variant from dominating `LoadMode`'s size.
189 // Only the system UUID and serial number are honored; the PCAT BIOS ROM
190 // self-describes everything else, so other overrides are rejected.
191 smbios: Box<SmbiosConfig>,
192 },
193 Igvm {
194 file: File,
195 cmdline: String,
196 vtl2_base_address: Vtl2BaseAddressType,
197 com_serial: Option<UartId>,
198 personality: IgvmPersonality,
199 },
200 None,
201}
202
203/// The firmware that an IGVM file contains.
204#[derive(Debug, Clone, Copy, PartialEq, Eq, MeshPayload)]
205pub enum IgvmPersonality {
206 /// The OpenHCL paravisor, hosted in VTL2.
207 Openhcl,
208 /// UEFI firmware.
209 Uefi,
210 /// A Linux kernel.
211 LinuxDirect,
212}
213
214/// Different types to specify the base address for the VTL2 region of the IGVM
215/// file.
216#[derive(Debug, Clone, Copy, MeshPayload)]
217pub enum Vtl2BaseAddressType {
218 /// Use the addresses specified in the file. The IGVM file does not need to
219 /// support relocations.
220 File,
221 /// Put VTL2 at the specified address. The IGVM file must support
222 /// relocations.
223 Absolute(u64),
224 /// Use the specified range in the supplied MemoryLayout, as the caller has
225 /// created a specific range for VTL2. The IGVM file must support
226 /// relocations.
227 ///
228 /// An optional size may be specified to override the size describing VTL2
229 /// provided in the IGVM file. It must be larger than the IGVM file provided
230 /// size.
231 MemoryLayout { size: Option<u64> },
232 /// Tell VTL2 to allocate out it's own memory. This will load the file at
233 /// the base address specified in the file, and the host will tell VTL2 the
234 /// size of memory to allocate for itself.
235 ///
236 /// An optional size may be specified to override the size describing VTL2
237 /// provided in the IGVM file. It must be larger than the IGVM file provided
238 /// size.
239 Vtl2Allocate { size: Option<u64> },
240}
241
242/// Specifies a PCIe MMIO BAR window, either by size (the resolver allocates) or
243/// by a fixed location. Fixed locations exist for assigned-device, IOMMU, and
244/// physical-topology compatibility.
245#[derive(Debug, MeshPayload)]
246pub enum PcieMmioRangeConfig {
247 /// Dynamically allocate a range of the given size.
248 Dynamic {
249 /// Size of the range in bytes.
250 size: u64,
251 },
252 /// Use the specified fixed memory range.
253 Fixed(MemoryRange),
254}
255
256#[derive(Debug, MeshPayload)]
257pub struct RootComplexCxlConfig {
258 /// HDM window size in bytes for this CXL root complex.
259 pub hdm_size: u64,
260 /// CFMWS HDM window restrictions bitmask.
261 pub hdm_window_restrictions: u16,
262}
263
264#[derive(Debug, MeshPayload)]
265pub struct PcieRootComplexConfig {
266 pub index: u32,
267 pub name: String,
268 pub segment: u16,
269 pub start_bus: u8,
270 pub end_bus: u8,
271 /// Whether this root complex owns legacy PCI configuration I/O ports.
272 pub legacy_pci_config_io: bool,
273 pub low_mmio: PcieMmioRangeConfig,
274 pub high_mmio: PcieMmioRangeConfig,
275 pub ports: Vec<PciePortConfig>,
276 /// Optional CXL configuration for root-complex CXL mode.
277 pub cxl: Option<RootComplexCxlConfig>,
278 /// Optional IOMMU for this root complex.
279 pub iommu: Option<PcieIommuConfig>,
280 /// NUMA node affinity for this root complex. Used to generate `_PXM` in
281 /// the ACPI SSDT so the guest OS sees correct NUMA locality for devices
282 /// under this root complex.
283 pub vnode: Option<u32>,
284 /// When true, treat non-zero BAR values found during probing as pinned
285 /// addresses. Used for P2P DMA with GPA = HPA.
286 pub preserve_bars: bool,
287}
288
289/// Configuration for a single PCIe port — either a root-complex root port or a
290/// switch downstream port.
291#[derive(Debug, MeshPayload)]
292pub struct PciePortConfig {
293 /// Port name used for topology wiring and lookup.
294 pub name: String,
295 /// The device/function (`device << 3 | function`) to place this port at on
296 /// its bus.
297 ///
298 /// When `None`, the port is assigned the lowest available devfn. Ports are
299 /// assigned in order, so an explicit devfn that collides with a
300 /// previously-assigned port (including one assigned automatically) is an
301 /// error. Honored for both root-complex root ports and switch downstream
302 /// ports.
303 pub devfn: Option<u8>,
304 /// Advertises native PCIe slot hotplug capability.
305 pub hotplug: bool,
306 /// Optional ACS capability bitmask to expose on this port.
307 pub acs_capabilities_supported: Option<u16>,
308 /// Marks this port as CXL-capable.
309 ///
310 /// Runtime port construction derives required BAR/subregion layout from
311 /// this flag (currently CXL component registers for BAR0).
312 pub cxl: bool,
313 /// Enables PASID support for functions downstream of this port.
314 pub pasid: bool,
315 /// Routes hotplug through ACPI even if the port advertises native PCIe
316 /// hotplug capability. Only one root port per VM may use ACPI hotplug.
317 pub acpi_hotplug: bool,
318}
319
320#[derive(Debug, MeshPayload)]
321pub struct PcieSwitchConfig {
322 pub name: String,
323 pub parent_port: String,
324 /// The downstream ports of this switch.
325 pub ports: Vec<PciePortConfig>,
326}
327
328/// Declares that the device directly behind a named PCIe port (a root port or
329/// a switch downstream port) is a generic initiator (GI) for the given NUMA
330/// node. Used to generate an SRAT Generic Initiator Affinity structure so the
331/// guest attaches the device's memory to that (typically CPU-less) proximity
332/// domain.
333///
334/// The port is resolved against the live topology by port name after switch
335/// downstream ports have been enumerated, so it can target devices that sit
336/// behind a switch.
337#[derive(Debug, MeshPayload)]
338pub struct PcieGenericInitiatorConfig {
339 /// Name of the PCIe port (root port or switch downstream port) behind
340 /// which the generic-initiator device resides.
341 pub port_name: String,
342 /// NUMA node the device is a generic initiator for.
343 pub node: u32,
344}
345
346#[derive(Debug, MeshPayload)]
347pub struct PcieDeviceConfig {
348 pub port_name: String,
349 pub resource: Resource<PciDeviceHandleKind>,
350}
351
352#[derive(Debug, MeshPayload)]
353pub struct VpciDeviceConfig {
354 pub vtl: DeviceVtl,
355 /// The ID of the device. Vpci devices are identified by a portion of `data2` and `data3` of the
356 /// instance ID, which is used to generate the guest-visible device ID.
357 pub instance_id: Guid,
358 pub resource: Resource<PciDeviceHandleKind>,
359 /// NUMA node affinity for this VPCI device.
360 pub vnode: Option<u32>,
361}
362
363#[derive(Debug, Protobuf)]
364pub struct ProcessorTopologyConfig {
365 pub proc_count: u32,
366 pub vps_per_socket: Option<u32>,
367 pub enable_smt: Option<bool>,
368 pub arch: Option<ArchTopologyConfig>,
369}
370
371#[derive(Debug, Protobuf, Default, Clone)]
372pub struct X86TopologyConfig {
373 pub apic_id_offset: u32,
374 pub x2apic: X2ApicConfig,
375}
376
377#[derive(Debug, Default, Copy, Clone, Protobuf)]
378pub enum X2ApicConfig {
379 #[default]
380 /// Support the X2APIC if recommended by the hypervisor or if needed by the
381 /// topology configuration.
382 Auto,
383 /// Support the X2APIC, and automatically enable it if needed to address all
384 /// processors.
385 Supported,
386 /// Do not support the X2APIC.
387 Unsupported,
388 /// Support and enable the X2APIC.
389 Enabled,
390}
391
392#[derive(Debug, Protobuf, Default, Clone)]
393pub enum PmuGsivConfig {
394 #[default]
395 /// Use the hypervisor's platform GSIV value for the PMU.
396 Platform,
397 /// Use the specified GSIV value for the PMU.
398 Gsiv(u32),
399 /// Disable the PMU.
400 Disabled,
401}
402
403/// MSI controller selection for aarch64 PCIe interrupt delivery.
404#[derive(Debug, Protobuf, Default, Clone)]
405pub enum GicMsiConfig {
406 /// Automatically select the best available MSI controller:
407 /// ITS when the hypervisor supports it, otherwise GICv2m.
408 #[default]
409 Auto,
410 /// Force GICv3 ITS for MSI delivery via LPIs.
411 Its,
412 /// Force GICv2m for MSI delivery via SPIs.
413 V2m {
414 /// Number of SPIs to reserve for PCIe MSIs. Defaults to a
415 /// platform-specific value when `None`.
416 spi_count: Option<u32>,
417 },
418}
419
420/// IOMMU configuration for a single PCIe root complex.
421#[derive(Debug, MeshPayload, Clone)]
422pub enum PcieIommuConfig {
423 /// AMD IOMMU (AMD-Vi) for x86_64 guests.
424 AmdVi,
425 /// Arm SMMUv3 for aarch64 guests.
426 Smmu {
427 /// Enable HW-accelerated nested translation (iommufd). Requires VFIO
428 /// devices with `iommu=` behind this SMMU.
429 accel: bool,
430 /// Output address size (OAS) resolution policy.
431 oas: SmmuOas,
432 /// SubstreamID width (SSIDSIZE) resolution policy.
433 ssidsize: SmmuSsidSize,
434 },
435 /// Intel VT-d for x86_64 guests.
436 IntelVtd,
437}
438
439/// Output address size (OAS) policy for an emulated SMMUv3.
440#[derive(Debug, MeshPayload, Clone, Copy)]
441pub enum SmmuOas {
442 /// Advertise a fixed default OAS. See `DEFAULT_AUTO_OAS_BITS` for the
443 /// sizing policy and its limits.
444 Auto,
445 /// Use a fixed OAS in bits (one of 32, 36, 40, 42, 44, 48, 52).
446 Fixed(u8),
447}
448
449/// SubstreamID width (SSIDSIZE) policy for an emulated SMMUv3.
450#[derive(Debug, MeshPayload, Clone, Copy)]
451pub enum SmmuSsidSize {
452 /// Disable substreams in software mode; under acceleration, adopt the
453 /// host's width before device start freezes the capabilities.
454 Auto,
455 /// Use a fixed width in bits (0..=20). Zero disables substreams.
456 /// Under acceleration, this cannot exceed the host's width.
457 Fixed(u8),
458}
459
460#[derive(Debug, Protobuf, Default, Clone)]
461pub struct Aarch64TopologyConfig {
462 pub gic_config: Option<GicConfig>,
463 pub pmu_gsiv: PmuGsivConfig,
464 pub gic_msi: GicMsiConfig,
465}
466
467/// GIC configuration for the virtual machine.
468///
469/// The variant selects the GIC version. `None` inner config means use
470/// defaults for that version's addresses.
471#[derive(Debug, Protobuf, Clone)]
472pub enum GicConfig {
473 /// GICv2 with optional address overrides.
474 V2(Option<GicV2Config>),
475 /// GICv3 with optional address overrides.
476 V3(Option<GicV3Config>),
477}
478
479/// GICv2-specific address configuration.
480#[derive(Debug, Protobuf, Clone)]
481pub struct GicV2Config {
482 pub gic_distributor_base: u64,
483 pub cpu_interface_base: u64,
484}
485
486/// GICv3-specific address configuration.
487#[derive(Debug, Protobuf, Clone)]
488pub struct GicV3Config {
489 pub gic_distributor_base: u64,
490 pub gic_redistributors_base: u64,
491}
492
493#[derive(Debug, Protobuf, Clone)]
494pub enum ArchTopologyConfig {
495 X86(X86TopologyConfig),
496 Aarch64(Aarch64TopologyConfig),
497}
498
499/// Per-node memory allocation configuration.
500#[derive(Debug, Clone, Copy, MeshPayload)]
501pub struct MemoryConfig {
502 pub mem_size: u64,
503 pub prefetch_memory: bool,
504 pub private_memory: bool,
505 pub transparent_hugepages: bool,
506 pub hugepages: bool,
507 pub hugepage_size: Option<u64>,
508 /// Host physical NUMA node to bind this allocation to (Linux:
509 /// `mbind(MPOL_BIND)`). `None` means OS default placement.
510 pub host_numa_node: Option<u32>,
511}
512
513/// Virtual NUMA topology for the VM.
514#[derive(Debug, MeshPayload)]
515pub struct NumaTopology {
516 /// NUMA nodes. The vnode ID is the index into this vector.
517 pub nodes: Vec<NumaNode>,
518 /// Inter-node distances for the SLIT. If empty, defaults are used
519 /// (10 for self, 20 for cross-node).
520 pub distances: Vec<NumaDistance>,
521}
522
523/// A single virtual NUMA node.
524#[derive(Debug, MeshPayload)]
525pub struct NumaNode {
526 /// Memory allocation for this node. `None` means a CPU-only or
527 /// device-only node.
528 pub mem: Option<MemoryConfig>,
529 /// VP assignment for this node.
530 pub vps: VpAssignment,
531}
532
533/// How VPs are assigned to a NUMA node.
534#[derive(Debug, MeshPayload)]
535pub enum VpAssignment {
536 /// Assign VPs to nodes by round-robining sockets over the CPU-bearing
537 /// nodes only: a VP with socket ID `vp_index / vps_per_socket` belongs to
538 /// the `(vp_index / vps_per_socket) % num_cpu_nodes`-th `FromTopology`
539 /// node. `vps_per_socket` comes from `ProcessorTopologyConfig`;
540 /// `num_cpu_nodes` is the number of `FromTopology` nodes, so `Empty`
541 /// (CPU-less) nodes are skipped and do not affect the distribution.
542 FromTopology,
543 /// Explicit VP indices assigned to this node.
544 Explicit(Vec<u32>),
545 /// A CPU-less node: no VPs are assigned to it. Unlike `Explicit`, this
546 /// may be combined with `FromTopology` nodes, so a memory- or
547 /// device-only node can be declared without forcing every other node to
548 /// spell out its VP set.
549 Empty,
550}
551
552/// An inter-node distance entry for the ACPI SLIT.
553#[derive(Debug, MeshPayload)]
554pub struct NumaDistance {
555 /// Source node index.
556 pub src: u32,
557 /// Destination node index.
558 pub dst: u32,
559 /// Distance value (10 = local, 20 = default cross-node, 255 = unreachable).
560 pub distance: u8,
561}
562
563#[derive(Debug, MeshPayload, Default)]
564pub struct VmbusConfig {
565 pub vsock_listener: Option<unix_socket::UnixListener>,
566 pub vsock_path: Option<String>,
567 pub vmbus_max_version: Option<u32>,
568 #[cfg(windows)]
569 pub vmbusproxy_handle: Option<vmbus_proxy::ProxyHandle>,
570 pub vtl2_redirect: bool,
571}
572
573#[derive(Debug, MeshPayload, Default)]
574pub struct HypervisorConfig {
575 pub with_hv: bool,
576 pub with_vtl2: Option<Vtl2Config>,
577 pub with_isolation: Option<IsolationType>,
578 /// Expose hardware virtualization (VMX/SVM) to the guest so that it can run
579 /// its own hypervisor. A backend that does not recognize this request
580 /// rejects it rather than silently ignoring it (see
581 /// `virt::Hypervisor::recognizes_nested_virt`).
582 pub nested_virt: bool,
583}
584
585#[derive(Debug, MeshPayload)]
586pub struct KernelVmNicConfig {
587 pub instance_id: Guid,
588 pub mac_address: MacAddress,
589 pub switch_port_id: SwitchPortId,
590}
591
592#[derive(Clone, Debug, MeshPayload)]
593pub struct SwitchPortId {
594 pub switch: Guid,
595 pub port: Guid,
596}
597
598pub const DEFAULT_PCAT_BOOT_ORDER: [PcatBootDevice; 4] = [
599 PcatBootDevice::Optical,
600 PcatBootDevice::HardDrive,
601 PcatBootDevice::Network,
602 PcatBootDevice::Floppy,
603];
604
605#[derive(MeshPayload, Debug, Clone, Copy, PartialEq)]
606pub enum PcatBootDevice {
607 Floppy,
608 HardDrive,
609 Optical,
610 Network,
611}
612
613#[derive(Eq, PartialEq, Debug, Copy, Clone, MeshPayload)]
614pub enum VirtioBus {
615 Mmio,
616 Pci,
617}
618
619/// Policy for the partition when mapping VTL0 memory late.
620#[derive(Eq, PartialEq, Debug, Copy, Clone, MeshPayload)]
621pub enum LateMapVtl0MemoryPolicy {
622 /// Halt execution of the VP if VTL0 memory is accessed.
623 Halt,
624 /// Log the error but emulate the access with the instruction emulator.
625 Log,
626 /// Inject an exception into the guest.
627 InjectException,
628}
629
630impl From<LateMapVtl0MemoryPolicy> for virt::LateMapVtl0MemoryPolicy {
631 fn from(value: LateMapVtl0MemoryPolicy) -> Self {
632 match value {
633 LateMapVtl0MemoryPolicy::Halt => virt::LateMapVtl0MemoryPolicy::Halt,
634 LateMapVtl0MemoryPolicy::Log => virt::LateMapVtl0MemoryPolicy::Log,
635 LateMapVtl0MemoryPolicy::InjectException => {
636 virt::LateMapVtl0MemoryPolicy::InjectException
637 }
638 }
639 }
640}
641
642/// Configuration for VTL2.
643///
644/// NOTE: This is distinct from `virt::Vtl2Config` to keep an abstraction
645/// between the virt crate and this crate. Users should not be specifying
646/// virt crate configuration directly.
647#[derive(Debug, Clone, MeshPayload)]
648pub struct Vtl2Config {
649 /// Enable the VTL0 alias map. This maps VTL0's view of memory in VTL2 at
650 /// the highest legal physical address bit.
651 pub vtl0_alias_map: bool,
652 /// If set, map VTL0 memory late after VTL2 has started. The current
653 /// heuristic is to defer mapping VTL0 memory until the first
654 /// `HvModifyVtlProtectionMask` hypercall is made.
655 pub late_map_vtl0_memory: Option<LateMapVtl0MemoryPolicy>,
656}
657
658// Isolation type for a partition.
659#[derive(Eq, PartialEq, Debug, Copy, Clone, MeshPayload)]
660pub enum IsolationType {
661 Vbs,
662 Snp {
663 /// Optional host-provided data included in SNP launch finish.
664 host_data: Option<[u8; 32]>,
665 },
666 Cca,
667}
668
669impl From<IsolationType> for virt::IsolationType {
670 fn from(value: IsolationType) -> Self {
671 match value {
672 IsolationType::Vbs => Self::Vbs,
673 IsolationType::Snp { .. } => Self::Snp,
674 IsolationType::Cca => Self::Cca,
675 }
676 }
677}
678
679/// Which VTL to assign a particular device to.
680#[derive(Copy, Clone, Debug, PartialEq, Eq, MeshPayload)]
681pub enum DeviceVtl {
682 Vtl0,
683 Vtl1,
684 Vtl2,
685}
686
687#[derive(Copy, Clone, Debug, MeshPayload)]
688pub enum UefiConsoleMode {
689 Default,
690 Com1,
691 Com2,
692 None,
693}