diff --git a/0003-hypervisor-kvm-Fix-setting-core-reg-error-when-resto.patch b/0003-hypervisor-kvm-Fix-setting-core-reg-error-when-resto.patch new file mode 100644 index 0000000..053333f --- /dev/null +++ b/0003-hypervisor-kvm-Fix-setting-core-reg-error-when-resto.patch @@ -0,0 +1,135 @@ +From 5551d6b5abaf9d5241904425e3991c256b30d22f Mon Sep 17 00:00:00 2001 +From: frankyj915 +Date: Sun, 15 Dec 2024 09:31:20 +0800 +Subject: [PATCH 1/2] hypervisor/kvm: Fix setting core reg error when restoring + VM + +vcpu_init() should be called before setting vcpu regs. + +Fix 5edbafc(migration: bugfix for mgiration) + +Signed-off-by: frankyj915 +--- + cpu/src/lib.rs | 20 +++++++++----------- + hypervisor/src/kvm/aarch64/mod.rs | 6 ++++-- + hypervisor/src/kvm/mod.rs | 4 ++-- + hypervisor/src/kvm/x86_64/mod.rs | 8 +++++--- + 4 files changed, 20 insertions(+), 18 deletions(-) + +diff --git a/cpu/src/lib.rs b/cpu/src/lib.rs +index 7698132..873cb49 100644 +--- a/cpu/src/lib.rs ++++ b/cpu/src/lib.rs +@@ -160,7 +160,7 @@ pub trait CPUHypervisorOps: Send + Sync { + fn set_boot_config( + &self, + arch_cpu: Arc>, +- boot_config: &CPUBootConfig, ++ boot_config: &Option, + #[cfg(target_arch = "aarch64")] vcpu_config: &CPUFeatures, + ) -> Result<()>; + +@@ -323,16 +323,14 @@ impl CPUInterface for CPU { + )))); + } + +- if let Some(boot) = boot { +- self.hypervisor_cpu +- .set_boot_config( +- self.arch_cpu.clone(), +- boot, +- #[cfg(target_arch = "aarch64")] +- config, +- ) +- .with_context(|| "Failed to realize arch cpu")?; +- } ++ self.hypervisor_cpu ++ .set_boot_config( ++ self.arch_cpu.clone(), ++ boot, ++ #[cfg(target_arch = "aarch64")] ++ config, ++ ) ++ .with_context(|| "Failed to realize arch cpu")?; + + self.arch_cpu + .lock() +diff --git a/hypervisor/src/kvm/aarch64/mod.rs b/hypervisor/src/kvm/aarch64/mod.rs +index 0721236..5d2a938 100644 +--- a/hypervisor/src/kvm/aarch64/mod.rs ++++ b/hypervisor/src/kvm/aarch64/mod.rs +@@ -135,7 +135,7 @@ impl KvmCpu { + pub fn arch_set_boot_config( + &self, + arch_cpu: Arc>, +- boot_config: &CPUBootConfig, ++ boot_config: &Option, + vcpu_config: &CPUFeatures, + ) -> Result<()> { + let mut kvi = self.kvi.lock().unwrap(); +@@ -169,7 +169,9 @@ impl KvmCpu { + } + drop(kvi); + +- arch_cpu.lock().unwrap().set_core_reg(boot_config); ++ if let Some(cfg) = boot_config { ++ arch_cpu.lock().unwrap().set_core_reg(cfg); ++ } + + self.arch_vcpu_init()?; + +diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs +index 671eb54..e20f102 100644 +--- a/hypervisor/src/kvm/mod.rs ++++ b/hypervisor/src/kvm/mod.rs +@@ -544,7 +544,7 @@ impl CPUHypervisorOps for KvmCpu { + fn set_boot_config( + &self, + arch_cpu: Arc>, +- boot_config: &CPUBootConfig, ++ boot_config: &Option, + #[cfg(target_arch = "aarch64")] vcpu_config: &CPUFeatures, + ) -> Result<()> { + #[cfg(target_arch = "aarch64")] +@@ -1067,7 +1067,7 @@ mod test { + let cpu = CPU::new(hypervisor_cpu.clone(), 0, x86_cpu, vm.clone()); + // test `set_boot_config` function + assert!(hypervisor_cpu +- .set_boot_config(cpu.arch().clone(), &cpu_config) ++ .set_boot_config(cpu.arch().clone(), &Some(cpu_config)) + .is_ok()); + + // test setup special registers +diff --git a/hypervisor/src/kvm/x86_64/mod.rs b/hypervisor/src/kvm/x86_64/mod.rs +index 7d7e7b5..e7d08ef 100644 +--- a/hypervisor/src/kvm/x86_64/mod.rs ++++ b/hypervisor/src/kvm/x86_64/mod.rs +@@ -84,7 +84,7 @@ impl KvmCpu { + pub fn arch_set_boot_config( + &self, + arch_cpu: Arc>, +- boot_config: &CPUBootConfig, ++ boot_config: &Option, + ) -> Result<()> { + let mut locked_arch_cpu = arch_cpu.lock().unwrap(); + let apic_id = locked_arch_cpu.apic_id; +@@ -93,12 +93,14 @@ impl KvmCpu { + .get_lapic() + .with_context(|| format!("Failed to get lapic for CPU {}/KVM", apic_id))?; + locked_arch_cpu.setup_lapic(lapic)?; +- locked_arch_cpu.setup_regs(boot_config); + let sregs = self + .fd + .get_sregs() + .with_context(|| format!("Failed to get sregs for CPU {}/KVM", apic_id))?; +- locked_arch_cpu.setup_sregs(sregs, boot_config)?; ++ if let Some(cfg) = boot_config { ++ locked_arch_cpu.setup_regs(cfg); ++ locked_arch_cpu.setup_sregs(sregs, cfg)?; ++ } + locked_arch_cpu.setup_fpu(); + locked_arch_cpu.setup_msrs(); + +-- +2.34.1 + diff --git a/0004-micro_comman-syscall-Update-ioctl-allow-list.patch b/0004-micro_comman-syscall-Update-ioctl-allow-list.patch new file mode 100644 index 0000000..fa22958 --- /dev/null +++ b/0004-micro_comman-syscall-Update-ioctl-allow-list.patch @@ -0,0 +1,50 @@ +From e9c9d3de82eb926ab6d494358c7a1891b171e190 Mon Sep 17 00:00:00 2001 +From: frankyj915 +Date: Sun, 15 Dec 2024 09:35:03 +0800 +Subject: [PATCH] micro_comman/syscall: Update ioctl allow list + +Signed-off-by: frankyj915 +--- + hypervisor/src/kvm/mod.rs | 6 ++++++ + machine/src/micro_common/syscall.rs | 8 +++++++- + 2 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs +index e20f102..b88aeed 100644 +--- a/hypervisor/src/kvm/mod.rs ++++ b/hypervisor/src/kvm/mod.rs +@@ -99,6 +99,12 @@ ioctl_iowr_nr!(KVM_GET_IRQCHIP, KVMIO, 0x62, kvm_irqchip); + ioctl_iow_nr!(KVM_IRQ_LINE, KVMIO, 0x61, kvm_irq_level); + ioctl_iow_nr!(KVM_SET_MP_STATE, KVMIO, 0x99, kvm_mp_state); + ioctl_iow_nr!(KVM_SET_VCPU_EVENTS, KVMIO, 0xa0, kvm_vcpu_events); ++#[cfg(target_arch = "x86_64")] ++ioctl_iow_nr!(KVM_SET_PIT2, KVMIO, 0xa0, kvm_pit_state2); ++#[cfg(target_arch = "x86_64")] ++ioctl_iow_nr!(KVM_SET_CLOCK, KVMIO, 0x7b, kvm_clock_data); ++#[cfg(target_arch = "x86_64")] ++ioctl_ior_nr!(KVM_SET_IRQCHIP, KVMIO, 0x63, kvm_irqchip); + + #[allow(clippy::upper_case_acronyms)] + #[derive(Default)] +diff --git a/machine/src/micro_common/syscall.rs b/machine/src/micro_common/syscall.rs +index 6ae9a56..ca8327f 100644 +--- a/machine/src/micro_common/syscall.rs ++++ b/machine/src/micro_common/syscall.rs +@@ -160,7 +160,13 @@ fn ioctl_allow_list() -> BpfRule { + .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_MP_STATE() as u32) + .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_MP_STATE() as u32) + .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_VCPU_EVENTS() as u32) +- .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_VCPU_EVENTS() as u32); ++ .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_VCPU_EVENTS() as u32) ++ .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_USER_MEMORY_REGION); ++ #[cfg(target_arch = "x86_64")] ++ let bpf_rule = bpf_rule ++ .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_PIT2() as u32) ++ .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_CLOCK() as u32) ++ .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_IRQCHIP() as u32); + arch_ioctl_allow_list(bpf_rule) + } + +-- +2.34.1 + diff --git a/stratovirt.spec b/stratovirt.spec index 59d37e0..306b1ed 100644 --- a/stratovirt.spec +++ b/stratovirt.spec @@ -6,7 +6,7 @@ Name: stratovirt Version: 2.4.0 -Release: 3 +Release: 5 Summary: StratoVirt is an opensource VMM(Virtual Machine Manager) which aims to perform next generation virtualization. License: MulanPSL-2.0 @@ -15,6 +15,8 @@ Source0: https://gitee.com/openeuler/stratovirt/releases/download/v%{vers Patch001:0001-Micro-fix-the-ioctl-allow-for-aarch64.patch Patch002:0002-snapshot-bugfix-VM-run-failed-from-memory-snapshot.patch +Patch003:0003-hypervisor-kvm-Fix-setting-core-reg-error-when-resto.patch +Patch004:0004-micro_comman-syscall-Update-ioctl-allow-list.patch ExclusiveArch: x86_64 aarch64 @@ -81,6 +83,9 @@ sed -i '/\[source.local-registry\]/a directory = "vendor"' ./.cargo/config sed -i '/^rustflags/d' ./.cargo/config sed -i '/\[build\]/arustflags = \["-Copt-level=3", "-Cdebuginfo=2", "-Clink-arg=-Wl,-z,relro,-z,now", "-Ccodegen-units=1", "--cap-lints=warn", \]' ./.cargo/config +sed -i '$a\[profile.release\]' ./.cargo/config +sed -i '$adebug = true' ./.cargo/config + %ifarch aarch64 sed -i 's/rustflags = \[/&"-Clink-arg=-lgcc", /' ./.cargo/config %endif @@ -102,12 +107,20 @@ install -d %{buildroot}%{_libdir}/stratovirt/static install -D -m555 ./target/%{rust_musl_target}/release/stratovirt %{buildroot}%{_libdir}/stratovirt/static %changelog -* Wed Dec 11 2024 Mingwang Li - 2.4.0-3 +* Tue Dec 17 2024 frankyj915 - 2.4.0-5 +- Fix setting core reg error when restoring VM. +- Update ioctl allow list. + +* Wed Dec 11 2024 Mingwang Li - 2.4.0-4 - bugfix VM run failed from memory snapshot -* Thu Nov 21 2024 jinyihua - 2.4.0-2 +* Thu Nov 21 2024 jinyihua - 2.4.0-3 - Micro fix the ioctl allow for aarch64 +* Tue Jul 30 2024 xufei - 2.4.0-2 +- set debug is true for build debug package +- add rust to BuildRequires + * Fri May 10 2024 wenyuanlau 2.4.0-1 - Update to StratoVirt 2.4.0