Skip to content

Commit

Permalink
Create a new hv1_structs crate, move vtl_array into it (#833)
Browse files Browse the repository at this point in the history
This new crate is intended to be a minimal dependency crate for sharing
useful data structures around, analogous to hvdef but for things we
define ourselves, without requiring crates to depend on all of
hv1_hypercall. Today it holds only VtlArray and Set, but I plan to add
more to it soon. Namely, a ProcessorSet to allow for lazy parsing of the
hypervisor's processor bank & mask structures.

See #835 for my planned first new data structure here
  • Loading branch information
smalis-msft authored Feb 11, 2025
1 parent 5035796 commit 8521b96
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 33 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ dependencies = [
"build_rs_guest_arch",
"fs-err",
"getrandom",
"hv1_structs",
"hvdef",
"inspect",
"libc",
Expand All @@ -2653,7 +2654,6 @@ dependencies = [
"thiserror 2.0.0",
"tracelimit",
"tracing",
"vtl_array",
"x86defs",
"zerocopy 0.8.14",
]
Expand Down Expand Up @@ -2785,6 +2785,7 @@ version = "0.0.0"
dependencies = [
"build_rs_guest_arch",
"guestmem",
"hv1_structs",
"hvdef",
"inspect",
"parking_lot",
Expand All @@ -2793,7 +2794,6 @@ dependencies = [
"virt",
"vm_topology",
"vmcore",
"vtl_array",
"x86defs",
"zerocopy 0.8.14",
]
Expand All @@ -2813,6 +2813,15 @@ dependencies = [
"zerocopy 0.8.14",
]

[[package]]
name = "hv1_structs"
version = "0.0.0"
dependencies = [
"bitvec",
"hvdef",
"inspect",
]

[[package]]
name = "hvdef"
version = "0.0.0"
Expand Down Expand Up @@ -7257,6 +7266,7 @@ dependencies = [
"guestmem",
"hcl",
"hv1_emulator",
"hv1_structs",
"hvdef",
"inspect",
"memory_range",
Expand All @@ -7269,7 +7279,6 @@ dependencies = [
"virt",
"virt_mshv_vtl",
"vm_topology",
"vtl_array",
"x86defs",
]

Expand Down Expand Up @@ -7616,6 +7625,7 @@ dependencies = [
"hcl",
"hv1_emulator",
"hv1_hypercall",
"hv1_structs",
"hvdef",
"inspect",
"inspect_counters",
Expand All @@ -7639,7 +7649,6 @@ dependencies = [
"virt_support_x86emu",
"vm_topology",
"vmcore",
"vtl_array",
"x86defs",
"x86emu",
"zerocopy 0.8.14",
Expand Down Expand Up @@ -7721,6 +7730,7 @@ dependencies = [
"guestmem",
"hv1_emulator",
"hv1_hypercall",
"hv1_structs",
"hvdef",
"inspect",
"inspect_counters",
Expand All @@ -7741,7 +7751,6 @@ dependencies = [
"virt_support_x86emu",
"vm_topology",
"vmcore",
"vtl_array",
"whp",
"winapi",
"x86defs",
Expand Down Expand Up @@ -8690,15 +8699,6 @@ dependencies = [
"serde",
]

[[package]]
name = "vtl_array"
version = "0.0.0"
dependencies = [
"bitvec",
"hvdef",
"inspect",
]

[[package]]
name = "w32-error"
version = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ vmbus_server = { path = "vm/devices/vmbus/vmbus_server" }
vmbus_user_channel = { path = "vm/devices/vmbus/vmbus_user_channel" }
hv1_emulator = { path = "vm/hv1/hv1_emulator" }
hv1_hypercall = { path = "vm/hv1/hv1_hypercall" }
hv1_structs = { path = "vm/hv1/hv1_structs" }
hvdef = { path = "vm/hv1/hvdef" }
vtl_array = { path = "vm/hv1/vtl_array" }
vhd1_defs = { path = "vm/vhd1_defs" }
kvm = { path = "vm/kvm" }
loader = { path = "vm/loader" }
Expand Down
2 changes: 1 addition & 1 deletion openhcl/hcl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ edition.workspace = true
rust-version.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
hv1_structs.workspace = true
hvdef.workspace = true
pal.workspace = true
memory_range.workspace = true
sidecar_client.workspace = true
tdcall = { workspace = true, features = ["tracing"] }
vtl_array.workspace = true
x86defs.workspace = true
inspect.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion openhcl/hcl/src/ioctl/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::NoRunner;
use super::ProcessorRunner;
use crate::vmsa::VmsaWrapper;
use crate::GuestVtl;
use hv1_structs::VtlArray;
use hvdef::HvRegisterName;
use hvdef::HvRegisterValue;
use hvdef::HV_PAGE_SIZE;
Expand All @@ -23,7 +24,6 @@ use sidecar_client::SidecarVp;
use std::os::fd::AsRawFd;
use std::ptr::NonNull;
use thiserror::Error;
use vtl_array::VtlArray;
use x86defs::snp::SevRmpAdjust;
use x86defs::snp::SevVmsa;

Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_mem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ rust-version.workspace = true
guestmem.workspace = true
hcl.workspace = true
hv1_emulator.workspace = true
hv1_structs.workspace = true
hvdef.workspace = true
memory_range.workspace = true
underhill_threadpool.workspace = true
virt.workspace = true
virt_mshv_vtl.workspace = true
vm_topology.workspace = true
x86defs.workspace = true
vtl_array.workspace = true

inspect.workspace = true
pal_async.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_mem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use hcl::ioctl::MshvHvcall;
use hcl::ioctl::MshvVtl;
use hcl::GuestVtl;
use hv1_emulator::hv::VtlProtectHypercallOverlay;
use hv1_structs::VtlArray;
use hvdef::hypercall::AcceptMemoryType;
use hvdef::hypercall::HostVisibilityType;
use hvdef::hypercall::HvInputVtl;
Expand All @@ -42,7 +43,6 @@ use thiserror::Error;
use virt::IsolationType;
use virt_mshv_vtl::ProtectIsolatedMemory;
use vm_topology::memory::MemoryLayout;
use vtl_array::VtlArray;
use x86defs::snp::SevRmpAdjust;
use x86defs::tdx::GpaVmAttributes;
use x86defs::tdx::TdgMemPageAttrWriteR8;
Expand Down
2 changes: 1 addition & 1 deletion openhcl/virt_mshv_vtl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ virt_support_x86emu.workspace = true
pci_core.workspace = true
hv1_emulator.workspace = true
hv1_hypercall.workspace = true
hv1_structs.workspace = true
hvdef.workspace = true
vtl_array.workspace = true
memory_range.workspace = true
vm_topology.workspace = true
guestmem.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion openhcl/virt_mshv_vtl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use hv1_emulator::hv::VtlProtectHypercallOverlay;
use hv1_emulator::message_queues::MessageQueues;
use hv1_emulator::synic::GlobalSynic;
use hv1_emulator::synic::SintProxied;
use hv1_structs::VtlArray;
use hvdef::hypercall::HostVisibilityType;
use hvdef::hypercall::HvGuestOsId;
use hvdef::hypercall::HvInputVtl;
Expand Down Expand Up @@ -108,7 +109,6 @@ use vm_topology::processor::TargetVpInfo;
use vmcore::monitor::MonitorPage;
use vmcore::reference_time_source::ReferenceTimeSource;
use vmcore::vmtime::VmTimeSource;
use vtl_array::VtlArray;
use x86defs::snp::REG_TWEAK_BITMAP_OFFSET;
use x86defs::snp::REG_TWEAK_BITMAP_SIZE;
use x86defs::tdx::TdCallResult;
Expand Down
4 changes: 2 additions & 2 deletions openhcl/virt_mshv_vtl/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use hcl::ioctl;
use hcl::ioctl::ProcessorRunner;
use hv1_emulator::message_queues::MessageQueues;
use hv1_hypercall::HvRepResult;
use hv1_structs::VtlArray;
use hvdef::hypercall::HostVisibilityType;
use hvdef::HvError;
use hvdef::HvMessage;
Expand Down Expand Up @@ -72,7 +73,6 @@ use virt::VpHaltReason;
use virt::VpIndex;
use vm_topology::processor::TargetVpInfo;
use vmcore::vmtime::VmTimeAccess;
use vtl_array::VtlArray;

/// An object to run lower VTLs and to access processor state.
///
Expand Down Expand Up @@ -169,14 +169,14 @@ mod private {
use hcl::ioctl::ProcessorRunner;
use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::synic::ProcessorSynic;
use hv1_structs::VtlArray;
use inspect::InspectMut;
use std::future::Future;
use virt::io::CpuIo;
use virt::vp::AccessVpState;
use virt::StopVp;
use virt::VpHaltReason;
use vm_topology::processor::TargetVpInfo;
use vtl_array::VtlArray;

pub struct BackingParams<'a, 'b, T: BackingPrivate> {
pub(crate) partition: &'a UhPartitionInner,
Expand Down
2 changes: 1 addition & 1 deletion openhcl/virt_mshv_vtl/src/processor/mshv/x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use hcl::protocol;
use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::synic::ProcessorSynic;
use hv1_hypercall::HvRepResult;
use hv1_structs::VtlSet;
use hvdef::hypercall;
use hvdef::HvDeliverabilityNotificationsRegister;
use hvdef::HvError;
Expand Down Expand Up @@ -62,7 +63,6 @@ use virt_support_x86emu::emulate::EmuCheckVtlAccessError;
use virt_support_x86emu::emulate::EmuTranslateError;
use virt_support_x86emu::emulate::EmuTranslateResult;
use virt_support_x86emu::emulate::EmulatorSupport;
use vtl_array::VtlSet;
use x86defs::xsave::Fxsave;
use x86defs::xsave::XsaveHeader;
use x86defs::xsave::XFEATURE_SSE;
Expand Down
2 changes: 1 addition & 1 deletion openhcl/virt_mshv_vtl/src/processor/snp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::synic::ProcessorSynic;
use hv1_hypercall::HvRepResult;
use hv1_hypercall::HypercallIo;
use hv1_structs::VtlArray;
use hvdef::hypercall::Control;
use hvdef::hypercall::HvFlushFlags;
use hvdef::hypercall::HvGvaRange;
Expand Down Expand Up @@ -60,7 +61,6 @@ use virt_support_x86emu::emulate::emulate_translate_gva;
use virt_support_x86emu::emulate::EmulatorSupport as X86EmulatorSupport;
use virt_support_x86emu::translate::TranslationRegisters;
use vmcore::vmtime::VmTimeAccess;
use vtl_array::VtlArray;
use x86defs::cpuid::CpuidFunction;
use x86defs::snp::SevEventInjectInfo;
use x86defs::snp::SevExitCode;
Expand Down
2 changes: 1 addition & 1 deletion openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use hv1_emulator::synic::ProcessorSynic;
use hv1_hypercall::AsHandler;
use hv1_hypercall::HvRepResult;
use hv1_hypercall::HypercallIo;
use hv1_structs::VtlArray;
use hvdef::hypercall::HvFlushFlags;
use hvdef::hypercall::HvGvaRange;
use hvdef::HvError;
Expand Down Expand Up @@ -71,7 +72,6 @@ use virt_support_x86emu::emulate::EmulatorSupport as X86EmulatorSupport;
use virt_support_x86emu::emulate::TranslateMode;
use virt_support_x86emu::translate::TranslationRegisters;
use vmcore::vmtime::VmTimeAccess;
use vtl_array::VtlArray;
use x86defs::apic::X2APIC_MSR_BASE;
use x86defs::cpuid::CpuidFunction;
use x86defs::tdx::TdCallResultCode;
Expand Down
2 changes: 1 addition & 1 deletion vm/hv1/hv1_emulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
hv1_structs.workspace = true
hvdef.workspace = true
vm_topology.workspace = true
guestmem.workspace = true
virt.workspace = true
vmcore.workspace = true
vtl_array.workspace = true
x86defs.workspace = true

inspect.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion vm/hv1/hv1_emulator/src/hv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use super::synic::GlobalSynic;
use super::synic::ProcessorSynic;
use guestmem::GuestMemory;
use guestmem::GuestMemoryError;
use hv1_structs::VtlArray;
use hvdef::HvRegisterVpAssistPage;
use hvdef::HvVpVtlControl;
use hvdef::HvVtlEntryReason;
Expand All @@ -22,7 +23,6 @@ use std::sync::Arc;
use virt::x86::MsrError;
use vm_topology::processor::VpIndex;
use vmcore::reference_time_source::ReferenceTimeSource;
use vtl_array::VtlArray;
use x86defs::cpuid::Vendor;
use zerocopy::FromZeros;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

[package]
name = "vtl_array"
name = "hv1_structs"
edition.workspace = true
rust-version.workspace = true

Expand Down
8 changes: 8 additions & 0 deletions vm/hv1/hv1_structs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Data structures that may be useful when working with hv1_hypercall.
mod vtl_array;

pub use vtl_array::*;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

//! Container data structures indexable by [`Vtl`].
#![no_std]
#![forbid(unsafe_code)]
#![warn(missing_docs)]

Expand Down
2 changes: 1 addition & 1 deletion vmm_core/virt_whp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ aarch64defs.workspace = true
chipset_device.workspace = true
hv1_emulator.workspace = true
hv1_hypercall.workspace = true
hv1_structs.workspace = true
hvdef.workspace = true
pci_core.workspace = true
memory_range = { workspace = true, features = ["inspect"] }
Expand All @@ -24,7 +25,6 @@ virt.workspace = true
virt_support_aarch64emu.workspace = true
virt_support_apic.workspace = true
virt_support_x86emu.workspace = true
vtl_array.workspace = true
whp.workspace = true
x86defs.workspace = true
x86emu.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions vmm_core/virt_whp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use hv1_emulator::hv::GlobalHv;
use hv1_emulator::hv::GlobalHvParams;
use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::message_queues::MessageQueues;
use hv1_structs::VtlSet;
use hvdef::HvDeliverabilityNotificationsRegister;
use hvdef::HvMessage;
use hvdef::HvMessageType;
Expand Down Expand Up @@ -68,7 +69,6 @@ use vmcore::vmtime::VmTimeAccess;
use vmcore::vmtime::VmTimeSource;
use vp::WhpRunVpError;
use vp_state::WhpVpStateAccess;
use vtl_array::VtlSet;
use x86defs::cpuid::Vendor;

#[derive(Debug)]
Expand Down Expand Up @@ -1349,7 +1349,7 @@ impl VtlPartition {
vendor,
tsc_frequency,
ref_time,
hypercall_page_protectors: vtl_array::VtlArray::from_fn(|_| None),
hypercall_page_protectors: hv1_structs::VtlArray::from_fn(|_| None),
}))
}
} else {
Expand Down

0 comments on commit 8521b96

Please sign in to comment.