Skip to content

Commit e7a20a2

Browse files
authored
feat: enable hyperlight-host compilation for aarch64 (#1285)
* refactor: move regs submodules into x86_64 subdirectory Move debug_regs, fpu, special_regs, and standard_regs into regs/x86_64/ and re-export through a new x86_64/mod.rs. Update regs.rs to delegate to the x86_64 submodule. This prepares the regs module for architecture-specific register definitions. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * refactor: move kvm.rs and mshv.rs into subdirectories Move kvm.rs → kvm/x86_64.rs and mshv.rs → mshv/x86_64.rs, adding mod.rs files that re-export through the x86_64 submodule. This prepares the virtual machine backends for architecture-specific implementations. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * refactor: convert hyperlight_vm.rs to module directory Rename hyperlight_vm.rs → hyperlight_vm/mod.rs with no content changes. This prepares for splitting architecture- specific code into separate submodules. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * refactor: split hyperlight_vm into shared and x86_64-specific code Extract x86_64-specific methods (new, initialise, dispatch_call_from_host, reset_vcpu, get_root_pt, get_snapshot_sregs, handle_debug, crashdump_context) and the debug submodule into hyperlight_vm/x86_64.rs. Keep shared code in mod.rs: struct definition, error types, helper functions, and architecture-independent methods (map_region, unmap_region, run, handle_io, etc.). Struct fields changed from private to pub(super) so the x86_64 submodule can access them. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * feat: enable hyperlight-host cross-compilation for aarch64 Add conditional compilation gates and aarch64 stub modules so that cargo build --target aarch64-unknown-linux-gnu -p hyperlight-host succeeds. No aarch64 implementation is added. All aarch64 code paths are stubs that panic at runtime. Changes: - Add aarch64 register stub types (CommonRegisters, etc.) - Add aarch64 KVM and MSHV backend stubs - Add aarch64 HyperlightVm method stubs (new, initialise, etc.) - Add aarch64 layout and vmem stubs in hyperlight_common - Gate VmExit::Debug fields with target_arch - Add hv_arm64_memory_intercept_message support - Update Cargo.toml dependencies for aarch64 - Update build.rs cfg aliases for aarch64 Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> * refactor: move error types before struct in hyperlight_vm Move all error type definitions (DispatchGuestCallError, InitializeError, RunVmError, etc.) above the HyperlightVm struct definition to group related error types together. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> --------- Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 98a9030 commit e7a20a2

File tree

24 files changed

+1211
-761
lines changed

24 files changed

+1211
-761
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// TODO(aarch64): change these, they are only provided in order to compile
18+
pub const MAX_GVA: usize = 0xffff_ffff_ffff_efff;
19+
pub const SNAPSHOT_PT_GVA_MIN: usize = 0xffff_8000_0000_0000;
20+
pub const SNAPSHOT_PT_GVA_MAX: usize = 0xffff_80ff_ffff_ffff;
21+
pub const MAX_GPA: usize = 0x0000_000f_ffff_ffff;
22+
23+
pub fn min_scratch_size(_input_data_size: usize, _output_data_size: usize) -> usize {
24+
unimplemented!("min_scratch_size")
25+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// TODO(aarch64): implement real page table operations
18+
19+
use crate::vmem::{Mapping, TableOps, TableReadOps, Void};
20+
21+
pub const PAGE_SIZE: usize = 4096;
22+
pub const PAGE_TABLE_SIZE: usize = 4096;
23+
pub type PageTableEntry = u64;
24+
pub type VirtAddr = u64;
25+
pub type PhysAddr = u64;
26+
27+
/// # Safety
28+
/// See `TableOps` documentation.
29+
#[allow(clippy::missing_safety_doc)]
30+
pub unsafe fn map<Op: TableOps>(_op: &Op, _mapping: Mapping) {
31+
unimplemented!("map")
32+
}
33+
34+
/// # Safety
35+
/// See `TableReadOps` documentation.
36+
#[allow(clippy::missing_safety_doc)]
37+
pub unsafe fn virt_to_phys<'a, Op: TableReadOps + 'a>(
38+
_op: impl core::convert::AsRef<Op> + Copy + 'a,
39+
_address: u64,
40+
_len: u64,
41+
) -> impl Iterator<Item = Mapping> + 'a {
42+
unimplemented!("virt_to_phys");
43+
#[allow(unreachable_code)]
44+
core::iter::empty()
45+
}
46+
47+
pub trait TableMovability<Op: TableReadOps + ?Sized, TableMoveInfo> {}
48+
impl<Op: TableOps<TableMovability = crate::vmem::MayMoveTable>> TableMovability<Op, Op::TableAddr>
49+
for crate::vmem::MayMoveTable
50+
{
51+
}
52+
impl<Op: TableReadOps> TableMovability<Op, Void> for crate::vmem::MayNotMoveTable {}

src/hyperlight_common/src/layout.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ limitations under the License.
2323
all(target_arch = "x86_64", feature = "nanvix-unstable"),
2424
path = "arch/i686/layout.rs"
2525
)]
26+
#[cfg_attr(target_arch = "aarch64", path = "arch/aarch64/layout.rs")]
2627
mod arch;
2728

2829
pub use arch::{MAX_GPA, MAX_GVA};
29-
#[cfg(all(target_arch = "x86_64", not(feature = "nanvix-unstable")))]
30+
#[cfg(any(
31+
all(target_arch = "x86_64", not(feature = "nanvix-unstable")),
32+
target_arch = "aarch64"
33+
))]
3034
pub use arch::{SNAPSHOT_PT_GVA_MAX, SNAPSHOT_PT_GVA_MIN};
3135

3236
// offsets down from the top of scratch memory for various things

src/hyperlight_common/src/vmem.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/vmem.rs")]
1818
#[cfg_attr(target_arch = "x86", path = "arch/i686/vmem.rs")]
19+
#[cfg_attr(target_arch = "aarch64", path = "arch/aarch64/vmem.rs")]
1920
mod arch;
2021

2122
/// This is always the page size that the /guest/ is being compiled

src/hyperlight_host/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ chrono = { version = "0.4", optional = true }
4949
anyhow = "1.0"
5050
metrics = "0.24.3"
5151
serde_json = "1.0"
52-
elfcore = "2.0"
52+
elfcore = { version = "2.0", optional = true }
5353
uuid = { version = "1.22.0", features = ["v4"] }
5454

5555
[target.'cfg(windows)'.dependencies]
@@ -128,7 +128,7 @@ executable_heap = []
128128
# This feature enables printing of debug information to stdout in debug builds
129129
print_debug = []
130130
# Dumps the VM state to a file on unexpected errors or crashes. The path of the file will be printed on stdout and logged.
131-
crashdump = ["dep:chrono"]
131+
crashdump = ["dep:chrono", "dep:elfcore"]
132132
trace_guest = ["dep:opentelemetry", "dep:tracing-opentelemetry", "dep:hyperlight-guest-tracing", "hyperlight-common/trace_guest"]
133133
mem_profile = [ "trace_guest", "dep:framehop", "dep:fallible-iterator", "hyperlight-common/mem_profile" ]
134134
kvm = ["dep:kvm-bindings", "dep:kvm-ioctls"]

src/hyperlight_host/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ fn main() -> Result<()> {
9999
// Essentially the kvm and mshv3 features are ignored on windows as long as you use #[cfg(kvm)] and not #[cfg(feature = "kvm")].
100100
// You should never use #[cfg(feature = "kvm")] or #[cfg(feature = "mshv3")] in the codebase.
101101
cfg_aliases::cfg_aliases! {
102-
gdb: { all(feature = "gdb", debug_assertions) },
102+
gdb: { all(feature = "gdb", debug_assertions, target_arch = "x86_64") },
103103
kvm: { all(feature = "kvm", target_os = "linux") },
104104
mshv3: { all(feature = "mshv3", target_os = "linux") },
105-
crashdump: { all(feature = "crashdump") },
105+
crashdump: { all(feature = "crashdump", target_arch = "x86_64") },
106106
// print_debug feature is aliased with debug_assertions to make it only available in debug-builds.
107107
print_debug: { all(feature = "print_debug", debug_assertions) },
108108
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// TODO(aarch64): implement arch-specific HyperlightVm methods
18+
19+
use std::sync::Arc;
20+
21+
use super::{
22+
AccessPageTableError, CreateHyperlightVmError, DispatchGuestCallError, HyperlightVm,
23+
InitializeError,
24+
};
25+
#[cfg(gdb)]
26+
use crate::hypervisor::gdb::{DebugCommChannel, DebugMsg, DebugResponse};
27+
use crate::hypervisor::regs::CommonSpecialRegisters;
28+
use crate::hypervisor::virtual_machine::RegisterError;
29+
use crate::mem::mgr::SandboxMemoryManager;
30+
use crate::mem::shared_mem::{GuestSharedMemory, HostSharedMemory};
31+
use crate::sandbox::SandboxConfiguration;
32+
use crate::sandbox::host_funcs::FunctionRegistry;
33+
use crate::sandbox::snapshot::NextAction;
34+
#[cfg(feature = "mem_profile")]
35+
use crate::sandbox::trace::MemTraceInfo;
36+
#[cfg(crashdump)]
37+
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
38+
39+
impl HyperlightVm {
40+
#[allow(clippy::too_many_arguments)]
41+
pub(crate) fn new(
42+
_snapshot_mem: GuestSharedMemory,
43+
_scratch_mem: GuestSharedMemory,
44+
_pml4_addr: u64,
45+
_entrypoint: NextAction,
46+
_rsp_gva: u64,
47+
_config: &SandboxConfiguration,
48+
#[cfg(gdb)] _gdb_conn: Option<DebugCommChannel<DebugResponse, DebugMsg>>,
49+
#[cfg(crashdump)] _rt_cfg: SandboxRuntimeConfig,
50+
#[cfg(feature = "mem_profile")] _trace_info: MemTraceInfo,
51+
) -> std::result::Result<Self, CreateHyperlightVmError> {
52+
unimplemented!("new")
53+
}
54+
55+
#[allow(clippy::too_many_arguments)]
56+
pub(crate) fn initialise(
57+
&mut self,
58+
_peb_addr: crate::mem::ptr::RawPtr,
59+
_seed: u64,
60+
_page_size: u32,
61+
_mem_mgr: &mut SandboxMemoryManager<HostSharedMemory>,
62+
_host_funcs: &Arc<std::sync::Mutex<FunctionRegistry>>,
63+
_guest_max_log_level: Option<tracing_core::LevelFilter>,
64+
#[cfg(gdb)] _dbg_mem_access_fn: Arc<
65+
std::sync::Mutex<SandboxMemoryManager<HostSharedMemory>>,
66+
>,
67+
) -> Result<(), InitializeError> {
68+
unimplemented!("initialise")
69+
}
70+
71+
pub(crate) fn dispatch_call_from_host(
72+
&mut self,
73+
_mem_mgr: &mut SandboxMemoryManager<HostSharedMemory>,
74+
_host_funcs: &Arc<std::sync::Mutex<FunctionRegistry>>,
75+
#[cfg(gdb)] _dbg_mem_access_fn: Arc<
76+
std::sync::Mutex<SandboxMemoryManager<HostSharedMemory>>,
77+
>,
78+
) -> Result<(), DispatchGuestCallError> {
79+
unimplemented!("dispatch_call_from_host")
80+
}
81+
82+
pub(crate) fn get_root_pt(&self) -> Result<u64, AccessPageTableError> {
83+
unimplemented!("get_root_pt")
84+
}
85+
86+
pub(crate) fn get_snapshot_sregs(
87+
&mut self,
88+
) -> Result<CommonSpecialRegisters, AccessPageTableError> {
89+
unimplemented!("get_snapshot_sregs")
90+
}
91+
92+
pub(crate) fn reset_vcpu(
93+
&mut self,
94+
_cr3: u64,
95+
_sregs: &CommonSpecialRegisters,
96+
) -> std::result::Result<(), RegisterError> {
97+
unimplemented!("reset_vcpu")
98+
}
99+
}

0 commit comments

Comments
 (0)