Skip to content

Expose one CPU feature set to MSHV and WHP guests - #2028

Draft
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:unify-partition-features
Draft

ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:unify-partition-features

Conversation

@ludfjig

@ludfjig ludfjig commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Draft until #2022 is merged.

MSHV and WHP use different default CPU features. Both expose features with guest state, such as speculation control, TSX, CET, and TSC_ADJUST. WHP guests also share the host process's speculation domain.

This sets one feature list for both backends in partition_features.rs and gives WHP guests their own speculation domain. The list keeps AVX through AVX-512. Hyperlight does not support AVX, but a guest can enable it. Restore resets XCR0 to x87 only.

Breaking: guests that use a removed feature fault on MSHV and WHP. See docs/guest-cpu.md for the list.

Fixes #1685

@ludfjig ludfjig added the C-enhancement For PRs adding features, improving functionality, docs, tests, etc. label Nov 5, 2026
Copilot AI balanced review requested due to automatic review settings November 5, 2026 22:49
@ludfjig
ludfjig marked this pull request as draft November 5, 2026 22:59

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.

🟡 Changes recommended

Failures in configure_partition can return before WhpVm owns the partition, bypassing cleanup and leaking partition handles on repeated creation attempts.

1 open issue
What changed in this PR

This PR gives MSHV and WHP a shared CPU feature policy, addressing differing backend defaults. It also isolates WHP guest speculation and enables TSC rewind coverage on WHP.

Changes:

  • Apply shared processor and XSAVE feature masks while retaining AVX through AVX-512.
  • Give WHP guests a separate speculation domain.
  • Add feature-exposure tests and document the guest compatibility changes.
File Description
src/​tests/​rust_guests/​simpleguest/​src/​main.rs Adds a guest CPUID query for tests.
src/​hyperlight_host/​src/​sandbox/​initialized.rs Tests feature exposure and TSC rewind on WHP.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​whp/​x86_64.rs Configures feature masks and a separate security domain.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​partition_features.rs Defines shared processor and XSAVE feature masks.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​mshv/​x86_64.rs Applies shared masks during partition creation.
src/​hyperlight_host/​src/​hypervisor/​virtual_machine/​mod.rs Registers the shared feature module.
src/​hyperlight_host/​src/​hypervisor/​regs/​x86_64/​msrs.rs Removes a TSC_ADJUST comment. No functional change.
docs/​README.md Links CPU feature and MSR documentation.
docs/​msr.md Aligns MSR documentation with the feature policy.
docs/​guest-cpu.md Documents exposed features and exclusions.
CHANGELOG.md Records feature restrictions, speculation isolation, and the TSC fix.

Review effort: Balanced

},
)?;

Self::configure_partition(p)?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The leak is older than this PR. On main, every failure after WHvCreatePartition in WhpVm::new leaks the handle. We should fix it in a separate PR.

@ludfjig
ludfjig force-pushed the unify-partition-features branch from 0b47648 to cc462d0 Compare November 5, 2026 23:12
@hyperlight-gh-bot

This comment has been minimized.

@ludfjig
ludfjig force-pushed the unify-partition-features branch from cc462d0 to f2e1995 Compare November 6, 2026 19:10
@yoshuawuyts yoshuawuyts added O-linux Linux host support O-mshv Linux MSHV backend for Microsoft Hyper-V O-whp Windows Hypervisor Platform backend O-windows Windows host support O-x86_64 Specific to x86-64 processors labels Nov 16, 2026
@ludfjig
ludfjig force-pushed the unify-partition-features branch from f2e1995 to 3fa891b Compare November 16, 2026 23:02
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig added the S-needs-goldens Regenerate snapshot golden fixtures label Nov 16, 2026
@ludfjig
ludfjig force-pushed the unify-partition-features branch from 3fa891b to 098cd5d Compare November 16, 2026 23:32
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 098cd5d7d175
Baseline commit: dd840be9125f

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 268.69 ns (➖ 1.04x faster)
vec_bytes 79.21 ns (➖ 1.01x faster)
371.96 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
262144 531.66 ns (➖ 1.01x slower)
65536 143.47 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 13.36 ms (➖ 1.00x faster)

slot_pool

alloc_dealloc_128 alloc_dealloc_4096 alloc_dealloc_1500
7.69 ns (➖ 1.00x faster) 7.68 ns (➖ 1.00x faster) 7.68 ns (➖ 1.04x faster)

snapshot_files

load_snapshot_unverified
small 99.24 µs (➖ 1.03x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
262144 7.38 µs (➖ 1.03x slower) 7.21 µs (➖ 1.02x faster)
65536 1.95 µs (➖ 1.07x faster) 2.04 µs (➖ 1.07x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
262144 28.49 µs (➖ 1.06x slower)
65536 6.37 µs (➖ 1.01x faster) 6.20 µs (➖ 1.09x faster)
8192 1.04 µs (➖ 1.03x slower) 1.04 µs (➖ 1.04x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 276.86 ns (➖ 1.04x faster)
vec_bytes 90.14 ns (➖ 1.02x faster)
690.92 µs (➖ 1.04x faster)

payload_allocation

slot_pool_segmented
262144 582.15 ns (➖ 1.00x slower)
65536 193.72 ns (➖ 1.02x faster)

sandboxes

create_initialized_and_drop
medium 15.65 ms (➖ 1.02x slower)

slot_pool

alloc_dealloc_128 alloc_dealloc_4096 alloc_dealloc_1500
7.91 ns (➖ 1.01x faster) 7.84 ns (➖ 1.02x faster) 7.88 ns (➖ 1.02x faster)

snapshot_files

load_snapshot_unverified
small 52.82 µs (➖ 1.11x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
262144 8.59 µs (➖ 1.00x slower) 8.63 µs (➖ 1.01x faster)
65536 2.35 µs (➖ 1.03x faster) 2.38 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
262144 32.81 µs (➖ 1.03x faster)
65536 7.81 µs (➖ 1.02x faster) 7.87 µs (➖ 1.01x faster)
8192 785.43 ns (➖ 1.01x faster) 797.56 ns (➖ 1.03x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 372.44 ns (➖ 1.05x slower)
vec_bytes 99.78 ns (➖ 1.03x faster)
352.61 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
262144 766.31 ns (➖ 1.05x slower)
65536 196.24 ns (➖ 1.02x slower)

sandboxes

create_initialized_and_drop
medium 67.00 ms (➖ 1.00x slower)

slot_pool

alloc_dealloc_128 alloc_dealloc_4096 alloc_dealloc_1500
9.55 ns (➖ 1.00x faster) 9.59 ns (➖ 1.00x faster) 9.61 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 105.05 µs (➖ 1.00x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
262144 9.60 µs (➖ 1.03x faster) 11.18 µs (➖ 1.03x slower)
65536 2.22 µs (➖ 1.00x faster) 2.38 µs (➖ 1.03x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
262144 35.75 µs (➖ 1.04x faster)
65536 8.38 µs (➖ 1.18x faster) 8.07 µs (➖ 1.18x faster)
8192 1.25 µs (➖ 1.04x slower) 1.24 µs (➖ 1.00x slower)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 348.41 ns (➖ 1.05x faster)
vec_bytes 90.45 ns (➖ 1.04x slower)
704.73 µs (➖ 1.05x faster)

payload_allocation

slot_pool_segmented
262144 709.50 ns (➖ 1.00x faster)
65536 239.24 ns (➖ 1.02x faster)

sandboxes

create_initialized_and_drop
medium 53.00 ms (➖ 1.04x faster)

slot_pool

alloc_dealloc_128 alloc_dealloc_4096 alloc_dealloc_1500
8.73 ns (➖ 1.01x faster) 8.73 ns (➖ 1.00x faster) 8.70 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 54.49 µs (➖ 1.01x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
262144 7.93 µs (➖ 1.00x faster) 7.99 µs (➖ 1.01x slower)
65536 2.29 µs (➖ 1.00x slower) 2.27 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
262144 39.38 µs (➖ 1.03x slower)
65536 7.47 µs (➖ 1.00x faster) 7.52 µs (➖ 1.01x slower)
8192 894.91 ns (➖ 1.01x faster) 906.33 ns (➖ 1.01x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 566.60 ns (➖ 1.05x slower)
vec_bytes 163.34 ns (➖ 1.03x slower)
2.00 ms (➖ 1.02x faster)

payload_allocation

slot_pool_segmented
262144 784.34 ns (➖ 1.03x faster)
65536 236.08 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 12.66 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_128 alloc_dealloc_4096 alloc_dealloc_1500
9.97 ns (➖ 1.00x faster) 9.98 ns (➖ 1.03x faster) 10.62 ns (➖ 1.03x slower)

snapshot_files

load_snapshot_unverified
small 767.36 µs (➖ 1.03x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
262144 9.26 µs (➖ 1.09x faster) 9.18 µs (➖ 1.10x faster)
65536 2.31 µs (➖ 1.04x faster) 2.33 µs (➖ 1.20x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
262144 38.66 µs (➖ 1.05x faster)
65536 9.06 µs (➖ 1.26x faster) 8.85 µs (➖ 1.10x faster)
8192 1.26 µs (➖ 1.13x faster) 1.28 µs (➖ 1.14x faster)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 572.14 ns (➖ 1.01x faster)
vec_bytes 170.13 ns (➖ 1.02x slower)
3.35 ms (➖ 1.04x faster)

payload_allocation

slot_pool_segmented
262144 783.15 ns (➖ 1.00x slower)
65536 217.03 ns (➖ 1.05x faster)

sandboxes

create_initialized_and_drop
medium 14.83 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_128 alloc_dealloc_4096 alloc_dealloc_1500
10.19 ns (➖ 1.00x faster) 10.64 ns (➖ 1.03x slower) 9.85 ns (➖ 1.02x faster)

snapshot_files

load_snapshot_unverified
small 759.00 µs (➖ 1.06x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
262144 7.77 µs (➖ 1.03x faster) 7.54 µs (➖ 1.07x faster)
65536 2.33 µs (➖ 1.03x faster) 2.27 µs (➖ 1.09x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
262144 46.61 µs (➖ 1.04x faster)
65536 8.64 µs (➖ 1.05x slower) 8.85 µs (➖ 1.06x slower)
8192 1.06 µs (➖ 1.16x faster) 1.11 µs (➖ 1.00x slower)

Reported by cargo ci bench-report --candidate run:43980132360 --config-file bench_report.toml.

This branch has not been deployed

No deployments
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. O-linux Linux host support O-mshv Linux MSHV backend for Microsoft Hyper-V O-whp Windows Hypervisor Platform backend O-windows Windows host support O-x86_64 Specific to x86-64 processors S-needs-goldens Regenerate snapshot golden fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify mshv and whp partition features

3 participants