Skip to content

Weakly link c_guest_dispatch_function - #1848

Merged
ludfjig merged 2 commits into
hyperlight-dev:mainfrom
ludfjig:weak_link_c_guest_dispatch_function
Oct 2, 2026
Merged

ludfjig merged 2 commits into
hyperlight-dev:mainfrom
ludfjig:weak_link_c_guest_dispatch_function

Conversation

@ludfjig

@ludfjig ludfjig commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #195
Closes #197

weak link default implementation of c_guest_dispatch_function so c guests dont need define one unless they want custom behavior when unknown guest function is called.

Matches implementation to how guest_dispatch_function is implmeented here

core::arch::global_asm!(
".weak guest_dispatch_function",
".set guest_dispatch_function, {}",
sym guest_dispatch_function_default,
);
.

Tested locally. I didn't want to add a new specific c guest just for this test

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

Only minor documentation and test-coverage nits remain; no blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Adds a weak default C dispatch function returning NULL, allowing C guests to omit custom unknown-function handling.

Changes:

  • Added weak fallback dispatch.
  • Documented C and Rust dispatch behavior.
  • Updated the changelog.
File Summary
src/​hyperlight_guest_capi/​src/​dispatch.rs Adds weak fallback dispatch.
docs/​how-to-build-a-hyperlight-guest-binary.md Documents default and override behavior.
CHANGELOG.md Records the user-facing change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ludfjig ludfjig added C-enhancement For PRs adding features, improving functionality, docs, tests, etc. S-needs-review PR is ready for (re-)review labels Sep 22, 2026
jsturtevant
jsturtevant previously approved these changes Sep 23, 2026
simongdavies
simongdavies previously approved these changes Sep 30, 2026
…nt it

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig
ludfjig force-pushed the weak_link_c_guest_dispatch_function branch from 647e601 to a01cd4d Compare October 2, 2026 17:12
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: a01cd4d80853
Baseline commit: 43cf3539bd10

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 771.67 ns (➖ 1.00x faster)
vec_bytes 588.50 ns (➖ 1.01x slower)
374.36 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
262144 550.39 ns (➖ 1.02x slower)
65536 141.48 ns (➖ 1.02x faster)

sandboxes

create_initialized_and_drop
medium 79.86 ms (➖ 1.00x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
7.74 ns (➖ 1.00x faster) 7.73 ns (➖ 1.01x slower) 7.74 ns (➖ 1.00x slower)

snapshot_files

load_snapshot_unverified
small 93.55 µs (➖ 1.02x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.17 µs (➖ 1.01x faster) 7.43 µs (➖ 1.01x slower)
65536 2.06 µs (➖ 1.00x slower) 1.94 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 6.40 µs (➖ 1.01x slower) 6.27 µs (➖ 1.02x faster)
8192 1.06 µs (➖ 1.00x slower) 1.05 µs (➖ 1.00x faster)
262144 27.29 µs (➖ 1.00x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 694.11 ns (➖ 1.08x faster)
vec_bytes 506.47 ns (➖ 1.08x faster)
664.03 µs (➖ 1.04x faster)

payload_allocation

slot_pool_segmented
262144 505.88 ns (➖ 1.13x faster)
65536 136.17 ns (➖ 1.13x faster)

sandboxes

create_initialized_and_drop
medium 75.33 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
6.94 ns (➖ 1.09x faster) 6.90 ns (➖ 1.09x faster) 6.92 ns (➖ 1.09x faster)

snapshot_files

load_snapshot_unverified
small 45.12 µs (➖ 1.08x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.55 µs (➖ 1.13x faster) 7.57 µs (➖ 1.13x faster)
65536 2.12 µs (➖ 1.13x faster) 2.13 µs (➖ 1.11x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.03 µs (➖ 1.12x faster) 7.10 µs (➖ 1.12x faster)
8192 747.00 ns (➖ 1.12x faster) 729.39 ns (➖ 1.08x faster)
262144 30.04 µs (➖ 1.11x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 940.14 ns (➖ 1.01x faster)
vec_bytes 697.08 ns (➖ 1.02x faster)
269.24 µs (➖ 1.32x faster)

payload_allocation

slot_pool_segmented
262144 728.21 ns (➖ 1.01x faster)
65536 195.90 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 56.40 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
9.98 ns (➖ 1.04x slower) 10.00 ns (➖ 1.05x slower) 9.67 ns (➖ 1.06x faster)

snapshot_files

load_snapshot_unverified
small 84.19 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 9.58 µs (➖ 1.04x faster) 9.99 µs (➖ 1.11x slower)
65536 2.41 µs (➖ 1.07x slower) 2.46 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.08 µs (➖ 1.00x slower) 9.03 µs (➖ 1.13x slower)
8192 1.27 µs (➖ 1.00x slower) 1.33 µs (➖ 1.01x slower)
262144 36.09 µs (➖ 1.01x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 943.40 ns (➖ 1.01x slower)
vec_bytes 660.49 ns (➖ 1.01x faster)
743.66 µs (➖ 1.11x slower)

payload_allocation

slot_pool_segmented
262144 632.94 ns (➖ 1.01x faster)
65536 165.04 ns (➖ 1.00x slower)

sandboxes

create_initialized_and_drop
medium 65.88 ms (➖ 1.06x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
8.78 ns (➖ 1.00x faster) 9.49 ns (➖ 1.04x slower) 8.97 ns (➖ 1.02x slower)

snapshot_files

load_snapshot_unverified
small 44.73 µs (➖ 1.02x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.77 µs (➖ 1.00x slower) 7.75 µs (➖ 1.04x faster)
65536 2.23 µs (➖ 1.00x faster) 2.28 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.49 µs (➖ 1.00x faster) 7.57 µs (➖ 1.01x slower)
8192 873.29 ns (➖ 1.01x slower) 864.94 ns (➖ 1.02x faster)
262144 40.71 µs (➖ 1.07x slower)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.20 µs (➖ 1.07x slower)
vec_bytes 820.98 ns (➖ 1.16x faster)
2.14 ms (➖ 1.17x faster)

payload_allocation

slot_pool_segmented
262144 784.62 ns (➖ 1.02x faster)
65536 242.11 ns (➖ 1.06x slower)

sandboxes

create_initialized_and_drop
medium 92.75 ms (➖ 1.19x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
10.07 ns (➖ 1.38x faster) 10.23 ns (➖ 1.04x faster) 10.20 ns (➖ 1.03x faster)

snapshot_files

load_snapshot_unverified
small 757.02 µs (➖ 1.04x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 9.07 µs (➖ 1.04x slower) 9.12 µs (➖ 1.02x faster)
65536 2.33 µs (➖ 1.09x faster) 2.38 µs (➖ 1.14x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 9.40 µs (➖ 1.10x slower) 8.78 µs (➖ 1.01x slower)
8192 1.34 µs (➖ 1.07x faster) 1.29 µs (➖ 1.09x faster)
262144 46.09 µs (➖ 1.28x slower)
hyperv-ws2025 / intel (Windows) (❌ 1.51x)

Top regressions

  • virtq_readwrite/slot_pool_segmented/262144 — ❌ 1.51x slower

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.82 µs (➖ 1.33x slower)
vec_bytes 817.67 ns (➖ 1.06x slower)
3.14 ms (➖ 1.01x slower)

payload_allocation

slot_pool_segmented
262144 741.18 ns (➖ 1.00x slower)
65536 212.55 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 113.11 ms (➖ 1.06x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
10.01 ns (➖ 1.01x slower) 10.11 ns (➖ 1.01x slower) 10.56 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 585.19 µs (➖ 1.04x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.81 µs (➖ 1.03x slower) 7.60 µs (➖ 1.02x faster)
65536 2.35 µs (➖ 1.03x slower) 2.33 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 10.36 µs (➖ 1.15x slower) 10.02 µs (➖ 1.13x slower)
8192 1.14 µs (➖ 1.10x faster) 1.20 µs (➖ 1.07x slower)
262144 69.41 µs (❌ 1.51x slower)

Reported by cargo ci bench-report --candidate run:37039166647 --baseline run:36945564806 --config-file bench_report.toml.

@ludfjig
ludfjig merged commit 66d5dd3 into hyperlight-dev:main Oct 2, 2026
68 of 76 checks passed
@github-actions github-actions Bot removed the S-needs-review PR is ready for (re-)review label Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

4 participants