Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Add versioning to all bindings and conditionally compiled serde support to x86 bindings relevant to Firecracker snapshotting #14

Closed
wants to merge 6 commits into from

Conversation

alxiord
Copy link
Member

@alxiord alxiord commented Dec 19, 2019

Fixes #5

This PR adds serde compatibility to the most restricted set of bindings relevant to Firecracker snapshotting (firecracker-microvm/firecracker#1184), following the requirements laid out in this doc.

It also introduces a static version variable, available on all platforms, composed of the architecture, kernel version and crate version. This will be relevant when deserializing bindings across different environments.

Regarding serde support, the following features stand out:

  • serde support is conditionally compiled and gated by the with-serde feature, in line with fam wrappers: add conditional serde compatibility vmm-sys-util#66.

  • Serialization code will need to be manually added for each new:

    • serializable binding,
    • kernel version,
    • architecture.

    This is a key difference from my previous proposal [RFC] Add serde [de]serialization for KVM bindings #4 and @jiangliu's current proposal RFC: enhance kvm-binding to optionally support serde #7. The reasoning is that deserialization introduces a new attack surface, so we should be as restrictive and attentive as possible. I am no longer of the opinion that serialization support should be easy to add automatically, with minimal interference from the developer. On the contrary, I'm now a firm believer in careful inspection of every new item that makes its way into a secure VMM's memory space.

  • Not all the bindings are serializable. Only the bare minimum required to hold the guest's state will be migrated / included in the snapshot, so why make them all serializable?

  • Bindings are not "byte-dump"-serialized anymore (as in [RFC] Add serde [de]serialization for KVM bindings #4 and RFC: enhance kvm-binding to optionally support serde #7). This is another item on which I've changed my mind. A corrupted byte-dump snapshot will be harder to detect and reject than a "well-typed" one. Furthermore, unlike a "well-typed", fully serde-compatible format, a byte dump will be useless to inspect in 3rd party tools and painful to debug. The current solution allows the data to be dumped to JSON, for example, with the serde-json crate, and inspected as text at struct field granularity. That's just not possible with a byte dump, and valuable for debugging.

Alexandra Iordache added 6 commits December 19, 2019 16:28
...for snapshotting, which can be directly interpreted by serde
with no additional work.
Added TODOs for remaining relevant structs (& unions) that need a
bit of handicraft.
Added ser/deser unit tests using serde_json as serializer.

Signed-off-by: Alexandra Iordache <[email protected]>
Add dummy serialization support for kvm_msrs and kvm_cpuid2.
These will be properly (de)serialized through their corresponding
FamStructWrappers (Cpuid and Msrs).

Signed-off-by: Alexandra Iordache <[email protected]>
Add serialization support for:
* kvm_ioapic_state__bindgen_ty_1 - needed for kvm_ioapic,
  later needed for kvm_irqchip
* kvm_irqchip__bindgen_ty_1 - needed for kvm_irqchip

For each union, the field that takes up the most space is
serialized.

Signed-off-by: Alexandra Iordache <[email protected]>
Composed of architecture, kernel version and crate version
(all strings). Up to the consumer to decide how to handle it.

Signed-off-by: Alexandra Iordache <[email protected]>
@alxiord alxiord self-assigned this Dec 19, 2019
@alxiord alxiord changed the title Add versioning to all bindings and conditionally compiler serde support to x86 bindings relevant to Firecracker snapshotting Add versioning to all bindings and conditionally compiled serde support to x86 bindings relevant to Firecracker snapshotting Dec 19, 2019
@@ -22,3 +22,51 @@ pub mod bindings {
#[cfg(all(not(feature = "kvm-v4_14_0"), not(feature = "kvm-v4_20_0")))]
pub use super::bindings_v4_20_0::*;
}

#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
Copy link
Member

Choose a reason for hiding this comment

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

We have a proposal for a new crate at:
rust-vmm/community#76
which aims to build a common serde framework for snapshot/live migration/live upgrading.
It helps to simplify the code as
#[derive(Deserialize, Serialize)]

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! 👍 I think I don't fully understand what the new crate wants to achieve, I added a couple of questions to start from in the PR.

This was referenced Jan 3, 2020
bjzhjing added a commit to bjzhjing/cloud-hypervisor that referenced this pull request Jan 8, 2020
kvm migration implementation dependent on the following open PRs:
rust-vmm/kvm-bindings#14
rust-vmm/vmm-sys-util#66

It requires to change the following dependencies URL to internal
kvm-bindings
kvm-ioctl
vmm-sys-util

Signed-off-by: Cathy Zhang <[email protected]>
yisun-git pushed a commit to sameo/cloud-hypervisor-1 that referenced this pull request Jan 15, 2020
kvm migration implementation dependent on the following open PRs:
rust-vmm/kvm-bindings#14
rust-vmm/vmm-sys-util#66

It requires to change the following dependencies URL to internal
kvm-bindings
kvm-ioctl
vmm-sys-util

Signed-off-by: Cathy Zhang <[email protected]>
Signed-off-by: Yi Sun <[email protected]>
@alxiord
Copy link
Member Author

alxiord commented May 25, 2020

Closing in favor of https://crates.io/crates/versionize

@alxiord alxiord closed this May 25, 2020
@alxiord alxiord deleted the serde_strict branch June 18, 2024 08:11
epilys pushed a commit to epilys/kvm-bindings that referenced this pull request Oct 28, 2024
They were unexported by commit 9527998.

Fixes: rust-vmm#14

Signed-off-by: Samuel Ortiz <[email protected]>
epilys pushed a commit to epilys/kvm-bindings that referenced this pull request Oct 28, 2024
The cargo tests run outside of the crate scope and allow us to verify
that our public structures are properly exported.

Fixes: rust-vmm#14

Signed-off-by: Samuel Ortiz <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scope serde serialization support for bindings structs
2 participants