Skip to content

Conversation

@ludfjig
Copy link
Contributor

@ludfjig ludfjig commented Jan 16, 2026

Enables 10 existing shared_memory tests to be run with Miri and adds them to CI. This allows us to exercise some of our unsafe code and increase confidence in correctness and not having UB.

Note:

  • For this PR I first intended on adding another rust-native Vec<u8> backing for for HostMapping which does not use platform apis (mmap, VirtualAlloc), but it turns out mmap is partially supported by Miri, but not with MAP_SHARED so I did that instead because it is easier. Aside: I don't think we need to use MAP_SHARED in general for hyperlight, but that not relevant to this PR.
  • the change to base_ptr() is intentional because we used to cast pointer to integer, which loses pointer provenance. The fix is to use pointer arithmetics instead to preserve provenance.

@ludfjig ludfjig requested a review from Copilot January 16, 2026 00:08
@ludfjig ludfjig added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Jan 16, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enables most of the existing shared_memory tests to run with Miri (Rust's interpreter for detecting undefined behavior) and adds them to CI. The changes are focused on making the memory management code compatible with Miri's stricter checking.

Changes:

  • Modified Linux shared memory allocation to use MAP_PRIVATE instead of MAP_SHARED when running under Miri
  • Disabled guard page protection (mprotect calls) when running under Miri since it's not supported
  • Fixed pointer provenance issue in base_ptr() by using pointer arithmetic instead of casting to integer
  • Updated dependency lockfile to remove duplicate spin crate version
  • Added conditional compilation attributes to skip proptest-based tests under Miri
  • Updated Justfile to add hyperlight-host shared_mem tests to miri test suite

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/hyperlight_host/src/mem/shared_mem.rs Added Miri-specific conditional compilation for memory mapping flags, guard page protection, and pointer provenance fix
src/hyperlight_host/src/mem/mod.rs Updated comment and added Miri exclusion for shared_mem_tests module
src/tests/rust_guests/simpleguest/Cargo.lock Removed duplicate spin 0.9.8 entry, consolidated to use spin 0.10.0
Justfile Added hyperlight-host shared_mem tests to miri-tests target
Comments suppressed due to low confidence (1)

src/hyperlight_host/src/mem/shared_mem.rs:657

  • The base_addr() function still uses pointer-to-integer casting followed by addition, which loses pointer provenance. This should be changed to use pointer arithmetic like base_ptr() was fixed: self.region().ptr.wrapping_add(PAGE_SIZE_USIZE) as usize. This would maintain consistency with the provenance fix applied to base_ptr() and ensure Miri compatibility throughout.
    fn base_addr(&self) -> usize {
        self.region().ptr as usize + PAGE_SIZE_USIZE
    }

Signed-off-by: Ludvig Liljenberg <[email protected]>
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.

1 participant