Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [Prerelease] - Unreleased

### Added
* ARM64 guests support CPUs without LSE atomics when built with `-C target-feature=-lse`.
* Add `HYPERLIGHT_SURROGATE_EXTRACT_DIR` to configure the surrogate extraction directory on Windows.
* Add `Sandbox::recreate()`, which rebuilds a sandbox's VM and memory from a snapshot. It recovers unrecoverable sandboxes and keeps configuration, host functions, and interrupt handles by @ludfjig in https://github.com/hyperlight-dev/hyperlight/pull/1751
* Add ARM64 Linux MSHV support by @cshung in https://github.com/hyperlight-dev/hyperlight/pull/1626
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build-and-move-c-guests: (build-c-guests "debug") (move-c-guests "debug") (build
# Uses plain cargo with non-PIE link flags and the sysroot of the PIE build.
# cargo-hyperlight would leak these RUSTFLAGS into its sysroot wrapper build.
build-rust-guests-non-pie target=default-target: (build-rust-guests target)
{{ if os() == "windows" { "$env:RUSTC_BOOTSTRAP=1; $env:RUSTFLAGS='--sysroot=' + (Resolve-Path src/tests/rust_guests/target/sysroot).Path + ' -C relocation-model=static -C link-args=--no-pie -C link-args=--image-base=0x1000000 --cfg=hyperlight --check-cfg=cfg(hyperlight) -Clink-args=-eentrypoint';" } else { "" } }} cd src/tests/rust_guests/simpleguest && {{ if os() == "windows" { "" } else { "RUSTC_BOOTSTRAP=1 RUSTFLAGS=\"--sysroot=$(cd .. && pwd)/target/sysroot -C relocation-model=static -C link-args=--no-pie -C link-args=--image-base=0x1000000 --cfg=hyperlight --check-cfg=cfg(hyperlight) -Clink-args=-eentrypoint\"" } }} cargo build --bin simpleguest --target {{ hyperlight-target }} --target-dir ../target-non-pie/build --profile={{ if target == "debug" { "dev" } else { target } }}
{{ if os() == "windows" { "$env:RUSTC_BOOTSTRAP=1; $env:RUSTFLAGS=$env:RUSTFLAGS + ' --sysroot=' + (Resolve-Path src/tests/rust_guests/target/sysroot).Path + ' -C relocation-model=static -C link-args=--no-pie -C link-args=--image-base=0x1000000 --cfg=hyperlight --check-cfg=cfg(hyperlight) -Clink-args=-eentrypoint';" } else { "" } }} cd src/tests/rust_guests/simpleguest && {{ if os() == "windows" { "" } else { "RUSTC_BOOTSTRAP=1 RUSTFLAGS=\"${RUSTFLAGS:-} --sysroot=$(cd .. && pwd)/target/sysroot -C relocation-model=static -C link-args=--no-pie -C link-args=--image-base=0x1000000 --cfg=hyperlight --check-cfg=cfg(hyperlight) -Clink-args=-eentrypoint\"" } }} cargo build --bin simpleguest --target {{ hyperlight-target }} --target-dir ../target-non-pie/build --profile={{ if target == "debug" { "dev" } else { target } }}

non_pie_guests_target := "src/tests/rust_guests/target-non-pie/build/" + hyperlight-target

Expand Down
23 changes: 23 additions & 0 deletions docs/how-to-build-a-hyperlight-guest-binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ only a host crate.
The rest of this document explains what the generated guest contains and how to
build one by hand.

## Raspberry Pi 4 and ARM64 CPUs without LSE

The default ARM64 guest target requires ARMv8.1 LSE atomics. The Pi 4's
Cortex-A72 does not support them. Disable LSE for the guest and its dependencies:

```sh
RUSTFLAGS="-C target-feature=-lse" cargo hyperlight build
```

To build this repository's Rust and C test guests on ARM64:

```sh
RUSTFLAGS="-C target-feature=-lse" just guests
just test
```

The physical-page allocator uses an exclusive load/store retry loop when LSE
is disabled. Default builds keep the LSE instruction. The loop can cost more
under contention. The host does not need this flag.

The Pi needs a 64-bit Linux kernel with readable and writable `/dev/kvm`.
Use a 64-bit userspace or a 64-bit build environment.

## Rust guest binary

### Minimal guest
Expand Down
19 changes: 17 additions & 2 deletions src/hyperlight_guest/src/arch/aarch64/prim_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@ use hyperlight_common::vmem;
pub unsafe fn alloc_phys_pages(n: u64) -> u64 {
let addr = crate::layout::allocator_gva();
let nbytes = n * vmem::PAGE_SIZE as u64;
let mut prev_base: u64 = 0;
let prev_base: u64;
// SAFETY: The caller guarantees initialized allocator state with a writable, aligned counter.
unsafe {
// todo: actually check for FEAT_LSE presence.
#[cfg(target_feature = "lse")]
core::arch::asm!("
ldadd {nbytes}, {prev_base}, [{addr}]
",
addr = in(reg) addr,
nbytes = in(reg) nbytes,
prev_base = out(reg) prev_base,
);
#[cfg(not(target_feature = "lse"))]
core::arch::asm!("
2:
ldxr {prev_base}, [{addr}]
add {next}, {prev_base}, {nbytes}
stxr {status:w}, {next}, [{addr}]
cbnz {status:w}, 2b
",
addr = in(reg) addr,
nbytes = in(reg) nbytes,
prev_base = out(reg) prev_base,
next = out(reg) _,
status = out(reg) _,
);
}
let limit = crate::layout::allocator_limit_gpa();
if prev_base.checked_add(nbytes).is_none_or(|end| end > limit) {
Expand Down
Loading