Skip to content

[feature/virtio-mem] Add dummy implementation for virtio-mem #5365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: feature/virtio-mem
Choose a base branch
from

Conversation

Manciukic
Copy link
Contributor

Changes

Add a dummy implementation for virtio-mem device.
Add PUT and GET APIs for /hotplug/memory.

Reason

Support for Virtio Mem

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.

We were using bindgen from 3 different sources:
 - installed headers in the system
 - linux-5.10.y branch from amazonlinux repo
 - linux-next branch from torvalds repo

This is overcomplicated and unnecessary as Linux doesn't break the UAPI.

This patch updates it to use a single stable branch (6.12), from which
the user headers are generated using `make headers_install` and
regenerates all the headers, fixing some minor incompatibilities in the
syntax.

While I was at it I also improved the generation for C enums to use
constified-enum-module style which is less verbose.

I had to fix an issue with the io_uring auto-generated structs not
implementing Copy due to FAM introduced in the latest kernels. I have
put a bindgen-patch to drop the FAM and derive Copy and Clone where
required to implement ByteValued. If we ever need to use those fields,
we'll need to find a different solution.

Signed-off-by: Riccardo Mancini <[email protected]>
Currently, the device ids (TYPE_*) are hardcoded in various places. With
this change, they are generated from linux headers.

Signed-off-by: Riccardo Mancini <[email protected]>
Update the Kconfig to enable support for virtio-mem in the guest.

Signed-off-by: Riccardo Mancini <[email protected]>
virtio-mem requires a new Kconfig, so I've rebuilt the artifacts and now
I'm making the devctr point to those.

Signed-off-by: Riccardo Mancini <[email protected]>
Automatically generate bindings for virtio-mem.

Signed-off-by: Riccardo Mancini <[email protected]>
Create the new module for the virtio-mem device.

Signed-off-by: Riccardo Mancini <[email protected]>
Allow to configure the virtio-mem device from the VmmConfig and the PUT
API to /hotplug/memory.

Signed-off-by: Riccardo Mancini <[email protected]>
Test the freshly added PUT API to /hotplug/memory.

Signed-off-by: Riccardo Mancini <[email protected]>
Add a dummy virtio-mem device that is detected by the guest driver.
The device is configured with total_size, block_size, and slot_size, and
uses a fixed address after the MMIO64 memory zone.

Signed-off-by: Riccardo Mancini <[email protected]>
Check that the driver correctly detects the virtio-mem device, with the
correct parameters.

Signed-off-by: Riccardo Mancini <[email protected]>
@Manciukic Manciukic changed the title Add dummy implementation for virtio-mem [feature/virtio-mem] Add dummy implementation for virtio-mem Aug 12, 2025
Make the with_virtio_device_with_id function more generic and introduce
its variant with error handling try_with_virtio_device_with_id. Then use
these new functions in vmm.rs whenever we need to perform an action on a
device.

To simplify the code, I also moved some balloon device error handling
back to the balloon device code and refactored it a little bit.

Signed-off-by: Riccardo Mancini <[email protected]>
Remove some error variants that were not used in the code.

Signed-off-by: Riccardo Mancini <[email protected]>
Add support for GET /hotplug/memory that returns the current status of
the virtio-mem device.

This API can only be called after boot.

Signed-off-by: Riccardo Mancini <[email protected]>
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 64.27105% with 174 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.28%. Comparing base (80aa1de) to head (904b043).

Files with missing lines Patch % Lines
src/vmm/src/lib.rs 0.00% 58 Missing ⚠️
src/vmm/src/devices/virtio/mem/device.rs 84.11% 27 Missing ⚠️
src/vmm/src/rpc_interface.rs 0.00% 21 Missing ⚠️
src/vmm/src/device_manager/mod.rs 0.00% 20 Missing ⚠️
.../firecracker/src/api_server/request/hotplug/mod.rs 0.00% 15 Missing ⚠️
src/vmm/src/devices/virtio/mem/event_handler.rs 83.60% 10 Missing ⚠️
src/vmm/src/resources.rs 25.00% 9 Missing ⚠️
src/vmm/src/builder.rs 73.33% 8 Missing ⚠️
src/firecracker/src/api_server/parsed_request.rs 0.00% 2 Missing ⚠️
src/vmm/src/devices/virtio/balloon/device.rs 80.00% 2 Missing ⚠️
... and 2 more
Additional details and impacted files
@@                  Coverage Diff                   @@
##           feature/virtio-mem    #5365      +/-   ##
======================================================
- Coverage               82.35%   82.28%   -0.07%     
======================================================
  Files                     265      270       +5     
  Lines                   30640    31005     +365     
======================================================
+ Hits                    25233    25512     +279     
- Misses                   5407     5493      +86     
Flag Coverage Δ
5.10-c5n.metal 82.23% <64.27%> (-0.10%) ⬇️
5.10-m5n.metal 82.22% <64.27%> (-0.11%) ⬇️
5.10-m6a.metal 81.51% <64.27%> (-0.09%) ⬇️
5.10-m6g.metal 78.88% <64.04%> (-0.04%) ⬇️
5.10-m6i.metal 82.22% <64.27%> (-0.10%) ⬇️
5.10-m7a.metal-48xl 81.50% <64.27%> (-0.10%) ⬇️
5.10-m7g.metal 78.88% <64.04%> (-0.04%) ⬇️
5.10-m7i.metal-24xl 82.20% <64.27%> (-0.10%) ⬇️
5.10-m7i.metal-48xl 82.20% <64.27%> (-0.10%) ⬇️
5.10-m8g.metal-24xl 78.88% <64.04%> (-0.04%) ⬇️
5.10-m8g.metal-48xl 78.88% <64.04%> (-0.05%) ⬇️
6.1-c5n.metal 82.26% <64.27%> (-0.11%) ⬇️
6.1-m5n.metal 82.27% <64.27%> (-0.10%) ⬇️
6.1-m6a.metal 81.55% <64.27%> (-0.10%) ⬇️
6.1-m6g.metal 78.88% <64.04%> (-0.04%) ⬇️
6.1-m6i.metal 82.26% <64.27%> (-0.10%) ⬇️
6.1-m7a.metal-48xl 81.54% <64.27%> (-0.10%) ⬇️
6.1-m7g.metal 78.88% <64.04%> (-0.04%) ⬇️
6.1-m7i.metal-24xl 82.28% <64.27%> (-0.10%) ⬇️
6.1-m7i.metal-48xl 82.28% <64.27%> (-0.10%) ⬇️
6.1-m8g.metal-24xl 78.88% <64.04%> (-0.04%) ⬇️
6.1-m8g.metal-48xl 78.88% <64.04%> (-0.04%) ⬇️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant