From 3c4ff7de0140db26ec9394ad670cf328a5d57c31 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Mon, 11 Mar 2024 12:02:57 -0700 Subject: [PATCH] hypervisor: Use legacy definitions of kvm structs for live-upgrade Use 'kvm_vcpu_events_old' and 'kvm_clock_data_old' to support deserialization from legacy definitions of kvm structs, so that we can support live-upgrade from previous point releases. Signed-off-by: Bo Chen --- Cargo.lock | 2 +- Cargo.toml | 2 +- fuzz/Cargo.lock | 2 +- fuzz/Cargo.toml | 2 +- hypervisor/Cargo.toml | 2 +- hypervisor/src/kvm/mod.rs | 8 ++++---- hypervisor/src/kvm/x86_64/mod.rs | 2 +- hypervisor/src/lib.rs | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b05b2ad3f..f19541693 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1152,7 +1152,7 @@ dependencies = [ [[package]] name = "kvm-bindings" version = "0.7.0" -source = "git+https://github.com/cloud-hypervisor/kvm-bindings?branch=ch-v0.7.0#2dcf85d4f8aa55befcaa996b699ddb18ec9ed059" +source = "git+https://github.com/cloud-hypervisor/kvm-bindings?branch=ch-live-upgrade-stable-37.x#f03fc575cdf20c3af9ca3d4d203f171943d95be4" dependencies = [ "serde", "serde_derive", diff --git a/Cargo.toml b/Cargo.toml index 2bce87916..6c3bcc04a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ zbus = { version = "3.11.1", optional = true } # List of patched crates [patch.crates-io] -kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0" } +kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-live-upgrade-stable-37.x" } versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch-0.1.6" } [dev-dependencies] diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 7c0efcd52..4cfb58170 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -477,7 +477,7 @@ dependencies = [ [[package]] name = "kvm-bindings" version = "0.7.0" -source = "git+https://github.com/cloud-hypervisor/kvm-bindings?branch=ch-v0.7.0#2dcf85d4f8aa55befcaa996b699ddb18ec9ed059" +source = "git+https://github.com/cloud-hypervisor/kvm-bindings?branch=ch-live-upgrade-stable-37.x#f03fc575cdf20c3af9ca3d4d203f171943d95be4" dependencies = [ "serde", "serde_derive", diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 5bec78384..c7931670c 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -35,7 +35,7 @@ vm-virtio = { path = "../vm-virtio" } path = ".." [patch.crates-io] -kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0" } +kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-live-upgrade-stable-37.x" } versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch-0.1.6" } # Prevent this from interfering with workspaces diff --git a/hypervisor/Cargo.toml b/hypervisor/Cargo.toml index ce49f50d4..44dee71e2 100644 --- a/hypervisor/Cargo.toml +++ b/hypervisor/Cargo.toml @@ -19,7 +19,7 @@ igvm_parser = { git = "https://github.com/microsoft/igvm", branch = "main", pack libc = "0.2.147" log = "0.4.20" kvm-ioctls = { version = "0.16.0", optional = true } -kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.7.0", features = ["with-serde", "fam-wrappers"], optional = true } +kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-live-upgrade-stable-37.x", features = ["with-serde", "fam-wrappers"], optional = true } mshv-bindings = { git = "https://github.com/rust-vmm/mshv", branch = "main", features = ["with-serde", "fam-wrappers"], optional = true } mshv-ioctls = { git = "https://github.com/rust-vmm/mshv", branch = "main", optional = true} serde = { version = "1.0.168", features = ["rc", "derive"] } diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 6d91452f7..00d4dfaa4 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -315,7 +315,7 @@ impl From for VcpuKvmState { #[cfg(target_arch = "x86_64")] impl From for ClockData { fn from(d: kvm_clock_data) -> Self { - ClockData::Kvm(d) + ClockData::Kvm(d.into()) } } @@ -323,7 +323,7 @@ impl From for ClockData { impl From for kvm_clock_data { fn from(ms: ClockData) -> Self { match ms { - ClockData::Kvm(s) => s, + ClockData::Kvm(s) => s.into(), /* Needed in case other hypervisors are enabled */ #[allow(unreachable_patterns)] _ => panic!("CpuState is not valid"), @@ -1977,7 +1977,7 @@ impl cpu::Vcpu for KvmVcpu { msr_entries }; - let vcpu_events = self.get_vcpu_events()?; + let vcpu_events = self.get_vcpu_events()?.into(); let tsc_khz = self.tsc_khz()?; Ok(VcpuKvmState { @@ -2130,7 +2130,7 @@ impl cpu::Vcpu for KvmVcpu { } } - self.set_vcpu_events(&state.vcpu_events)?; + self.set_vcpu_events(&state.vcpu_events.into())?; Ok(()) } diff --git a/hypervisor/src/kvm/x86_64/mod.rs b/hypervisor/src/kvm/x86_64/mod.rs index cb4d069e3..953daffc4 100644 --- a/hypervisor/src/kvm/x86_64/mod.rs +++ b/hypervisor/src/kvm/x86_64/mod.rs @@ -22,7 +22,7 @@ pub use { kvm_bindings::kvm_cpuid_entry2, kvm_bindings::kvm_dtable, kvm_bindings::kvm_fpu, kvm_bindings::kvm_lapic_state, kvm_bindings::kvm_mp_state as MpState, kvm_bindings::kvm_msr_entry, kvm_bindings::kvm_regs, kvm_bindings::kvm_segment, - kvm_bindings::kvm_sregs, kvm_bindings::kvm_vcpu_events as VcpuEvents, + kvm_bindings::kvm_sregs, kvm_bindings::kvm_vcpu_events_old as VcpuEvents, kvm_bindings::kvm_xcrs as ExtendedControlRegisters, kvm_bindings::kvm_xsave, kvm_bindings::CpuId, kvm_bindings::MsrList, kvm_bindings::Msrs as MsrEntries, kvm_bindings::KVM_CPUID_FLAG_SIGNIFCANT_INDEX, diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index 447e8abd4..d5a7ed1f1 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -162,7 +162,7 @@ pub enum CpuState { #[cfg(target_arch = "x86_64")] pub enum ClockData { #[cfg(feature = "kvm")] - Kvm(kvm_bindings::kvm_clock_data), + Kvm(kvm_bindings::kvm_clock_data_old), #[cfg(feature = "mshv")] Mshv, /* MSHV does not support ClockData yet */ }