From 3ffd2cb9bea0d98c09874483199812c21a0b7345 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 26 May 2021 15:28:15 +0000 Subject: [PATCH] pci: Versionize PCI state Signed-off-by: Rob Bradford --- Cargo.lock | 5 ++--- pci/Cargo.toml | 5 ++--- pci/src/configuration.rs | 16 ++++++++++------ pci/src/lib.rs | 2 -- pci/src/msix.rs | 14 +++++++++----- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17df7a188..a46f7a993 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,9 +642,8 @@ dependencies = [ "hypervisor", "libc", "log", - "serde", - "serde_derive", - "serde_json", + "versionize", + "versionize_derive", "vfio-bindings", "vfio-ioctls", "vm-allocator", diff --git a/pci/Cargo.toml b/pci/Cargo.toml index 849490d33..584100b6c 100644 --- a/pci/Cargo.toml +++ b/pci/Cargo.toml @@ -12,9 +12,8 @@ vfio-ioctls = { git = "https://github.com/rust-vmm/vfio-ioctls", branch = "maste vmm-sys-util = ">=0.3.1" libc = "0.2.95" log = "0.4.14" -serde = {version = ">=1.0.27", features = ["rc"] } -serde_derive = ">=1.0.27" -serde_json = ">=1.0.9" +versionize = "0.1.6" +versionize_derive = "0.1.4" vm-allocator = { path = "../vm-allocator" } vm-device = { path = "../vm-device" } vm-memory = "0.5.0" diff --git a/pci/src/configuration.rs b/pci/src/configuration.rs index d7a7ef705..a5f8d3eab 100644 --- a/pci/src/configuration.rs +++ b/pci/src/configuration.rs @@ -7,7 +7,9 @@ use crate::{MsixConfig, PciInterruptPin}; use byteorder::{ByteOrder, LittleEndian}; use std::fmt::{self, Display}; use std::sync::{Arc, Mutex}; -use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable}; +use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult}; +use versionize_derive::Versionize; +use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; // The number of 32bit registers in the config space, 4096 bytes. const NUM_CONFIGURATION_REGISTERS: usize = 1024; @@ -276,7 +278,7 @@ fn decode_64_bits_bar_size(bar_size_hi: u32, bar_size_lo: u32) -> Option { None } -#[derive(Serialize, Deserialize, Default, Clone, Copy)] +#[derive(Default, Clone, Copy, Versionize)] struct PciBar { addr: u32, size: u32, @@ -284,7 +286,7 @@ struct PciBar { r#type: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] struct PciConfigurationState { registers: Vec, writable_bits: Vec, @@ -296,6 +298,8 @@ struct PciConfigurationState { msix_cap_reg_idx: Option, } +impl VersionMapped for PciConfigurationState {} + /// Contains the configuration space of a PCI node. /// See the [specification](https://en.wikipedia.org/wiki/PCI_configuration_space). /// The configuration space is accessed with DWORD reads and writes from the guest. @@ -313,7 +317,7 @@ pub struct PciConfiguration { } /// See pci_regs.h in kernel -#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Copy, Clone, PartialEq, Versionize)] pub enum PciBarRegionType { Memory32BitRegion = 0, IoRegion = 0x01, @@ -881,11 +885,11 @@ impl Snapshottable for PciConfiguration { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id(), &self.state()) + Snapshot::new_from_versioned_state(&self.id(), &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id())?); + self.set_state(&snapshot.to_versioned_state(&self.id())?); Ok(()) } } diff --git a/pci/src/lib.rs b/pci/src/lib.rs index d1c4caf31..a76457a18 100644 --- a/pci/src/lib.rs +++ b/pci/src/lib.rs @@ -5,8 +5,6 @@ //! Implements pci devices and busses. #[macro_use] extern crate log; -#[macro_use] -extern crate serde_derive; mod bus; mod configuration; diff --git a/pci/src/msix.rs b/pci/src/msix.rs index 819934d7a..16d11a3d2 100644 --- a/pci/src/msix.rs +++ b/pci/src/msix.rs @@ -9,11 +9,13 @@ use byteorder::{ByteOrder, LittleEndian}; use std::io; use std::result; use std::sync::Arc; +use versionize::{VersionMap, Versionize, VersionizeResult}; +use versionize_derive::Versionize; use vm_device::interrupt::{ InterruptIndex, InterruptSourceConfig, InterruptSourceGroup, MsiIrqSourceConfig, }; use vm_memory::ByteValued; -use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable}; +use vm_migration::{MigratableError, Pausable, Snapshot, Snapshottable, VersionMapped}; const MAX_MSIX_VECTORS_PER_DEVICE: u16 = 2048; const MSIX_TABLE_ENTRIES_MODULO: u64 = 16; @@ -33,7 +35,7 @@ enum Error { UpdateInterruptRoute(io::Error), } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Versionize)] pub struct MsixTableEntry { pub msg_addr_lo: u32, pub msg_addr_hi: u32, @@ -58,7 +60,7 @@ impl Default for MsixTableEntry { } } -#[derive(Serialize, Deserialize)] +#[derive(Versionize)] struct MsixConfigState { table_entries: Vec, pba_entries: Vec, @@ -66,6 +68,8 @@ struct MsixConfigState { enabled: bool, } +impl VersionMapped for MsixConfigState {} + pub struct MsixConfig { pub table_entries: Vec, pub pba_entries: Vec, @@ -429,11 +433,11 @@ impl Snapshottable for MsixConfig { } fn snapshot(&mut self) -> std::result::Result { - Snapshot::new_from_state(&self.id(), &self.state()) + Snapshot::new_from_versioned_state(&self.id(), &self.state()) } fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> { - self.set_state(&snapshot.to_state(&self.id())?) + self.set_state(&snapshot.to_versioned_state(&self.id())?) .map_err(|e| { MigratableError::Restore(anyhow!( "Could not restore state for {}: {:?}",