From 9edcd42ebdb014fda4ccde8db80911f75bb902e9 Mon Sep 17 00:00:00 2001 From: yyjeqhc Date: Mon, 9 Jun 2025 12:06:42 +0800 Subject: [PATCH] Rework patch 9/10/11 as patch 12/13. Adjust spec file to apply them for riscv64. --- ...-Rust-VMM-dependencies-and-re-vendor.patch | 14 +- 0012-fix-patch9-for-riscv64.patch | 215 ++++++++++++++++++ 0013-fix-patch10-for-riscv64.patch | 136 +++++++++++ stratovirt.spec | 14 +- 4 files changed, 365 insertions(+), 14 deletions(-) create mode 100644 0012-fix-patch9-for-riscv64.patch create mode 100644 0013-fix-patch10-for-riscv64.patch diff --git a/0005-update-Rust-VMM-dependencies-and-re-vendor.patch b/0005-update-Rust-VMM-dependencies-and-re-vendor.patch index a73ffff..7530e68 100644 --- a/0005-update-Rust-VMM-dependencies-and-re-vendor.patch +++ b/0005-update-Rust-VMM-dependencies-and-re-vendor.patch @@ -5,7 +5,6 @@ Subject: [PATCH] Update Rust-VMM dependencies and re-vendor Signed-off-by: Ruoqing He --- - .cargo/config | 1 - Cargo.lock | 51 +- address_space/Cargo.toml | 2 +- block_backend/Cargo.toml | 2 +- @@ -251,18 +250,7 @@ Signed-off-by: Ruoqing He create mode 100644 vendor/kvm-bindings/src/x86_64/mod.rs create mode 100644 vendor/kvm-bindings/src/x86_64/serialize.rs -diff --git a/.cargo/config b/.cargo/config -index 31ec474..1f84b46 100644 ---- a/.cargo/config -+++ b/.cargo/config -@@ -11,7 +11,6 @@ - # See the Mulan PSL v2 for more details. - - [build] -- - [target.'cfg(target_arch = "aarch64", not(target_env = "ohos"))'] - rustflags = [ - "-C", "link-arg=-lgcc", + diff --git a/Cargo.lock b/Cargo.lock index fba3e56..99a1e19 100644 --- a/Cargo.lock diff --git a/0012-fix-patch9-for-riscv64.patch b/0012-fix-patch9-for-riscv64.patch new file mode 100644 index 0000000..698f13e --- /dev/null +++ b/0012-fix-patch9-for-riscv64.patch @@ -0,0 +1,215 @@ +diff --git a/machine/src/micro_common/mod.rs b/machine/src/micro_common/mod.rs +index 7fb530e..04b6916 100644 +--- a/machine/src/micro_common/mod.rs ++++ b/machine/src/micro_common/mod.rs +@@ -644,6 +644,35 @@ impl DeviceInterface for LightMachine { + Response::create_response(cpu_vec.into(), None) + } + ++ fn query_cpus_fast(&self) -> Response { ++ let mut cpu_vec: Vec = Vec::new(); ++ let cpu_topo = self.get_cpu_topo(); ++ let cpus = self.get_cpus(); ++ for cpu_index in 0..cpu_topo.max_cpus { ++ if cpu_topo.get_mask(cpu_index as usize) == 1 { ++ let thread_id = cpus[cpu_index as usize].tid(); ++ let cpu_instance = cpu_topo.get_topo_instance_for_qmp(cpu_index as usize); ++ #[cfg(target_arch = "x86_64")] ++ let target = String::from("x86_64"); ++ #[cfg(target_arch = "aarch64")] ++ let target = String::from("aarch64"); ++ #[cfg(target_arch = "riscv64")] ++ let target = String::from("riscv64"); ++ let cpu_info = qmp_schema::CpuInfoFast { ++ qom_path: String::from("/machine/unattached/device[") ++ + &cpu_index.to_string() ++ + "]", ++ props: Some(cpu_instance), ++ cpu_index: cpu_index as isize, ++ thread_id: thread_id as isize, ++ target: target, ++ }; ++ cpu_vec.push(serde_json::to_value(cpu_info).unwrap()); ++ } ++ } ++ Response::create_response(cpu_vec.into(), None) ++ } ++ + fn query_hotpluggable_cpus(&self) -> Response { + let mut hotplug_vec: Vec = Vec::new(); + #[cfg(target_arch = "x86_64")] +diff --git a/machine/src/standard_common/mod.rs b/machine/src/standard_common/mod.rs +index f18350a..72f9002 100644 +--- a/machine/src/standard_common/mod.rs ++++ b/machine/src/standard_common/mod.rs +@@ -1010,6 +1010,35 @@ impl DeviceInterface for StdMachine { + Response::create_response(cpu_vec.into(), None) + } + ++ fn query_cpus_fast(&self) -> Response { ++ let mut cpu_vec: Vec = Vec::new(); ++ let cpu_topo = self.get_cpu_topo(); ++ let cpus = self.get_cpus(); ++ for cpu_index in 0..cpu_topo.max_cpus { ++ if cpu_topo.get_mask(cpu_index as usize) == 1 { ++ let thread_id = cpus[cpu_index as usize].tid(); ++ let cpu_instance = cpu_topo.get_topo_instance_for_qmp(cpu_index as usize); ++ #[cfg(target_arch = "x86_64")] ++ let target = String::from("x86_64"); ++ #[cfg(target_arch = "aarch64")] ++ let target = String::from("aarch64"); ++ #[cfg(target_arch = "riscv64")] ++ let target = String::from("riscv64"); ++ let cpu_info = qmp_schema::CpuInfoFast { ++ qom_path: String::from("/machine/unattached/device[") ++ + &cpu_index.to_string() ++ + "]", ++ props: Some(cpu_instance), ++ cpu_index: cpu_index as isize, ++ thread_id: thread_id as isize, ++ target: target, ++ }; ++ cpu_vec.push(serde_json::to_value(cpu_info).unwrap()); ++ } ++ } ++ Response::create_response(cpu_vec.into(), None) ++ } ++ + fn query_hotpluggable_cpus(&self) -> Response { + Response::create_empty_response() + } +diff --git a/machine_manager/src/machine.rs b/machine_manager/src/machine.rs +index 4579439..91ede9b 100644 +--- a/machine_manager/src/machine.rs ++++ b/machine_manager/src/machine.rs +@@ -174,6 +174,8 @@ pub trait DeviceInterface { + /// Query each cpu's the topology info. + fn query_cpus(&self) -> Response; + ++ fn query_cpus_fast(&self) -> Response; ++ + /// Query each `hotpluggable_cpus`'s topology info and hotplug message. + fn query_hotpluggable_cpus(&self) -> Response; + +diff --git a/machine_manager/src/qmp/qmp_schema.rs b/machine_manager/src/qmp/qmp_schema.rs +index c3a8f7f..4fe0cd7 100644 +--- a/machine_manager/src/qmp/qmp_schema.rs ++++ b/machine_manager/src/qmp/qmp_schema.rs +@@ -92,6 +92,7 @@ define_qmp_command_enum!( + cameradev_del("cameradev_del", cameradev_del), + query_hotpluggable_cpus("query-hotpluggable-cpus", query_hotpluggable_cpus, default), + query_cpus("query-cpus", query_cpus, default), ++ query_cpus_fast("query-cpus-fast", query_cpus_fast, default), + query_status("query-status", query_status, default), + getfd("getfd", getfd), + blockdev_add("blockdev-add", Box), +@@ -859,6 +860,63 @@ pub struct CpuInfoX86 {} + #[derive(Default, Debug, Clone, Serialize, Deserialize)] + pub struct CpuInfoArm {} + ++/// @query-cpus-fast: ++/// ++/// Returns information about all virtual CPUs. ++/// ++/// Returns: list of @CpuInfoFast ++/// ++/// Since: 2.12 ++/// ++/// Example: ++/// ++/// -> { "execute": "query-cpus-fast" } ++/// <- { "return": [ ++/// { ++/// "thread-id": 25627, ++/// "props": { ++/// "core-id": 0, ++/// "thread-id": 0, ++/// "socket-id": 0 ++/// }, ++/// "qom-path": "/machine/unattached/device[0]", ++/// "target":"x86_64", ++/// "cpu-index": 0 ++/// }, ++/// { ++/// "thread-id": 25628, ++/// "props": { ++/// "core-id": 0, ++/// "thread-id": 0, ++/// "socket-id": 1 ++/// }, ++/// "qom-path": "/machine/unattached/device[2]", ++/// "target":"x86_64", ++/// "cpu-index": 1 ++/// } ++/// ] ++/// } ++/// ++/// ``` ++#[derive(Default, Debug, Clone, Serialize, Deserialize)] ++#[serde(deny_unknown_fields)] ++pub struct query_cpus_fast {} ++generate_command_impl!(query_cpus_fast, Vec); ++ ++#[derive(Debug, Clone, Serialize, Deserialize)] ++pub struct CpuInfoFast { ++ #[serde(rename = "qom_path")] ++ pub qom_path: String, ++ #[serde(rename = "props", default, skip_serializing_if = "Option::is_none")] ++ pub props: Option, ++ #[serde(rename = "cpu-index")] ++ pub cpu_index: isize, ++ #[serde(rename = "thread-id")] ++ pub thread_id: isize, ++ #[serde(rename = "target")] ++ pub target: String, ++} ++ + #[derive(Default, Debug, Clone, Serialize, Deserialize)] + pub struct CpuInfoRISCV {} + +@@ -2181,6 +2239,33 @@ mod tests { + let ret_msg = r#"invalid type: string "isdf", expected struct query_cpus"#; + assert!(err_msg == ret_msg); + ++ // qmp: query-cpus-fast. ++ let json_msg = r#" ++ { ++ "execute": "query-cpus-fast" ++ } ++ "#; ++ let err_msg = match serde_json::from_str::(json_msg) { ++ Ok(_) => "ok".to_string(), ++ Err(e) => e.to_string(), ++ }; ++ let ret_msg = r#"ok"#; ++ assert!(err_msg == ret_msg); ++ ++ // unexpected arguments for query-cpus-fast. ++ let json_msg = r#" ++ { ++ "execute": "query-cpus-fast" , ++ "arguments": "isdf" ++ } ++ "#; ++ let err_msg = match serde_json::from_str::(json_msg) { ++ Ok(_) => "ok".to_string(), ++ Err(e) => e.to_string(), ++ }; ++ let ret_msg = r#"invalid type: string "isdf", expected struct query_cpus_fast"#; ++ assert!(err_msg == ret_msg); ++ + // qmp: query-ststus. + let json_msg = r#" + { +diff --git a/machine_manager/src/qmp/qmp_socket.rs b/machine_manager/src/qmp/qmp_socket.rs +index 35ad238..3ae155c 100644 +--- a/machine_manager/src/qmp/qmp_socket.rs ++++ b/machine_manager/src/qmp/qmp_socket.rs +@@ -460,6 +460,7 @@ fn qmp_command_exec( + (query_migrate, query_migrate), + (cancel_migrate, cancel_migrate), + (query_cpus, query_cpus), ++ (query_cpus_fast, query_cpus_fast), + (query_balloon, query_balloon), + (query_mem, query_mem), + (query_vnc, query_vnc), diff --git a/0013-fix-patch10-for-riscv64.patch b/0013-fix-patch10-for-riscv64.patch new file mode 100644 index 0000000..cb183db --- /dev/null +++ b/0013-fix-patch10-for-riscv64.patch @@ -0,0 +1,136 @@ +diff --git a/machine_manager/src/cmdline.rs b/machine_manager/src/cmdline.rs +index 619a7c2..69bd79f 100644 +--- a/machine_manager/src/cmdline.rs ++++ b/machine_manager/src/cmdline.rs +@@ -184,8 +184,8 @@ pub fn create_args_parser<'a>() -> ArgParser<'a> { + Arg::with_name("qmp") + .long("qmp") + .value_name("") +- .help("\n\t\tset unix socket path: unix:,server,nowait; \ +- \n\t\tset tcp socket path: tcp:ip:port,server,nowait") ++ .help("\n\t\tset unix socket path: unix:,server,nowait/wait=off; \ ++ \n\t\tset tcp socket path: tcp:ip:port,server,nowait/wait=off") + .takes_value(true) + ) + .arg( +@@ -223,8 +223,9 @@ pub fn create_args_parser<'a>() -> ArgParser<'a> { + .help("\n\t\tadd standard i/o device: -chardev stdio,id=; \ + \n\t\tadd pseudo-terminal: -chardev pty,id=; \ + \n\t\tadd file: -chardev file,id=,path=; \ +- \n\t\tadd unix-socket: -chardev socket,id=,path=[,server][,nowait]; \ +- \n\t\tadd tcp-socket: -chardev socket,id=,port=[,host=host][,server][,nowait];") ++ \n\t\tadd unix-socket: -chardev socket,id=,path=[,server][,nowait/wait=off]; \ ++ \n\t\tadd tcp-socket: -chardev socket,id=,port=[,host=host][,server][,nowait/wait=off];") ++ + .takes_values(true), + ) + .arg( +@@ -267,8 +268,8 @@ pub fn create_args_parser<'a>() -> ArgParser<'a> { + \n\t\tuse standard i/o device: -serial stdio; \ + \n\t\tuse pseudo-terminal: -serial pty; \ + \n\t\tuse file: -serial file,path=; \ +- \n\t\tuse unix-socket: -serial socket,path=[,server][,nowait]; \ +- \n\t\tuse tcp-socket: -serial socket,port=[,host=][,server][,nowait]; \ ++ \n\t\tuse unix-socket: -serial socket,path=[,server][,nowait/wait=off]; \ ++ \n\t\tuse tcp-socket: -serial socket,port=[,host=][,server][,nowait/wait=off]; \ + ") + .takes_value(true), + ) +diff --git a/machine_manager/src/machine.rs b/machine_manager/src/machine.rs +index 91ede9b..d1e976c 100644 +--- a/machine_manager/src/machine.rs ++++ b/machine_manager/src/machine.rs +@@ -375,6 +375,7 @@ pub trait DeviceInterface { + ("usb-kbd", "usb-hid"), + ("usb-storage", "usb-storage-dev"), + ("virtio-gpu-pci", "virtio-gpu"), ++ ("pl011", "sys-bus-device"), + ]; + + for list in list_types { +@@ -384,6 +385,11 @@ pub trait DeviceInterface { + Response::create_response(serde_json::to_value(&vec_types).unwrap(), None) + } + ++ fn qom_list_properties(&self, _typename: String) -> Response { ++ let types = Vec::::new(); ++ Response::create_response(serde_json::to_value(types).unwrap(), None) ++ } ++ + fn device_list_properties(&self, typename: String) -> Response { + let mut vec_props = Vec::::new(); + let prop = DeviceProps { +@@ -444,7 +450,18 @@ pub trait DeviceInterface { + } + + fn query_qmp_schema(&self) -> Response { +- Response::create_empty_response() ++ let mut vec_types = Vec::new(); ++ let list_types: Vec<(&str, &str)> = vec![ ++ ("name", "query-status"), ++ ("ret-type", "1"), ++ ("meta-type", "command"), ++ ("arg-type", "0"), ++ ]; ++ for list in list_types { ++ let re = TypeLists::new(String::from(list.0), String::from(list.1)); ++ vec_types.push(re); ++ } ++ Response::create_response(serde_json::to_value(&vec_types).unwrap(), None) + } + + fn query_sev_capabilities(&self) -> Response { +diff --git a/machine_manager/src/qmp/qmp_schema.rs b/machine_manager/src/qmp/qmp_schema.rs +index 4fe0cd7..daf253e 100644 +--- a/machine_manager/src/qmp/qmp_schema.rs ++++ b/machine_manager/src/qmp/qmp_schema.rs +@@ -114,6 +114,7 @@ define_qmp_command_enum!( + query_machines("query-machines", query_machines, default), + query_events("query-events", query_events, default), + list_type("qom-list-types", list_type, default), ++ qom_list_properties("qom-list-properties", qom_list_properties, default), + device_list_properties("device-list-properties", device_list_properties, default), + block_commit("block-commit", block_commit, default), + query_tpm_models("query-tpm-models", query_tpm_models, default), +@@ -1377,6 +1378,29 @@ impl TypeLists { + } + } + ++/// qom-list-properties ++/// ++/// List properties associated with a qom. ++/// ++/// # Examples ++/// ++/// ```text ++/// -> { "execute": "qom-list-properties", "arguments": { "typename": "memory-backend-file" } } ++/// <- { "return": [] } ++/// ``` ++#[derive(Default, Debug, Clone, Serialize, Deserialize)] ++pub struct qom_list_properties { ++ pub typename: String, ++} ++generate_command_impl!(qom_list_properties, Vec); ++ ++#[derive(Default, Debug, Clone, Serialize, Deserialize)] ++pub struct QomListProps { ++ pub name: String, ++ #[serde(rename = "typename")] ++ pub prop_type: String, ++} ++ + /// device-list-properties + /// + /// List properties associated with a device. +diff --git a/machine_manager/src/qmp/qmp_socket.rs b/machine_manager/src/qmp/qmp_socket.rs +index 3ae155c..2372c96 100644 +--- a/machine_manager/src/qmp/qmp_socket.rs ++++ b/machine_manager/src/qmp/qmp_socket.rs +@@ -468,6 +468,7 @@ fn qmp_command_exec( + (list_type, list_type), + (query_hotpluggable_cpus, query_hotpluggable_cpus); + (input_event, input_event, key, value), ++ (qom_list_properties, qom_list_properties, typename), + (device_list_properties, device_list_properties, typename), + (device_del, device_del, id), + (switch_audio_record, switch_audio_record, authorized), diff --git a/stratovirt.spec b/stratovirt.spec index 27361b1..d57a958 100644 --- a/stratovirt.spec +++ b/stratovirt.spec @@ -6,7 +6,7 @@ Name: stratovirt Version: 2.4.0 -Release: 10 +Release: 11 Summary: StratoVirt is an opensource VMM(Virtual Machine Manager) which aims to perform next generation virtualization. License: MulanPSL-2.0 @@ -25,9 +25,17 @@ Patch006:0006-introduce-riscv64-architecture-support.patch Patch007:0007-vfio-pci-fix-a-deadlock-problem.patch Patch008:0008-QMP-bugfix-the-error-in-the-return-result-of-query_c.patch + +%ifnarch riscv64 Patch009:0009-QMP-add-query-cpus-fast.patch Patch010:0010-add-support-to-interconnecting-with-libvirt.patch Patch011:0011-virtio-net-do-not-delete-fd-which-has-not-been-added.patch +%endif + +%ifarch riscv64 +Patch012:0012-fix-patch9-for-riscv64.patch +Patch013:0013-fix-patch10-for-riscv64.patch +%endif ExclusiveArch: x86_64 aarch64 riscv64 @@ -133,6 +141,10 @@ install -D -m555 ./target/%{rust_musl_target}/release/stratovirt %{buildroot}%{_ %endif %changelog +* Sun Jun 22 2025 yyjeqhc 2.4.0-11 +- Rework patch 9/10/11 as patch 12/13. +- Adjust spec file to apply them for riscv64. + * Thu Jun 19 2025 Yan Wang 2.4.0-10 - Do not delete fd which has not been added -- Gitee