Skip to content

feat: Add KVM Nested State support and upgrade to Rust edition 2024 #331

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

SteelCrab
Copy link

Summary

This PR adds KVM Nested State functionality and upgrades the project to Rust edition 2024.

Changes

New Features

  • Added get_nested_state() and set_nested_state() methods for nested virtualization state management
  • Introduced KvmNestedStateBuffer helper for managing nested state buffers
  • Added nested state bindings and wrappers for x86_64, ARM64, and RISC-V architectures

Infrastructure

  • Upgraded kvm-bindings and kvm-ioctls crates to Rust edition 2024
  • Enhanced VCPU interface with nested state management capabilities

Modified Components

  • kvm-bindings: Enhanced with nested state structures and cross-platform bindings
  • kvm-ioctls: Extended VCPU interface with nested state management

Testing

  • Tested on x86_64 with nested virtualization enabled
  • Verified compatibility across supported architectures
  • Confirmed backward compatibility with existing code

Breaking Changes

None - all changes are additive and maintain backward compatibility.

phip1611 and others added 5 commits June 19, 2025 14:18
This type is a helper, making the use of get_nested_state() and
set_nested_state(), which are added in a following commit, much more
convenient.

Note that this type's name uses UpperCamelCase as it is not just
a plain old data type but actually contains some logic: the
`size` field is properly initialized.

Effectively, KVM expects a dynamic buffer with a header reporting
the size to either store the nested state in or load it from. As such
data structures with a certain alignment are challenging to work with
(note that Vec<u8> always have an alignment of 1 but we need 4),
this type sacrifices a little memory overhead in some cases for
better UX; copying 8K once is cheap anyway.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
More info: https://docs.kernel.org/virt/kvm/api.html#capabilities-that-can-be-enabled-on-vcpus

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
These calls are relevant for live-migration and state save/resume
when nested virtualization is used.

I tested everything with a nested guest in Cloud Hypervisor, but these
patches are not yet upstream.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit upgrades kvm-bindings from the default Rust edition 2015
to edition 2024, addressing the need for explicit unsafe blocks and
proper module path resolution.

Changes:
- Add \`edition = \"2024\"\` to kvm-bindings/Cargo.toml
- Wrap unsafe function calls in explicit unsafe blocks in bindings.rs
  - from_raw_parts, from_raw_parts_mut, transmute calls
- Fix import paths in fam_wrappers.rs and nested.rs:
  - \`use x86_64::bindings::*\` → \`use crate::x86_64::bindings::*\`
  - Add explicit \`crate::\` prefix for module imports
- Remove \`extern crate core;\` (automatic in edition 2024)

All tests pass with no warnings.

Fixes rust-vmm#329

Signed-off-by: SteelCrab <pyh5523@gmail.com>
- Fix import paths: use bindings:: → use crate::bindings::
- Resolve zerocopy trait conflicts for union types
- Add comprehensive serde support for KVM structures
- Fix cross-platform compilation for x86_64, ARM64, RISC-V64
- Ensure MUSL compatibility

Signed-off-by: SteelCrab <pyh5523@gmail.com>
- Add safety comments for unsafe blocks to satisfy clippy
- Fix test module imports with crate:: prefix

Signed-off-by: SteelCrab <pyh5523@gmail.com>
Signed-off-by: SteelCrab <pyh5523@gmail.com>
- Add safety comments for unsafe blocks to satisfy clippy

Signed-off-by: SteelCrab <pyh5523@gmail.com>
@roypat
Copy link
Member

roypat commented Jun 19, 2025

Hey @SteelCrab, sorrry, this isn't quite what I had in mind. The nested state stuff we'll merge through #322, so please don't include them in your PR. Instead please just start with the current main, and upgrade to edition 2024 starting from there, completely ignoring the nested state PR :)

@roypat
Copy link
Member

roypat commented Jun 23, 2025

Hey @SteelCrab, now that #322 is merged, can you rebase this on top of main?

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.

3 participants