Skip to content

Conversation

@Manciukic
Copy link
Contributor

@Manciukic Manciukic commented Oct 23, 2025

Changes

  • Add support for dynamic slots to make unplugged memory unaccessible from the guest
  • Add performance tests
  • Add mprotect to protect unplugged slots from the VMM device emulation.
  • Add tests for dirty page tracking and incremental snapshots.

Reason

virtio-mem feature work.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

Add a slot_cnt parameter to next_kvm_slot. This will be used to allocate
multiple slots for a slotted hotpluggable region.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
To avoid boilerplate code in multiple places, let's just define it once
and use it everywhere.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
In preparation to adding support for multiple memory slots, refactor the
mincore_bitmap function to accept a pointer and length rather than an
entire memory region object.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
@Manciukic Manciukic force-pushed the virtio-mem/mprotect branch from a94732d to 418d9be Compare October 23, 2025 14:58
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 97.34848% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.30%. Comparing base (f6e1740) to head (25fa432).

Files with missing lines Patch % Lines
src/vmm/src/vstate/memory.rs 97.17% 5 Missing ⚠️
src/vmm/src/builder.rs 75.00% 1 Missing ⚠️
src/vmm/src/vstate/vm.rs 98.21% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           feature/virtio-mem    #5490      +/-   ##
======================================================
+ Coverage               83.23%   83.30%   +0.07%     
======================================================
  Files                     276      276              
  Lines                   28666    28836     +170     
======================================================
+ Hits                    23861    24023     +162     
- Misses                   4805     4813       +8     
Flag Coverage Δ
5.10-m5n.metal 83.51% <97.34%> (+0.07%) ⬆️
5.10-m6a.metal 82.83% <97.34%> (+0.07%) ⬆️
5.10-m6g.metal 80.29% <94.31%> (+0.10%) ⬆️
5.10-m6i.metal 83.52% <97.34%> (+0.07%) ⬆️
5.10-m7a.metal-48xl 82.82% <97.34%> (+0.07%) ⬆️
5.10-m7g.metal 80.29% <94.31%> (+0.11%) ⬆️
5.10-m7i.metal-24xl 83.48% <97.34%> (+0.06%) ⬆️
5.10-m7i.metal-48xl 83.48% <97.34%> (+0.06%) ⬆️
5.10-m8g.metal-24xl 80.29% <94.31%> (+0.10%) ⬆️
5.10-m8g.metal-48xl 80.29% <94.31%> (+0.10%) ⬆️
6.1-m5n.metal 83.55% <97.34%> (+0.07%) ⬆️
6.1-m6a.metal 82.87% <97.34%> (+0.08%) ⬆️
6.1-m6g.metal 80.29% <94.31%> (+0.10%) ⬆️
6.1-m6i.metal 83.54% <97.34%> (+0.07%) ⬆️
6.1-m7a.metal-48xl 82.85% <97.34%> (+0.08%) ⬆️
6.1-m7g.metal 80.29% <94.31%> (+0.10%) ⬆️
6.1-m7i.metal-24xl 83.55% <97.34%> (+0.07%) ⬆️
6.1-m7i.metal-48xl 83.55% <97.34%> (+0.06%) ⬆️
6.1-m8g.metal-24xl 80.28% <94.31%> (+0.10%) ⬆️
6.1-m8g.metal-48xl 80.29% <94.31%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A single GuestMemoryRegion can be split into multiple KVM slots. This is
used for Hotplug type regions where we can dynamically remove access to
the region from the guest.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Dynamically plug/unplug KVM slots when any/all of the blocks are
plugged/unplugged.

This prevents the guest from accessing unplugged memory.
However, this doesn't yet prevent the device emulation from accessing
the slots.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
@Manciukic Manciukic force-pushed the virtio-mem/mprotect branch from 418d9be to 9f5740e Compare October 23, 2025 15:07
Add a performance test that measures the latency to hot(un)plug
different amounts of memory.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Add the memory hotplug tests to buildkite.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
@Manciukic Manciukic force-pushed the virtio-mem/mprotect branch from 9f5740e to 84671d9 Compare October 23, 2025 15:18
This prevents the device emulation to be tricked into accessing
unplugged memory ranges. If a malicious driver tries to do so, the VMM
will crash with a memory error.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
These two functions were doing a similar thing. Let's extend the
build_from_snapshot to support uffd and drop the newly introduced
clone_vm.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Extend the tests to also check that everything works with diff snapshots
(dirty page tracking and mincore).

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Add a test that verifies that incremental snapshots work as expected.
Each generation will plug more memory and verify that the contents in
memory from previous generations are persisted.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
@Manciukic Manciukic force-pushed the virtio-mem/mprotect branch from 84671d9 to 25fa432 Compare October 23, 2025 15:23
@Manciukic Manciukic marked this pull request as ready for review October 23, 2025 16:03
@Manciukic Manciukic added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting review Indicates that a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant