Skip to content

Use WHvResetPartition on windows#1360

Open
ludfjig wants to merge 2 commits intohyperlight-dev:mainfrom
ludfjig:windows_scrub2
Open

Use WHvResetPartition on windows#1360
ludfjig wants to merge 2 commits intohyperlight-dev:mainfrom
ludfjig:windows_scrub2

Conversation

@ludfjig
Copy link
Copy Markdown
Contributor

@ludfjig ludfjig commented Apr 3, 2026

Addresses #791 for windows (WHP), by resetting all guest visible state on the partition. Resets more vm state on restore() at the expense of some performance (roughly ~100micros). MSHV is planned to use the same hv call, but doesn't exist in mshv crate yet, although dom0 kernel should have support already. KVM doesn't have a nice api like this, so will still manual work for KVM.

Note: the second commit is a workaround for a hyper-v bug

@ludfjig ludfjig added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Apr 3, 2026
@ludfjig ludfjig force-pushed the windows_scrub2 branch 3 times, most recently from 4d1a570 to 2b61178 Compare April 3, 2026 17:23
ludfjig added 2 commits April 3, 2026 11:57
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig marked this pull request as ready for review April 3, 2026 20:54
Copy link
Copy Markdown
Member

@simongdavies simongdavies left a comment

Choose a reason for hiding this comment

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

Looks good , just a few comments, it would be good to tighten up the AMD fix targeting and also see if we can get rid of the need to call sregs reset independently

///
/// This does NOT restore special registers (except on windows). Call `restore_sregs` separately
/// after memory mappings are established.
// TODO: check if other state needs to be reset
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this TODO still valid (presumably not on Windows) is there an issue to track this

/// GP registers, debug registers, XSAVE, MSRs, APIC, etc.)
/// - On Linux: explicitly resets GP registers, debug registers, and XSAVE
///
/// This does NOT restore special registers (except on windows). Call `restore_sregs` separately
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems a bit fragile, why can we can restore_sregs from here?

..Default::default()
};
assert_ne!(
regs.rdx, 0x4444444444444444,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the significance of this value?

@@ -107,7 +107,7 @@ pub(crate) enum HypervisorType {
/// Minimum XSAVE buffer size: 512 bytes legacy region + 64 bytes header.
/// Only used by MSHV and WHP which use compacted XSAVE format and need to
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment needs updating

///
/// This bug most commonly surfaces as the `interrupt_same_thread_no_barrier`
/// integration test failing on AMD Windows hosts. @ludfjig has verified
/// the fix works on Windows Insider builds; this workaround can be
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we get an issue to track this? Even better is there a way we can have a test that fails when this is fixed in windows? That will force us then to gate this code on a specific windows version or lower since I think the comment is wrong, we will need this to endure but will only need to apply it on impacted versions of windows

/// The workaround unmaps and remaps a dummy page after each
/// `WHvResetPartition`, which forces the hypervisor to invalidate
/// NPT entries.
mod npt_flush {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we also gate this on affected CPUs only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants