Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4ffba75
feat(virtq): add packed virtual queue implementation
andreiltd Dec 8, 2025
95069bd
feat(virtq): add virtqueue ring plumbing in scratch region
andreiltd Mar 25, 2026
4f8e444
feat(virtq): add MemOps for host and guest
andreiltd Mar 25, 2026
4ebb110
feat(virtq): create G2H producer during guest init
andreiltd Mar 25, 2026
2c8c7df
feat(virtq): add reset API
andreiltd Mar 26, 2026
f07523c
feat(virtq): replace guest-to-host calls with virtqueue
andreiltd Mar 26, 2026
502ad6d
feat(virtq): replace host-to-guest calls with virtq
andreiltd Apr 3, 2026
b9f805e
feat(virtq): cleanup send + sync bounds
andreiltd Apr 3, 2026
6977382
feat(virtq): send logs over virtq
andreiltd Apr 7, 2026
9ad22cf
feat(virtq): use virtq for capi ret error
andreiltd Apr 7, 2026
e3d5c15
feat(virtq): remove unused stack based io path
andreiltd Apr 7, 2026
395dd12
feat(virtq): remove input output regions from ABI
andreiltd Apr 7, 2026
b816203
feat(virtq): fix host function error test
andreiltd Apr 8, 2026
e973810
feat(virtq): micro optimize consumer state
andreiltd Apr 8, 2026
89e144e
feat(virtq): add support for multi-descriptor payloads
andreiltd Apr 9, 2026
ba91b9d
feat(virtq): do not swallow errors
andreiltd Apr 9, 2026
674616d
fix(virtq): adjust sizes for benchmarks
andreiltd Apr 10, 2026
3cbe9d1
fix(virtq): make clippy happy
andreiltd Apr 10, 2026
1e4cd16
feat(virtq): add recycle pool tests
andreiltd Apr 10, 2026
8ca0844
feat(virtq): implement G2H reply backlog guard
andreiltd Apr 10, 2026
811fc98
fix(virtq): add copyright header to benches
andreiltd Apr 10, 2026
16344cf
fix(virtq): we gonna need a bigger boat
andreiltd Apr 10, 2026
30f8ffc
fix(virtq): add instrumentation to virtq host calls
andreiltd Apr 10, 2026
1a36bbb
fix(virtq): truncate error message so it fits completion
andreiltd Apr 10, 2026
dccb077
fix(virtq): move log tests to integration tests
andreiltd Apr 13, 2026
74f3898
chore(virtq): update lock file
andreiltd Apr 13, 2026
068d73a
feat(virtq): add with_hint function call API
andreiltd Apr 16, 2026
a3542ac
feat(virtq): estimate completion capacity based on ret type
andreiltd Apr 16, 2026
2763ac0
fix(virtq): cargo fmt
andreiltd May 12, 2026
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = src/hyperlight_libc/third_party/picolibc
url = https://github.com/hyperlight-dev/picolibc-bsd.git
shallow = true
[submodule "src/hyperlight_libc/third_party/mimalloc"]
path = src/hyperlight_libc/third_party/mimalloc
url = https://github.com/microsoft/mimalloc
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ hyperlight-component-macro = { path = "src/hyperlight_component_macro", version

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "deny"
unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(loom)' ] }

# this will generate symbols for release builds
# so is handy for debugging issues in release builds
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test-unit target=default-target features="":
test-isolated target=default-target features="" :
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_log_trace --exact --ignored
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::outb::tests::test_log_outb_log --exact --ignored
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --test integration_test -- log_message --exact --ignored
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --test integration_test -- --test-threads=1 --ignored
@# metrics tests
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F function_call_metrics," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- metrics::tests::test_metrics_are_emitted --exact

Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/guest_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl<'a> Arbitrary<'a> for FuzzInput {
fuzz_target!(
init: {
let mut cfg = SandboxConfiguration::default();
// In local tests, 256 KiB seemed sufficient for deep recursion
cfg.set_scratch_size(256 * 1024);
// In local tests, 512 KiB seemed sufficient for deep recursion
cfg.set_scratch_size(512 * 1024);
let path = simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing");
let u_sbox = UninitializedSandbox::new(
GuestBinary::FilePath(path),
Expand Down
8 changes: 5 additions & 3 deletions fuzz/fuzz_targets/host_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
fuzz_target!(
init: {
let mut cfg = SandboxConfiguration::default();
cfg.set_output_data_size(64 * 1024); // 64 KB output buffer
cfg.set_input_data_size(64 * 1024); // 64 KB input buffer
cfg.set_scratch_size(512 * 1024); // large scratch region to contain those buffers, any data copies, etc.
cfg.set_g2h_pool_pages(16); // 64 KB / 4096 = 16 pages
cfg.set_h2g_pool_pages(16); // 64 KB / 4096 = 16 pages
cfg.set_scratch_size(512 * 1024); // large scratch region
let u_sbox = UninitializedSandbox::new(
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
Some(cfg)
Expand All @@ -61,6 +61,8 @@ fuzz_target!(
HyperlightError::GuestError(ErrorCode::HostFunctionError, msg) if msg.contains("The number of arguments to the function is wrong") => {}
HyperlightError::ParameterValueConversionFailure(_, _) => {},
HyperlightError::GuestError(ErrorCode::HostFunctionError, msg) if msg.contains("Failed To Convert Parameter Value") => {}
HyperlightError::GuestError(ErrorCode::HostFunctionError, msg) if msg.contains("The parameter value type is unexpected") => {}
HyperlightError::GuestError(ErrorCode::HostFunctionError, msg) if msg.contains("The return value type is unexpected") => {}

// any other error should be reported
_ => panic!("Guest Aborted with Unexpected Error: {:?}", e),
Expand Down
11 changes: 11 additions & 0 deletions src/hyperlight_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ arbitrary = {version = "1.4.2", optional = true, features = ["derive"]}
anyhow = { version = "1.0.102", default-features = false }
bitflags = "2.10.0"
bytemuck = { version = "1.24", features = ["derive"] }
bytes = { version = "1", default-features = false }
fixedbitset = { version = "0.5.7", default-features = false }
flatbuffers = { version = "25.12.19", default-features = false }
log = "0.4.29"
smallvec = "1.15.1"
Expand All @@ -39,9 +41,18 @@ nanvix-unstable = ["i686-guest"]
guest-counter = []

[dev-dependencies]
criterion = "0.8.1"
hyperlight-testing = { workspace = true }
quickcheck = "1.0.3"
rand = "0.9.2"

[target.'cfg(loom)'.dev-dependencies]
loom = "0.7"

[lib]
bench = false # see https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
doctest = false # reduce noise in test output

[[bench]]
name = "buffer_pool"
harness = false
192 changes: 192 additions & 0 deletions src/hyperlight_common/benches/buffer_pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
Copyright 2026 The Hyperlight Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use std::hint::black_box;

use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use hyperlight_common::virtq::{BufferPool, BufferProvider};

// Helper to create a pool for benchmarking
fn make_pool<const L: usize, const U: usize>(size: usize) -> BufferPool<L, U> {
let base = 0x10000;
BufferPool::<L, U>::new(base, size).unwrap()
}

// Single allocation performance
fn bench_alloc_single(c: &mut Criterion) {
let mut group = c.benchmark_group("alloc_single");

for size in [64, 128, 256, 512, 1024, 1500, 4096].iter() {
group.throughput(Throughput::Elements(1));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
let alloc = pool.alloc(black_box(size)).unwrap();
pool.dealloc(alloc).unwrap();
});
});
}
group.finish();
}

// LIFO recycling
fn bench_alloc_lifo(c: &mut Criterion) {
let mut group = c.benchmark_group("alloc_lifo");

for size in [256, 1500, 4096].iter() {
group.throughput(Throughput::Elements(100));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
for _ in 0..100 {
let alloc = pool.alloc(black_box(size)).unwrap();
pool.dealloc(alloc).unwrap();
}
});
});
}
group.finish();
}

// Fragmented allocation worst case
fn bench_alloc_fragmented(c: &mut Criterion) {
let mut group = c.benchmark_group("alloc_fragmented");

group.bench_function("fragmented_256", |b| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);

// Create fragmentation pattern: allocate many, free every other
let mut allocations = Vec::new();
for _ in 0..100 {
allocations.push(pool.alloc(128).unwrap());
}
for i in (0..100).step_by(2) {
pool.dealloc(allocations[i]).unwrap();
}

b.iter(|| {
let alloc = pool.alloc(black_box(256)).unwrap();
pool.dealloc(alloc).unwrap();
});
});

group.finish();
}

// Realloc operations
fn bench_realloc(c: &mut Criterion) {
let mut group = c.benchmark_group("realloc");

// In-place grow (same tier)
group.bench_function("grow_inplace", |b| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
let alloc = pool.alloc(256).unwrap();
let grown = pool.resize(alloc, black_box(512)).unwrap();
pool.dealloc(grown).unwrap();
});
});

// Relocate grow (cross tier)
group.bench_function("grow_relocate", |b| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
let alloc = pool.alloc(128).unwrap();
// Block in-place growth
let blocker = pool.alloc(256).unwrap();
let grown = pool.resize(alloc, black_box(1500)).unwrap();
pool.dealloc(grown).unwrap();
pool.dealloc(blocker).unwrap();
});
});

// Shrink
group.bench_function("shrink", |b| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
let alloc = pool.alloc(1500).unwrap();
let shrunk = pool.resize(alloc, black_box(256)).unwrap();
pool.dealloc(shrunk).unwrap();
});
});

group.finish();
}

// Free performance
fn bench_free(c: &mut Criterion) {
let mut group = c.benchmark_group("free");

for size in [256, 1500, 4096].iter() {
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
let alloc = pool.alloc(size).unwrap();
pool.dealloc(black_box(alloc)).unwrap();
});
});
}

group.finish();
}

// Cursor optimization
fn bench_last_free_run(c: &mut Criterion) {
let mut group = c.benchmark_group("last_free_run");

// With cursor optimization (LIFO)
group.bench_function("lifo_pattern", |b| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
b.iter(|| {
let alloc = pool.alloc(256).unwrap();
pool.dealloc(alloc).unwrap();
let alloc2 = pool.alloc(black_box(256)).unwrap();
pool.dealloc(alloc2).unwrap();
});
});

// Without cursor benefit (FIFO-like)
group.bench_function("fifo_pattern", |b| {
let pool = make_pool::<256, 4096>(4 * 1024 * 1024);
let mut queue = Vec::new();

// Pre-fill queue
for _ in 0..10 {
queue.push(pool.alloc(256).unwrap());
}

b.iter(|| {
// FIFO: free oldest, allocate new
let old = queue.remove(0);
pool.dealloc(old).unwrap();
queue.push(pool.alloc(black_box(256)).unwrap());
});
});

group.finish();
}

criterion_group!(
benches,
bench_alloc_single,
bench_alloc_lifo,
bench_alloc_fragmented,
bench_realloc,
bench_free,
bench_last_free_run,
);

criterion_main!(benches);
2 changes: 1 addition & 1 deletion src/hyperlight_common/src/arch/aarch64/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub const SNAPSHOT_PT_GVA_MIN: usize = 0xffff_8000_0000_0000;
pub const SNAPSHOT_PT_GVA_MAX: usize = 0xffff_80ff_ffff_ffff;
pub const MAX_GPA: usize = 0x0000_000f_ffff_ffff;

pub fn min_scratch_size(_input_data_size: usize, _output_data_size: usize) -> usize {
pub fn min_scratch_size(_g2h_num_descs: usize, _h2g_num_descs: usize) -> usize {
unimplemented!("min_scratch_size")
}
9 changes: 6 additions & 3 deletions src/hyperlight_common/src/arch/amd64/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ pub const MAX_GPA: usize = 0x0000_000f_ffff_ffff;
/// - A page for the smallest possible non-exception stack
/// - (up to) 3 pages for mapping that
/// - Two pages for the exception stack and metadata
/// - A page-aligned amount of memory for I/O buffers (for now)
pub fn min_scratch_size(input_data_size: usize, output_data_size: usize) -> usize {
(input_data_size + output_data_size).next_multiple_of(crate::vmem::PAGE_SIZE)
/// - A page-aligned amount of memory for virtqueue rings
pub fn min_scratch_size(g2h_num_descs: usize, h2g_num_descs: usize) -> usize {
let g2h_ring_size = crate::virtq::Layout::query_size(g2h_num_descs);
let h2g_ring_size = crate::virtq::Layout::query_size(h2g_num_descs);

(g2h_ring_size + h2g_ring_size).next_multiple_of(crate::vmem::PAGE_SIZE)
+ 12 * crate::vmem::PAGE_SIZE
}
8 changes: 2 additions & 6 deletions src/hyperlight_common/src/arch/i686/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ pub const MAX_GVA: usize = 0xffff_ffff;
/// regions are large enough to reach that address.
pub const MAX_GPA: usize = 0xFEDF_FFFF;

/// Minimum scratch region size: IO buffers (page-aligned) plus 12 pages
/// for bookkeeping and the exception stack. Page table space is validated
/// separately by `set_pt_size()`.
pub fn min_scratch_size(input_data_size: usize, output_data_size: usize) -> usize {
(input_data_size + output_data_size).next_multiple_of(crate::vmem::PAGE_SIZE)
+ 12 * crate::vmem::PAGE_SIZE
pub fn min_scratch_size(_g2h_num_descs: usize, _h2g_num_descs: usize) -> usize {
crate::vmem::PAGE_SIZE
}
Loading
Loading