Skip to content

membacking: label memory regions for smaps debugging#3041

Merged
jstarks merged 3 commits intomicrosoft:mainfrom
jstarks:name_regions
Mar 18, 2026
Merged

membacking: label memory regions for smaps debugging#3041
jstarks merged 3 commits intomicrosoft:mainfrom
jstarks:name_regions

Conversation

@jstarks
Copy link
Member

@jstarks jstarks commented Mar 18, 2026

Add SparseMapping::set_name() using prctl(PR_SET_VMA_ANON_NAME) on Linux to label anonymous mappings in /proc/{pid}/smaps. No-op on non-Linux platforms and Windows. Label the guest memory VA reservation as 'guest-memory' and private RAM allocations as 'guest-ram-private'.

Also add a name parameter to alloc_shared_memory() so memfd_create uses descriptive names visible as /memfd: in smaps: guest-ram, rom, vram, page-pool.

Add SparseMapping::set_name() using prctl(PR_SET_VMA_ANON_NAME) on Linux
to label anonymous mappings in /proc/{pid}/smaps. No-op on non-Linux
platforms and Windows. Label the guest memory VA reservation as
'guest-memory' and private RAM allocations as 'guest-ram-private'.

Also add a name parameter to alloc_shared_memory() so memfd_create uses
descriptive names visible as /memfd:<name> in smaps: guest-ram, rom,
vram, page-pool.
@jstarks jstarks requested a review from a team as a code owner March 18, 2026 06:16
Copilot AI review requested due to automatic review settings March 18, 2026 06:16
@github-actions github-actions bot added the unsafe Related to unsafe code label Mar 18, 2026
@github-actions
Copy link

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

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

Adds optional, platform-appropriate naming for memory mappings to improve /proc/{pid}/smaps readability during debugging, and threads descriptive names through shared-memory allocation sites.

Changes:

  • Add SparseMapping::set_name() (Linux prctl(PR_SET_VMA_ANON_NAME); no-op elsewhere) and use it to label guest VA reservations and private RAM allocations.
  • Extend alloc_shared_memory() to accept a name so Linux memfd_create produces descriptive /memfd:<name> entries.
  • Update call sites (tests/fuzz/OpenVMM/petri/page-pool) to pass appropriate mapping names (e.g., vram, rom, page-pool, guest-ram).

Reviewed changes

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

Show a summary per file
File Description
vm/page_pool_alloc/src/lib.rs Passes a descriptive name (page-pool) into shared-memory allocation for smaps visibility.
support/sparse_mmap/src/windows.rs Adds SparseMapping::set_name no-op and updates alloc_shared_memory signature to accept (ignored) name.
support/sparse_mmap/src/unix.rs Implements Linux set_name via prctl, and threads name into memfd_create (and signature updates).
support/sparse_mmap/src/lib.rs Updates tests to use new alloc_shared_memory(size, name) signature.
support/sparse_mmap/fuzz/fuzz_sparse_mmap.rs Updates fuzz target to use new shared-memory allocation signature.
petri/src/vm/openvmm/construct.rs Names VRAM shared memory (vram) for smaps debugging.
openvmm/openvmm_entry/src/lib.rs Names VRAM shared memory (vram) for smaps debugging in CLI-driven VM construction.
openvmm/openvmm_core/src/worker/rom.rs Names ROM shared memory (rom) for smaps debugging.
openvmm/membacking/src/memory_manager/mod.rs Names guest RAM memfd (guest-ram) and private RAM anonymous mappings (guest-ram-private).
openvmm/membacking/src/mapping_manager/va_mapper.rs Labels the guest VA reservation as guest-memory and exposes set_range_name().

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link

Copy link
Contributor

@smalis-msft smalis-msft left a comment

Choose a reason for hiding this comment

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

Windows doesn't offer a similar feature? Unfortunate.

Copilot AI review requested due to automatic review settings March 18, 2026 17:38
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

Adds smaps-friendly naming for guest memory mappings to improve debugging of OpenVMM memory usage on Linux, while keeping behavior as a no-op on non-Linux/Windows.

Changes:

  • Introduce SparseMapping::set_name() (Linux via prctl(PR_SET_VMA_ANON_NAME), no-op elsewhere) and apply it to guest VA reservations and private RAM allocations.
  • Extend alloc_shared_memory() to accept a descriptive name and pass it through to Linux memfd_create() (ignored on Windows / non-Linux Unix).
  • Update call sites (OpenVMM, Petri, fuzz/tests) to provide descriptive names (e.g., guest-ram, rom, vram, page-pool).

Reviewed changes

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

Show a summary per file
File Description
vm/page_pool_alloc/src/lib.rs Passes "page-pool" into alloc_shared_memory() for clearer memfd naming.
support/sparse_mmap/src/windows.rs Adds no-op set_name() and updates alloc_shared_memory() signature to accept a name (ignored).
support/sparse_mmap/src/unix.rs Implements Linux set_name() via prctl and threads name through memfd_create() / shm_open path.
support/sparse_mmap/src/lib.rs Updates unit test to use new alloc_shared_memory(size, name) API.
support/sparse_mmap/fuzz/fuzz_sparse_mmap.rs Updates fuzz harness to pass a name into alloc_shared_memory().
petri/src/vm/openvmm/construct.rs Names VRAM shared memory "vram".
openvmm/openvmm_entry/src/lib.rs Names VRAM shared memory "vram" for smaps visibility.
openvmm/openvmm_core/src/worker/rom.rs Names ROM backing shared memory "rom".
openvmm/membacking/src/memory_manager/mod.rs Names guest RAM shared memory "guest-ram" and labels private RAM ranges "guest-ram-private".
openvmm/membacking/src/mapping_manager/va_mapper.rs Labels the VA reservation "guest-memory" and exposes set_range_name().

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Member

@chris-oo chris-oo left a comment

Choose a reason for hiding this comment

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

other than stevens' comment about the CString conversion should never fail, LGTM. neat stuff

@github-actions
Copy link

@jstarks jstarks merged commit 90f88cc into microsoft:main Mar 18, 2026
84 of 86 checks passed
@jstarks jstarks deleted the name_regions branch March 18, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants