diff --git a/0001-docs-update-the-document-remove-the-other-features-t.patch b/0001-docs-update-the-document-remove-the-other-features-t.patch deleted file mode 100644 index 926005e6e1200e247890306829d3cff0ca020324..0000000000000000000000000000000000000000 --- a/0001-docs-update-the-document-remove-the-other-features-t.patch +++ /dev/null @@ -1,297 +0,0 @@ -From d9ca9f3eeab0381b28248f3a823eb8e46056f520 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Tue, 15 Feb 2022 17:12:35 +0800 -Subject: [PATCH 1/5] docs: update the document, remove the other features - title. - -Signed-off-by: zhouli57 ---- - docs/config_guidebook.md | 110 +++++++++++++-------------- - docs/interconnect_with_libvirt.ch.md | 2 +- - docs/interconnect_with_libvirt.md | 2 +- - docs/qmp.md | 16 ++-- - docs/quickstart.ch.md | 2 +- - docs/quickstart.md | 2 +- - docs/snapshot.md | 2 +- - 7 files changed, 68 insertions(+), 68 deletions(-) - -diff --git a/docs/config_guidebook.md b/docs/config_guidebook.md -index e0b8bdc..7594dfe 100644 ---- a/docs/config_guidebook.md -+++ b/docs/config_guidebook.md -@@ -131,6 +131,52 @@ If you want to use initrd as rootfs, `root=/dev/ram` and `rdinit=/bin/sh` must b - -initrd /path/to/initrd - ``` - -+### 1.7 Global config -+ -+Users can set the global configuration using the -global parameter. -+ -+One property can be set: -+ -+* pcie-root-port.fast-unplug: the fast unplug feature switch, only Kata is supported. -+ -+```shell -+-global pcie-root-port.fast-unplug=1 -+``` -+ -+### 1.8 Logging -+ -+StratoVirt supports to output log to stderr and log file. -+ -+You can enable StratoVirt's logging by: -+ -+```shell -+# Output log to stderr -+-D -+# Output log to log file -+-D /path/to/log/file -+``` -+ -+StratoVirt's log-level depends on env `STRATOVIRT_LOG_LEVEL`. -+StratoVirt supports five log-levels: `trace`, `debug`, `info`, `warn`, `error`. The default level is `error`. -+ -+### 1.9 Daemonize -+ -+StratoVirt supports to run as a daemon. -+ -+```shell -+# cmdline -+-daemonize -+``` -+ -+**When run StratoVirt as a daemon, you are not allowed to bind serial with stdio or output log to stdio.** -+ -+And you can also restore StratoVirt's **pid number** to a file by: -+ -+```shell -+# cmdline -+-pidfile /path/to/pidfile -+``` -+ - ## 2. Device Configuration - - For machine type "microvm", only virtio-mmio and legacy devices are supported. -@@ -492,7 +538,8 @@ Five properties can be set for chardev. - -chardev file,id=chardev_id,path=file_path - ``` - --### 2.13 Trace -+## 3. Trace -+ - Users can specify the configuration file which lists events to trace. - - One property can be set: -@@ -503,38 +550,7 @@ One property can be set: - -trace events= - ``` - --### 2.14 Global config --Users can set the global configuration using the -global parameter. -- --One property can be set: -- --* pcie-root-port.fast-unplug: the fast unplug feature switch, only Kata is supported. -- --```shell ---global pcie-root-port.fast-unplug=1 --``` -- --## 3. Other Features -- --### 3.1 Daemonize -- --StratoVirt supports to run as a daemon. -- --```shell --# cmdline ---daemonize --``` -- --**When run StratoVirt as a daemon, you are not allowed to bind serial with stdio or output log to stdio.** -- --And you can also restore StratoVirt's **pid number** to a file by: -- --```shell --# cmdline ---pidfile /path/to/pidfile --``` -- --### 3.2 Seccomp -+## 4. Seccomp - - StratoVirt use [seccomp(2)](https://man7.org/linux/man-pages/man2/seccomp.2.html) to limit the syscalls - in StratoVirt process by default. It will make a slight influence on performance to StratoVirt. -@@ -558,27 +574,11 @@ If you want to disable seccomp, you can run StratoVirt with `-disable-seccomp`. - -disable-seccomp - ``` - --### 3.3 Logging -- --StratoVirt supports to output log to stderr and log file. -- --You can enable StratoVirt's logging by: -- --```shell --# Output log to stderr ---D --# Output log to log file ---D /path/to/log/file --``` -- --StratoVirt's log-level depends on env `STRATOVIRT_LOG_LEVEL`. --StratoVirt supports five log-levels: `trace`, `debug`, `info`, `warn`, `error`. The default level is `error`. -- --### 3.4 Snapshot and Restore -+## 5. Snapshot and Restore - - StratoVirt supports to take a snapshot of a paused VM as VM template. This template can be used to warm start a new VM. Warm start skips the kernel boot stage and userspace initialization stage to boot VM in a very short time. - --#### 3.4.1 Restore from VM template -+### 5.1 Restore from VM template - - Restore from VM template with below command: - ```shell -@@ -597,11 +597,11 @@ $ ./stratovirt \ - - See [Snapshot and Restore](./snapshot.md) for details. - --## 4. Ozone -+## 6. Ozone - Ozone is a lightweight secure sandbox for StratoVirt, it provides secure environment for StratoVirt - by limiting resources of StratoVirt using 'namespace'. Please run ozone with root permission. - --### 4.1 Usage -+### 6.1 Usage - Ozone can be launched by the following commands: - ```shell - $ ./ozone \ -@@ -632,7 +632,7 @@ About the arguments: - * `cgroup` : set cgroup controller value. supported controller: `cpuset.cpus` and `memory.limit_in_bytes`. - * `--` : these two dashes are used to splite args, the args followed are used to launched StratoVirt. - --### 4.2 Example -+### 6.2 Example - As ozone uses a directory to mount as a root directory, after ozone is launched, the directory "/srv/zozne/{exec_file}/{name}" will be created. (Where, `exec_file` is the executable binary file, usually it is `stratovirt`, while `name` is the name of ozone, it is given by users, but the length of it should be no more than 255 bytes.) In order to run ozone normally, please make sure that the directory "/srv/zozne/{exec_file}/{name}" does not exists before launching ozone. - - On top of that, the path-related arguments are different. They are all in the current(`./`) directory. -@@ -677,7 +677,7 @@ $ ./ozone \ - -clean-resource - ``` - --## 5. Libvirt -+## 7. Libvirt - Libvirt launches StratoVirt by creating cmdlines. But some of these commands - such as: cpu, overcommit, uuid, no-user-config, nodefaults, sandbox, msg, rtc, no-shutdown, - nographic, realtime, display, usb, mem-prealloc and boot, are not supported by StratoVirt. -diff --git a/docs/interconnect_with_libvirt.ch.md b/docs/interconnect_with_libvirt.ch.md -index be5313c..d0323e2 100644 ---- a/docs/interconnect_with_libvirt.ch.md -+++ b/docs/interconnect_with_libvirt.ch.md -@@ -1,5 +1,5 @@ - # libvirt --Libvirt是StratoVirt的管理软件,它是通过创建命令行来运行StratoVirt和发送qmp命令来管理StratoVirt。目前,支持五个virsh命令来管理StratoVirt: -+Libvirt是StratoVirt的管理软件,它是通过创建命令行来运行StratoVirt和发送QMP命令来管理StratoVirt。目前,支持五个virsh命令来管理StratoVirt: - `virsh create`, `virsh destroy`, `virsh suspend`, `virsh resume` 和 `virsh console`. - - -diff --git a/docs/interconnect_with_libvirt.md b/docs/interconnect_with_libvirt.md -index 787afae..88ec77f 100644 ---- a/docs/interconnect_with_libvirt.md -+++ b/docs/interconnect_with_libvirt.md -@@ -1,6 +1,6 @@ - # libvirt - Libvirt is one of manager for StratoVirt, it manages StratoVirt by creating cmdlines to launch StratoVirt --and giving commands via qmp. Currently, five virsh commands are supported to manage StratoVirt: -+and giving commands via QMP. Currently, five virsh commands are supported to manage StratoVirt: - `virsh create`, `virsh destroy`, `virsh suspend`, `virsh resume` and `virsh console`. - - -diff --git a/docs/qmp.md b/docs/qmp.md -index 215cb57..be933fa 100644 ---- a/docs/qmp.md -+++ b/docs/qmp.md -@@ -3,13 +3,13 @@ - ## Introduction - - StratoVirt controls VM's lifecycle and external api interface with [QMP](https://wiki.qemu.org/Documentation/QMP) -- in current version. -+ in the current version. - --## qmp Creation -+## QMP Creation - --When running StratoVirt, you must create qmp in cmdline arguments as a management interface. -+When running StratoVirt, you must create QMP in cmdline arguments as a management interface. - --StratoVirt supports UnixSocket-type qmp, you can set it by: -+StratoVirt supports UnixSocket-type QMP, you can set it by: - - ```shell - # cmdline -@@ -17,7 +17,7 @@ StratoVirt supports UnixSocket-type qmp, you can set it by: - ``` - Where, the information about 'server' and 'nowait' can be found in [section 2.12 Chardev](#212-chardev) - --On top of that, monitor can be used to create qmp connection as well. -+On top of that, monitor can be used to create QMP connection as well. - The following commands can be used to create a monitor. - - Three properties can be set for monitor. -@@ -33,11 +33,11 @@ Three properties can be set for monitor. - -mon chardev=chardev_id,id=monitor_id,mode=control - ``` - --## qmp Connection -+## QMP Connection - --After StratoVirt started, you can connect to StratoVirt's qmp and manage it by QMP. -+After StratoVirt started, you can connect to StratoVirt's QMP and manage it by QMP. - --Several steps to connect qmp are showed as following: -+Several steps to connect QMP are showed as following: - - ```shell - # Start with UnixSocket -diff --git a/docs/quickstart.ch.md b/docs/quickstart.ch.md -index 02a3ea5..29e1496 100644 ---- a/docs/quickstart.ch.md -+++ b/docs/quickstart.ch.md -@@ -72,7 +72,7 @@ socket_path=`pwd`"/stratovirt.sock" - kernel_path=`pwd`"/vmlinux.bin" - rootfs_path=`pwd`"/rootfs.ext4" - --# 保证qmp通信socket文件路径可以被创建。 -+# 保证QMP通信socket文件路径可以被创建。 - rm -f ${socket_path} - - # 通过StratoVirt启动轻量化机型的Linux客户机。 -diff --git a/docs/quickstart.md b/docs/quickstart.md -index ce9af50..add534c 100644 ---- a/docs/quickstart.md -+++ b/docs/quickstart.md -@@ -75,7 +75,7 @@ socket_path=`pwd`"/stratovirt.sock" - kernel_path=`pwd`"/vmlinux.bin" - rootfs_path=`pwd`"/rootfs.ext4" - --# Make sure qmp can be created. -+# Make sure QMP can be created. - rm -f ${socket_path} - - # Start linux VM with machine type "microvm" by StratoVirt. -diff --git a/docs/snapshot.md b/docs/snapshot.md -index dbecc7f..a8ebffd 100644 ---- a/docs/snapshot.md -+++ b/docs/snapshot.md -@@ -59,7 +59,7 @@ The device configuration must be the same with template VM. Its cpu number, gues - - ## Snapshot state check - --Use qmp command `query-migrate` to check snapshot state: -+Use QMP command `query-migrate` to check snapshot state: - ```shell - $ ncat -U path/to/socket - {"QMP":{"version":{"StratoVirt":{"micro":1,"minor":0,"major":0},"package":""},"capabilities":[]}} --- -2.25.1 - diff --git a/0002-legacy-fwcfg-fix-bug-of-wrong-size-judgment.patch b/0002-legacy-fwcfg-fix-bug-of-wrong-size-judgment.patch deleted file mode 100644 index 9dc23b929196f2d16fe43746c9fc47d807626e99..0000000000000000000000000000000000000000 --- a/0002-legacy-fwcfg-fix-bug-of-wrong-size-judgment.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 048b51010d25187799632082917b8b883df98df7 Mon Sep 17 00:00:00 2001 -From: Jiajie Li -Date: Thu, 17 Feb 2022 18:11:07 +0800 -Subject: [PATCH 2/5] legacy/fwcfg: fix bug of wrong size judgment - -When call `read_data_reg`, the size should be in (0,8], not (0,8). -Fix it. - -Signed-off-by: Jiajie Li ---- - devices/src/legacy/fwcfg.rs | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/devices/src/legacy/fwcfg.rs b/devices/src/legacy/fwcfg.rs -index 7e9e73f..866bab2 100644 ---- a/devices/src/legacy/fwcfg.rs -+++ b/devices/src/legacy/fwcfg.rs -@@ -688,7 +688,7 @@ impl FwCfgCommon { - /// Return the value of the register - /// - fn read_data_reg(&mut self, _addr: u64, mut size: u32) -> Result { -- if size == 0 || size >= std::mem::size_of::() as u32 { -+ if size == 0 || size > std::mem::size_of::() as u32 { - bail!( - "Failed to read from FWcfg data register, size {} overflows", - size --- -2.25.1 - diff --git a/0003-standard_vm-add-FACS-acpi-table-on-x86-plantform.patch b/0003-standard_vm-add-FACS-acpi-table-on-x86-plantform.patch deleted file mode 100644 index 8394c56d0806509a50cf035ad35ac49d5738c6a9..0000000000000000000000000000000000000000 --- a/0003-standard_vm-add-FACS-acpi-table-on-x86-plantform.patch +++ /dev/null @@ -1,77 +0,0 @@ -From d3f8796887051e3975bed57bd7bc3c3def392841 Mon Sep 17 00:00:00 2001 -From: Jiajie Li -Date: Thu, 17 Feb 2022 18:12:47 +0800 -Subject: [PATCH 3/5] standard_vm: add FACS acpi table on x86 plantform - -When a standard vm starts, the hardware reduced feature needs to -be turned off, so an additional FACS acpi table needs to be added - -Signed-off-by: Jiajie Li ---- - machine/src/standard_vm/mod.rs | 43 ++++++++++++++++++++++++++++++++++ - 1 file changed, 43 insertions(+) - -diff --git a/machine/src/standard_vm/mod.rs b/machine/src/standard_vm/mod.rs -index fe7435a..1fca3bf 100644 ---- a/machine/src/standard_vm/mod.rs -+++ b/machine/src/standard_vm/mod.rs -@@ -111,6 +111,13 @@ trait StdMachineOps: AcpiBuilder { - - let mut xsdt_entries = Vec::new(); - -+ #[cfg(target_arch = "x86_64")] -+ { -+ let facs_addr = Self::build_facs_table(&acpi_tables, &mut loader) -+ .chain_err(|| "Failed to build ACPI FACS table")?; -+ xsdt_entries.push(facs_addr); -+ } -+ - let dsdt_addr = self - .build_dsdt_table(&acpi_tables, &mut loader) - .chain_err(|| "Failed to build ACPI DSDT table")?; -@@ -394,6 +401,42 @@ trait AcpiBuilder { - Ok(fadt_begin as u64) - } - -+ /// Build ACPI FACS table, returns the offset of ACPI FACS table in `acpi_data`. -+ /// -+ /// # Arguments -+ /// -+ /// `acpi_data` - Bytes streams that ACPI tables converts to. -+ /// `loader` - ACPI table loader. -+ #[cfg(target_arch = "x86_64")] -+ fn build_facs_table(acpi_data: &Arc>>, loader: &mut TableLoader) -> Result -+ where -+ Self: Sized, -+ { -+ let mut facs_data = vec![0_u8; 0x40]; -+ // FACS table signature. -+ facs_data[0] = b'F'; -+ facs_data[1] = b'A'; -+ facs_data[2] = b'C'; -+ facs_data[3] = b'S'; -+ // FACS table length. -+ facs_data[4] = 0x40; -+ -+ let mut locked_acpi_data = acpi_data.lock().unwrap(); -+ let facs_begin = locked_acpi_data.len() as u32; -+ locked_acpi_data.extend(facs_data); -+ let facs_end = locked_acpi_data.len() as u32; -+ drop(locked_acpi_data); -+ -+ loader.add_cksum_entry( -+ ACPI_TABLE_FILE, -+ facs_begin + TABLE_CHECKSUM_OFFSET, -+ facs_begin, -+ facs_end - facs_begin, -+ )?; -+ -+ Ok(facs_begin as u64) -+ } -+ - /// Build ACPI XSDT table, returns the offset of ACPI XSDT table in `acpi_data`. - /// - /// # Arguments --- -2.25.1 - diff --git a/0004-docs-build_guide-Update-suggested-rustc-version.patch b/0004-docs-build_guide-Update-suggested-rustc-version.patch deleted file mode 100644 index 7a69e4aeea462e3bc0788c55b6aef38fd3270eb0..0000000000000000000000000000000000000000 --- a/0004-docs-build_guide-Update-suggested-rustc-version.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 54f5311907d66a4c35ea5d250714973a04a7fd30 Mon Sep 17 00:00:00 2001 -From: Jie Yang -Date: Thu, 17 Feb 2022 21:59:29 +0800 -Subject: [PATCH 4/5] docs/build_guide: Update suggested rustc version - -Signed-off-by: Jie Yang ---- - docs/build_guide.ch.md | 4 ++-- - docs/build_guide.md | 6 +++--- - 2 files changed, 5 insertions(+), 5 deletions(-) - -diff --git a/docs/build_guide.ch.md b/docs/build_guide.ch.md -index c4eba88..ac9d466 100644 ---- a/docs/build_guide.ch.md -+++ b/docs/build_guide.ch.md -@@ -4,11 +4,11 @@ - ## 1. 检查Rust构建环境 - - 为了构建StratoVirt,需保证已经安装了Rust语言环境和Cargo软件。 --rustc的推荐版本为1.45.2及其之后的版本。 -+rustc的推荐版本为1.51.0及其之后的版本, 否则编译可能失败。 - - ```shell - $ rustc --version --rustc 1.45.2 -+rustc 1.51.0 - ``` - - 如果你想部署rust环境,下面的链接可以帮助你: -diff --git a/docs/build_guide.md b/docs/build_guide.md -index fd3e3d1..3d7320e 100644 ---- a/docs/build_guide.md -+++ b/docs/build_guide.md -@@ -4,11 +4,11 @@ - ## 1. Check Rust environment - - To build StratoVirt, make sure that Rust language environment and Cargo have already been installed. -- The recommended version of rustc is 1.45.2 or later. -+The recommended version of rustc is 1.51.0 or later, otherwise compilation may be failed. - - ```shell - $ rustc --version --rustc 1.45.2 -+rustc 1.51.0 - ``` - - If you want to deploy rust environment, the following link will help you: -@@ -32,7 +32,7 @@ Now you can find StratoVirt binary file in `target/${arch}-unknown-linux-gnu/rel - - ## 3. Build with musl-libc - --StratoVirt can also be built using musl-libc toolchains. By this way, StratoVirt is linked statically -+StratoVirt can also be built using musl-libc toolchains. By this way, StratoVirt is linked statically - and has no library dependencies. - - ```shell --- -2.25.1 - diff --git a/0005-standard_vm-syscall-Add-new-seccomp-rules.patch b/0005-standard_vm-syscall-Add-new-seccomp-rules.patch deleted file mode 100644 index 34119facaa68491240ded00cb159171977fd7721..0000000000000000000000000000000000000000 --- a/0005-standard_vm-syscall-Add-new-seccomp-rules.patch +++ /dev/null @@ -1,101 +0,0 @@ -From 4692011120135105d686a05b276926745f3328a2 Mon Sep 17 00:00:00 2001 -From: Jie Yang -Date: Thu, 17 Feb 2022 21:49:41 +0800 -Subject: [PATCH 5/5] standard_vm/syscall: Add new seccomp rules - -Fix VFIO hotplugging failure when seccomp is enabled if StratoVirt is -compiled with musl toolchain. - -Signed-off-by: Jie Yang ---- - docs/config_guidebook.md | 2 +- - docs/design.md | 2 +- - machine/src/standard_vm/aarch64/syscall.rs | 19 +++++++++++++++---- - machine/src/standard_vm/x86_64/syscall.rs | 4 +++- - 4 files changed, 20 insertions(+), 7 deletions(-) - -diff --git a/docs/config_guidebook.md b/docs/config_guidebook.md -index e0b8bdc..1764f30 100644 ---- a/docs/config_guidebook.md -+++ b/docs/config_guidebook.md -@@ -543,7 +543,7 @@ in StratoVirt process by default. It will make a slight influence on performance - | Number of Syscalls | GNU Toolchain | MUSL Toolchain | - | :----------------: | :-----------: | :------------: | - | microvm | 46 | 46 | --| q35 | 49 | 50 | -+| q35 | 49 | 51 | - - * aarch64 - -diff --git a/docs/design.md b/docs/design.md -index 3223605..44ae335 100644 ---- a/docs/design.md -+++ b/docs/design.md -@@ -38,7 +38,7 @@ in Kubernetes ecosystem perfectly; - - Multi-platform support: Fully support for Intel and Arm platform; - - Expansibility: StratoVirt reserves interface and design for importing more features, - even expand to standard virtualization support; --- Security: less than 51 syscalls while running; -+- Security: less than 52 syscalls while running; - - ## Implementation - -diff --git a/machine/src/standard_vm/aarch64/syscall.rs b/machine/src/standard_vm/aarch64/syscall.rs -index da663b9..e8ecdd5 100644 ---- a/machine/src/standard_vm/aarch64/syscall.rs -+++ b/machine/src/standard_vm/aarch64/syscall.rs -@@ -114,10 +114,7 @@ pub fn syscall_whitelist() -> Vec { - BpfRule::new(libc::SYS_statx), - BpfRule::new(libc::SYS_mkdirat), - BpfRule::new(libc::SYS_unlinkat), -- BpfRule::new(libc::SYS_madvise) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32), -+ madvise_rule(), - BpfRule::new(libc::SYS_msync), - BpfRule::new(libc::SYS_readlinkat), - ] -@@ -178,3 +175,17 @@ fn ioctl_allow_list() -> BpfRule { - .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_REG_LIST() as u32) - .add_constraint(SeccompCmpOpt::Eq, 1, KVM_ARM_VCPU_INIT() as u32) - } -+ -+fn madvise_rule() -> BpfRule { -+ #[cfg(target_env = "musl")] -+ return BpfRule::new(libc::SYS_madvise) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_FREE as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32); -+ #[cfg(target_env = "gnu")] -+ return BpfRule::new(libc::SYS_madvise) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32); -+} -diff --git a/machine/src/standard_vm/x86_64/syscall.rs b/machine/src/standard_vm/x86_64/syscall.rs -index 9836066..f39170a 100644 ---- a/machine/src/standard_vm/x86_64/syscall.rs -+++ b/machine/src/standard_vm/x86_64/syscall.rs -@@ -54,7 +54,7 @@ const KVM_RUN: u32 = 0xae80; - /// # Notes - /// This allowlist limit syscall with: - /// * x86_64-unknown-gnu: 46 syscalls --/// * x86_64-unknown-musl: 47 syscalls -+/// * x86_64-unknown-musl: 48 syscalls - /// To reduce performance losses, the syscall rules is ordered by frequency. - pub fn syscall_whitelist() -> Vec { - vec![ -@@ -124,6 +124,8 @@ pub fn syscall_whitelist() -> Vec { - .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32), - BpfRule::new(libc::SYS_msync), - BpfRule::new(libc::SYS_readlinkat), -+ #[cfg(target_env = "musl")] -+ BpfRule::new(libc::SYS_readlink), - ] - } - --- -2.25.1 - diff --git a/0006-Implement-a-safe-offset_of-macro-function.patch b/0006-Implement-a-safe-offset_of-macro-function.patch deleted file mode 100644 index 33e373b241e946e401d75aaa21cc0f5b6c1a1f19..0000000000000000000000000000000000000000 --- a/0006-Implement-a-safe-offset_of-macro-function.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 03fe93ad1f5a5d8f3a132ea419e4a509069e2130 Mon Sep 17 00:00:00 2001 -From: ace yan -Date: Sun, 20 Feb 2022 14:57:34 +0800 -Subject: [PATCH 01/10] Implement a safe offset_of macro function -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Original offset_of macro implementation reference to packed field is unaligned, -and creating a misaligned reference is undefined behavior。 -In the higher version of the rustc compiler, -there will be a compilation warning prompt: this was previously accepted by the compiler -but is being phased out; it will become a hard error in a future release! - -Signed-off-by: Yan Wen ---- - util/src/offsetof.rs | 14 +++++++++++--- - 1 file changed, 11 insertions(+), 3 deletions(-) - -diff --git a/util/src/offsetof.rs b/util/src/offsetof.rs -index c2696c8..a6b55d8 100644 ---- a/util/src/offsetof.rs -+++ b/util/src/offsetof.rs -@@ -13,9 +13,17 @@ - /// Macro: Calculate offset of specified field in a type. - #[macro_export] - macro_rules! __offset_of { -- ($type_name:ty, $field:ident) => { -- unsafe { &(*(std::ptr::null::<$type_name>())).$field as *const _ as usize } -- }; -+ ($type_name:ty, $field:ident) => {{ -+ let tmp = core::mem::MaybeUninit::<$type_name>::uninit(); -+ let outer = tmp.as_ptr(); -+ // Safe because the pointer is valid and aligned, just not initialised; `addr_of` ensures that -+ // we don't actually read from `outer` (which would be UB) nor create an intermediate reference. -+ let inner = unsafe { core::ptr::addr_of!((*outer).$field) } as *const u8; -+ // Safe because the two pointers are within the same allocation block. -+ unsafe { -+ inner.offset_from(outer as *const u8) as usize -+ } -+ }}; - } - - /// Macro: Calculate offset of a field in a recursive type. --- -2.25.1 - diff --git a/0007-loop_context-fix-the-bug-that-parked-event-not-remov.patch b/0007-loop_context-fix-the-bug-that-parked-event-not-remov.patch deleted file mode 100644 index b85550351b9e3c0eccd575eb86a0733d8aeafc31..0000000000000000000000000000000000000000 --- a/0007-loop_context-fix-the-bug-that-parked-event-not-remov.patch +++ /dev/null @@ -1,51 +0,0 @@ -From 4f51bd38fbc248e045dc1bcebba54c7bc5e4c66b Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Tue, 15 Feb 2022 18:06:29 +0800 -Subject: [PATCH 02/10] loop_context: fix the bug that parked event not remove - from events_map - -Signed-off-by: zhouli57 ---- - util/src/loop_context.rs | 24 ++++++++++++------------ - 1 file changed, 12 insertions(+), 12 deletions(-) - -diff --git a/util/src/loop_context.rs b/util/src/loop_context.rs -index 9ac8ed7..2c9c8c0 100644 ---- a/util/src/loop_context.rs -+++ b/util/src/loop_context.rs -@@ -222,20 +222,20 @@ impl EventLoopContext { - let mut events_map = self.events.write().unwrap(); - match events_map.get_mut(&event.raw_fd) { - Some(notifier) => { -- if let EventStatus::Parked = notifier.status { -- return Ok(()); -- } -- -- if let Err(error) = self.epoll.ctl( -- ControlOperation::Delete, -- notifier.raw_fd, -- EpollEvent::default(), -- ) { -- let error_num = error.raw_os_error().unwrap(); -- if error_num != libc::EBADF && error_num != libc::ENOENT { -- return Err(ErrorKind::BadSyscall(error).into()); -+ if let EventStatus::Alive = notifier.status { -+ // No need to delete fd if status is Parked, it's done in park_event. -+ if let Err(error) = self.epoll.ctl( -+ ControlOperation::Delete, -+ notifier.raw_fd, -+ EpollEvent::default(), -+ ) { -+ let error_num = error.raw_os_error().unwrap(); -+ if error_num != libc::EBADF && error_num != libc::ENOENT { -+ return Err(ErrorKind::BadSyscall(error).into()); -+ } - } - } -+ - notifier.status = EventStatus::Removed; - - if let Some(parked_fd) = notifier.parked_fd { --- -2.25.1 - diff --git a/0008-migration-use-device-id-as-snapshot-id.patch b/0008-migration-use-device-id-as-snapshot-id.patch deleted file mode 100644 index 9c4da35913bc131ef8516b82a95a4f687aa175c8..0000000000000000000000000000000000000000 --- a/0008-migration-use-device-id-as-snapshot-id.patch +++ /dev/null @@ -1,926 +0,0 @@ -From 030d9763b2fc3b04a45ae764821914e9369e0491 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Wed, 5 Jan 2022 09:48:27 +0800 -Subject: [PATCH 03/10] migration: use device id as snapshot id - -At present, snapshots use the device initialization sequence as the key, -but after the introduction of the device hot-plug mechanism, due to the -dynamic addition of devices, the sequence of snapshot restoration may be -in consistent with the original sequence, resulting in abnormal device -state restoration. Therefore, a new interface is provided, which can -specify the device id during registration, so as to ensure that the -snapshot is restored to match the original device. -In addition, an unregister interface has been added for device -destruction to clean up related resources. - -Signed-off-by: zhouli57 ---- - Cargo.lock | 1 + - address_space/src/state.rs | 4 +- - .../src/interrupt_controller/aarch64/gicv3.rs | 10 +- - hypervisor/src/kvm/mod.rs | 6 +- - machine/src/lib.rs | 17 +- - machine/src/standard_vm/mod.rs | 44 +++-- - migration/Cargo.toml | 1 + - migration/src/device_state.rs | 7 - - migration/src/lib.rs | 4 +- - migration/src/manager.rs | 181 +++++++++++++----- - migration/src/snapshot.rs | 63 ++++-- - migration_derive/src/struct_parser.rs | 11 +- - pci/src/msix.rs | 10 +- - pci/src/root_port.rs | 9 +- - virtio/src/block.rs | 4 + - virtio/src/net.rs | 4 + - virtio/src/virtio_pci.rs | 20 +- - 17 files changed, 287 insertions(+), 109 deletions(-) - -diff --git a/Cargo.lock b/Cargo.lock -index df5dc88..215f1d5 100644 ---- a/Cargo.lock -+++ b/Cargo.lock -@@ -327,6 +327,7 @@ version = "2.1.0" - dependencies = [ - "error-chain", - "kvm-ioctls", -+ "log", - "migration_derive", - "once_cell", - "serde", -diff --git a/address_space/src/state.rs b/address_space/src/state.rs -index 2347378..eb34e91 100644 ---- a/address_space/src/state.rs -+++ b/address_space/src/state.rs -@@ -17,7 +17,7 @@ use std::sync::Arc; - - use crate::{AddressSpace, FileBackend, GuestAddress, HostMemMapping, Region}; - use migration::errors::{ErrorKind, Result, ResultExt}; --use migration::{DeviceStateDesc, FieldDesc, MigrationHook, MigrationManager, StateTransfer}; -+use migration::{DeviceStateDesc, FieldDesc, MigrationHook, StateTransfer}; - use util::byte_code::ByteCode; - use util::unix::host_page_size; - -@@ -76,7 +76,7 @@ impl StateTransfer for AddressSpace { - } - - impl MigrationHook for AddressSpace { -- fn pre_save(&self, _id: u64, writer: &mut dyn Write) -> Result<()> { -+ fn pre_save(&self, _id: &str, writer: &mut dyn Write) -> Result<()> { - let ram_state = self.get_state_vec()?; - writer.write_all(&ram_state)?; - let padding_buffer = -diff --git a/devices/src/interrupt_controller/aarch64/gicv3.rs b/devices/src/interrupt_controller/aarch64/gicv3.rs -index 21008a6..79ebb27 100644 ---- a/devices/src/interrupt_controller/aarch64/gicv3.rs -+++ b/devices/src/interrupt_controller/aarch64/gicv3.rs -@@ -21,7 +21,7 @@ use super::{ - use crate::interrupt_controller::errors::{ErrorKind, Result, ResultExt}; - use hypervisor::kvm::KVM_FDS; - use machine_manager::machine::{KvmVmState, MachineLifecycle}; --use migration::MigrationManager; -+use migration::{MigrationManager, MigrationRestoreOrder}; - use util::device_tree::{self, FdtBuilder}; - - // See arch/arm64/include/uapi/asm/kvm.h file from the linux kernel. -@@ -393,10 +393,14 @@ impl GICDevice for GICv3 { - MigrationManager::register_device_instance( - GICv3ItsState::descriptor(), - gicv3.its_dev.as_ref().unwrap().clone(), -- true, -+ MigrationRestoreOrder::Gicv3Its, - ); - } -- MigrationManager::register_device_instance(GICv3State::descriptor(), gicv3.clone(), true); -+ MigrationManager::register_device_instance( -+ GICv3State::descriptor(), -+ gicv3.clone(), -+ MigrationRestoreOrder::Gicv3, -+ ); - - Ok(gicv3) - } -diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs -index a318a65..80012bb 100644 ---- a/hypervisor/src/kvm/mod.rs -+++ b/hypervisor/src/kvm/mod.rs -@@ -27,6 +27,8 @@ use once_cell::sync::Lazy; - use vmm_sys_util::eventfd::EventFd; - - use crate::errors::{Result, ResultExt}; -+#[cfg(target_arch = "x86_64")] -+use migration::{MigrationManager, MigrationRestoreOrder}; - - // See: https://elixir.bootlin.com/linux/v4.19.123/source/include/uapi/asm-generic/kvm.h - pub const KVM_SET_DEVICE_ATTR: u32 = 0x4018_aee1; -@@ -124,10 +126,10 @@ impl KVMFds { - }; - - #[cfg(target_arch = "x86_64")] -- migration::MigrationManager::register_device_instance( -+ MigrationManager::register_device_instance( - state::KvmDeviceState::descriptor(), - Arc::new(state::KvmDevice {}), -- false, -+ MigrationRestoreOrder::Default, - ); - - kvm_fds -diff --git a/machine/src/lib.rs b/machine/src/lib.rs -index 4421deb..7f88b22 100644 ---- a/machine/src/lib.rs -+++ b/machine/src/lib.rs -@@ -132,7 +132,7 @@ use machine_manager::config::{ - }; - use machine_manager::event_loop::EventLoop; - use machine_manager::machine::{KvmVmState, MachineInterface}; --use migration::MigrationManager; -+use migration::{MigrationManager, MigrationRestoreOrder}; - use util::loop_context::{EventNotifier, NotifierCallback, NotifierOperation}; - use util::seccomp::{BpfRule, SeccompOpt, SyscallFilter}; - use vfio::{VfioDevice, VfioPciDevice}; -@@ -243,7 +243,11 @@ pub trait MachineOps { - )); - cpus.push(cpu.clone()); - -- MigrationManager::register_device_instance(cpu::ArchCPU::descriptor(), cpu, false); -+ MigrationManager::register_device_instance( -+ cpu::ArchCPU::descriptor(), -+ cpu, -+ MigrationRestoreOrder::Default, -+ ); - } - - if let Some(boot_config) = boot_cfg { -@@ -486,7 +490,11 @@ pub trait MachineOps { - let device_cfg = parse_blk(vm_config, cfg_args)?; - let device = Arc::new(Mutex::new(Block::new(device_cfg.clone()))); - self.add_virtio_pci_device(&device_cfg.id, &bdf, device.clone(), multi_func)?; -- MigrationManager::register_device_instance_mutex(BlockState::descriptor(), device); -+ MigrationManager::register_device_instance_mutex_with_id( -+ BlockState::descriptor(), -+ device, -+ &device_cfg.id, -+ ); - self.reset_bus(&device_cfg.id)?; - Ok(()) - } -@@ -502,9 +510,10 @@ pub trait MachineOps { - ))) - } else { - let device = Arc::new(Mutex::new(virtio::Net::new(device_cfg.clone()))); -- MigrationManager::register_device_instance_mutex( -+ MigrationManager::register_device_instance_mutex_with_id( - VirtioNetState::descriptor(), - device.clone(), -+ &device_cfg.id, - ); - device - }; -diff --git a/machine/src/standard_vm/mod.rs b/machine/src/standard_vm/mod.rs -index 1fca3bf..c96f89a 100644 ---- a/machine/src/standard_vm/mod.rs -+++ b/machine/src/standard_vm/mod.rs -@@ -80,10 +80,11 @@ use machine_manager::config::{ - }; - use machine_manager::machine::{DeviceInterface, KvmVmState}; - use machine_manager::qmp::{qmp_schema, QmpChannel, Response}; -+use migration::MigrationManager; - use pci::hotplug::{handle_plug, handle_unplug_request}; - use pci::PciBus; - use util::byte_code::ByteCode; --use virtio::{qmp_balloon, qmp_query_balloon, Block, VhostKern, VirtioDevice}; -+use virtio::{qmp_balloon, qmp_query_balloon, Block, BlockState, VhostKern, VirtioNetState}; - - #[cfg(target_arch = "aarch64")] - use aarch64::{LayoutEntryType, MEM_LAYOUT}; -@@ -549,7 +550,7 @@ impl StdMachine { - - let blk = if let Some(conf) = self.get_vm_config().lock().unwrap().drives.get(drive) { - let dev = BlkDevConfig { -- id: conf.id.clone(), -+ id: args.id.clone(), - path_on_host: conf.path_on_host.clone(), - read_only: conf.read_only, - direct: conf.direct, -@@ -558,13 +559,22 @@ impl StdMachine { - iops: conf.iops, - }; - dev.check()?; -- Arc::new(Mutex::new(Block::new(dev))) -+ dev - } else { - bail!("Drive not found"); - }; - -- self.add_virtio_pci_device(&args.id, pci_bdf, blk, multifunction) -- .chain_err(|| "Failed to add virtio pci block device") -+ let blk_id = blk.id.clone(); -+ let blk = Arc::new(Mutex::new(Block::new(blk))); -+ self.add_virtio_pci_device(&args.id, pci_bdf, blk.clone(), multifunction) -+ .chain_err(|| "Failed to add virtio pci block device")?; -+ -+ MigrationManager::register_device_instance_mutex_with_id( -+ BlockState::descriptor(), -+ blk, -+ &blk_id, -+ ); -+ Ok(()) - } - - fn plug_virtio_pci_net( -@@ -581,7 +591,7 @@ impl StdMachine { - - let dev = if let Some(conf) = self.get_vm_config().lock().unwrap().netdevs.get(netdev) { - let dev = NetworkInterfaceConfig { -- id: conf.id.clone(), -+ id: args.id.clone(), - host_dev_name: conf.ifname.clone(), - mac: args.mac.clone(), - tap_fd: conf.tap_fd, -@@ -595,14 +605,22 @@ impl StdMachine { - bail!("Netdev not found"); - }; - -- let net: Arc> = if dev.vhost_type.is_some() { -- Arc::new(Mutex::new(VhostKern::Net::new(&dev, self.get_sys_mem()))) -+ if dev.vhost_type.is_some() { -+ let net = Arc::new(Mutex::new(VhostKern::Net::new(&dev, self.get_sys_mem()))); -+ self.add_virtio_pci_device(&args.id, &pci_bdf, net, multifunction) -+ .chain_err(|| "Failed to add virtio net device")?; - } else { -- Arc::new(Mutex::new(virtio::Net::new(dev))) -- }; -- -- self.add_virtio_pci_device(&args.id, &pci_bdf, net, multifunction) -- .chain_err(|| "Failed to add virtio pci net device") -+ let net_id = dev.id.clone(); -+ let net = Arc::new(Mutex::new(virtio::Net::new(dev))); -+ self.add_virtio_pci_device(&args.id, &pci_bdf, net.clone(), multifunction) -+ .chain_err(|| "Failed to add virtio net device")?; -+ MigrationManager::register_device_instance_mutex_with_id( -+ VirtioNetState::descriptor(), -+ net, -+ &net_id, -+ ); -+ } -+ Ok(()) - } - - fn plug_vfio_pci_device( -diff --git a/migration/Cargo.toml b/migration/Cargo.toml -index fc877ad..6991804 100644 ---- a/migration/Cargo.toml -+++ b/migration/Cargo.toml -@@ -11,6 +11,7 @@ kvm-ioctls = "0.6.0" - serde = { version = ">=1.0.114", features = ["derive"] } - serde_json = "1.0.55" - once_cell = "1.9.0" -+log = "0.4.8" - - [dev-dependencies] - migration_derive = { path = "../migration_derive" } -diff --git a/migration/src/device_state.rs b/migration/src/device_state.rs -index 75bf3b9..de9c16c 100644 ---- a/migration/src/device_state.rs -+++ b/migration/src/device_state.rs -@@ -171,13 +171,6 @@ pub mod tests { - use super::{DeviceStateDesc, FieldDesc, StateTransfer, VersionCheck}; - use util::byte_code::ByteCode; - -- struct MigrationManager {} -- impl MigrationManager { -- fn desc_db_len() -> u64 { -- 0 -- } -- } -- - #[derive(Default)] - // A simple device version 1. - pub struct DeviceV1 { -diff --git a/migration/src/lib.rs b/migration/src/lib.rs -index 9751fd3..9ccab5f 100644 ---- a/migration/src/lib.rs -+++ b/migration/src/lib.rs -@@ -19,6 +19,8 @@ extern crate error_chain; - #[cfg(test)] - #[macro_use] - extern crate migration_derive; -+#[macro_use] -+extern crate log; - - mod device_state; - mod header; -@@ -27,7 +29,7 @@ mod snapshot; - mod status; - - pub use device_state::{DeviceStateDesc, FieldDesc, StateTransfer}; --pub use manager::{MigrationHook, MigrationManager}; -+pub use manager::{MigrationHook, MigrationManager, MigrationRestoreOrder}; - pub use status::MigrationStatus; - - pub mod errors { -diff --git a/migration/src/manager.rs b/migration/src/manager.rs -index f5d52b1..ef903f9 100644 ---- a/migration/src/manager.rs -+++ b/migration/src/manager.rs -@@ -10,8 +10,11 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --use std::collections::{BTreeMap, HashMap}; -+use std::cmp; -+use std::collections::hash_map::DefaultHasher; -+use std::collections::HashMap; - use std::fs::File; -+use std::hash::{Hash, Hasher}; - use std::io::{Read, Write}; - use std::sync::{Arc, Mutex, RwLock}; - -@@ -23,11 +26,27 @@ use util::byte_code::ByteCode; - - /// Glocal MigrationManager to manage all migration combined interface. - pub(crate) static MIGRATION_MANAGER: Lazy = Lazy::new(|| MigrationManager { -- entry: Arc::new(RwLock::new(BTreeMap::::new())), -+ entry: Arc::new(RwLock::new([ -+ Vec::<(String, MigrationEntry)>::new(), -+ Vec::<(String, MigrationEntry)>::new(), -+ Vec::<(String, MigrationEntry)>::new(), -+ ])), - desc_db: Arc::new(RwLock::new(HashMap::::new())), - status: Arc::new(RwLock::new(MigrationStatus::None)), - }); - -+/// Used to map Device id from String to u64 only. -+/// Because instance_id in InstanceId can't be String for it has no Copy trait. -+/// -+/// # Arguments -+/// -+/// * `dev_id` - The device id. -+pub fn id_remap(dev_id: &str) -> u64 { -+ let mut hash = DefaultHasher::new(); -+ dev_id.hash(&mut hash); -+ hash.finish() -+} -+ - /// A hook for `Device` to save device state to `Write` object and load device - /// from `[u8]` slice. - /// -@@ -44,7 +63,7 @@ pub trait MigrationHook: StateTransfer { - /// * `id` - This unique id to represent a single device. It can be treated - /// as `object_id` in `InstanceId`. - /// * `writer` - The `Write` trait object to store or receive data. -- fn pre_save(&self, id: u64, writer: &mut dyn Write) -> Result<()> { -+ fn pre_save(&self, id: &str, writer: &mut dyn Write) -> Result<()> { - let state_data = self - .get_state_vec() - .chain_err(|| "Failed to get device state")?; -@@ -52,7 +71,7 @@ pub trait MigrationHook: StateTransfer { - let device_alias = self.get_device_alias(); - let instance_id = InstanceId { - object_type: device_alias, -- object_id: id, -+ object_id: id_remap(&id), - }; - - writer -@@ -131,11 +150,36 @@ pub enum MigrationEntry { - Memory(Arc), - } - -+/// Ensure the recovery sequence of different devices based on priorities. -+/// At present, we need to ensure that the state recovery of the gic device -+/// must be after the cpu, so different priorities are defined. -+#[derive(Debug)] -+pub enum MigrationRestoreOrder { -+ Default = 0, -+ Gicv3 = 1, -+ Gicv3Its = 2, -+ Max = 3, -+} -+ -+impl From for u16 { -+ fn from(order: MigrationRestoreOrder) -> u16 { -+ match order { -+ MigrationRestoreOrder::Default => 0, -+ MigrationRestoreOrder::Gicv3 => 1, -+ MigrationRestoreOrder::Gicv3Its => 2, -+ _ => 3, -+ } -+ } -+} -+ -+/// The entry list size is the same as the MigrationRestoreOrder number -+type MigrationEntryList = [Vec<(String, MigrationEntry)>; 3]; -+ - /// This structure is to manage all resource during migration. - /// It is also the only way to call on `MIGRATION_MANAGER`. - pub struct MigrationManager { - /// The map offers the device_id and combined migratable device entry. -- pub(crate) entry: Arc>>, -+ pub(crate) entry: Arc>, - /// The map offers the device type and its device state describe structure. - pub(crate) desc_db: Arc>>, - /// The status of migration work. -@@ -161,28 +205,23 @@ impl MigrationManager { - /// - /// * `device_desc` - The `DeviceStateDesc` of device instance. - /// * `entry` - Device instance with migratable interface. -- /// * `reverse` - Register device in order or in the reverse order. -+ /// * `restore_order` - device restore order. - pub fn register_device_instance( - device_desc: DeviceStateDesc, - device_entry: Arc, -- reverse: bool, -+ restore_order: MigrationRestoreOrder, - ) where - T: MigrationHook + Sync + Send + 'static, - { -+ let name = device_desc.name.clone(); - Self::register_device_desc(device_desc); - - let entry = MigrationEntry::Safe(device_entry); -- let nr_entry = if reverse { -- !0 - Self::entry_db_len() -- } else { -- Self::entry_db_len() -- }; -- -- MIGRATION_MANAGER -- .entry -- .write() -- .unwrap() -- .insert(nr_entry, entry); -+ info!( -+ "Register device instance: id {} order {:?}", -+ &name, &restore_order -+ ); -+ MigrationManager::insert_entry(name, restore_order.into(), entry, true); - } - - /// Register mutex device instance to entry hashmap with instance_id. -@@ -197,16 +236,34 @@ impl MigrationManager { - ) where - T: MigrationHook + Sync + Send + 'static, - { -+ let name = device_desc.name.clone(); -+ let order = MigrationRestoreOrder::Default.into(); - Self::register_device_desc(device_desc); - - let entry = MigrationEntry::Mutex(device_entry); -- let nr_entry = Self::entry_db_len(); -+ info!("Register device instance mutex: id {}", &name); -+ MigrationManager::insert_entry(name, order, entry, true); -+ } -+ -+ pub fn register_device_instance_mutex_with_id( -+ device_desc: DeviceStateDesc, -+ device_entry: Arc>, -+ id: &str, -+ ) where -+ T: MigrationHook + Sync + Send + 'static, -+ { -+ let name = device_desc.name.clone() + "/" + id; -+ let order = MigrationRestoreOrder::Default.into(); -+ Self::register_device_desc(device_desc); -+ let entry = MigrationEntry::Mutex(device_entry); -+ info!("Register device instance with id: id {}", &name); -+ MigrationManager::insert_entry(name, order, entry, false); -+ } - -- MIGRATION_MANAGER -- .entry -- .write() -- .unwrap() -- .insert(nr_entry, entry); -+ pub fn unregister_device_instance_mutex_by_id(device_desc: DeviceStateDesc, id: &str) { -+ let name = device_desc.name + "/" + id; -+ info!("Unregister device instance: id {}", &name); -+ MigrationManager::remove_entry(&name); - } - - /// Register memory instance. -@@ -219,23 +276,55 @@ impl MigrationManager { - T: MigrationHook + Sync + Send + 'static, - { - let entry = MigrationEntry::Memory(entry); -- let nr_entry = Self::entry_db_len(); -- -- MIGRATION_MANAGER -- .entry -- .write() -- .unwrap() -- .insert(nr_entry, entry); -+ info!("Register memory instance"); -+ MigrationManager::insert_entry(String::from("MemoryState/Memory"), 0, entry, true); - } - -- /// Get entry_db's length. -- pub fn entry_db_len() -> u64 { -- MIGRATION_MANAGER.entry.read().unwrap().len() as u64 -+ /// Insert entry. If the name is duplicated, you should set gen_instance_id to true to -+ /// generated instance id to ensure that the id is unique. -+ /// -+ /// # Arguments -+ /// -+ /// * `name` - Entry name. -+ /// * `order` - Restore order. -+ /// * `entry` - Instance with migratable interface. -+ /// * `gen_instance_id` - If auto-generated instance id. -+ fn insert_entry(name: String, order: u16, entry: MigrationEntry, gen_instance_id: bool) { -+ let mut entrys = MIGRATION_MANAGER.entry.write().unwrap(); -+ let mut index = 0; -+ if gen_instance_id { -+ for (key, _) in &entrys[order as usize] { -+ if let Some(pos) = key.rfind(':') { -+ let (tmp_id, num_id) = key.split_at(pos); -+ if tmp_id == name { -+ let num = num_id.strip_prefix(':').unwrap(); -+ index = cmp::max(index, num.parse::().unwrap() + 1); -+ } -+ } -+ } -+ } -+ // ID is format as "{name}:{instance_id}" -+ let id = format!("{}:{}", name, index); -+ debug!("Insert entry: id {}", &id); -+ entrys[order as usize].push((id, entry)); - } - -- /// Get desc_db's length. -- pub fn desc_db_len() -> u64 { -- MIGRATION_MANAGER.desc_db.read().unwrap().len() as u64 -+ /// Remove entry by the unique name. Not support to remove the entry with instance id. -+ /// -+ /// # Arguments -+ /// -+ /// * `name` - Entry name. -+ fn remove_entry(name: &str) { -+ let eid = format!("{}:0", name); -+ let mut entrys = MIGRATION_MANAGER.entry.write().unwrap(); -+ for (i, item) in entrys.iter().enumerate() { -+ let pos = item.iter().position(|(key, _)| key == &eid); -+ if let Some(index) = pos { -+ debug!("Remove entry: eid {}", &eid); -+ entrys[i].remove(index); -+ return; -+ } -+ } - } - - /// Get `Device`'s alias from device type string. -@@ -244,12 +333,7 @@ impl MigrationManager { - /// - /// * `device_type` - The type string of device instance. - pub fn get_desc_alias(device_type: &str) -> Option { -- MIGRATION_MANAGER -- .desc_db -- .read() -- .unwrap() -- .get(device_type) -- .map(|desc| desc.alias) -+ Some(id_remap(device_type)) - } - - /// Return `desc_db` value len(0 restored as `serde_json`) -@@ -340,23 +424,26 @@ mod tests { - let device_v2 = Arc::new(DeviceV2::default()); - let device_v2_mutex = Arc::new(Mutex::new(DeviceV2::default())); - -- MigrationManager::register_device_instance(DeviceV1State::descriptor(), device_v1, false); -+ MigrationManager::register_device_instance( -+ DeviceV1State::descriptor(), -+ device_v1, -+ MigrationRestoreOrder::Default, -+ ); - MigrationManager::register_memory_instance(device_v2); - MigrationManager::register_device_instance_mutex( - DeviceV2State::descriptor(), - device_v2_mutex, - ); - -- assert_eq!(MigrationManager::desc_db_len(), 2); - assert!(MigrationManager::get_desc_alias("DeviceV1State").is_some()); - assert_eq!( - MigrationManager::get_desc_alias("DeviceV1State").unwrap(), -- 0 -+ id_remap("DeviceV1State") - ); - assert!(MigrationManager::get_desc_alias("DeviceV2State").is_some()); - assert_eq!( - MigrationManager::get_desc_alias("DeviceV2State").unwrap(), -- 0 -+ id_remap("DeviceV2State") - ); - } - } -diff --git a/migration/src/snapshot.rs b/migration/src/snapshot.rs -index edea8ce..30ee13c 100644 ---- a/migration/src/snapshot.rs -+++ b/migration/src/snapshot.rs -@@ -23,7 +23,7 @@ use util::unix::host_page_size; - use crate::device_state::{DeviceStateDesc, VersionCheck}; - use crate::errors::{ErrorKind, Result, ResultExt}; - use crate::header::{FileFormat, MigrationHeader}; --use crate::manager::{InstanceId, MigrationEntry, MigrationManager, MIGRATION_MANAGER}; -+use crate::manager::{id_remap, InstanceId, MigrationEntry, MigrationManager, MIGRATION_MANAGER}; - use crate::status::MigrationStatus; - - /// The length of `MigrationHeader` part occupies bytes in snapshot file. -@@ -187,10 +187,13 @@ impl MigrationManager { - /// - /// * `writer` - The `Write` trait object. - fn save_memory(writer: &mut dyn Write) -> Result<()> { -- for (id, entry) in MIGRATION_MANAGER.entry.read().unwrap().iter() { -- if let MigrationEntry::Memory(i) = entry { -- i.pre_save(*id, writer) -- .chain_err(|| "Failed to save vm memory")?; -+ let entry = MIGRATION_MANAGER.entry.read().unwrap(); -+ for item in entry.iter() { -+ for (id, entry) in item.iter() { -+ if let MigrationEntry::Memory(i) = entry { -+ i.pre_save(id, writer) -+ .chain_err(|| "Failed to save vm memory")?; -+ } - } - } - -@@ -205,10 +208,13 @@ impl MigrationManager { - fn load_memory(file: &mut File) -> Result<()> { - let mut state_bytes = [0_u8].repeat((host_page_size() as usize) * 2 - HEADER_LENGTH); - file.read_exact(&mut state_bytes)?; -- for (_, entry) in MIGRATION_MANAGER.entry.read().unwrap().iter() { -- if let MigrationEntry::Memory(i) = entry { -- i.pre_load(&state_bytes, Some(file)) -- .chain_err(|| "Failed to load vm memory")?; -+ let entry = MIGRATION_MANAGER.entry.read().unwrap(); -+ for item in entry.iter() { -+ for (_, entry) in item.iter() { -+ if let MigrationEntry::Memory(i) = entry { -+ i.pre_load(&state_bytes, Some(file)) -+ .chain_err(|| "Failed to load vm memory")?; -+ } - } - } - -@@ -221,11 +227,14 @@ impl MigrationManager { - /// - /// * `writer` - The `Write` trait object. - fn save_device_state(writer: &mut dyn Write) -> Result<()> { -- for (device_id, entry) in MIGRATION_MANAGER.entry.read().unwrap().iter() { -- match entry { -- MigrationEntry::Safe(i) => i.pre_save(*device_id, writer)?, -- MigrationEntry::Mutex(i) => i.lock().unwrap().pre_save(*device_id, writer)?, -- _ => {} -+ let entry = MIGRATION_MANAGER.entry.read().unwrap(); -+ for item in entry.iter() { -+ for (id, entry) in item.iter() { -+ match entry { -+ MigrationEntry::Safe(i) => i.pre_save(id, writer)?, -+ MigrationEntry::Mutex(i) => i.lock().unwrap().pre_save(id, writer)?, -+ _ => {} -+ } - } - } - -@@ -275,10 +284,19 @@ impl MigrationManager { - } - } - -- match device_entry.get(&instance_id.object_id).unwrap() { -- MigrationEntry::Safe(i) => i.pre_load(&state_data, None)?, -- MigrationEntry::Mutex(i) => i.lock().unwrap().pre_load_mut(&state_data, None)?, -- _ => {} -+ for item in device_entry.iter() { -+ for (key, state) in item { -+ if id_remap(key) == instance_id.object_id { -+ info!("Load VM state: key {}", key); -+ match state { -+ MigrationEntry::Safe(i) => i.pre_load(&state_data, None)?, -+ MigrationEntry::Mutex(i) => { -+ i.lock().unwrap().pre_load_mut(&state_data, None)? -+ } -+ _ => {} -+ } -+ } -+ } - } - } - -@@ -288,9 +306,12 @@ impl MigrationManager { - /// Resume recovered device. - /// This function will be called after restore device state. - fn resume() -> Result<()> { -- for (_, entry) in MIGRATION_MANAGER.entry.read().unwrap().iter() { -- if let MigrationEntry::Mutex(i) = entry { -- i.lock().unwrap().resume()? -+ let entry = MIGRATION_MANAGER.entry.read().unwrap(); -+ for item in entry.iter() { -+ for (_, state) in item { -+ if let MigrationEntry::Mutex(i) = state { -+ i.lock().unwrap().resume()? -+ } - } - } - Ok(()) -diff --git a/migration_derive/src/struct_parser.rs b/migration_derive/src/struct_parser.rs -index bc7d9d2..4e66d7e 100644 ---- a/migration_derive/src/struct_parser.rs -+++ b/migration_derive/src/struct_parser.rs -@@ -26,10 +26,19 @@ pub fn parse_struct( - - let fields = parse_fields(&input.fields, ident); - -+ use std::collections::hash_map::DefaultHasher; -+ use std::hash::{Hash, Hasher}; -+ -+ let id_remap = |s: &str| -> u64 { -+ let mut hash = DefaultHasher::new(); -+ s.hash(&mut hash); -+ hash.finish() -+ }; -+ let alias = id_remap(&name); - quote! { - #struct_ident { - name: #name.to_string(), -- alias: MigrationManager::desc_db_len(), -+ alias: #alias, - size: std::mem::size_of::<#ident>() as u32, - current_version: #current_version, - compat_version: #compat_version, -diff --git a/pci/src/msix.rs b/pci/src/msix.rs -index 83b3d05..71d172e 100644 ---- a/pci/src/msix.rs -+++ b/pci/src/msix.rs -@@ -405,6 +405,7 @@ pub fn init_msix( - vector_nr: u32, - config: &mut PciConfig, - dev_id: Arc, -+ id: &str, - ) -> Result<()> { - if vector_nr > MSIX_TABLE_SIZE_MAX as u32 + 1 { - bail!("Too many msix vectors."); -@@ -439,7 +440,7 @@ pub fn init_msix( - config.msix = Some(msix.clone()); - - #[cfg(not(test))] -- MigrationManager::register_device_instance_mutex(MsixState::descriptor(), msix); -+ MigrationManager::register_device_instance_mutex_with_id(MsixState::descriptor(), msix, id); - - Ok(()) - } -@@ -469,11 +470,12 @@ mod tests { - 0, - MSIX_TABLE_SIZE_MAX as u32 + 2, - &mut pci_config, -- Arc::new(AtomicU16::new(0)) -+ Arc::new(AtomicU16::new(0)), -+ "msix" - ) - .is_err()); - -- init_msix(1, 2, &mut pci_config, Arc::new(AtomicU16::new(0))).unwrap(); -+ init_msix(1, 2, &mut pci_config, Arc::new(AtomicU16::new(0)), "msix").unwrap(); - let msix_cap_start = 64_u8; - assert_eq!(pci_config.last_cap_end, 64 + MSIX_CAP_SIZE as u16); - // Capabilities pointer -@@ -538,7 +540,7 @@ mod tests { - #[test] - fn test_write_config() { - let mut pci_config = PciConfig::new(PCI_CONFIG_SPACE_SIZE, 2); -- init_msix(0, 2, &mut pci_config, Arc::new(AtomicU16::new(0))).unwrap(); -+ init_msix(0, 2, &mut pci_config, Arc::new(AtomicU16::new(0)), "msix").unwrap(); - let msix = pci_config.msix.as_ref().unwrap(); - let mut locked_msix = msix.lock().unwrap(); - locked_msix.enabled = false; -diff --git a/pci/src/root_port.rs b/pci/src/root_port.rs -index b00c14a..286e92d 100644 ---- a/pci/src/root_port.rs -+++ b/pci/src/root_port.rs -@@ -289,7 +289,7 @@ impl PciDevOps for RootPort { - .add_pcie_cap(self.devfn, self.port_num, PcieDevType::RootPort as u8)?; - - self.dev_id.store(self.devfn as u16, Ordering::SeqCst); -- init_msix(0, 1, &mut self.config, self.dev_id.clone())?; -+ init_msix(0, 1, &mut self.config, self.dev_id.clone(), &self.name)?; - - let parent_bus = self.parent_bus.upgrade().unwrap(); - let mut locked_parent_bus = parent_bus.lock().unwrap(); -@@ -303,6 +303,7 @@ impl PciDevOps for RootPort { - .add_subregion(self.sec_bus.lock().unwrap().mem_region.clone(), 0) - .chain_err(|| "Failed to register subregion in memory space.")?; - -+ let name = self.name.clone(); - let root_port = Arc::new(Mutex::new(self)); - #[allow(unused_mut)] - let mut locked_root_port = root_port.lock().unwrap(); -@@ -327,7 +328,11 @@ impl PciDevOps for RootPort { - } - // Need to drop locked_root_port in order to register root_port instance. - drop(locked_root_port); -- MigrationManager::register_device_instance_mutex(RootPortState::descriptor(), root_port); -+ MigrationManager::register_device_instance_mutex_with_id( -+ RootPortState::descriptor(), -+ root_port, -+ &name, -+ ); - - Ok(()) - } -diff --git a/virtio/src/block.rs b/virtio/src/block.rs -index e0ced06..a2e35e8 100644 ---- a/virtio/src/block.rs -+++ b/virtio/src/block.rs -@@ -967,6 +967,10 @@ impl VirtioDevice for Block { - } - - fn unrealize(&mut self) -> Result<()> { -+ MigrationManager::unregister_device_instance_mutex_by_id( -+ BlockState::descriptor(), -+ &self.blk_cfg.id, -+ ); - Ok(()) - } - -diff --git a/virtio/src/net.rs b/virtio/src/net.rs -index bbb1cc7..096121b 100644 ---- a/virtio/src/net.rs -+++ b/virtio/src/net.rs -@@ -620,6 +620,10 @@ impl VirtioDevice for Net { - } - - fn unrealize(&mut self) -> Result<()> { -+ MigrationManager::unregister_device_instance_mutex_by_id( -+ VirtioNetState::descriptor(), -+ &self.net_cfg.id, -+ ); - Ok(()) - } - -diff --git a/virtio/src/virtio_pci.rs b/virtio/src/virtio_pci.rs -index bf1f58a..9eae777 100644 ---- a/virtio/src/virtio_pci.rs -+++ b/virtio/src/virtio_pci.rs -@@ -24,7 +24,7 @@ use pci::config::{ - VENDOR_ID, - }; - use pci::errors::{ErrorKind, Result as PciResult, ResultExt}; --use pci::msix::update_dev_id; -+use pci::msix::{update_dev_id, MsixState}; - use pci::{ - config::PciConfig, init_msix, init_multifunction, le_write_u16, ranges_overlap, PciBus, - PciDevOps, -@@ -939,6 +939,7 @@ impl PciDevOps for VirtioPciDevice { - nvectors as u32, - &mut self.config, - self.dev_id.clone(), -+ &self.name, - )?; - - self.assign_interrupt_cb(); -@@ -964,6 +965,7 @@ impl PciDevOps for VirtioPciDevice { - .realize() - .chain_err(|| "Failed to realize virtio device")?; - -+ let name = self.name.clone(); - let devfn = self.devfn; - let dev = Arc::new(Mutex::new(self)); - let pci_bus = dev.lock().unwrap().parent_bus.upgrade().unwrap(); -@@ -978,7 +980,11 @@ impl PciDevOps for VirtioPciDevice { - pci_device.unwrap().lock().unwrap().name() - ); - } -- MigrationManager::register_device_instance_mutex(VirtioPciState::descriptor(), dev); -+ MigrationManager::register_device_instance_mutex_with_id( -+ VirtioPciState::descriptor(), -+ dev, -+ &name, -+ ); - - Ok(()) - } -@@ -992,6 +998,15 @@ impl PciDevOps for VirtioPciDevice { - - let bus = self.parent_bus.upgrade().unwrap(); - self.config.unregister_bars(&bus)?; -+ -+ MigrationManager::unregister_device_instance_mutex_by_id( -+ MsixState::descriptor(), -+ &self.name, -+ ); -+ MigrationManager::unregister_device_instance_mutex_by_id( -+ VirtioPciState::descriptor(), -+ &self.name, -+ ); - Ok(()) - } - -@@ -1491,6 +1506,7 @@ mod tests { - virtio_pci.device.lock().unwrap().queue_num() as u32 + 1, - &mut virtio_pci.config, - virtio_pci.dev_id.clone(), -+ &virtio_pci.name, - ) - .unwrap(); - // Prepare valid queue config --- -2.25.1 - diff --git a/0009-tests-fix-the-test_standvm_quickstart.patch b/0009-tests-fix-the-test_standvm_quickstart.patch deleted file mode 100644 index 176a71f0c7862366de8b776ae853cf69946a79df..0000000000000000000000000000000000000000 --- a/0009-tests-fix-the-test_standvm_quickstart.patch +++ /dev/null @@ -1,38 +0,0 @@ -From e72471b34c285b6eb70860be23a87dfaea928280 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Thu, 6 Jan 2022 15:27:59 +0800 -Subject: [PATCH 04/10] tests: fix the test_standvm_quickstart - -Currently, device IDs are used to distinguish devices in snapshot. -Therefore, ensure that IDs before and after shapshot are consistent. - -Signed-off-by: zhouli57 ---- - tests/hydropper/virt/standvm.py | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/tests/hydropper/virt/standvm.py b/tests/hydropper/virt/standvm.py -index 5208ddd..ae6cc43 100644 ---- a/tests/hydropper/virt/standvm.py -+++ b/tests/hydropper/virt/standvm.py -@@ -205,13 +205,13 @@ class StandVM(BaseVM): - # only one device is supported(pcie root port) - if self.pcie_root_port_remain <= 0: - raise PcierootportError -- _temp_device_args = "virtio-net-pci,netdev=%s,id=%s,bus=pcie.%s,addr=0x0"\ -- % (tapname, tapname, self.pcie_root_port_remain + 4) -+ _temp_device_args = "virtio-net-pci,netdev=%s,id=net-%s,bus=pcie.%s,addr=0x0"\ -+ % (tapname, i, self.pcie_root_port_remain + 4) - self.pcie_root_port_remain -= 1 - self.pcie_root_port["net"] = False - else: -- _temp_device_args = "virtio-net-pci,netdev=%s,id=%s,bus=pcie.0,addr=%s.0x0"\ -- % (tapname, tapname, hex(i)) -+ _temp_device_args = "virtio-net-pci,netdev=%s,id=net-%s,bus=pcie.0,addr=%s.0x0"\ -+ % (tapname, i, hex(i)) - if self.multifunction["net"]: - _temp_device_args += ",multifunction=on" - if self.net_iothread: --- -2.25.1 - diff --git a/0010-root_port-correct-the-log-of-printing-device-info-du.patch b/0010-root_port-correct-the-log-of-printing-device-info-du.patch deleted file mode 100644 index f7afb6256cadf5b2fac834a092f5eb92428e50d0..0000000000000000000000000000000000000000 --- a/0010-root_port-correct-the-log-of-printing-device-info-du.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 415d62b9115181bcfc16a23b3b02542ee9753334 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Mon, 21 Feb 2022 16:38:18 +0800 -Subject: [PATCH 05/10] root_port: correct the log of printing device info - during hot unplug - -Signed-off-by: zhouli57 ---- - pci/src/root_port.rs | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/pci/src/root_port.rs b/pci/src/root_port.rs -index 286e92d..3dc97dd 100644 ---- a/pci/src/root_port.rs -+++ b/pci/src/root_port.rs -@@ -168,6 +168,7 @@ impl RootPort { - error!("{}", e.display_chain()); - error!("Failed to unrealize device {}.", locked_dev.name()); - } -+ info!("Device {} unplug from {}", locked_dev.name(), self.name); - - // Send QMP event for successful hot unplugging. - if QmpChannel::is_connected() { -@@ -237,7 +238,6 @@ impl RootPort { - && (old_ctl & PCI_EXP_SLTCTL_PCC != PCI_EXP_SLTCTL_PCC - || old_ctl & PCI_EXP_SLTCTL_PWR_IND_OFF != PCI_EXP_SLTCTL_PWR_IND_OFF) - { -- info!("Device {} unplug", self.name()); - self.remove_devices(); - - if let Err(e) = self.update_register_status() { --- -2.25.1 - diff --git a/0011-tests-add-stand-kata-testcases.patch b/0011-tests-add-stand-kata-testcases.patch deleted file mode 100644 index b730e990f5a5d54a6837a80e1d15b49004d502b5..0000000000000000000000000000000000000000 --- a/0011-tests-add-stand-kata-testcases.patch +++ /dev/null @@ -1,387 +0,0 @@ -From b714b4272f8c84060a08f4966b87247e054680c6 Mon Sep 17 00:00:00 2001 -From: Zhu Huankai -Date: Tue, 18 Jan 2022 20:55:42 +0800 -Subject: [PATCH 06/10] tests:add stand kata testcases - -Add new testcode to test kata container of standvm and move -some functions of vfio to utils_coommon. - -Add some new testcases for standvm of isula: -1.test start kata container with initrd. -2.test start kata container with rootfs. -3.test kata container create template and start from template. -4.test start kata container in sandbox -5.test start kata container with vfio net device -6.test start kata container with vfrtio fs - -Signed-off-by: Zhu Huankai ---- - .../standvm/functional/test_standvm_isula.py | 228 ++++++++++++++++++ - .../standvm/functional/test_standvm_vfio.py | 34 +-- - tests/hydropper/utils/utils_common.py | 31 ++- - 3 files changed, 265 insertions(+), 28 deletions(-) - create mode 100644 tests/hydropper/testcases/standvm/functional/test_standvm_isula.py - -diff --git a/tests/hydropper/testcases/standvm/functional/test_standvm_isula.py b/tests/hydropper/testcases/standvm/functional/test_standvm_isula.py -new file mode 100644 -index 0000000..5e01685 ---- /dev/null -+++ b/tests/hydropper/testcases/standvm/functional/test_standvm_isula.py -@@ -0,0 +1,228 @@ -+# Copyright (c) 2021 Huawei Technologies Co.,Ltd. All rights reserved. -+# -+# StratoVirt is licensed under Mulan PSL v2. -+# You can use this software according to the terms and conditions of the Mulan -+# PSL v2. -+# You may obtain a copy of Mulan PSL v2 at: -+# http:#license.coscl.org.cn/MulanPSL2 -+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY -+# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -+# NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -+# See the Mulan PSL v2 for more details. -+"""Test standvm isula""" -+ -+import os -+import logging -+import subprocess -+import pytest -+import utils.utils_common as utils -+from utils.utils_logging import TestLog -+ -+LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" -+logging.basicConfig(filename="/var/log/pytest.log", level=logging.DEBUG, format=LOG_FORMAT) -+LOG = TestLog.get_global_log() -+SHELL_TIMEOUT = 10 -+ -+def test_standvm_isula_initrd(container): -+ """ -+ Test run isula with initrd: -+ -+ 1) run isula with initrd -+ 2) execute shell command in isula -+ """ -+ LOG.info("----------test_standvm_isula_initrd----------") -+ kata_container = container -+ container_id = None -+ try: -+ kata_container.replace_configuration(cig_name='configuration-initrd-stand.toml') -+ container_id = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ image="busybox:latest", -+ name="initrd1-hydropper-stand") -+ LOG.info("initrd-stand container id:%s", container_id) -+ -+ session = kata_container.create_isula_shellsession("initrd1-hydropper-stand") -+ status, _ = session.cmd_status_output("ls", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ -+ session.close() -+ kata_container.stop_isula("initrd1-hydropper-stand") -+ finally: -+ kata_container.remove_isula_force("initrd1-hydropper-stand") -+ -+def test_standvm_isula_rootfs(container): -+ """ -+ Test run isula with rootfs: -+ -+ 1) run isula with rootfs -+ 2) execute shell command in isula -+ """ -+ LOG.info("----------test_standvm_isula_rootfs----------") -+ kata_container = container -+ container_id = None -+ try: -+ kata_container.replace_configuration(cig_name='configuration-rootfs-stand.toml') -+ container_id = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ image="busybox:latest", -+ name="rootfs1-hydropper-stand") -+ LOG.info("rootfs-stand container id:%s", container_id) -+ -+ session = kata_container.create_isula_shellsession("rootfs1-hydropper-stand") -+ status, _ = session.cmd_status_output("ls", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ -+ session.close() -+ kata_container.stop_isula("rootfs1-hydropper-stand") -+ finally: -+ kata_container.remove_isula_force("rootfs1-hydropper-stand") -+ -+def test_standvm_isula_template(container): -+ """ -+ Test run isula with template: -+ -+ 1) run template isula and create a template auto matically -+ 2) assert template has been created. -+ 3) run a new isula container from template -+ """ -+ LOG.info("----------test_standvm_isula_template----------") -+ kata_container = container -+ container_id1 = container_id2 = None -+ if os.path.exists("/run/vc/vm/template/"): -+ subprocess.run("rm -rf /run/vc/vm/template/", shell=True, check=True) -+ try: -+ kata_container.replace_configuration(cig_name='configuration-template-stand.toml') -+ container_id1 = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ image="busybox:latest", -+ name="template1-hydropper-stand") -+ LOG.info("template container id:%s", container_id1) -+ session = kata_container.create_isula_shellsession("template1-hydropper-stand") -+ status, _ = session.cmd_status_output("ls", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ session.close() -+ -+ assert os.path.exists("/run/vc/vm/template/") -+ -+ container_id2 = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ image="busybox:latest", -+ name="template2-hydropper-stand") -+ LOG.info("run container from template, id:%s", container_id2) -+ session = kata_container.create_isula_shellsession("template2-hydropper-stand") -+ status, _ = session.cmd_status_output("ls", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ session.close() -+ -+ kata_container.stop_isula("template1-hydropper-stand") -+ kata_container.stop_isula("template2-hydropper-stand") -+ finally: -+ kata_container.remove_isula_force("template1-hydropper-stand") -+ kata_container.remove_isula_force("template2-hydropper-stand") -+ if os.path.exists("/run/vc/vm/template/"): -+ subprocess.run("rm -rf /run/vc/vm/template/", shell=True, check=True) -+ -+def test_standvm_isula_sandbox(container): -+ """ -+ Test run isula with sandbox: -+ -+ 1) run podsandbox container firstly. -+ 2) run a new container in podsanbox. -+ """ -+ LOG.info("----------test_standvm_isula_sandbox----------") -+ kata_container = container -+ container_id = podsandbox_id = None -+ try: -+ kata_container.replace_configuration(cig_name='configuration-initrd-stand.toml') -+ podsandbox_id = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ image="busybox:latest", -+ name="sandbox1-hydropper-stand", -+ annotation="io.kubernetes.docker.type=podsandbox") -+ LOG.info("podsandbox container id:%s", podsandbox_id) -+ -+ podsandbox_id = podsandbox_id.strip('\n') -+ container_id = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ image="busybox:latest", -+ name="sandbox2-hydropper-stand", -+ annotation=["io.kubernetes.docker.type=container", -+ ("io.kubernetes.sandbox.id=%s" % podsandbox_id)]) -+ LOG.info("container id:%s", container_id) -+ session = kata_container.create_isula_shellsession("sandbox2-hydropper-stand") -+ status, _ = session.cmd_status_output("ls", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ session.close() -+ -+ kata_container.stop_isula("sandbox2-hydropper-stand") -+ kata_container.stop_isula("sandbox1-hydropper-stand") -+ finally: -+ kata_container.remove_isula_force("sandbox2-hydropper-stand") -+ kata_container.remove_isula_force("sandbox1-hydropper-stand") -+ -+@pytest.mark.skip -+@pytest.mark.parametrize("net_type, bdf, pf_name", -+ [('1822', '0000:03:00.0', 'enp3s0')]) -+def test_standvm_isula_vfionet(container, net_type, bdf, pf_name): -+ """ -+ Test run isula with vfio net device: -+ """ -+ LOG.info("----------test_standvm_isula_vfionet----------") -+ kata_container = container -+ container_id = None -+ vf_bdf = bdf.split('.')[0] + '.1' -+ try: -+ kata_container.replace_configuration(cig_name='configuration-initrd-stand.toml') -+ utils.config_host_vfio(net_type=net_type, number='2', bdf=bdf) -+ utils.check_vf(pf_name=pf_name) -+ subprocess.run("modprobe vfio-pci", shell=True, check=True) -+ utils.rebind_vfio_pci(bdf=vf_bdf) -+ iommu_group = utils.get_iommu_group(vf_bdf) -+ container_id = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ device="/dev/vfio/%s" % iommu_group, -+ net="none", -+ image="busybox:latest", -+ name="vfionet1-hydropper-stand") -+ LOG.info("vfio net container id:%s", container_id) -+ -+ session = kata_container.create_isula_shellsession("vfionet1-hydropper-stand") -+ status, _ = session.cmd_status_output("ip a", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ -+ session.close() -+ kata_container.stop_isula("vfionet1-hydropper-stand") -+ finally: -+ utils.clean_vf(bdf=bdf) -+ kata_container.remove_isula_force("vfionet1-hydropper-stand") -+ -+@pytest.mark.skip -+def test_standvm_isula_virtiofs(container): -+ """ -+ Test run isula with virtio fs: -+ """ -+ LOG.info("----------test_standvm_isula_virtiofs----------") -+ kata_container = container -+ container_id = None -+ test_dir = "/tmp/hydropper_virtio_fs" -+ if not os.path.exists(test_dir): -+ subprocess.run("mkdir %s" % test_dir, shell=True, check=True) -+ subprocess.run("touch %s/hydropper1.log" % test_dir, shell=True, check=True) -+ try: -+ kata_container.replace_configuration(cig_name='configuration-virtiofs-stand.toml') -+ container_id = kata_container.run_isula(options="-tid", -+ runtime="io.containerd.kata.v2", -+ net="none -v %s:/tmp/" % test_dir, -+ image="busybox:latest", -+ name="virtiofs1-hydropper-stand") -+ LOG.info("virtio fs container id:%s", container_id) -+ -+ session = kata_container.create_isula_shellsession("virtiofs1-hydropper-stand") -+ status, _ = session.cmd_status_output("ls /tmp/hydropper1.log", timeout=SHELL_TIMEOUT) -+ assert status == 0 -+ -+ session.close() -+ kata_container.stop_isula("virtiofs1-hydropper-stand") -+ finally: -+ kata_container.remove_isula_force("virtiofs1-hydropper-stand") -+ subprocess.run("rm -rf /tmp/hydropper_virtio_fs", shell=True, check=True) -diff --git a/tests/hydropper/testcases/standvm/functional/test_standvm_vfio.py b/tests/hydropper/testcases/standvm/functional/test_standvm_vfio.py -index e6ca2b3..dc399a5 100644 ---- a/tests/hydropper/testcases/standvm/functional/test_standvm_vfio.py -+++ b/tests/hydropper/testcases/standvm/functional/test_standvm_vfio.py -@@ -15,33 +15,13 @@ import logging - import pytest - import platform - from subprocess import run -- -+import utils.utils_common as utils - from utils.utils_logging import TestLog - - LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" - logging.basicConfig(filename="/var/log/pytest.log", level=logging.DEBUG, format=LOG_FORMAT) - LOG = TestLog.get_global_log() - --def config_host_vfio(net_type, number, bdf): -- """configure vf in host""" -- ret = run("lspci -v | grep 'Eth' | grep %s" % net_type, shell=True, check=True).stdout -- LOG.debug(ret) -- ret = run("echo %s > /sys/bus/pci/devices/%s/sriov_numvfs" % (number, bdf), shell=True, check=True) -- --def rebind_vfio_pci(bdf): -- """unbind old driver and bind a new one""" -- run("echo %s > /sys/bus/pci/devices/%s/driver/unbind" % (bdf, bdf), shell=True, check=True) -- run("echo `lspci -ns %s | awk -F':| ' '{print $5\" \"$6}'` > /sys/bus/pci/drivers/vfio-pci/new_id"\ -- %bdf, shell=True, check=True) -- --def check_vf(pf_name): -- """check whether vf is enabled""" -- run("ip link show %s | grep vf" % pf_name, shell=True, check=True) -- --def clean_vf(bdf): -- """clean host vf""" -- ret = run("echo 0 > /sys/bus/pci/devices/%s/sriov_numvfs" % bdf, shell=True, check=True) -- - @pytest.mark.standvm_accept - @pytest.mark.parametrize("host_ip, net_type, bdf, pf_name", - [('9.13.7.139', '1822', '0000:03:00.0', 'enp3s0')]) -@@ -57,11 +37,11 @@ def test_standvm_vfio_net(standvm, host_ip, net_type, bdf, pf_name): - flag = False - - testvm = standvm -- config_host_vfio(net_type=net_type, number='2', bdf=bdf) -+ utils.config_host_vfio(net_type=net_type, number='2', bdf=bdf) - try: -- check_vf(pf_name=pf_name) -+ utils.check_vf(pf_name=pf_name) - run("modprobe vfio-pci", shell=True, check=True) -- rebind_vfio_pci(bdf=vf_bdf) -+ utils.rebind_vfio_pci(bdf=vf_bdf) - testvm.basic_config(vfio=True, bdf=vf_bdf) - testvm.launch() - _cmd = "ip a | awk '{ print $2 }' | cut -d ':' -f 1" -@@ -80,7 +60,7 @@ def test_standvm_vfio_net(standvm, host_ip, net_type, bdf, pf_name): - assert flag == True - finally: - testvm.shutdown() -- clean_vf(bdf=bdf) -+ utils.clean_vf(bdf=bdf) - - @pytest.mark.standvm_accept - @pytest.mark.parametrize("bdf",[('0000:08:00.0')]) -@@ -95,7 +75,7 @@ def test_standvm_vfio_ssd(standvm, bdf): - testvm = standvm - run("lspci | grep 'Non-Volatile memory'", shell=True, check=True) - run("modprobe vfio-pci", shell=True, check=True) -- rebind_vfio_pci(bdf=bdf) -+ utils.rebind_vfio_pci(bdf=bdf) - testvm.basic_config(vfio=True, bdf=bdf) - testvm.launch() - session = testvm.create_ssh_session() -@@ -111,4 +91,4 @@ def test_standvm_vfio_ssd(standvm, bdf): - assert ret == 0 - - session.close() -- testvm.shutdown() -\ No newline at end of file -+ testvm.shutdown() -diff --git a/tests/hydropper/utils/utils_common.py b/tests/hydropper/utils/utils_common.py -index 949cb5c..7713bef 100644 ---- a/tests/hydropper/utils/utils_common.py -+++ b/tests/hydropper/utils/utils_common.py -@@ -14,6 +14,8 @@ import os - import errno - import ctypes - import shutil -+from subprocess import run -+from subprocess import PIPE - from utils.utils_logging import TestLog - - LOG = TestLog.get_global_log() -@@ -57,4 +59,31 @@ def get_timestamp(timestamp): - minute = int(datetime.split(':')[1]) - second = int(datetime.split(':')[2]) - -- return float(str(second + minute * 60 + hour * 60 * 24) + '.' + mill) -\ No newline at end of file -+ return float(str(second + minute * 60 + hour * 60 * 24) + '.' + mill) -+ -+ -+def config_host_vfio(net_type, number, bdf): -+ """configure vf in host""" -+ ret = run("lspci -v | grep 'Eth' | grep %s" % net_type, shell=True, check=True).stdout -+ LOG.debug(ret) -+ ret = run("echo %s > /sys/bus/pci/devices/%s/sriov_numvfs" % (number, bdf), shell=True, check=True) -+ -+def rebind_vfio_pci(bdf): -+ """unbind old driver and bind a new one""" -+ run("echo %s > /sys/bus/pci/devices/%s/driver/unbind" % (bdf, bdf), shell=True, check=True) -+ run("echo `lspci -ns %s | awk -F':| ' '{print $5\" \"$6}'` > /sys/bus/pci/drivers/vfio-pci/new_id"\ -+ %bdf, shell=True, check=True) -+ -+def check_vf(pf_name): -+ """check whether vf is enabled""" -+ run("ip link show %s | grep vf" % pf_name, shell=True, check=True) -+ -+def clean_vf(bdf): -+ """clean host vf""" -+ ret = run("echo 0 > /sys/bus/pci/devices/%s/sriov_numvfs" % bdf, shell=True, check=True) -+ -+def get_iommu_group(bdf): -+ """get iommu group id""" -+ read_cmd = "readlink /sys/bus/pci/devices/%s/iommu_group" % bdf -+ return run(read_cmd, shell=True, check=True, stdout=PIPE) \ -+ .stdout.decode('utf-8').splitlines()[0].split('/')[-1] --- -2.25.1 - diff --git a/0012-net-fix-the-bug-when-tap-is-abnormally-removed.patch b/0012-net-fix-the-bug-when-tap-is-abnormally-removed.patch deleted file mode 100644 index 7230a52d2965ecdea074a735e46917585968949e..0000000000000000000000000000000000000000 --- a/0012-net-fix-the-bug-when-tap-is-abnormally-removed.patch +++ /dev/null @@ -1,50 +0,0 @@ -From ea2c4cb7831aaa7a98f7d3d7379f6262bbbf2153 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Tue, 22 Feb 2022 10:51:40 +0800 -Subject: [PATCH 07/10] net: fix the bug when tap is abnormally removed - -If the backend tap device is removed, readv returns less than 0. -At this time, the content in the tap needs to be cleaned up. -Here, read is called to process, otherwise handle_rx may be triggered -all the time, resulting in an infinite loop. - -Signed-off-by: zhouli57 ---- - virtio/src/net.rs | 14 +++++++++++++- - 1 file changed, 13 insertions(+), 1 deletion(-) - -diff --git a/virtio/src/net.rs b/virtio/src/net.rs -index bbb1cc7..69ecc36 100644 ---- a/virtio/src/net.rs -+++ b/virtio/src/net.rs -@@ -149,6 +149,18 @@ impl NetIoHandler { - if e.kind() == std::io::ErrorKind::WouldBlock { - break; - } -+ -+ // If the backend tap device is removed, readv returns less than 0. -+ // At this time, the content in the tap needs to be cleaned up. -+ // Here, read is called to process, otherwise handle_rx may be triggered all the time. -+ let mut buf = [0; 1024]; -+ match tap.read(&mut buf) { -+ Ok(cnt) => error!("Failed to call readv but tap read is ok: cnt {}", cnt), -+ Err(e) => { -+ // When the backend tap device is abnormally removed, read return EBADFD. -+ error!("Failed to read tap: {}", e); -+ } -+ } - bail!("Failed to call readv for net handle_rx: {}", e); - } - -@@ -446,7 +458,7 @@ impl EventNotifierHelper for NetIoHandler { - tap_fd, - Some(handler), - NotifierOperation::AddShared, -- EventSet::IN, -+ EventSet::IN | EventSet::EDGE_TRIGGERED, - )); - } - --- -2.25.1 - diff --git a/0013-docs-boot-update-detailed-usage-for-standard-boot.patch b/0013-docs-boot-update-detailed-usage-for-standard-boot.patch deleted file mode 100644 index f8b0f85c922c5cb97d0e8b587fa5c8d78696aa72..0000000000000000000000000000000000000000 --- a/0013-docs-boot-update-detailed-usage-for-standard-boot.patch +++ /dev/null @@ -1,376 +0,0 @@ -From 08eae86c65a91827a0f0c8de3849b6f46f097fba Mon Sep 17 00:00:00 2001 -From: Jiajie Li -Date: Mon, 21 Feb 2022 18:10:01 +0800 -Subject: [PATCH 08/10] docs/boot: update detailed usage for standard boot - -1. Fix some clerical error in boot cmdline. -2. Add download link for kernel image. -3. Differentiate the two modes supported by standard boot to - make it easier to understand. - -Signed-off-by: Jiajie Li ---- - docs/boot.ch.md | 94 +++++++++++++++++++++++++++---------------------- - docs/boot.md | 89 +++++++++++++++++++++++++--------------------- - 2 files changed, 99 insertions(+), 84 deletions(-) - -diff --git a/docs/boot.ch.md b/docs/boot.ch.md -index b8eec27..31153a9 100644 ---- a/docs/boot.ch.md -+++ b/docs/boot.ch.md -@@ -1,13 +1,13 @@ - # StratoVirt 启动准备 - --StratoVirt提供了微虚拟机和标准虚拟机两种机型。两种机型的启动过程如下。 -+StratoVirt提供了轻量虚拟机和标准虚拟机两种机型。两种机型的启动过程如下。 - --## 微虚拟机启动过程 -+## 轻量虚拟机启动过程 - - ### 1. 构建内核镜像 - --StratoVirt的微虚拟机机型在x86_64和aarch64平台都支持PE格式或是bzImage格式 --(仅x86_64平台支持)的内核镜像。通过以下步骤来构建内核镜像: -+StratoVirt的轻量虚拟机机型在x86_64平台上支持PE格式或是bzImage格式的内核镜像,在 -+aarch64平台上支持PE格式的内核镜像。通过以下步骤来构建内核镜像: - - 1. 首先,获取openEuler内核源码: - -@@ -22,7 +22,7 @@ StratoVirt的微虚拟机机型在x86_64和aarch64平台都支持PE格式或是b - $ cd /usr/src/linux-5.10.0-0.0.0.7.oe1.$(uname -m)/ - ``` - --2. 配置linux内核信息。你可以使用 [我们提供的微虚拟机内核配置文件](./kernel_config/micro_vm) -+2. 配置linux内核信息。你可以使用 [我们提供的轻量虚拟机内核配置文件](./kernel_config/micro_vm) - 并且将配置文件重命名为`.config`拷贝至`kernel`路径下。 当然你也可以通过命令修改内 - 核编译选项: - -@@ -33,12 +33,12 @@ StratoVirt的微虚拟机机型在x86_64和aarch64平台都支持PE格式或是b - 3. 构建并将内核镜像转换为PE格式。 - - ```shell -- $ make -j vmlinux && objcopy -O binary vmlinux vmlinux.bin -+ $ make -j$(nproc) vmlinux && objcopy -O binary vmlinux vmlinux.bin - ``` - - 4. 如果你想要在x86_64平台编译bzImage格式内核镜像。 - ```shell -- $ make -j bzImage -+ $ make -j$(nproc) bzImage - ``` - - ### 2. 构建rootfs镜像 -@@ -66,33 +66,10 @@ Rootfs镜像是一种文件系统镜像。在StratoVirt启动时可以挂载带 - 标准虚拟机有两种启动方式,第一种使用kernel+rootfs;另一种是使用预先安装好guest 操 - 作系统的raw格式镜像。 - --### 1. 构建内核镜像 -- --StratoVirt的标准虚拟机机型支持x86_64平台的bzImage格式内核镜像和aarch64平台的PE格 --式内核镜像。内核镜像构建如下: -- --1. 首先,获取openEuler内核源码: -- -- ```shell -- $ git clone -b kernel-5.10 --depth=1 https://gitee.com/openeuler/kernel -- $ cd kernel -- ``` -- --2. 配置linux内核信息。你可以使用 [我们提供的标准虚拟机内核配置文件](./kernel_config/standard_vm) -- 并且将配置文件重命名为`.config`拷贝至`kernel`路径下。 -- --3. 构建内核镜像 -- -- ```shell -- # 在aarch64平台,将内核镜像转换为PE格式。 -- $ make -j vmlinux && objcopy -O binary vmlinux vmlinux.bin -- -- # 在x86_64平台,将内核镜像转换为bzImage格式. -- $ make -j bzImage -- ``` -- -+接下来讲解如何通过以上所述的两种方式启动标准虚拟机。以上两种启动方式均需使用标准启动 -+固件,为此首先讲解如何获取标准启动固件。 - --### 2. 获取标准启动固件 -+### 1. 获取标准启动固件 - - 标准启动需要启动固件。Stratovirt仅支持在x86_64和aarch64平台上从UEFI(统一可扩展 - 固件接口)启动。 -@@ -103,7 +80,7 @@ EDK2是一个实现了UEFI规范的开源项目。我们使用EDK2作为固件 - 有两种方法可以获取EDK2二进制文件,通过yum源直接安装或从源代码编译。具体步骤如下。 - 请注意,EDK2二进制文件包含两个文件,一个用于存储可执行代码,另一个用于存储引导数据。 - --#### 2.1 直接安装EDK2 -+#### 1.1 直接安装EDK2 - - 在x86_64平台, 运行 - -@@ -121,7 +98,7 @@ $ sudo yum install -y edk2-aarch64 - `/usr/share/edk2/ovmf` 目录下。 在aarch64平台, `QEMU_EFI-pflash.raw` 和 - `vars-template-pflash.raw` 文件会存在于`/usr/share/edk2/aarch64` 目录下。 - --#### 2.2 从源代码编译 -+#### 1.2 从源代码编译 - - ```shell - # 安装必要依赖包用于编译edk2。 -@@ -169,13 +146,44 @@ fi - 目录下。在aarch64平台, `STRATOVIRT_EFI.raw` 和 `STRATOVIRT_VAR.raw` 文件会位于 - `/home` 目录下. - --### 3. 构建rootfs镜像 -+### 2. 以 kernel + rootfs 方式启动标准虚拟机 -+ -+#### 2.1 构建内核镜像 -+ -+StratoVirt的标准虚拟机机型支持x86_64平台的bzImage格式内核镜像和aarch64平台的PE格 -+式内核镜像。内核镜像构建如下: -+ -+1. 获取openEuler内核源码: -+ -+ ```shell -+ $ git clone -b kernel-5.10 --depth=1 https://gitee.com/openeuler/kernel -+ $ cd kernel -+ ``` -+ -+2. 配置linux内核信息。你可以使用我们提供的标准虚拟机 [内核配置文件](./kernel_config/standard_vm) -+ 并且将配置文件重命名为`.config`拷贝至`kernel`路径下。 -+ -+3. 构建内核镜像 -+ -+ ```shell -+ # 在aarch64平台,将内核镜像转换为PE格式。 -+ $ make -j$(nproc) vmlinux && objcopy -O binary vmlinux vmlinux.bin -+ -+ # 在x86_64平台,将内核镜像转换为bzImage格式. -+ $ make -j$(nproc) bzImage -+ ``` -+ -+除了手动构建内核镜像的方式以外,也可以直接从 openEuler 官网下载对应的 -+[内核镜像](https://repo.openeuler.org/openEuler-21.09/stratovirt_img/x86_64/std-vmlinuxz)。 -+ -+#### 2.2 构建rootfs镜像 - --为标准虚拟机构建rootfs镜像实际上与微虚拟机相同。你可以通过[附录](#2附录)查看更多 -+为标准虚拟机构建rootfs镜像实际上与轻量虚拟机相同。你可以通过[附录](#2附录)查看更多 - 的详细信息。 - -+### 3. 以 raw 格式镜像启动标准虚拟机 - --### 4. 获取 raw 格式镜像 -+#### 3.1 获取 raw 格式镜像 - - 你可以从 openEuler 官网下载已经安装好的 [qcow2 镜像](https://repo.openeuler.org/openEuler-21.03/virtual_machine_img/x86_64/openEuler-21.03-x86_64.qcow2.xz)。 - -@@ -189,7 +197,7 @@ $ qemu-img convert -f qcow2 -O raw openEuler-21.03-x86_64.qcow2 openEuler-21.03- - - 至此就获得了可以使用的 raw 格式镜像。 - --### 5. 启动命令行样例 -+### 4. 启动命令行样例 - - 请注意,标准虚拟机需要两个PFlash设备,它们将使用来自与EDK2二进制的两个固件文件。 - 如果你不需要保持启动信息,单元序列为1的数据存储文件可以被省略。但是单元序号为0的 -@@ -215,11 +223,11 @@ fi - -kernel /path/to/kernel \ - -smp 1 \ - -m 2G \ -- -append "console=${con} reboot=k panic=1 root=/dev/vda" \ -+ -append "console=${con} reboot=k panic=1 root=/dev/vda rw" \ - -drive file=/path/to/rootfs,id=rootfs,readonly=off,direct=off \ - -device virtio-blk-device,drive=rootfs,id=rootfs \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ -- -drive file=/path/to/OVMF_VARS.fd,if=pfalsh,unit=1 \ -+ -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ - -serial stdio - ``` -@@ -232,11 +240,11 @@ fi - -kernel /path/to/kernel \ - -smp 1 \ - -m 2G \ -- -append "console=${con} reboot=k panic=1 root=/dev/vda" \ -+ -append "console=${con} reboot=k panic=1 root=/dev/vda rw" \ - -drive file=/path/to/rootfs,id=rootfs,readonly=off,direct=off \ - -device virtio-blk-device,drive=rootfs \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ -- -drive file=/path/to/OVMF_VARS.fd,if=pfalsh,unit=1 \ -+ -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ - -serial stdio - ``` -diff --git a/docs/boot.md b/docs/boot.md -index f7227df..64d75b4 100644 ---- a/docs/boot.md -+++ b/docs/boot.md -@@ -7,9 +7,9 @@ boot process of these two machines are as follows. - - ### 1. Build kernel - --The microvm machine type of StratoVirt supports PE or bzImage (only x86_64) format --kernel images on both x86_64 and aarch64 platforms. Kernel image can be built with --following steps: -+The microvm machine type of StratoVirt supports PE or bzImage format kernel images -+on x86_64 platforms, and supports PE format kernel images on aarch64 platforms. -+Kernel image can be built with following steps: - - 1. Firstly, get the openEuler kernel source code with: - -@@ -35,12 +35,12 @@ and copy it to `kernel` path as `.config`. You can also modify config options by - 3. Build and transform kernel image to PE format. - - ```shell -- $ make -j vmlinux && objcopy -O binary vmlinux vmlinux.bin -+ $ make -j$(nproc) vmlinux && objcopy -O binary vmlinux vmlinux.bin - ``` - - 4. If you want to compile bzImage format kernel in x86_64. - ```shell -- $ make -j bzImage -+ $ make -j$(nproc) bzImage - ``` - - ### 2. Build rootfs -@@ -68,34 +68,10 @@ be mounted at boot time in StratoVirt. You can check [Appendix](#2Appendix). - Standard VMs can boot in two modes. The first mode is kernel + rootfs.The other - is to use the raw image that has been preinstalled with the guest OS. - --### 1. Build kernel -- --The standard_ machine in StratoVirt supports bzImage format kernel image --on x86_64 platform; and supports PE format kernel image on aarch64 platform. --Kernel image can be built with: -- --1. Firstly, get the openEuler kernel source code with: -- -- ```shell -- $ git clone -b kernel-5.10 --depth=1 https://gitee.com/openeuler/kernel -- $ cd kernel -- ``` -- --2. Configure your linux kernel. You should use [our recommended standard_vm config] --(./kernel_config/standard_vm) and copy it to `kernel` path as `.config`. -- --3. Build kernel image -- -- ```shell -- # on aarch64 platform, transform kernel image to PE format. -- $ make -j vmlinux && objcopy -O binary vmlinux vmlinux.bin -- -- # on x86_64 platform, get bzImage format kernel image. -- $ make -j bzImage -- ``` -- -+The preceding two boot modes both require standard boot firmware. So we first -+describe how to obtain the standard boot firmware. - --### 2. Get firmware for standard boot -+### 1. Get firmware for standard boot - - Standard boot needs firmware. Stratovirt only supports booting from UEFI (Unified - Extensible Firmware Interface) on x86_64 and aarch64 platform. -@@ -108,7 +84,7 @@ or compiling from source code. The specific steps are as follows. Notes that EDK - binary contains two files, one for executable code storage and the other for boot - data storage. - --#### 2.1 Directly install EDK II -+#### 1.1 Directly install EDK II - - On x86_64 platform, run - -@@ -126,7 +102,7 @@ After installing edk2, on x86_64 platform, `OVMF_CODE.fd` and `OVMF_VARS.fd` are - located in `/usr/share/edk2/ovmf` directory. On aarch64 platform, `QEMU_EFI-pflash.raw` - and `vars-template-pflash.raw` are located in `/usr/share/edk2/aarch64` directory. - --#### 2.2 Compile from source code -+#### 1.2 Compile from source code - - ```shell - # Install necessary packages to compile edk2. -@@ -174,13 +150,44 @@ After compiling edk2, on x86_64 platform, `OVMF_CODE.fd` and `OVMF_VARS.fd` loca - underneath `/home` directory. On aarch64 platform, `STRATOVIRT_EFI.raw` and - `STRATOVIRT_VAR.raw` locates underneath `/home` directory. - --### 3. Build rootfs -+### 2. Boot with kernel and rootfs -+#### 2.1 Build kernel -+ -+The standard_ machine in StratoVirt supports bzImage format kernel image -+on x86_64 platform; and supports PE format kernel image on aarch64 platform. -+Kernel image can be built with: -+ -+1. Firstly, get the openEuler kernel source code with: -+ -+ ```shell -+ $ git clone -b kernel-5.10 --depth=1 https://gitee.com/openeuler/kernel -+ $ cd kernel -+ ``` -+ -+2. Configure your linux kernel. You should use [our recommended standard_vm config] -+(./kernel_config/standard_vm) and copy it to `kernel` path as `.config`. -+ -+3. Build kernel image -+ -+ ```shell -+ # on aarch64 platform, transform kernel image to PE format. -+ $ make -j$(nproc) vmlinux && objcopy -O binary vmlinux vmlinux.bin -+ -+ # on x86_64 platform, get bzImage format kernel image. -+ $ make -j$(nproc) bzImage -+ ``` -+In addition to manually building the kernel image, you can also download the -+[kernel image](https://repo.openeuler.org/openEuler-21.09/stratovirt_img/x86_64/std-vmlinuxz) -+from the openEuler official website. -+ -+#### 2.2 Build rootfs - - The building of rootfs for standard VM is exactly the same with microvm. You can - check [Appendix](#2Appendix) for more detailed information. - - --### 4. Get raw image -+### 3. Boot with raw image -+#### 3.1 Get raw image - - You can download the installed [qcow2 image](https://repo.openeuler.org/openEuler-21.03/virtual_machine_img/x86_64/openEuler-21.03-x86_64.qcow2.xz) - from the OpenEuler official website. -@@ -195,7 +202,7 @@ $ qemu-img convert -f qcow2 -O raw openEuler-21.03-x86_64.qcow2 openEuler-21.03- - - Now the available raw image is obtained. - --### 5. Boot command line sample -+### 4. Boot command line sample - - Note that standard need two PFlash devices which will use two firmware files from - EDK II binary. If you don't need to store boot information, data storage file can -@@ -221,11 +228,11 @@ fi - -kernel /path/to/kernel \ - -smp 1 \ - -m 2G \ -- -append "console=${con} reboot=k panic=1 root=/dev/vda" \ -+ -append "console=${con} reboot=k panic=1 root=/dev/vda rw" \ - -drive file=/path/to/rootfs,id=rootfs,readonly=off,direct=off \ - -device virtio-blk-device,drive=rootfs,id=rootfs \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ -- -drive file=/path/to/OVMF_VARS.fd,if=pfalsh,unit=1 \ -+ -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ - -serial stdio - ``` -@@ -240,10 +247,10 @@ The command for booting with the raw image is as follows: - -drive file=/path/to/raw_image,id=raw_image,readonly=off,direct=off \ - -device virtio-blk-device,drive=raw_image \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ -- -drive file=/path/to/OVMF_VARS.fd,if=pfalsh,unit=1 \ -+ -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ - -serial stdio --```F -+``` - - ## Appendix - --- -2.25.1 - diff --git a/0014-virtio-queue-fix-error-access-queue-s-host-virtual-a.patch b/0014-virtio-queue-fix-error-access-queue-s-host-virtual-a.patch deleted file mode 100644 index 82bd7834564028d26a1b34715088ffc32888e00a..0000000000000000000000000000000000000000 --- a/0014-virtio-queue-fix-error-access-queue-s-host-virtual-a.patch +++ /dev/null @@ -1,78 +0,0 @@ -From 55c4ba8eb8b6a6bf58709ece92f689b3e3556a0d Mon Sep 17 00:00:00 2001 -From: "Xinle.Guo" -Date: Sat, 26 Feb 2022 12:05:10 +0800 -Subject: [PATCH 09/10] virtio/queue: fix error access queue's host virtual - address on x86_64 architecture - -On x86_64 architecture, there is a hole(2G ~ 4G) in the memory -layout. If just convert guest physical address(gpa) directly to -the host virtual address(hva), it may access address out of bounds. -Call `get_host_address()` function to get hva from gpa. - -Signed-off-by: Xinle.Guo ---- - virtio/src/queue.rs | 31 ++++++++++++------------------- - 1 file changed, 12 insertions(+), 19 deletions(-) - -diff --git a/virtio/src/queue.rs b/virtio/src/queue.rs -index bb39723..b2c7132 100644 ---- a/virtio/src/queue.rs -+++ b/virtio/src/queue.rs -@@ -423,8 +423,6 @@ impl SplitVringDesc { - fn get_indirect_desc( - &self, - sys_mem: &Arc, -- desc_table: GuestAddress, -- desc_table_host: u64, - index: u16, - cache: &mut Option, - elem: &mut Element, -@@ -434,13 +432,15 @@ impl SplitVringDesc { - } - - let desc_num = self.get_desc_num(); -- let desc_hva = desc_table_host + self.addr.0 - desc_table.0; -- let desc_table = self.addr; -+ let desc_hva = match sys_mem.get_host_address(self.addr) { -+ Some(addr) => addr, -+ None => bail!("Failed to get descriptor table entry host address"), -+ }; - let desc = Self::next_desc(sys_mem, desc_hva, desc_num, 0, cache)?; - Self::get_element(sys_mem, desc_hva, desc_num, index, desc, cache, elem) - .chain_err(|| -- format!("Failed to get element from indirect descriptor chain {}, table addr: 0x{:X}, size: {}", -- index, desc_table.raw_value(), desc_num) -+ format!("Failed to get element from indirect descriptor chain {}, table entry addr: 0x{:X}, size: {}", -+ index, self.addr.0, desc_num) - ) - } - -@@ -765,19 +765,12 @@ impl SplitVring { - bail!("Unexpected descriptor for writing only for popping avail ring"); - } - -- desc.get_indirect_desc( -- sys_mem, -- self.desc_table, -- self.addr_cache.desc_table_host, -- desc_index, -- &mut self.cache, -- elem, -- ) -- .map(|elem| { -- self.next_avail += Wrapping(1); -- elem -- }) -- .chain_err(|| "Failed to get indirect desc for popping avail ring")? -+ desc.get_indirect_desc(sys_mem, desc_index, &mut self.cache, elem) -+ .map(|elem| { -+ self.next_avail += Wrapping(1); -+ elem -+ }) -+ .chain_err(|| "Failed to get indirect desc for popping avail ring")? - } else { - desc.get_nonindirect_desc( - sys_mem, --- -2.25.1 - diff --git a/0015-vfio-doc-create-a-new-document-for-using-vfio.patch b/0015-vfio-doc-create-a-new-document-for-using-vfio.patch deleted file mode 100644 index ac9d8c1f58e590f671101573eb7ff796dfcbef84..0000000000000000000000000000000000000000 --- a/0015-vfio-doc-create-a-new-document-for-using-vfio.patch +++ /dev/null @@ -1,146 +0,0 @@ -From f2d1cd2444616b91be7b99a0fefa9b4d0a5174b8 Mon Sep 17 00:00:00 2001 -From: "Xinle.Guo" -Date: Fri, 18 Feb 2022 16:17:57 +0800 -Subject: [PATCH 10/10] vfio/doc: create a new document for using vfio - -Signed-off-by: Xinle.Guo ---- - docs/config_guidebook.md | 26 +++++-------- - docs/vfio.md | 79 ++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 88 insertions(+), 17 deletions(-) - create mode 100644 docs/vfio.md - -diff --git a/docs/config_guidebook.md b/docs/config_guidebook.md -index e0b8bdc..f541e16 100644 ---- a/docs/config_guidebook.md -+++ b/docs/config_guidebook.md -@@ -447,32 +447,24 @@ Four properties can be set for PFlash device. - ``` - - ### 2.11 VFIO --The VFIO driver is an IOMMU/device agnostic framework for exposing direct access to userspace, in a secure, IOMMU protected environment. Virtual machine often makes use of direct device access when configured for the highest possible I/O performance. -+The VFIO driver is an IOMMU/device agnostic framework for exposing direct access to userspace, in a secure, -+IOMMU protected environment. Virtual machine often makes use of direct device access when configured for the highest -+possible I/O performance. - --In order to successfully use VFIO device, it is mandatory that hardware supports virtualization and IOMMU groups. -- --Assume user wants to access PCI device 0000:1a:00.3. --The device is attached to PCI bus, therefore user will make use of vfio-pci to manage the group: --```shell --# cmdline --modprobe vfio-pci --``` --Binding this device to the vfio-pci driver, it will create the VFIO group character devices for this group. --```shell --# cmdline --echo 0000:1a:00.3 > /sys/bus/pci/devices/0000:1a:00.3/driver/unbind --echo `lspci -ns 0000:1a:00.3 | awk -F':| ' '{print $5" "$6}'` > /sys/bus/pci/drivers/vfio-pci/new_id --``` - Four properties are supported for VFIO device --* host: PCI device info in the system that contains domain, bus number, slot number and function number. -+* host: PCI device info in the system that contains domain, bus number, slot number and function number. - * id: VFIO device name. - * bus: bus number of VFIO device. - * addr: including slot number and function number. -+ - ```shell --# cmdline - -device vfio-pci,host=0000:1a:00.3,id=net,bus=pcie.0,addr=0x03.0x0[,multifunction=on] - ``` - -+Note: the kernel must contain physical device drivers, otherwise it cannot be loaded normally. -+ -+See [VFIO](./vfio.md) for more details. -+ - ### 2.12 Chardev - The type of chardev backend could be: stdio, pty, socket and file(output only). - -diff --git a/docs/vfio.md b/docs/vfio.md -new file mode 100644 -index 0000000..bd0aeea ---- /dev/null -+++ b/docs/vfio.md -@@ -0,0 +1,79 @@ -+# VFIO User Manual -+ -+## Introduction -+ -+The VFIO driver is an IOMMU/device agnostic framework for exposing direct access to userspace, in a secure, -+IOMMU protected environment. Virtual machine often makes use of direct device access when configured for the highest -+possible I/O performance. -+ -+## Preparation -+ -+In order to successfully use VFIO device, it is mandatory that hardware supports virtualization and IOMMU groups. -+Execute the following command on your host OS to check whether the IOMMU has been turned on. -+```shell -+# dmesg | grep iommu -+``` -+If the IOMMU is turned on, the terminal display as follows: -+```shell -+iommu: Default domain type: Translated -+hibmc-drm 0000:0a:00.0: Adding to iommu group 0 -+ehci-pci 0000:7a:01.0: Adding to iommu group 1 -+ehci-pci 0000:ba:01.0: Adding to iommu group 2 -+ohci-pci 0000:7a:00.0: Adding to iommu group 3 -+ohci-pci 0000:ba:00.0: Adding to iommu group 4 -+xhci_hcd 0000:7a:02.0: Adding to iommu group 5 -+... -+``` -+Assume user wants to access PCI device 0000:1a:00.3. -+The device is attached to PCI bus, therefore user will make use of vfio-pci to manage the group: -+```shell -+# modprobe vfio-pci -+``` -+ -+## Bind VFIO device -+ -+Binding this device to the vfio-pci driver, it will create the VFIO group character devices for this group. -+```shell -+# echo 0000:1a:00.3 > /sys/bus/pci/devices/0000:1a:00.3/driver/unbind -+# echo `lspci -ns 0000:1a:00.3 | awk -F':| ' '{print $5" "$6}'` > /sys/bus/pci/drivers/vfio-pci/new_id -+``` -+ -+## Command line -+ -+Four properties are supported for VFIO device -+* host: PCI device info in the system that contains domain, bus number, slot number and function number. -+* id: VFIO device name. -+* bus: bus number of VFIO device. -+* addr: including slot number and function number. -+```shell -+-device vfio-pci,host=0000:1a:00.3,id=net,bus=pcie.0,addr=0x03.0x0[,multifunction=on] -+``` -+Note: the kernel must contain physical device drivers, otherwise it cannot be loaded normally. -+ -+## Hot plug management -+ -+StratoVirt standard VM supports hot-plug VFIO devices with QMP. -+Refer to qmp.md for specific command line parameters. -+ -+### Example -+ -+hot plug VFIO device: -+```json -+<- {"execute":"device_add", "arguments":{"id":"vfio-0", "driver":"vfio-pci", "bus": "pcie.1", "addr":"0x0", "host": "0000:1a:00.3"}} -+-> {"return": {}} -+``` -+hot unplug VFIO device: -+```json -+<- {"execute": "device_del", "arguments": {"id": "vfio-0"}} -+-> {"event":"DEVICE_DELETED","data":{"device":"vfio-0","path":"vfio-0"},"timestamp":{"seconds":1614310541,"microseconds":554250}} -+-> {"return": {}} -+``` -+ -+## Unbind VFIO device -+ -+If it is necessary to unbind VFIO device directly, you can execute the following command. -+Note: assume uses hinic driver -+```shell -+# echo 0000:03:00.0 > /sys/bus/pci/drivers/vfio-pci/unbind -+# echo 0000:03:00.0 > /sys/bus/pci/drivers/hinic/bind -+``` --- -2.25.1 - diff --git a/0016-docs-correct-the-command-for-booting-with-the-raw-im.patch b/0016-docs-correct-the-command-for-booting-with-the-raw-im.patch deleted file mode 100644 index 27bb0aea4dea2b8fad44dfcf0ee0ca01230bb537..0000000000000000000000000000000000000000 --- a/0016-docs-correct-the-command-for-booting-with-the-raw-im.patch +++ /dev/null @@ -1,64 +0,0 @@ -From f5435cecabd10dd8d7a97d9e0091e28b45e46957 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Mon, 7 Mar 2022 08:43:32 +0800 -Subject: [PATCH 1/8] docs: correct the command for booting with the raw image - -Signed-off-by: zhouli57 ---- - docs/boot.ch.md | 8 +++----- - docs/boot.md | 4 ++-- - 2 files changed, 5 insertions(+), 7 deletions(-) - -diff --git a/docs/boot.ch.md b/docs/boot.ch.md -index 31153a9..774e4a8 100644 ---- a/docs/boot.ch.md -+++ b/docs/boot.ch.md -@@ -225,7 +225,7 @@ fi - -m 2G \ - -append "console=${con} reboot=k panic=1 root=/dev/vda rw" \ - -drive file=/path/to/rootfs,id=rootfs,readonly=off,direct=off \ -- -device virtio-blk-device,drive=rootfs,id=rootfs \ -+ -device virtio-blk-pci,drive=rootfs,id=blk1,bus=pcie.0,addr=0x2 \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ - -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ -@@ -237,12 +237,10 @@ fi - ```shell - /usr/bin/stratovirt \ - -machine ${machine} \ -- -kernel /path/to/kernel \ - -smp 1 \ - -m 2G \ -- -append "console=${con} reboot=k panic=1 root=/dev/vda rw" \ -- -drive file=/path/to/rootfs,id=rootfs,readonly=off,direct=off \ -- -device virtio-blk-device,drive=rootfs \ -+ -drive file=/path/to/raw_image,id=raw_image,readonly=off,direct=off \ -+ -device virtio-blk-pci,drive=raw_image,id=blk1,bus=pcie.0,addr=0x2 \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ - -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ -diff --git a/docs/boot.md b/docs/boot.md -index 64d75b4..66541fa 100644 ---- a/docs/boot.md -+++ b/docs/boot.md -@@ -230,7 +230,7 @@ fi - -m 2G \ - -append "console=${con} reboot=k panic=1 root=/dev/vda rw" \ - -drive file=/path/to/rootfs,id=rootfs,readonly=off,direct=off \ -- -device virtio-blk-device,drive=rootfs,id=rootfs \ -+ -device virtio-blk-pci,drive=rootfs,id=blk1,bus=pcie.0,addr=0x2 \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ - -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ -@@ -245,7 +245,7 @@ The command for booting with the raw image is as follows: - -smp 1 \ - -m 2G \ - -drive file=/path/to/raw_image,id=raw_image,readonly=off,direct=off \ -- -device virtio-blk-device,drive=raw_image \ -+ -device virtio-blk-pci,drive=raw_image,id=blk1,bus=pcie.0,addr=0x2 \ - -drive file=/path/to/OVMF_CODE.fd,if=pflash,unit=0,readonly=true \ - -drive file=/path/to/OVMF_VARS.fd,if=pflash,unit=1 \ - -qmp unix:/path/to/socket,server,nowait \ --- -2.20.1 - diff --git a/0017-pci-no-need-to-delete-the-unmapped-region.patch b/0017-pci-no-need-to-delete-the-unmapped-region.patch deleted file mode 100644 index c15392f4e6b22465f5c6de4f8d4644632fcf47f7..0000000000000000000000000000000000000000 --- a/0017-pci-no-need-to-delete-the-unmapped-region.patch +++ /dev/null @@ -1,112 +0,0 @@ -From cd3d687aeaee2d94a1b09895b14f87a3f232cb22 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Mon, 7 Mar 2022 20:51:56 +0800 -Subject: [PATCH 2/8] pci: no need to delete the unmapped region - -When we hot-plug a pci device but fail for some reason, for example, -hot-plug to an unsupported bus, at this point, the device has finished -registering the region, and we need to clean up the registered region. -Because the device has not been actually used, the address in the BAR -may not have been updated, so there may be an error in unregister_bars. -in fact, there is no need to delete the unmapped region. - -Signed-off-by: zhouli57 ---- - pci/src/config.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++--- - 1 file changed, 71 insertions(+), 4 deletions(-) - -diff --git a/pci/src/config.rs b/pci/src/config.rs -index 88d7f03..c2b4c88 100644 ---- a/pci/src/config.rs -+++ b/pci/src/config.rs -@@ -569,11 +569,12 @@ impl PciConfig { - pub fn unregister_bars(&mut self, bus: &Arc>) -> Result<()> { - let locked_bus = bus.lock().unwrap(); - for bar in self.bars.iter_mut() { -+ if bar.address == BAR_SPACE_UNMAPPED || bar.size == 0 { -+ continue; -+ } - match bar.region_type { -- RegionType::Io => { -- if bar.address == BAR_SPACE_UNMAPPED || bar.size == 0 { -- continue; -- } -+ RegionType::Io => -+ { - #[cfg(target_arch = "x86_64")] - if let Some(region) = bar.region.as_ref() { - locked_bus -@@ -1102,4 +1103,70 @@ mod tests { - assert_eq!(size1, 0x10); - assert_eq!(size2, 0x40); - } -+ -+ #[test] -+ fn test_unregister_bars() { -+ let read_ops = move |_data: &mut [u8], _addr: GuestAddress, _offset: u64| -> bool { true }; -+ let write_ops = move |_data: &[u8], _addr: GuestAddress, _offset: u64| -> bool { true }; -+ let region_ops = RegionOps { -+ read: Arc::new(read_ops), -+ write: Arc::new(write_ops), -+ }; -+ let region = Region::init_io_region(2048, region_ops); -+ let mut pci_config = PciConfig::new(PCI_CONFIG_SPACE_SIZE, 3); -+ -+ // bar is unmapped -+ #[cfg(target_arch = "x86_64")] -+ pci_config.register_bar(0, region.clone(), RegionType::Io, false, 2048); -+ pci_config.register_bar(1, region.clone(), RegionType::Mem32Bit, false, 2048); -+ pci_config.register_bar(2, region.clone(), RegionType::Mem64Bit, true, 2048); -+ -+ #[cfg(target_arch = "x86_64")] -+ let io_region = Region::init_container_region(1 << 16); -+ let mem_region = Region::init_container_region(u64::max_value()); -+ let bus = Arc::new(Mutex::new(PciBus::new( -+ String::from("bus"), -+ #[cfg(target_arch = "x86_64")] -+ io_region.clone(), -+ mem_region.clone(), -+ ))); -+ -+ assert!(pci_config.unregister_bars(&bus).is_ok()); -+ -+ // bar is mapped -+ #[cfg(target_arch = "x86_64")] -+ pci_config.register_bar(0, region.clone(), RegionType::Io, false, 2048); -+ pci_config.register_bar(1, region.clone(), RegionType::Mem32Bit, false, 2048); -+ pci_config.register_bar(2, region.clone(), RegionType::Mem64Bit, true, 2048); -+ -+ #[cfg(target_arch = "x86_64")] -+ le_write_u32( -+ &mut pci_config.config, -+ BAR_0 as usize, -+ 2048 | BAR_IO_SPACE as u32, -+ ) -+ .unwrap(); -+ le_write_u32(&mut pci_config.config, BAR_0 as usize + REG_SIZE, 2048).unwrap(); -+ le_write_u32( -+ &mut pci_config.config, -+ BAR_0 as usize + 2 * REG_SIZE, -+ 2048 | BAR_MEM_64BIT as u32 | BAR_PREFETCH as u32, -+ ) -+ .unwrap(); -+ le_write_u16( -+ &mut pci_config.config, -+ COMMAND as usize, -+ COMMAND_IO_SPACE | COMMAND_MEMORY_SPACE, -+ ) -+ .unwrap(); -+ pci_config -+ .update_bar_mapping( -+ #[cfg(target_arch = "x86_64")] -+ &io_region, -+ &mem_region, -+ ) -+ .unwrap(); -+ -+ assert!(pci_config.unregister_bars(&bus).is_ok()); -+ } - } --- -2.20.1 - diff --git a/0018-arm-use-the-HighPcieEcam-region.patch b/0018-arm-use-the-HighPcieEcam-region.patch deleted file mode 100644 index 47cc00c47dfb6b8b5d79499cb61f03425503d49b..0000000000000000000000000000000000000000 --- a/0018-arm-use-the-HighPcieEcam-region.patch +++ /dev/null @@ -1,61 +0,0 @@ -From afe05089a4284acef30a97fb88435fea46e29d8e Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Fri, 11 Mar 2022 14:22:07 +0800 -Subject: [PATCH 3/8] arm: use the HighPcieEcam region - -We use 16MB ECAM region on arm, which only support 16 pcie buses, and -now we use the high ECAM region, which can support 256 pcie buses. - -Signed-off-by: zhouli57 ---- - machine/src/standard_vm/aarch64/mod.rs | 14 +++++++------- - 1 file changed, 7 insertions(+), 7 deletions(-) - -diff --git a/machine/src/standard_vm/aarch64/mod.rs b/machine/src/standard_vm/aarch64/mod.rs -index 1e6fc6c..ddf8a41 100644 ---- a/machine/src/standard_vm/aarch64/mod.rs -+++ b/machine/src/standard_vm/aarch64/mod.rs -@@ -141,8 +141,8 @@ impl StdMachine { - sysbus, - pci_host: Arc::new(Mutex::new(PciHost::new( - &sys_mem, -- MEM_LAYOUT[LayoutEntryType::PcieEcam as usize], -- MEM_LAYOUT[LayoutEntryType::PcieMmio as usize], -+ MEM_LAYOUT[LayoutEntryType::HighPcieEcam as usize], -+ MEM_LAYOUT[LayoutEntryType::HighPcieMmio as usize], - ))), - boot_source: Arc::new(Mutex::new(vm_config.clone().boot_source)), - vm_state: Arc::new((Mutex::new(KvmVmState::Created), Condvar::new())), -@@ -221,14 +221,14 @@ impl StdMachineOps for StdMachine { - let root_bus = Arc::downgrade(&self.pci_host.lock().unwrap().root_bus); - let mmconfig_region_ops = PciHost::build_mmconfig_ops(self.pci_host.clone()); - let mmconfig_region = Region::init_io_region( -- MEM_LAYOUT[LayoutEntryType::PcieEcam as usize].1, -+ MEM_LAYOUT[LayoutEntryType::HighPcieEcam as usize].1, - mmconfig_region_ops, - ); - self.sys_mem - .root() - .add_subregion( - mmconfig_region, -- MEM_LAYOUT[LayoutEntryType::PcieEcam as usize].0, -+ MEM_LAYOUT[LayoutEntryType::HighPcieEcam as usize].0, - ) - .chain_err(|| "Failed to register ECAM in memory space.")?; - -@@ -645,9 +645,9 @@ impl EventLoopManager for StdMachine { - // - // * `fdt` - Flatted device-tree blob where node will be filled into. - fn generate_pci_host_node(fdt: &mut FdtBuilder) -> util::errors::Result<()> { -- let pcie_ecam_base = MEM_LAYOUT[LayoutEntryType::PcieEcam as usize].0; -- let pcie_ecam_size = MEM_LAYOUT[LayoutEntryType::PcieEcam as usize].1; -- let pcie_buses_num = MEM_LAYOUT[LayoutEntryType::PcieEcam as usize].1 >> 20; -+ let pcie_ecam_base = MEM_LAYOUT[LayoutEntryType::HighPcieEcam as usize].0; -+ let pcie_ecam_size = MEM_LAYOUT[LayoutEntryType::HighPcieEcam as usize].1; -+ let pcie_buses_num = MEM_LAYOUT[LayoutEntryType::HighPcieEcam as usize].1 >> 20; - let node = format!("pcie@{:x}", pcie_ecam_base); - let pci_node_dep = fdt.begin_node(&node)?; - fdt.set_property_string("compatible", "pci-host-ecam-generic")?; --- -2.20.1 - diff --git a/0019-vfio-fix-hot-plug-the-same-device-multiple-times-pro.patch b/0019-vfio-fix-hot-plug-the-same-device-multiple-times-pro.patch deleted file mode 100644 index 1f5847899186608d250a47000e34958ea74659de..0000000000000000000000000000000000000000 --- a/0019-vfio-fix-hot-plug-the-same-device-multiple-times-pro.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 13e120e99398ece2ceab00f90d0087123309ea60 Mon Sep 17 00:00:00 2001 -From: "Xinle.Guo" -Date: Fri, 11 Mar 2022 14:50:48 +0800 -Subject: [PATCH 4/8] vfio: fix hot plug the same device multiple times problem - -It will success to hot plug the same device after the second -time. But this is not what we expected. So, we check if the -device name is repeated before get VFIO device. - -Signed-off-by: Xinle.Guo ---- - vfio/src/vfio_dev.rs | 17 ++++++++++++++--- - 1 file changed, 14 insertions(+), 3 deletions(-) - -diff --git a/vfio/src/vfio_dev.rs b/vfio/src/vfio_dev.rs -index 9607b71..198421c 100644 ---- a/vfio/src/vfio_dev.rs -+++ b/vfio/src/vfio_dev.rs -@@ -464,6 +464,8 @@ pub struct VfioDevInfo { - pub struct VfioDevice { - /// File descriptor for a VFIO device instance. - pub fd: File, -+ /// Identify the unique VFIO device. -+ pub name: String, - /// Vfio group the device belongs to. - pub group: Weak, - /// Vfio container the device belongs to. -@@ -515,10 +517,12 @@ impl VfioDevice { - - let group = - Self::vfio_get_group(&path, mem_as).chain_err(|| "Failed to get iommu group")?; -- let fd = Self::vfio_get_device(&group, &path).chain_err(|| "Failed to get vfio device")?; -+ let (name, fd) = -+ Self::vfio_get_device(&group, &path).chain_err(|| "Failed to get vfio device")?; - let dev_info = Self::get_dev_info(&fd).chain_err(|| "Failed to get device info")?; - let vfio_dev = Arc::new(Mutex::new(VfioDevice { - fd, -+ name, - group: Arc::downgrade(&group), - container: group.container.clone(), - dev_info, -@@ -569,11 +573,18 @@ impl VfioDevice { - Ok(group) - } - -- fn vfio_get_device(group: &VfioGroup, name: &Path) -> Result { -+ fn vfio_get_device(group: &VfioGroup, name: &Path) -> Result<(String, File)> { - let mut dev_name: &str = ""; - if let Some(n) = name.file_name() { - dev_name = n.to_str().chain_err(|| "Invalid device path")?; - } -+ -+ for device in group.devices.lock().unwrap().iter() { -+ if device.1.lock().unwrap().name == dev_name { -+ bail!("Device {} is already attached", dev_name); -+ } -+ } -+ - let path: CString = CString::new(dev_name.as_bytes()) - .chain_err(|| "Failed to convert device name to CString type of data")?; - let ptr = path.as_ptr(); -@@ -589,7 +600,7 @@ impl VfioDevice { - - // Safe as we have verified that fd is a valid FD. - let device = unsafe { File::from_raw_fd(fd) }; -- Ok(device) -+ Ok((String::from(dev_name), device)) - } - - fn get_dev_info(device: &File) -> Result { --- -2.20.1 - diff --git a/0020-machine-update-seccomp-rules.patch b/0020-machine-update-seccomp-rules.patch deleted file mode 100644 index ebf29ee567c6219b3742687a2c1703be2a9c62f6..0000000000000000000000000000000000000000 --- a/0020-machine-update-seccomp-rules.patch +++ /dev/null @@ -1,226 +0,0 @@ -From 639982129fb79cc8f175497cd5b091a6dfd3ec40 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Tue, 8 Mar 2022 15:42:13 +0800 -Subject: [PATCH 5/8] machine: update seccomp rules - -Fix the problem of snapshot failure caused by compiling with a new -version(1.57) of the compiler on openEuler 22.03 LTS. - -Signed-off-by: zhouli57 ---- - machine/src/micro_vm/syscall.rs | 46 ++++++++++++++++---- - machine/src/standard_vm/aarch64/syscall.rs | 33 +++++++++++---- - machine/src/standard_vm/x86_64/syscall.rs | 49 +++++++++++++++++----- - 3 files changed, 102 insertions(+), 26 deletions(-) - -diff --git a/machine/src/micro_vm/syscall.rs b/machine/src/micro_vm/syscall.rs -index ff066a9..5e9c6d8 100644 ---- a/machine/src/micro_vm/syscall.rs -+++ b/machine/src/micro_vm/syscall.rs -@@ -22,6 +22,7 @@ const FUTEX_CMP_REQUEUE: u32 = 4; - const FUTEX_WAKE_OP: u32 = 5; - const FUTEX_WAIT_BITSET: u32 = 9; - const FUTEX_PRIVATE_FLAG: u32 = 128; -+const FUTEX_CLOCK_REALTIME: u32 = 256; - const FUTEX_WAIT_PRIVATE: u32 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; - const FUTEX_WAKE_PRIVATE: u32 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; - const FUTEX_CMP_REQUEUE_PRIVATE: u32 = FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG; -@@ -88,12 +89,7 @@ pub fn syscall_whitelist() -> Vec { - BpfRule::new(libc::SYS_munmap), - BpfRule::new(libc::SYS_accept4), - BpfRule::new(libc::SYS_lseek), -- BpfRule::new(libc::SYS_futex) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE), -+ futex_rule(), - BpfRule::new(libc::SYS_exit), - BpfRule::new(libc::SYS_exit_group), - BpfRule::new(libc::SYS_rt_sigreturn), -@@ -121,9 +117,7 @@ pub fn syscall_whitelist() -> Vec { - BpfRule::new(libc::SYS_mkdir), - #[cfg(target_arch = "aarch64")] - BpfRule::new(libc::SYS_mkdirat), -- BpfRule::new(libc::SYS_madvise) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32), -+ madvise_rule(), - ] - } - -@@ -181,3 +175,37 @@ fn ioctl_arch_allow_list(bpf_rule: BpfRule) -> BpfRule { - .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_DEVICE_ATTR() as u32) - .add_constraint(SeccompCmpOpt::Eq, 1, KVM_GET_REG_LIST() as u32) - } -+ -+fn madvise_rule() -> BpfRule { -+ #[cfg(all(target_env = "musl", target_arch = "x86_64"))] -+ return BpfRule::new(libc::SYS_madvise) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_FREE as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32); -+ #[cfg(not(all(target_env = "musl", target_arch = "x86_64")))] -+ return BpfRule::new(libc::SYS_madvise) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32); -+} -+ -+fn futex_rule() -> BpfRule { -+ #[cfg(target_env = "musl")] -+ return BpfRule::new(libc::SYS_futex) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE); -+ #[cfg(target_env = "gnu")] -+ return BpfRule::new(libc::SYS_futex) -+ .add_constraint( -+ SeccompCmpOpt::Eq, -+ 1, -+ FUTEX_WAIT_BITSET_PRIVATE | FUTEX_CLOCK_REALTIME, -+ ) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE); -+} -diff --git a/machine/src/standard_vm/aarch64/syscall.rs b/machine/src/standard_vm/aarch64/syscall.rs -index e8ecdd5..ed3140e 100644 ---- a/machine/src/standard_vm/aarch64/syscall.rs -+++ b/machine/src/standard_vm/aarch64/syscall.rs -@@ -28,6 +28,7 @@ const FUTEX_CMP_REQUEUE: u32 = 4; - const FUTEX_WAKE_OP: u32 = 5; - const FUTEX_WAIT_BITSET: u32 = 9; - const FUTEX_PRIVATE_FLAG: u32 = 128; -+const FUTEX_CLOCK_REALTIME: u32 = 256; - const FUTEX_WAIT_PRIVATE: u32 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; - const FUTEX_WAKE_PRIVATE: u32 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; - const FUTEX_CMP_REQUEUE_PRIVATE: u32 = FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG; -@@ -91,13 +92,7 @@ pub fn syscall_whitelist() -> Vec { - BpfRule::new(libc::SYS_munmap), - BpfRule::new(libc::SYS_accept4), - BpfRule::new(libc::SYS_lseek), -- BpfRule::new(libc::SYS_futex) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE), -+ futex_rule(), - BpfRule::new(libc::SYS_exit), - BpfRule::new(libc::SYS_exit_group), - BpfRule::new(libc::SYS_rt_sigreturn), -@@ -189,3 +184,27 @@ fn madvise_rule() -> BpfRule { - .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) - .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32); - } -+ -+fn futex_rule() -> BpfRule { -+ #[cfg(target_env = "musl")] -+ return BpfRule::new(libc::SYS_futex) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE); -+ #[cfg(target_env = "gnu")] -+ return BpfRule::new(libc::SYS_futex) -+ .add_constraint( -+ SeccompCmpOpt::Eq, -+ 1, -+ FUTEX_WAIT_BITSET_PRIVATE | FUTEX_CLOCK_REALTIME, -+ ) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE); -+} -diff --git a/machine/src/standard_vm/x86_64/syscall.rs b/machine/src/standard_vm/x86_64/syscall.rs -index f39170a..6f8e10d 100644 ---- a/machine/src/standard_vm/x86_64/syscall.rs -+++ b/machine/src/standard_vm/x86_64/syscall.rs -@@ -28,6 +28,7 @@ const FUTEX_CMP_REQUEUE: u32 = 4; - const FUTEX_WAKE_OP: u32 = 5; - const FUTEX_WAIT_BITSET: u32 = 9; - const FUTEX_PRIVATE_FLAG: u32 = 128; -+const FUTEX_CLOCK_REALTIME: u32 = 256; - const FUTEX_WAIT_PRIVATE: u32 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; - const FUTEX_WAKE_PRIVATE: u32 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; - const FUTEX_CMP_REQUEUE_PRIVATE: u32 = FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG; -@@ -94,12 +95,7 @@ pub fn syscall_whitelist() -> Vec { - BpfRule::new(libc::SYS_munmap), - BpfRule::new(libc::SYS_accept4), - BpfRule::new(libc::SYS_lseek), -- BpfRule::new(libc::SYS_futex) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -- .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE), -+ futex_rule(), - BpfRule::new(libc::SYS_exit), - BpfRule::new(libc::SYS_exit_group), - BpfRule::new(libc::SYS_rt_sigreturn), -@@ -118,10 +114,7 @@ pub fn syscall_whitelist() -> Vec { - BpfRule::new(libc::SYS_statx), - BpfRule::new(libc::SYS_mkdir), - BpfRule::new(libc::SYS_unlink), -- BpfRule::new(libc::SYS_madvise) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) -- .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32), -+ madvise_rule(), - BpfRule::new(libc::SYS_msync), - BpfRule::new(libc::SYS_readlinkat), - #[cfg(target_env = "musl")] -@@ -202,3 +195,39 @@ fn ioctl_allow_list() -> BpfRule { - .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_MSRS() as u32) - .add_constraint(SeccompCmpOpt::Eq, 1, KVM_SET_VCPU_EVENTS() as u32) - } -+ -+fn madvise_rule() -> BpfRule { -+ #[cfg(target_env = "musl")] -+ return BpfRule::new(libc::SYS_madvise) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_FREE as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32); -+ #[cfg(target_env = "gnu")] -+ return BpfRule::new(libc::SYS_madvise) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_WILLNEED as u32) -+ .add_constraint(SeccompCmpOpt::Eq, 2, libc::MADV_DONTDUMP as u32); -+} -+ -+fn futex_rule() -> BpfRule { -+ #[cfg(target_env = "musl")] -+ return BpfRule::new(libc::SYS_futex) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE); -+ #[cfg(target_env = "gnu")] -+ return BpfRule::new(libc::SYS_futex) -+ .add_constraint( -+ SeccompCmpOpt::Eq, -+ 1, -+ FUTEX_WAIT_BITSET_PRIVATE | FUTEX_CLOCK_REALTIME, -+ ) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_CMP_REQUEUE_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAKE_OP_PRIVATE) -+ .add_constraint(SeccompCmpOpt::Eq, 1, FUTEX_WAIT_BITSET_PRIVATE); -+} --- -2.20.1 - diff --git a/0021-console-fix-the-bug-of-delete-park-fd.patch b/0021-console-fix-the-bug-of-delete-park-fd.patch deleted file mode 100644 index ed17ecbe0ffab12878e946639c50e8f76e03b820..0000000000000000000000000000000000000000 --- a/0021-console-fix-the-bug-of-delete-park-fd.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 0dbad5e4ba71f344767fee9d7180495d8cb26a84 Mon Sep 17 00:00:00 2001 -From: Jiajie Li -Date: Fri, 11 Mar 2022 21:24:16 +0800 -Subject: [PATCH 6/8] console: fix the bug of delete park fd - -Console device need two fd: listen_fd and stream_fd. Only one of -them can be valid in event loop. When stream_fd is valid, it will -park stream fd. At this time, send the reboot command through the -console device, deactivate function will delete both of these fds. -But the sequence is importent. If you delete listen_fd first, then -deleting stream_fd will try to delete the listen_fd which is it's -park fd. It will get an error: NoParkedFd. - -Fix it by delete delete stream_fd first. - -Signed-off-by: Jiajie Li ---- - virtio/src/console.rs | 16 ++++++++-------- - 1 file changed, 8 insertions(+), 8 deletions(-) - -diff --git a/virtio/src/console.rs b/virtio/src/console.rs -index 48d3838..1192d28 100644 ---- a/virtio/src/console.rs -+++ b/virtio/src/console.rs -@@ -234,14 +234,6 @@ impl ConsoleHandler { - } - } - ChardevType::Socket(_) => { -- let listener_fd = locked_chardev.listener.as_ref().unwrap().as_raw_fd(); -- notifiers.push(EventNotifier::new( -- NotifierOperation::Delete, -- listener_fd, -- None, -- EventSet::IN, -- Vec::new(), -- )); - if let Some(stream_fd) = locked_chardev.stream_fd { - notifiers.push(EventNotifier::new( - NotifierOperation::Delete, -@@ -251,6 +243,14 @@ impl ConsoleHandler { - Vec::new(), - )); - } -+ let listener_fd = locked_chardev.listener.as_ref().unwrap().as_raw_fd(); -+ notifiers.push(EventNotifier::new( -+ NotifierOperation::Delete, -+ listener_fd, -+ None, -+ EventSet::IN, -+ Vec::new(), -+ )); - } - _ => (), - } --- -2.20.1 - diff --git a/0022-docs-add-the-description-of-hot-plug-of-PCI-devices.patch b/0022-docs-add-the-description-of-hot-plug-of-PCI-devices.patch deleted file mode 100644 index 15bba5113d3c84a73b2fa621c98220078db224cb..0000000000000000000000000000000000000000 --- a/0022-docs-add-the-description-of-hot-plug-of-PCI-devices.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 00927b92ea59d61ac757f942c0b88a9413ab1105 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Sat, 12 Mar 2022 09:05:03 +0800 -Subject: [PATCH 7/8] docs: add the description of hot plug of PCI devices - -Signed-off-by: zhouli57 ---- - docs/qmp.md | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/docs/qmp.md b/docs/qmp.md -index be933fa..ceee6fd 100644 ---- a/docs/qmp.md -+++ b/docs/qmp.md -@@ -166,6 +166,8 @@ Add a device. - - * Guest kernel config: CONFIG_HOTPLUG_PCI_PCIE=y - -+* You are not advised to hot plug/unplug devices during VM startup, shutdown or suspension, or when the VM is under high pressure. In this case, the driver in the VM may not respond to requests, causing VM exceptions. -+ - #### Example - - ```json --- -2.20.1 - diff --git a/0023-Modify-cargo-cllippy-warning-when-compiling-cargo-cl.patch b/0023-Modify-cargo-cllippy-warning-when-compiling-cargo-cl.patch deleted file mode 100644 index a573d85568ede99f2987005557f0033b40c366bc..0000000000000000000000000000000000000000 --- a/0023-Modify-cargo-cllippy-warning-when-compiling-cargo-cl.patch +++ /dev/null @@ -1,1439 +0,0 @@ -From 4df5013eb6ac7e2e24445bc87e4d92840c70611a Mon Sep 17 00:00:00 2001 -From: ace yan -Date: Sat, 12 Mar 2022 22:35:04 +0800 -Subject: [PATCH 8/8] Modify cargo cllippy warning when compiling cargo cllippy - in high version rust. - -Signed-off-by: Yan Wen ---- - acpi/src/aml_compiler.rs | 6 ++--- - address_space/src/address.rs | 2 +- - address_space/src/address_space.rs | 4 +-- - address_space/src/host_mmap.rs | 2 +- - address_space/src/region.rs | 2 +- - boot_loader/src/x86_64/bootparam.rs | 28 ++++++++++---------- - boot_loader/src/x86_64/direct_boot/mod.rs | 12 ++++----- - boot_loader/src/x86_64/standard_boot/mod.rs | 4 +-- - cpu/src/x86_64/caps.rs | 8 +----- - cpu/src/x86_64/mod.rs | 6 ++--- - devices/src/legacy/pflash.rs | 24 +++++++---------- - machine/src/lib.rs | 10 +++---- - machine/src/micro_vm/mod.rs | 6 ++--- - machine/src/standard_vm/aarch64/mod.rs | 9 ------- - machine/src/standard_vm/mod.rs | 12 ++++----- - machine/src/standard_vm/x86_64/ich9_lpc.rs | 1 - - machine_manager/src/cmdline.rs | 4 +-- - machine_manager/src/config/boot_source.rs | 3 --- - machine_manager/src/config/chardev.rs | 2 +- - machine_manager/src/config/devices.rs | 4 +-- - machine_manager/src/config/drive.rs | 19 +++---------- - machine_manager/src/config/machine_config.rs | 13 ++++----- - machine_manager/src/config/mod.rs | 8 +++--- - machine_manager/src/config/network.rs | 3 --- - machine_manager/src/config/vfio.rs | 10 +------ - machine_manager/src/event_loop.rs | 2 -- - machine_manager/src/lib.rs | 1 - - machine_manager/src/machine.rs | 6 ++--- - machine_manager/src/qmp/mod.rs | 2 -- - machine_manager/src/qmp/qmp_schema.rs | 7 ----- - machine_manager/src/socket.rs | 3 ++- - migration/src/header.rs | 2 ++ - migration/src/manager.rs | 4 +-- - migration_derive/src/field_parser.rs | 10 +++---- - migration_derive/src/lib.rs | 1 - - ozone/src/capability.rs | 2 +- - ozone/src/cgroup.rs | 4 +-- - pci/src/bus.rs | 4 +-- - pci/src/host.rs | 1 + - pci/src/lib.rs | 2 +- - pci/src/msix.rs | 8 +++--- - src/main.rs | 8 +++--- - util/src/arg_parser.rs | 6 ++--- - util/src/daemonize.rs | 2 -- - util/src/logger.rs | 3 --- - util/src/seccomp.rs | 2 -- - util/src/tap.rs | 2 +- - util/src/unix.rs | 2 -- - vfio/src/vfio_dev.rs | 9 +++---- - vfio/src/vfio_pci.rs | 6 +---- - virtio/src/balloon.rs | 6 +++-- - virtio/src/block.rs | 2 +- - virtio/src/queue.rs | 8 +++--- - virtio/src/vhost/kernel/mod.rs | 4 +-- - 54 files changed, 120 insertions(+), 201 deletions(-) - -diff --git a/acpi/src/aml_compiler.rs b/acpi/src/aml_compiler.rs -index 0c4c59d..3fa4fa0 100644 ---- a/acpi/src/aml_compiler.rs -+++ b/acpi/src/aml_compiler.rs -@@ -153,7 +153,7 @@ fn build_name_string(name: &str) -> Vec { - 2 => { - bytes.push(0x2E); - bytes.append(&mut build_name_seg(&remain_first)); -- bytes.append(&mut build_name_seg(&strs[1].to_string())); -+ bytes.append(&mut build_name_seg(strs[1])); - } - _ => { - bytes.push(0x2F); -@@ -161,7 +161,7 @@ fn build_name_string(name: &str) -> Vec { - bytes.append(&mut build_name_seg(&remain_first)); - - strs.iter().skip(1).for_each(|s| { -- bytes.extend(build_name_seg(&s.to_string())); -+ bytes.extend(build_name_seg(s)); - }) - } - } -@@ -604,7 +604,7 @@ impl AmlBuilder for AmlFieldUnit { - let mut bytes = self - .name - .as_ref() -- .map(|str| build_name_seg(&str)) -+ .map(|str| build_name_seg(str)) - .unwrap_or_else(|| vec![0x0_u8]); - bytes.extend(build_pkg_length(self.length as usize, false)); - bytes -diff --git a/address_space/src/address.rs b/address_space/src/address.rs -index 803b672..e7760c3 100644 ---- a/address_space/src/address.rs -+++ b/address_space/src/address.rs -@@ -143,7 +143,7 @@ impl PartialOrd for AddressRange { - /// Implement Ord trait for AddressRange. - impl Ord for AddressRange { - fn cmp(&self, other: &AddressRange) -> Ordering { -- self.partial_cmp(&other).unwrap() -+ self.partial_cmp(other).unwrap() - } - } - -diff --git a/address_space/src/address_space.rs b/address_space/src/address_space.rs -index 949c305..81774da 100644 ---- a/address_space/src/address_space.rs -+++ b/address_space/src/address_space.rs -@@ -112,7 +112,7 @@ impl AddressSpace { - pub fn register_listener(&self, listener: ListenerObj) -> Result<()> { - let mut locked_listener = listener.lock().unwrap(); - for fr in self.flat_view.load().0.iter() { -- locked_listener.handle_request(Some(&fr), None, ListenerReqType::AddRegion)?; -+ locked_listener.handle_request(Some(fr), None, ListenerReqType::AddRegion)?; - } - locked_listener.enable(); - -@@ -141,7 +141,7 @@ impl AddressSpace { - pub fn unregister_listener(&self, listener: ListenerObj) -> Result<()> { - let mut locked_listener = listener.lock().unwrap(); - for fr in self.flat_view.load().0.iter() { -- locked_listener.handle_request(Some(&fr), None, ListenerReqType::DeleteRegion)?; -+ locked_listener.handle_request(Some(fr), None, ListenerReqType::DeleteRegion)?; - } - locked_listener.disable(); - drop(locked_listener); -diff --git a/address_space/src/host_mmap.rs b/address_space/src/host_mmap.rs -index 27e768b..1a6b0a8 100644 ---- a/address_space/src/host_mmap.rs -+++ b/address_space/src/host_mmap.rs -@@ -220,7 +220,7 @@ pub fn create_host_mmaps( - if let Some(path) = &mem_config.mem_path { - let file_len = ranges.iter().fold(0, |acc, x| acc + x.1); - f_back = Some( -- FileBackend::new_mem(&path, file_len) -+ FileBackend::new_mem(path, file_len) - .chain_err(|| "Failed to create file that backs memory")?, - ); - } else if mem_config.mem_share { -diff --git a/address_space/src/region.rs b/address_space/src/region.rs -index f88c63e..7c9e8da 100644 ---- a/address_space/src/region.rs -+++ b/address_space/src/region.rs -@@ -358,7 +358,7 @@ impl Region { - /// - /// * `space` - The AddressSpace that the region belongs to. - pub(crate) fn set_belonged_address_space(&self, space: &Arc) { -- *self.space.write().unwrap() = Arc::downgrade(&space); -+ *self.space.write().unwrap() = Arc::downgrade(space); - } - - /// Release the address space this region belongs to, -diff --git a/boot_loader/src/x86_64/bootparam.rs b/boot_loader/src/x86_64/bootparam.rs -index 82beb21..8f1b35d 100644 ---- a/boot_loader/src/x86_64/bootparam.rs -+++ b/boot_loader/src/x86_64/bootparam.rs -@@ -267,22 +267,22 @@ mod test { - boot_params.setup_e820_entries(&config, &space); - assert_eq!(boot_params.e820_entries, 4); - -- unsafe { -- assert_eq!(boot_params.e820_table[0].addr, 0); -- assert_eq!(boot_params.e820_table[0].size, 0x0009_FC00); -- assert_eq!(boot_params.e820_table[0].type_, 1); -+ assert!(boot_params.e820_table[0].addr == 0); - -- assert_eq!(boot_params.e820_table[1].addr, 0x0009_FC00); -- assert_eq!(boot_params.e820_table[1].size, 0x400); -- assert_eq!(boot_params.e820_table[1].type_, 2); -+ assert!(boot_params.e820_table[0].addr == 0); -+ assert!(boot_params.e820_table[0].size == 0x0009_FC00); -+ assert!(boot_params.e820_table[0].type_ == 1); - -- assert_eq!(boot_params.e820_table[2].addr, 0x000F_0000); -- assert_eq!(boot_params.e820_table[2].size, 0); -- assert_eq!(boot_params.e820_table[2].type_, 2); -+ assert!(boot_params.e820_table[1].addr == 0x0009_FC00); -+ assert!(boot_params.e820_table[1].size == 0x400); -+ assert!(boot_params.e820_table[1].type_ == 2); - -- assert_eq!(boot_params.e820_table[3].addr, 0x0010_0000); -- assert_eq!(boot_params.e820_table[3].size, 0x0ff0_0000); -- assert_eq!(boot_params.e820_table[3].type_, 1); -- } -+ assert!(boot_params.e820_table[2].addr == 0x000F_0000); -+ assert!(boot_params.e820_table[2].size == 0); -+ assert!(boot_params.e820_table[2].type_ == 2); -+ -+ assert!(boot_params.e820_table[3].addr == 0x0010_0000); -+ assert!(boot_params.e820_table[3].size == 0x0ff0_0000); -+ assert!(boot_params.e820_table[3].type_ == 1); - } - } -diff --git a/boot_loader/src/x86_64/direct_boot/mod.rs b/boot_loader/src/x86_64/direct_boot/mod.rs -index 915b0cf..da0c123 100644 ---- a/boot_loader/src/x86_64/direct_boot/mod.rs -+++ b/boot_loader/src/x86_64/direct_boot/mod.rs -@@ -55,7 +55,7 @@ pub fn load_bzimage(kernel_image: &mut File) -> Result { - - kernel_image.seek(SeekFrom::Start(BOOT_HDR_START))?; - kernel_image -- .read_exact(&mut boot_hdr.as_mut_bytes()) -+ .read_exact(boot_hdr.as_mut_bytes()) - .chain_err(|| "Failed to read boot_hdr from bzImage kernel")?; - boot_hdr.type_of_loader = UNDEFINED_ID; - -@@ -115,7 +115,7 @@ fn load_kernel_image( - ) - }; - -- load_image(&mut kernel_image, vmlinux_start, &sys_mem).chain_err(|| "Failed to load image")?; -+ load_image(&mut kernel_image, vmlinux_start, sys_mem).chain_err(|| "Failed to load image")?; - - boot_layout.boot_ip = kernel_start; - -@@ -142,7 +142,7 @@ fn load_initrd( - let initrd_size = initrd_image.metadata().unwrap().len() as u64; - let initrd_addr = (initrd_addr_max - initrd_size) & !0xfff_u64; - -- load_image(&mut initrd_image, initrd_addr, &sys_mem).chain_err(|| "Failed to load image")?; -+ load_image(&mut initrd_image, initrd_addr, sys_mem).chain_err(|| "Failed to load image")?; - - header.set_ramdisk(initrd_addr as u32, initrd_size as u32); - -@@ -186,7 +186,7 @@ fn setup_boot_params( - boot_hdr: &RealModeKernelHeader, - ) -> Result<()> { - let mut boot_params = BootParams::new(*boot_hdr); -- boot_params.setup_e820_entries(&config, sys_mem); -+ boot_params.setup_e820_entries(config, sys_mem); - sys_mem - .write_object(&boot_params, GuestAddress(ZERO_PAGE_START)) - .chain_err(|| format!("Failed to load zero page to 0x{:x}", ZERO_PAGE_START))?; -@@ -244,7 +244,7 @@ pub fn load_linux( - ..Default::default() - }; - let mut boot_header = load_kernel_image( -- &config.kernel.as_ref().unwrap(), -+ config.kernel.as_ref().unwrap(), - sys_mem, - &mut boot_loader_layout, - )?; -@@ -252,7 +252,7 @@ pub fn load_linux( - load_initrd(config, sys_mem, &mut boot_header) - .chain_err(|| "Failed to load initrd to vm memory")?; - -- setup_kernel_cmdline(&config, sys_mem, &mut boot_header) -+ setup_kernel_cmdline(config, sys_mem, &mut boot_header) - .chain_err(|| "Failed to setup kernel cmdline")?; - - setup_boot_params(config, sys_mem, &boot_header).chain_err(|| "Failed to setup boot params")?; -diff --git a/boot_loader/src/x86_64/standard_boot/mod.rs b/boot_loader/src/x86_64/standard_boot/mod.rs -index 92a0552..49e8a03 100644 ---- a/boot_loader/src/x86_64/standard_boot/mod.rs -+++ b/boot_loader/src/x86_64/standard_boot/mod.rs -@@ -21,13 +21,13 @@ use address_space::AddressSpace; - use devices::legacy::{FwCfgEntryType, FwCfgOps}; - use util::byte_code::ByteCode; - -+use self::elf::load_elf_kernel; - use super::bootparam::RealModeKernelHeader; - use super::X86BootLoaderConfig; - use super::{BOOT_HDR_START, CMDLINE_START}; - use crate::errors::{ErrorKind, Result, ResultExt}; - use crate::x86_64::bootparam::{E820Entry, E820_RAM, E820_RESERVED, UEFI_OVMF_ID}; - use crate::x86_64::{INITRD_ADDR_MAX, SETUP_START}; --use elf::load_elf_kernel; - - fn load_image( - image: &mut File, -@@ -219,7 +219,7 @@ pub fn load_linux( - if let Err(e) = boot_header.check_valid_kernel() { - match e.kind() { - ErrorKind::ElfKernel => { -- load_elf_kernel(&mut kernel_image, &sys_mem, fwcfg)?; -+ load_elf_kernel(&mut kernel_image, sys_mem, fwcfg)?; - return Ok(()); - } - _ => return Err(e), -diff --git a/cpu/src/x86_64/caps.rs b/cpu/src/x86_64/caps.rs -index 7b0a34c..4bf75fb 100644 ---- a/cpu/src/x86_64/caps.rs -+++ b/cpu/src/x86_64/caps.rs -@@ -40,13 +40,7 @@ impl X86CPUCaps { - X86CPUCaps { - has_xsave: kvm.check_extension(Cap::Xsave), - has_xcrs: kvm.check_extension(Cap::Xcrs), -- supported_msrs: kvm -- .get_msr_index_list() -- .unwrap() -- .as_slice() -- .iter() -- .copied() -- .collect(), -+ supported_msrs: kvm.get_msr_index_list().unwrap().as_slice().to_vec(), - } - } - -diff --git a/cpu/src/x86_64/mod.rs b/cpu/src/x86_64/mod.rs -index 7b7a183..37e0f84 100644 ---- a/cpu/src/x86_64/mod.rs -+++ b/cpu/src/x86_64/mod.rs -@@ -22,9 +22,9 @@ use kvm_bindings::{ - }; - use kvm_ioctls::{Kvm, VcpuFd}; - -+use self::cpuid::host_cpuid; - use crate::errors::{Result, ResultExt}; - use crate::CPU; --use cpuid::host_cpuid; - use migration::{DeviceStateDesc, FieldDesc, MigrationHook, MigrationManager, StateTransfer}; - use util::byte_code::ByteCode; - -@@ -145,8 +145,8 @@ impl X86CPUState { - boot_config: &X86CPUBootConfig, - ) -> Result<()> { - self.setup_lapic(vcpu_fd)?; -- self.setup_regs(&boot_config); -- self.setup_sregs(vcpu_fd, &boot_config)?; -+ self.setup_regs(boot_config); -+ self.setup_sregs(vcpu_fd, boot_config)?; - self.setup_fpu(); - self.setup_msrs(); - -diff --git a/devices/src/legacy/pflash.rs b/devices/src/legacy/pflash.rs -index 0446f91..36f708d 100644 ---- a/devices/src/legacy/pflash.rs -+++ b/devices/src/legacy/pflash.rs -@@ -251,24 +251,19 @@ impl PFlash { - } - - fn query_devid(&mut self, offset: u64) -> Result { -- let mut resp: u32; - let index: u64 = offset - >> (self.bank_width.trailing_zeros() + self.max_device_width.trailing_zeros() - - self.device_width.trailing_zeros()); - - // Mask off upper bits, the rest (ident[2] and ident[3]) is not emulated. -- match index & 0xFF { -- 0 => { -- resp = self.ident[0]; -- } -- 1 => { -- resp = self.ident[1]; -- } -+ let mut resp: u32 = match index & 0xFF { -+ 0 => self.ident[0], -+ 1 => self.ident[1], - _ => { - debug!("Device ID 2 and 3 are not supported"); - return Ok(0); - } -- } -+ }; - - if self.device_width < self.bank_width { - let mut i: u32 = self.device_width; -@@ -283,7 +278,6 @@ impl PFlash { - } - - fn query_cfi(&mut self, offset: u64) -> Result { -- let mut resp: u32; - // Adjust index for expected device-width addressing. - let index: u64 = offset - >> (self.bank_width.trailing_zeros() + self.max_device_width.trailing_zeros() -@@ -293,7 +287,7 @@ impl PFlash { - return Err(ErrorKind::PFlashIndexOverflow(index, self.cfi_table.len()).into()); - } - -- resp = self.cfi_table[index as usize].into(); -+ let mut resp: u32 = self.cfi_table[index as usize].into(); - if self.device_width != self.max_device_width { - if self.device_width != 1 || self.bank_width > 4 { - return Err( -@@ -359,7 +353,7 @@ impl PFlash { - std::slice::from_raw_parts_mut((host_addr + offset) as *mut u8, data.len() as usize) - }; - data.as_mut() -- .write_all(&src) -+ .write_all(src) - .chain_err(|| "Failed to read data from PFlash Rom")?; - - Ok(()) -@@ -378,7 +372,7 @@ impl PFlash { - let mut dst = unsafe { - std::slice::from_raw_parts_mut((host_addr + offset) as *mut u8, data.len() as usize) - }; -- dst.write_all(&data) -+ dst.write_all(data) - .chain_err(|| "Failed to write data to PFlash Rom")?; - - Ok(()) -@@ -476,7 +470,7 @@ impl PFlash { - match self.cmd { - 0x10 | 0x40 => { - if !self.read_only { -- if let Err(e) = self.write_data(&data, offset) { -+ if let Err(e) = self.write_data(data, offset) { - error!("Failed to write to PFlash device: {}.", e.display_chain()); - } - if let Err(e) = self.update_content(offset, data_len.into()) { -@@ -592,7 +586,7 @@ impl PFlash { - match self.cmd { - 0xe8 => { - if !self.read_only { -- if let Err(e) = self.write_data(&data, offset) { -+ if let Err(e) = self.write_data(data, offset) { - error!("Failed to write to PFlash device: {}.", e.display_chain()); - } - } else { -diff --git a/machine/src/lib.rs b/machine/src/lib.rs -index 7f88b22..e759bd8 100644 ---- a/machine/src/lib.rs -+++ b/machine/src/lib.rs -@@ -180,7 +180,7 @@ pub trait MachineOps { - let mut mem_mappings = Vec::new(); - if !is_migrate { - let ram_ranges = self.arch_ram_ranges(mem_config.mem_size); -- mem_mappings = create_host_mmaps(&ram_ranges, &mem_config, nr_cpus) -+ mem_mappings = create_host_mmaps(&ram_ranges, mem_config, nr_cpus) - .chain_err(|| "Failed to mmap guest ram.")?; - } - -@@ -253,7 +253,7 @@ pub trait MachineOps { - if let Some(boot_config) = boot_cfg { - for cpu_index in 0..nr_cpus as usize { - cpus[cpu_index as usize] -- .realize(&boot_config) -+ .realize(boot_config) - .chain_err(|| { - format!( - "Failed to realize arch cpu register for CPU {}/KVM", -@@ -529,7 +529,7 @@ pub trait MachineOps { - host: &str, - multifunc: bool, - ) -> Result<()> { -- let (devfn, parent_bus) = self.get_devfn_and_parent_bus(&bdf)?; -+ let (devfn, parent_bus) = self.get_devfn_and_parent_bus(bdf)?; - let path = format!("/sys/bus/pci/devices/{}", host); - let device = VfioDevice::new(Path::new(&path), self.get_sys_mem()) - .chain_err(|| "Failed to create vfio device.")?; -@@ -595,7 +595,7 @@ pub trait MachineOps { - device: Arc>, - multi_func: bool, - ) -> Result<()> { -- let (devfn, parent_bus) = self.get_devfn_and_parent_bus(&bdf)?; -+ let (devfn, parent_bus) = self.get_devfn_and_parent_bus(bdf)?; - let sys_mem = self.get_sys_mem(); - let pcidev = VirtioPciDevice::new( - id.to_string(), -@@ -616,7 +616,7 @@ pub trait MachineOps { - let pci_host = self.get_pci_host()?; - let locked_pci_host = pci_host.lock().unwrap(); - let bus = -- if let Some((bus, _)) = PciBus::find_attached_bus(&locked_pci_host.root_bus, &dev_id) { -+ if let Some((bus, _)) = PciBus::find_attached_bus(&locked_pci_host.root_bus, dev_id) { - bus - } else { - bail!("Bus not found, dev id {}", dev_id); -diff --git a/machine/src/micro_vm/mod.rs b/machine/src/micro_vm/mod.rs -index 5952c58..c3bffdd 100644 ---- a/machine/src/micro_vm/mod.rs -+++ b/machine/src/micro_vm/mod.rs -@@ -906,7 +906,7 @@ impl DeviceInterface for LightMachine { - current: true, - qom_path: String::from("/machine/unattached/device[") - + &cpu_index.to_string() -- + &"]".to_string(), -+ + "]", - halted: false, - props: Some(cpu_instance), - CPU: cpu_index as isize, -@@ -971,9 +971,7 @@ impl DeviceInterface for LightMachine { - vcpus_count: 1, - props: cpu_instance, - qom_path: Some( -- String::from("/machine/unattached/device[") -- + &cpu_index.to_string() -- + &"]".to_string(), -+ String::from("/machine/unattached/device[") + &cpu_index.to_string() + "]", - ), - }; - hotplug_vec.push(serde_json::to_value(hotpluggable_cpu).unwrap()); -diff --git a/machine/src/standard_vm/aarch64/mod.rs b/machine/src/standard_vm/aarch64/mod.rs -index ddf8a41..3fd2de3 100644 ---- a/machine/src/standard_vm/aarch64/mod.rs -+++ b/machine/src/standard_vm/aarch64/mod.rs -@@ -155,15 +155,6 @@ impl StdMachine { - }) - } - -- /// Run `LightMachine` with `paused` flag. -- /// -- /// # Arguments -- /// -- /// * `paused` - Flag for `paused` when `LightMachine` starts to run. -- pub fn run(&self, paused: bool) -> Result<()> { -- ::vm_start(paused, &self.cpus, &mut self.vm_state.0.lock().unwrap()) -- } -- - pub fn handle_reset_request(vm: &Arc>) -> Result<()> { - use crate::errors::ResultExt; - -diff --git a/machine/src/standard_vm/mod.rs b/machine/src/standard_vm/mod.rs -index c96f89a..98916f1 100644 ---- a/machine/src/standard_vm/mod.rs -+++ b/machine/src/standard_vm/mod.rs -@@ -607,12 +607,12 @@ impl StdMachine { - - if dev.vhost_type.is_some() { - let net = Arc::new(Mutex::new(VhostKern::Net::new(&dev, self.get_sys_mem()))); -- self.add_virtio_pci_device(&args.id, &pci_bdf, net, multifunction) -+ self.add_virtio_pci_device(&args.id, pci_bdf, net, multifunction) - .chain_err(|| "Failed to add virtio net device")?; - } else { - let net_id = dev.id.clone(); - let net = Arc::new(Mutex::new(virtio::Net::new(dev))); -- self.add_virtio_pci_device(&args.id, &pci_bdf, net.clone(), multifunction) -+ self.add_virtio_pci_device(&args.id, pci_bdf, net.clone(), multifunction) - .chain_err(|| "Failed to add virtio net device")?; - MigrationManager::register_device_instance_mutex_with_id( - VirtioNetState::descriptor(), -@@ -684,7 +684,7 @@ impl DeviceInterface for StdMachine { - current: true, - qom_path: String::from("/machine/unattached/device[") - + &cpu_index.to_string() -- + &"]".to_string(), -+ + "]", - halted: false, - props: Some(cpu_instance), - CPU: cpu_index as isize, -@@ -750,7 +750,7 @@ impl DeviceInterface for StdMachine { - "virtio-blk-pci" => { - if let Err(e) = self.plug_virtio_pci_blk(&pci_bdf, args.as_ref()) { - error!("{}", e.display_chain()); -- let err_str = format!("Failed to add virtio pci blk: {}", e.to_string()); -+ let err_str = format!("Failed to add virtio pci blk: {}", e); - return Response::create_error_response( - qmp_schema::QmpErrorClass::GenericError(err_str), - None, -@@ -760,7 +760,7 @@ impl DeviceInterface for StdMachine { - "virtio-net-pci" => { - if let Err(e) = self.plug_virtio_pci_net(&pci_bdf, args.as_ref()) { - error!("{}", e.display_chain()); -- let err_str = format!("Failed to add virtio pci net: {}", e.to_string()); -+ let err_str = format!("Failed to add virtio pci net: {}", e); - return Response::create_error_response( - qmp_schema::QmpErrorClass::GenericError(err_str), - None, -@@ -794,7 +794,7 @@ impl DeviceInterface for StdMachine { - error!("{}", e.display_chain()); - error!("Failed to detach device"); - } -- let err_str = format!("Failed to plug device: {}", e.to_string()); -+ let err_str = format!("Failed to plug device: {}", e); - Response::create_error_response( - qmp_schema::QmpErrorClass::GenericError(err_str), - None, -diff --git a/machine/src/standard_vm/x86_64/ich9_lpc.rs b/machine/src/standard_vm/x86_64/ich9_lpc.rs -index 9053bd4..24a8770 100644 ---- a/machine/src/standard_vm/x86_64/ich9_lpc.rs -+++ b/machine/src/standard_vm/x86_64/ich9_lpc.rs -@@ -297,7 +297,6 @@ impl PciDevOps for LPCBridge { - ) { - if let Err(e) = self.update_pm_base() { - error!("Failed to update PM base addr: {}", e.display_chain()); -- return; - } - } - } -diff --git a/machine_manager/src/cmdline.rs b/machine_manager/src/cmdline.rs -index b8e3645..24c34ab 100644 ---- a/machine_manager/src/cmdline.rs -+++ b/machine_manager/src/cmdline.rs -@@ -401,6 +401,7 @@ pub fn create_vmconfig(args: &ArgMatches) -> Result { - add_args_to_config!((args.value_of("smp")), vm_cfg, add_cpu); - add_args_to_config!((args.value_of("kernel")), vm_cfg, add_kernel); - add_args_to_config!((args.value_of("initrd-file")), vm_cfg, add_initrd); -+ add_args_to_config!((args.value_of("serial")), vm_cfg, add_serial); - add_args_to_config!( - (args.is_present("mem-prealloc")), - vm_cfg, -@@ -417,9 +418,8 @@ pub fn create_vmconfig(args: &ArgMatches) -> Result { - add_args_to_config_multi!((args.values_of("object")), vm_cfg, add_object); - add_args_to_config_multi!((args.values_of("netdev")), vm_cfg, add_netdev); - add_args_to_config_multi!((args.values_of("chardev")), vm_cfg, add_chardev); -- add_args_to_config_multi!((args.values_of("device")), vm_cfg, add_devices); -+ add_args_to_config_multi!((args.values_of("device")), vm_cfg, add_device); - add_args_to_config_multi!((args.values_of("global")), vm_cfg, add_global_config); -- add_args_to_config!((args.value_of("serial")), vm_cfg, add_serial); - - if let Some(s) = args.value_of("trace") { - add_trace_events(&s)?; -diff --git a/machine_manager/src/config/boot_source.rs b/machine_manager/src/config/boot_source.rs -index 81b9d1e..81cc0f5 100644 ---- a/machine_manager/src/config/boot_source.rs -+++ b/machine_manager/src/config/boot_source.rs -@@ -10,9 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate serde; --extern crate serde_json; -- - use std::fmt; - use std::path::PathBuf; - -diff --git a/machine_manager/src/config/chardev.rs b/machine_manager/src/config/chardev.rs -index 187de49..2eb435b 100644 ---- a/machine_manager/src/config/chardev.rs -+++ b/machine_manager/src/config/chardev.rs -@@ -221,7 +221,7 @@ impl VmConfig { - } - } - _ => { -- let chardev_config = serial_config.to_string() + &",id=serial_chardev".to_string(); -+ let chardev_config = serial_config.to_string() + ",id=serial_chardev"; - self.add_chardev(&chardev_config) - .chain_err(|| "Failed to add chardev")?; - "serial_chardev" -diff --git a/machine_manager/src/config/devices.rs b/machine_manager/src/config/devices.rs -index c9d60bd..cfc972c 100644 ---- a/machine_manager/src/config/devices.rs -+++ b/machine_manager/src/config/devices.rs -@@ -14,11 +14,11 @@ use super::errors::Result; - use super::{CmdParser, VmConfig}; - - impl VmConfig { -- pub fn add_devices(&mut self, device_config: &str) -> Result<()> { -+ pub fn add_device(&mut self, device_config: &str) -> Result<()> { - let mut cmd_params = CmdParser::new("device"); - cmd_params.push(""); - -- cmd_params.get_parameters(&device_config)?; -+ cmd_params.get_parameters(device_config)?; - if let Some(device_type) = cmd_params.get_value::("")? { - self.devices.push((device_type, device_config.to_string())); - } -diff --git a/machine_manager/src/config/drive.rs b/machine_manager/src/config/drive.rs -index 9670161..88d78f2 100644 ---- a/machine_manager/src/config/drive.rs -+++ b/machine_manager/src/config/drive.rs -@@ -10,9 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate serde; --extern crate serde_json; -- - use std::fs::metadata; - use std::os::linux::fs::MetadataExt; - use std::path::Path; -@@ -276,7 +273,7 @@ pub fn parse_blk(vm_config: &mut VmConfig, drive_config: &str) -> Result Self { -- PFlashConfig { -- path_on_host: String::new(), -- read_only: false, -- unit: 0_usize, -- } -- } --} -- - impl ConfigCheck for PFlashConfig { - fn check(&self) -> Result<()> { - if self.path_on_host.len() > MAX_PATH_LENGTH { -@@ -325,10 +312,10 @@ impl VmConfig { - }; - match drive_type.as_str() { - "none" => { -- self.add_block_drive(&drive_config)?; -+ self.add_block_drive(drive_config)?; - } - "pflash" => { -- self.add_pflash(&drive_config)?; -+ self.add_pflash(drive_config)?; - } - _ => { - bail!("Unknow 'if' argument: {:?}", drive_type.as_str()); -diff --git a/machine_manager/src/config/machine_config.rs b/machine_manager/src/config/machine_config.rs -index f1b5533..92fddab 100644 ---- a/machine_manager/src/config/machine_config.rs -+++ b/machine_manager/src/config/machine_config.rs -@@ -10,9 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate serde; --extern crate serde_json; -- - use std::str::FromStr; - - use serde::{Deserialize, Serialize}; -@@ -238,7 +235,7 @@ impl VmConfig { - } - - pub fn add_mem_path(&mut self, mem_path: &str) -> Result<()> { -- self.machine_config.mem_config.mem_path = Some(mem_path.replace("\"", "")); -+ self.machine_config.mem_config.mem_path = Some(mem_path.replace('\"', "")); - Ok(()) - } - -@@ -251,8 +248,8 @@ fn memory_unit_conversion(origin_value: &str) -> Result { - if (origin_value.ends_with('M') | origin_value.ends_with('m')) - && (origin_value.contains('M') ^ origin_value.contains('m')) - { -- let value = origin_value.replacen("M", "", 1); -- let value = value.replacen("m", "", 1); -+ let value = origin_value.replacen('M', "", 1); -+ let value = value.replacen('m', "", 1); - get_inner( - value - .parse::() -@@ -264,8 +261,8 @@ fn memory_unit_conversion(origin_value: &str) -> Result { - } else if (origin_value.ends_with('G') | origin_value.ends_with('g')) - && (origin_value.contains('G') ^ origin_value.contains('g')) - { -- let value = origin_value.replacen("G", "", 1); -- let value = value.replacen("g", "", 1); -+ let value = origin_value.replacen('G', "", 1); -+ let value = value.replacen('g', "", 1); - get_inner( - value - .parse::() -diff --git a/machine_manager/src/config/mod.rs b/machine_manager/src/config/mod.rs -index 14e2ec8..56e8a51 100644 ---- a/machine_manager/src/config/mod.rs -+++ b/machine_manager/src/config/mod.rs -@@ -123,7 +123,7 @@ fn parse_rng_obj(object_args: &str) -> Result { - let mut cmd_params = CmdParser::new("rng-object"); - cmd_params.push("").push("id").push("filename"); - -- cmd_params.parse(&object_args)?; -+ cmd_params.parse(object_args)?; - let id = if let Some(obj_id) = cmd_params.get_value::("id")? { - obj_id - } else { -@@ -221,7 +221,7 @@ impl VmConfig { - let mut cmd_params = CmdParser::new("object"); - cmd_params.push(""); - -- cmd_params.get_parameters(&object_args)?; -+ cmd_params.get_parameters(object_args)?; - let obj_type = cmd_params.get_value::("")?; - if obj_type.is_none() { - bail!("Object type not specified"); -@@ -229,11 +229,11 @@ impl VmConfig { - let device_type = obj_type.unwrap(); - match device_type.as_str() { - "iothread" => { -- self.add_iothread(&object_args) -+ self.add_iothread(object_args) - .chain_err(|| "Failed to add iothread")?; - } - "rng-random" => { -- let rng_cfg = parse_rng_obj(&object_args)?; -+ let rng_cfg = parse_rng_obj(object_args)?; - let id = rng_cfg.id.clone(); - let object_config = ObjConfig::Rng(rng_cfg); - if self.object.get(&id).is_none() { -diff --git a/machine_manager/src/config/network.rs b/machine_manager/src/config/network.rs -index 9d17ead..b0cdf76 100644 ---- a/machine_manager/src/config/network.rs -+++ b/machine_manager/src/config/network.rs -@@ -10,9 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate serde; --extern crate serde_json; -- - use serde::{Deserialize, Serialize}; - - use super::{ -diff --git a/machine_manager/src/config/vfio.rs b/machine_manager/src/config/vfio.rs -index dc18615..8acb4df 100644 ---- a/machine_manager/src/config/vfio.rs -+++ b/machine_manager/src/config/vfio.rs -@@ -13,20 +13,12 @@ - use super::errors::{ErrorKind, Result}; - use crate::config::{CmdParser, ConfigCheck, MAX_STRING_LENGTH}; - -+#[derive(Default)] - pub struct VfioConfig { - pub host: String, - pub id: String, - } - --impl Default for VfioConfig { -- fn default() -> Self { -- VfioConfig { -- host: String::new(), -- id: String::new(), -- } -- } --} -- - impl ConfigCheck for VfioConfig { - fn check(&self) -> Result<()> { - if self.host.len() > MAX_STRING_LENGTH { -diff --git a/machine_manager/src/event_loop.rs b/machine_manager/src/event_loop.rs -index fa973f6..72ef64f 100644 ---- a/machine_manager/src/event_loop.rs -+++ b/machine_manager/src/event_loop.rs -@@ -10,8 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate util; -- - use std::collections::HashMap; - use std::sync::{Arc, Mutex}; - use std::{process, thread}; -diff --git a/machine_manager/src/lib.rs b/machine_manager/src/lib.rs -index 8de5dae..a544c60 100644 ---- a/machine_manager/src/lib.rs -+++ b/machine_manager/src/lib.rs -@@ -25,7 +25,6 @@ - extern crate log; - #[macro_use] - extern crate error_chain; --extern crate serde_json; - - pub mod cmdline; - pub mod config; -diff --git a/machine_manager/src/machine.rs b/machine_manager/src/machine.rs -index df6d899..02d8900 100644 ---- a/machine_manager/src/machine.rs -+++ b/machine_manager/src/machine.rs -@@ -10,8 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate util; -- - use std::os::unix::io::RawFd; - use std::sync::Mutex; - -@@ -351,8 +349,8 @@ pub trait DeviceInterface { - let chardev_label = &path.label; - let info = ChardevInfo { - open: true, -- filename: chardev_path.to_string().replace("\"", ""), -- label: chardev_label.to_string().replace("\"", ""), -+ filename: chardev_path.to_string().replace('\"', ""), -+ label: chardev_label.to_string().replace('\"', ""), - }; - vec_chardev_info.push(info); - } -diff --git a/machine_manager/src/qmp/mod.rs b/machine_manager/src/qmp/mod.rs -index 365ef93..12e493a 100644 ---- a/machine_manager/src/qmp/mod.rs -+++ b/machine_manager/src/qmp/mod.rs -@@ -25,8 +25,6 @@ - //! 3. Qmp's message structure base is transformed by scripts from Qemu's - //! `qmp-schema.json`. It's can be compatible by Qemu's zoology. Those - //! transformed structures can be found in `machine_manager/src/qmp/qmp_schema.rs` --extern crate serde; --extern crate serde_json; - - #[allow(non_upper_case_globals)] - #[allow(non_camel_case_types)] -diff --git a/machine_manager/src/qmp/qmp_schema.rs b/machine_manager/src/qmp/qmp_schema.rs -index f1e0096..0058e94 100644 ---- a/machine_manager/src/qmp/qmp_schema.rs -+++ b/machine_manager/src/qmp/qmp_schema.rs -@@ -10,11 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate serde; --extern crate serde_json; --extern crate strum; --extern crate strum_macros; -- - use serde::{Deserialize, Serialize}; - pub use serde_json::Value as Any; - use strum_macros::{EnumIter, EnumString, EnumVariantNames}; -@@ -1741,8 +1736,6 @@ impl Command for query_iothreads { - - #[cfg(test)] - mod tests { -- extern crate serde; -- extern crate serde_json; - use super::*; - - #[test] -diff --git a/machine_manager/src/socket.rs b/machine_manager/src/socket.rs -index c0813c4..594ef64 100644 ---- a/machine_manager/src/socket.rs -+++ b/machine_manager/src/socket.rs -@@ -197,7 +197,7 @@ impl Socket { - let performer = &socket_mutexed.performer.as_ref().unwrap(); - if let Err(e) = crate::qmp::handle_qmp( - stream_fd, -- &performer, -+ performer, - &mut shared_leak_bucket.lock().unwrap(), - ) { - error!("{}", e); -@@ -297,6 +297,7 @@ struct SocketStream { - /// `RawFd` for socket - socket_fd: RawFd, - /// Make `UnixStream` persistent without `drop` -+ #[allow(dead_code)] - persistent: Option, - } - -diff --git a/migration/src/header.rs b/migration/src/header.rs -index e39ab52..46833b4 100644 ---- a/migration/src/header.rs -+++ b/migration/src/header.rs -@@ -80,6 +80,7 @@ pub struct MigrationHeader { - /// Magic number for migration file/stream. - magic_num: [u8; 16], - /// Current version of migration. -+ #[allow(dead_code)] - current_version: u32, - /// Compatible version of migration. - compat_version: u32, -@@ -88,6 +89,7 @@ pub struct MigrationHeader { - /// Endianness of byte order. - byte_order: EndianType, - /// The type of hypervisor. -+ #[allow(dead_code)] - hypervisor_type: [u8; 8], - /// The version of hypervisor. - hypervisor_version: u32, -diff --git a/migration/src/manager.rs b/migration/src/manager.rs -index ef903f9..1ea194e 100644 ---- a/migration/src/manager.rs -+++ b/migration/src/manager.rs -@@ -71,11 +71,11 @@ pub trait MigrationHook: StateTransfer { - let device_alias = self.get_device_alias(); - let instance_id = InstanceId { - object_type: device_alias, -- object_id: id_remap(&id), -+ object_id: id_remap(id), - }; - - writer -- .write_all(&instance_id.as_bytes()) -+ .write_all(instance_id.as_bytes()) - .chain_err(|| "Failed to write instance id.")?; - writer - .write_all(&state_data) -diff --git a/migration_derive/src/field_parser.rs b/migration_derive/src/field_parser.rs -index 2318a74..2403399 100644 ---- a/migration_derive/src/field_parser.rs -+++ b/migration_derive/src/field_parser.rs -@@ -21,7 +21,7 @@ pub fn parse_fields(input: &syn::Fields, ident: &syn::Ident) -> Vec { - let pairs = name_fields.named.pairs(); -- for field in pairs.into_iter() { -+ for field in pairs { - fields.push(parse_field(field, ident)); - } - } -@@ -51,11 +51,7 @@ fn parse_field( - let ty = input.value().ty.clone(); - let (ty_ident, len, is_array) = parse_ty(ty); - let type_name = if is_array { -- format!( -- "[{};{}]", -- ty_ident.path.get_ident().unwrap().to_string(), -- len -- ) -+ format!("[{};{}]", ty_ident.path.get_ident().unwrap(), len) - } else { - ty_ident.path.get_ident().unwrap().to_string() - }; -@@ -113,7 +109,7 @@ pub fn parse_fields_default(input: &syn::Fields) -> Vec { - let pairs = name_fields.named.pairs(); -- for field in pairs.into_iter() { -+ for field in pairs { - fields.push(parse_field_default(field)); - } - } -diff --git a/migration_derive/src/lib.rs b/migration_derive/src/lib.rs -index abb17b4..a71ab54 100644 ---- a/migration_derive/src/lib.rs -+++ b/migration_derive/src/lib.rs -@@ -50,7 +50,6 @@ - - #[macro_use] - extern crate syn; --extern crate quote; - - use proc_macro::TokenStream; - use quote::quote; -diff --git a/ozone/src/capability.rs b/ozone/src/capability.rs -index d1fb21d..e7eae70 100644 ---- a/ozone/src/capability.rs -+++ b/ozone/src/capability.rs -@@ -140,7 +140,7 @@ pub fn set_capability_for_ozone(capability: &str) -> Result<()> { - } - - for item in all_caps.iter() { -- if cap_add_arr.contains(&item.0) { -+ if cap_add_arr.contains(item.0) { - continue; - } - if has_cap(item.1 .0).chain_err(|| ErrorKind::CapsError("CAPGET"))? { -diff --git a/ozone/src/cgroup.rs b/ozone/src/cgroup.rs -index c5763d4..8ce6539 100644 ---- a/ozone/src/cgroup.rs -+++ b/ozone/src/cgroup.rs -@@ -112,8 +112,8 @@ fn get_base_location(controller: &str, exec_file: &str, name: &str) -> Result Result<()> { -- let write_path = get_base_location("cpuset", &exec_file, &name)?; -- write_cgroup_value(&write_path, "cpuset.mems", &node) -+ let write_path = get_base_location("cpuset", exec_file, name)?; -+ write_cgroup_value(&write_path, "cpuset.mems", node) - .chain_err(|| ErrorKind::WriteError("cpuset.mems".to_string(), node.to_string()))?; - - let mut upper_path = write_path.clone(); -diff --git a/pci/src/bus.rs b/pci/src/bus.rs -index 53f94d5..8fb9d1e 100644 ---- a/pci/src/bus.rs -+++ b/pci/src/bus.rs -@@ -125,7 +125,7 @@ impl PciBus { - } - if locked_bus.in_range(bus_num) { - for sub_bus in &locked_bus.child_buses { -- if let Some(b) = PciBus::find_bus_by_num(&sub_bus, bus_num) { -+ if let Some(b) = PciBus::find_bus_by_num(sub_bus, bus_num) { - return Some(b); - } - } -@@ -145,7 +145,7 @@ impl PciBus { - return Some((*bus).clone()); - } - for sub_bus in &locked_bus.child_buses { -- if let Some(b) = PciBus::find_bus_by_name(&sub_bus, bus_name) { -+ if let Some(b) = PciBus::find_bus_by_name(sub_bus, bus_name) { - return Some(b); - } - } -diff --git a/pci/src/host.rs b/pci/src/host.rs -index df7b617..1713c2e 100644 ---- a/pci/src/host.rs -+++ b/pci/src/host.rs -@@ -51,6 +51,7 @@ const ECAM_OFFSET_MASK: u64 = 0xfff; - #[derive(Clone)] - pub struct PciHost { - pub root_bus: Arc>, -+ #[allow(dead_code)] - device: Option>>, - #[cfg(target_arch = "x86_64")] - config_addr: u32, -diff --git a/pci/src/lib.rs b/pci/src/lib.rs -index 03b1b8c..87eb163 100644 ---- a/pci/src/lib.rs -+++ b/pci/src/lib.rs -@@ -225,7 +225,7 @@ pub fn init_multifunction( - parent_bus: Weak>, - ) -> Result<()> { - let mut header_type = -- le_read_u16(&config, HEADER_TYPE as usize)? & (!HEADER_TYPE_MULTIFUNC as u16); -+ le_read_u16(config, HEADER_TYPE as usize)? & (!HEADER_TYPE_MULTIFUNC as u16); - if multifunction { - header_type |= HEADER_TYPE_MULTIFUNC as u16; - } -diff --git a/pci/src/msix.rs b/pci/src/msix.rs -index 71d172e..cbf27ea 100644 ---- a/pci/src/msix.rs -+++ b/pci/src/msix.rs -@@ -364,7 +364,7 @@ impl MigrationHook for Msix { - - pub fn is_msix_enabled(msix_cap_offset: usize, config: &[u8]) -> bool { - let offset: usize = msix_cap_offset + MSIX_CAP_CONTROL as usize; -- let msix_ctl = le_read_u16(&config, offset).unwrap(); -+ let msix_ctl = le_read_u16(config, offset).unwrap(); - if msix_ctl & MSIX_CAP_ENABLE > 0 { - return true; - } -@@ -373,7 +373,7 @@ pub fn is_msix_enabled(msix_cap_offset: usize, config: &[u8]) -> bool { - - fn is_msix_func_masked(msix_cap_offset: usize, config: &[u8]) -> bool { - let offset: usize = msix_cap_offset + MSIX_CAP_CONTROL as usize; -- let msix_ctl = le_read_u16(&config, offset).unwrap(); -+ let msix_ctl = le_read_u16(config, offset).unwrap(); - if msix_ctl & MSIX_CAP_FUNC_MASK > 0 { - return true; - } -@@ -405,7 +405,7 @@ pub fn init_msix( - vector_nr: u32, - config: &mut PciConfig, - dev_id: Arc, -- id: &str, -+ _id: &str, - ) -> Result<()> { - if vector_nr > MSIX_TABLE_SIZE_MAX as u32 + 1 { - bail!("Too many msix vectors."); -@@ -440,7 +440,7 @@ pub fn init_msix( - config.msix = Some(msix.clone()); - - #[cfg(not(test))] -- MigrationManager::register_device_instance_mutex_with_id(MsixState::descriptor(), msix, id); -+ MigrationManager::register_device_instance_mutex_with_id(MsixState::descriptor(), msix, _id); - - Ok(()) - } -diff --git a/src/main.rs b/src/main.rs -index b0a7c77..1b974ee 100644 ---- a/src/main.rs -+++ b/src/main.rs -@@ -135,12 +135,12 @@ fn real_main(cmd_args: &arg_parser::ArgMatches, vm_config: &mut VmConfig) -> Res - EventLoop::object_init(&vm_config.iothreads)?; - register_kill_signal(); - -- let listeners = check_api_channel(&cmd_args, vm_config)?; -+ let listeners = check_api_channel(cmd_args, vm_config)?; - let mut sockets = Vec::new(); - let vm: Arc> = match vm_config.machine_config.mach_type { - MachineType::MicroVm => { - let vm = Arc::new(Mutex::new( -- LightMachine::new(&vm_config).chain_err(|| "Failed to init MicroVM")?, -+ LightMachine::new(vm_config).chain_err(|| "Failed to init MicroVM")?, - )); - MachineOps::realize(&vm, vm_config, cmd_args.is_present("incoming")) - .chain_err(|| "Failed to realize micro VM.")?; -@@ -153,7 +153,7 @@ fn real_main(cmd_args: &arg_parser::ArgMatches, vm_config: &mut VmConfig) -> Res - } - MachineType::StandardVm => { - let vm = Arc::new(Mutex::new( -- StdMachine::new(&vm_config).chain_err(|| "Failed to init StandardVM")?, -+ StdMachine::new(vm_config).chain_err(|| "Failed to init StandardVM")?, - )); - MachineOps::realize(&vm, vm_config, cmd_args.is_present("incoming")) - .chain_err(|| "Failed to realize standard VM.")?; -@@ -166,7 +166,7 @@ fn real_main(cmd_args: &arg_parser::ArgMatches, vm_config: &mut VmConfig) -> Res - } - MachineType::None => { - let vm = Arc::new(Mutex::new( -- StdMachine::new(&vm_config).chain_err(|| "Failed to init NoneVM")?, -+ StdMachine::new(vm_config).chain_err(|| "Failed to init NoneVM")?, - )); - EventLoop::set_manager(vm.clone(), None); - for listener in listeners { -diff --git a/util/src/arg_parser.rs b/util/src/arg_parser.rs -index 2285284..48ba493 100644 ---- a/util/src/arg_parser.rs -+++ b/util/src/arg_parser.rs -@@ -579,7 +579,7 @@ impl<'a> ArgMatches<'a> { - if let Some(index) = args.iter().position(|arg| arg == ARG_SEPARATOR) { - return (&args[..index], &args[index + 1..]); - } -- (&args, &[]) -+ (args, &[]) - } - - pub fn extra_args(&self) -> Vec { -@@ -592,14 +592,14 @@ fn parse_cmdline( - cmd_args: &[String], - allow_list: &[String], - ) -> Result<(ArgsMap, Vec, Vec)> { -- let (cmd_args, sub_args) = ArgMatches::split_arg(&cmd_args); -+ let (cmd_args, sub_args) = ArgMatches::split_arg(cmd_args); - let mut arg_map: BTreeMap> = BTreeMap::new(); - let mut multi_vec: Vec = Vec::new(); - - let mut i = (0, ""); - let mut j = 1; - for cmd_arg in &cmd_args[1..] { -- if !allow_list.contains(&cmd_arg) && cmd_arg.starts_with(PREFIX_CHARS_SHORT) { -+ if !allow_list.contains(cmd_arg) && cmd_arg.starts_with(PREFIX_CHARS_SHORT) { - return Err(ErrorKind::UnexpectedArguments(cmd_arg.to_string()).into()); - } - -diff --git a/util/src/daemonize.rs b/util/src/daemonize.rs -index 043251b..a057ebe 100644 ---- a/util/src/daemonize.rs -+++ b/util/src/daemonize.rs -@@ -31,8 +31,6 @@ - //! sent to the process group. - //! 8. Handle any `SIGCLD` signals. - --extern crate libc; -- - use std::cmp::Ordering; - use std::fs::{File, OpenOptions}; - use std::io::prelude::*; -diff --git a/util/src/logger.rs b/util/src/logger.rs -index da155b4..ae562cb 100644 ---- a/util/src/logger.rs -+++ b/util/src/logger.rs -@@ -10,9 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate libc; --extern crate log; -- - use std::io::prelude::*; - use std::sync::Mutex; - -diff --git a/util/src/seccomp.rs b/util/src/seccomp.rs -index 87591c9..40ab17e 100644 ---- a/util/src/seccomp.rs -+++ b/util/src/seccomp.rs -@@ -77,8 +77,6 @@ - //! ``` - //! This programe will be trapped. - --extern crate libc; -- - use crate::errors::Result; - use crate::offset_of; - -diff --git a/util/src/tap.rs b/util/src/tap.rs -index 1668a71..1530f97 100644 ---- a/util/src/tap.rs -+++ b/util/src/tap.rs -@@ -106,7 +106,7 @@ impl Tap { - } - - pub fn write(&mut self, buf: &[u8]) -> IoResult { -- self.file.write(&buf) -+ self.file.write(buf) - } - - pub fn as_raw_fd(&self) -> RawFd { -diff --git a/util/src/unix.rs b/util/src/unix.rs -index bdfdc3f..a41c81a 100644 ---- a/util/src/unix.rs -+++ b/util/src/unix.rs -@@ -10,8 +10,6 @@ - // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - // See the Mulan PSL v2 for more details. - --extern crate libc; -- - use std::fs::File; - use std::os::unix::io::AsRawFd; - -diff --git a/vfio/src/vfio_dev.rs b/vfio/src/vfio_dev.rs -index 198421c..db0c58d 100644 ---- a/vfio/src/vfio_dev.rs -+++ b/vfio/src/vfio_dev.rs -@@ -515,10 +515,9 @@ impl VfioDevice { - bail!("No provided host PCI device, use -device vfio-pci,host=DDDD:BB:DD.F"); - } - -- let group = -- Self::vfio_get_group(&path, mem_as).chain_err(|| "Failed to get iommu group")?; -+ let group = Self::vfio_get_group(path, mem_as).chain_err(|| "Failed to get iommu group")?; - let (name, fd) = -- Self::vfio_get_device(&group, &path).chain_err(|| "Failed to get vfio device")?; -+ Self::vfio_get_device(&group, path).chain_err(|| "Failed to get vfio device")?; - let dev_info = Self::get_dev_info(&fd).chain_err(|| "Failed to get device info")?; - let vfio_dev = Arc::new(Mutex::new(VfioDevice { - fd, -@@ -813,12 +812,12 @@ impl VfioDevice { - irq_set[0].count = irq_fds.len() as u32; - - // It is safe as enough memory space to save irq_set data. -- let mut data: &mut [u8] = unsafe { -+ let data: &mut [u8] = unsafe { - irq_set[0] - .data - .as_mut_slice(irq_fds.len() * size_of::()) - }; -- LittleEndian::write_i32_into(irq_fds.as_slice(), &mut data); -+ LittleEndian::write_i32_into(irq_fds.as_slice(), data); - // Safe as device is the owner of file, and we will verify the result is valid. - let ret = unsafe { ioctl_with_ref(&self.fd, VFIO_DEVICE_SET_IRQS(), &irq_set[0]) }; - if ret < 0 { -diff --git a/vfio/src/vfio_pci.rs b/vfio/src/vfio_pci.rs -index bfb2334..abc8f6c 100644 ---- a/vfio/src/vfio_pci.rs -+++ b/vfio/src/vfio_pci.rs -@@ -479,7 +479,7 @@ impl VfioPciDevice { - let write = move |data: &[u8], _: GuestAddress, offset: u64| -> bool { - let mut locked_msix = msix.lock().unwrap(); - locked_msix.table[offset as usize..(offset as usize + data.len())] -- .copy_from_slice(&data); -+ .copy_from_slice(data); - let vector = offset / MSIX_TABLE_ENTRY_SIZE as u64; - if locked_msix.is_vector_masked(vector as u16) { - return true; -@@ -955,7 +955,6 @@ impl PciDevOps for VfioPciDevice { - - if let Err(e) = self.setup_bars_mmap() { - error!("Failed to map bar regions, error is {}", e.display_chain()); -- return; - } - } - } else if ranges_overlap(offset, end, BAR_0 as usize, (BAR_5 as usize) + REG_SIZE) { -@@ -971,7 +970,6 @@ impl PciDevOps for VfioPciDevice { - &locked_parent_bus.mem_region, - ) { - error!("Failed to update bar, error is {}", e.display_chain()); -- return; - } - } - } else if ranges_overlap(offset, end, cap_offset, cap_offset + MSIX_CAP_SIZE as usize) { -@@ -983,12 +981,10 @@ impl PciDevOps for VfioPciDevice { - if !was_enable && is_enable { - if let Err(e) = self.vfio_enable_msix() { - error!("{}\nFailed to enable MSI-X.", e.display_chain()); -- return; - } - } else if was_enable && !is_enable { - if let Err(e) = self.vfio_disable_msix() { - error!("{}\nFailed to disable MSI-X.", e.display_chain()); -- return; - } - } - } else { -diff --git a/virtio/src/balloon.rs b/virtio/src/balloon.rs -index 300876e..a2aa067 100644 ---- a/virtio/src/balloon.rs -+++ b/virtio/src/balloon.rs -@@ -67,8 +67,10 @@ struct Iovec { - #[derive(Copy, Clone, Default)] - struct VirtioBalloonConfig { - /// Number of pages host wants Guest to give up. -+ #[allow(dead_code)] - pub num_pages: u32, - /// Number of pages we've actually got in balloon. -+ #[allow(dead_code)] - pub actual: u32, - } - -@@ -419,13 +421,13 @@ impl Listener for BlnMemInfo { - ListenerReqType::AddRegion => { - let fr = range.unwrap(); - if fr.owner.region_type() == RegionType::Ram { -- self.add_mem_range(&fr); -+ self.add_mem_range(fr); - } - } - ListenerReqType::DeleteRegion => { - let fr = range.unwrap(); - if fr.owner.region_type() == RegionType::Ram { -- self.delete_mem_range(&fr); -+ self.delete_mem_range(fr); - } - } - _ => {} -diff --git a/virtio/src/block.rs b/virtio/src/block.rs -index a2e35e8..6c36e77 100644 ---- a/virtio/src/block.rs -+++ b/virtio/src/block.rs -@@ -303,7 +303,7 @@ impl Request { - } - VIRTIO_BLK_T_GET_ID => { - if let Some(serial) = serial_num { -- let serial_vec = get_serial_num_config(&serial); -+ let serial_vec = get_serial_num_config(serial); - - for iov in self.iovec.iter() { - if (iov.iov_len as usize) < serial_vec.len() { -diff --git a/virtio/src/queue.rs b/virtio/src/queue.rs -index b2c7132..13409a8 100644 ---- a/virtio/src/queue.rs -+++ b/virtio/src/queue.rs -@@ -316,7 +316,7 @@ impl SplitVringDesc { - } - - if miss_cached { -- if let Err(ref e) = checked_offset_mem(&sys_mem, self.addr, u64::from(self.len)) { -+ if let Err(ref e) = checked_offset_mem(sys_mem, self.addr, u64::from(self.len)) { - error!( - "The memory of descriptor is invalid, {} ", - error_chain::ChainedError::display_chain(e), -@@ -653,7 +653,7 @@ impl SplitVring { - - fn is_invalid_memory(&self, sys_mem: &Arc, actual_size: u64) -> bool { - let desc_table_end = -- match checked_offset_mem(&sys_mem, self.desc_table, DESCRIPTOR_LEN * actual_size) { -+ match checked_offset_mem(sys_mem, self.desc_table, DESCRIPTOR_LEN * actual_size) { - Ok(addr) => addr, - Err(ref e) => { - error!( -@@ -667,7 +667,7 @@ impl SplitVring { - }; - - let desc_avail_end = match checked_offset_mem( -- &sys_mem, -+ sys_mem, - self.avail_ring, - VRING_AVAIL_LEN_EXCEPT_AVAILELEM + AVAILELEM_LEN * actual_size, - ) { -@@ -684,7 +684,7 @@ impl SplitVring { - }; - - if let Err(ref e) = checked_offset_mem( -- &sys_mem, -+ sys_mem, - self.used_ring, - VRING_USED_LEN_EXCEPT_USEDELEM + USEDELEM_LEN * actual_size, - ) { -diff --git a/virtio/src/vhost/kernel/mod.rs b/virtio/src/vhost/kernel/mod.rs -index 3a273eb..ccc85e9 100644 ---- a/virtio/src/vhost/kernel/mod.rs -+++ b/virtio/src/vhost/kernel/mod.rs -@@ -200,14 +200,14 @@ impl Listener for VhostMemInfo { - ) -> std::result::Result<(), address_space::errors::Error> { - match req_type { - ListenerReqType::AddRegion => { -- if Self::check_vhost_mem_range(&range.unwrap()) { -+ if Self::check_vhost_mem_range(range.unwrap()) { - self.add_mem_range(range.unwrap()); - } - } - ListenerReqType::DeleteRegion => { - let fr = range.unwrap(); - if fr.owner.region_type() == RegionType::Ram { -- self.delete_mem_range(&fr); -+ self.delete_mem_range(fr); - } - } - _ => {} --- -2.20.1 - diff --git a/0024-machine-clear-some-warnings.patch b/0024-machine-clear-some-warnings.patch deleted file mode 100644 index 8e3dada1ef4dcabbd0651e935934111dee65ab29..0000000000000000000000000000000000000000 --- a/0024-machine-clear-some-warnings.patch +++ /dev/null @@ -1,113 +0,0 @@ -From 1dc4eb0d201f4cfbb22206cd9e53dffd3d8d51e3 Mon Sep 17 00:00:00 2001 -From: zhouli57 -Date: Mon, 14 Mar 2022 14:56:32 +0800 -Subject: [PATCH] machine: clear some warnings - -Signed-off-by: zhouli57 ---- - cpu/src/aarch64/core_regs.rs | 12 ++++++------ - devices/src/legacy/rtc.rs | 2 +- - machine/src/micro_vm/syscall.rs | 1 + - machine/src/standard_vm/aarch64/syscall.rs | 1 + - machine/src/standard_vm/x86_64/syscall.rs | 1 + - 5 files changed, 10 insertions(+), 7 deletions(-) - -diff --git a/cpu/src/aarch64/core_regs.rs b/cpu/src/aarch64/core_regs.rs -index ba3b400..bc46f69 100644 ---- a/cpu/src/aarch64/core_regs.rs -+++ b/cpu/src/aarch64/core_regs.rs -@@ -194,15 +194,15 @@ pub fn get_core_regs(vcpu_fd: &VcpuFd) -> Result { - - for i in 0..KVM_NR_FP_REGS as usize { - let register_value_vec = -- get_one_reg_vec(&vcpu_fd, Arm64CoreRegs::UserFPSIMDStateVregs(i).into())?; -+ get_one_reg_vec(vcpu_fd, Arm64CoreRegs::UserFPSIMDStateVregs(i).into())?; - core_regs.fp_regs.vregs[i][0] = *u64::from_bytes(®ister_value_vec[0..8]).unwrap(); - core_regs.fp_regs.vregs[i][1] = *u64::from_bytes(®ister_value_vec[8..16]).unwrap(); - } - -- let register_value_vec = get_one_reg_vec(&vcpu_fd, Arm64CoreRegs::UserFPSIMDStateFpsr.into())?; -+ let register_value_vec = get_one_reg_vec(vcpu_fd, Arm64CoreRegs::UserFPSIMDStateFpsr.into())?; - core_regs.fp_regs.fpsr = *u32::from_bytes(®ister_value_vec[0..4]).unwrap(); - -- let register_value_vec = get_one_reg_vec(&vcpu_fd, Arm64CoreRegs::UserFPSIMDStateFpcr.into())?; -+ let register_value_vec = get_one_reg_vec(vcpu_fd, Arm64CoreRegs::UserFPSIMDStateFpcr.into())?; - core_regs.fp_regs.fpcr = *u32::from_bytes(®ister_value_vec[0..4]).unwrap(); - - Ok(core_regs) -@@ -239,20 +239,20 @@ pub fn set_core_regs(vcpu_fd: &VcpuFd, core_regs: kvm_regs) -> Result<()> { - data.append(&mut core_regs.fp_regs.vregs[i][0].as_bytes().to_vec()); - data.append(&mut core_regs.fp_regs.vregs[i][1].as_bytes().to_vec()); - set_one_reg_vec( -- &vcpu_fd, -+ vcpu_fd, - Arm64CoreRegs::UserFPSIMDStateVregs(i).into(), - &data, - )?; - } - - set_one_reg_vec( -- &vcpu_fd, -+ vcpu_fd, - Arm64CoreRegs::UserFPSIMDStateFpsr.into(), - &core_regs.fp_regs.fpsr.as_bytes().to_vec(), - )?; - - set_one_reg_vec( -- &vcpu_fd, -+ vcpu_fd, - Arm64CoreRegs::UserFPSIMDStateFpcr.into(), - &core_regs.fp_regs.fpcr.as_bytes().to_vec(), - )?; -diff --git a/devices/src/legacy/rtc.rs b/devices/src/legacy/rtc.rs -index 0ec8658..a549bfb 100644 ---- a/devices/src/legacy/rtc.rs -+++ b/devices/src/legacy/rtc.rs -@@ -59,7 +59,7 @@ const CMOS_MEM_BELOW_4GB: (u8, u8) = (0x34, 0x35); - const CMOS_MEM_ABOVE_4GB: (u8, u8, u8) = (0x5B, 0x5C, 0x5D); - - fn get_utc_time() -> libc::tm { -- let time_val: libc::time_t = 0_i64; -+ let time_val = 0_i64; - - // Safe because `libc::time` only get time. - unsafe { libc::time(time_val as *mut i64) }; -diff --git a/machine/src/micro_vm/syscall.rs b/machine/src/micro_vm/syscall.rs -index 5e9c6d8..81637a3 100644 ---- a/machine/src/micro_vm/syscall.rs -+++ b/machine/src/micro_vm/syscall.rs -@@ -22,6 +22,7 @@ const FUTEX_CMP_REQUEUE: u32 = 4; - const FUTEX_WAKE_OP: u32 = 5; - const FUTEX_WAIT_BITSET: u32 = 9; - const FUTEX_PRIVATE_FLAG: u32 = 128; -+#[cfg(target_env = "gnu")] - const FUTEX_CLOCK_REALTIME: u32 = 256; - const FUTEX_WAIT_PRIVATE: u32 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; - const FUTEX_WAKE_PRIVATE: u32 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; -diff --git a/machine/src/standard_vm/aarch64/syscall.rs b/machine/src/standard_vm/aarch64/syscall.rs -index ed3140e..f44c5f7 100644 ---- a/machine/src/standard_vm/aarch64/syscall.rs -+++ b/machine/src/standard_vm/aarch64/syscall.rs -@@ -28,6 +28,7 @@ const FUTEX_CMP_REQUEUE: u32 = 4; - const FUTEX_WAKE_OP: u32 = 5; - const FUTEX_WAIT_BITSET: u32 = 9; - const FUTEX_PRIVATE_FLAG: u32 = 128; -+#[cfg(target_env = "gnu")] - const FUTEX_CLOCK_REALTIME: u32 = 256; - const FUTEX_WAIT_PRIVATE: u32 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; - const FUTEX_WAKE_PRIVATE: u32 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; -diff --git a/machine/src/standard_vm/x86_64/syscall.rs b/machine/src/standard_vm/x86_64/syscall.rs -index 6f8e10d..1fe711b 100644 ---- a/machine/src/standard_vm/x86_64/syscall.rs -+++ b/machine/src/standard_vm/x86_64/syscall.rs -@@ -28,6 +28,7 @@ const FUTEX_CMP_REQUEUE: u32 = 4; - const FUTEX_WAKE_OP: u32 = 5; - const FUTEX_WAIT_BITSET: u32 = 9; - const FUTEX_PRIVATE_FLAG: u32 = 128; -+#[cfg(target_env = "gnu")] - const FUTEX_CLOCK_REALTIME: u32 = 256; - const FUTEX_WAIT_PRIVATE: u32 = FUTEX_WAIT | FUTEX_PRIVATE_FLAG; - const FUTEX_WAKE_PRIVATE: u32 = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; --- -2.17.1 - diff --git a/stratovirt-2.1.0.tar.gz b/stratovirt-2.2.0.tar.gz similarity index 72% rename from stratovirt-2.1.0.tar.gz rename to stratovirt-2.2.0.tar.gz index b65c3a77f198f6310a8a99c9a9b5758ef10a6a51..04bc7839a9e7ae6ffa069c3a37fc03a65bff8a75 100644 Binary files a/stratovirt-2.1.0.tar.gz and b/stratovirt-2.2.0.tar.gz differ diff --git a/stratovirt.spec b/stratovirt.spec index 95d3853b834504f3822dc6b8ed427de751f55f90..f91ed0a846396b22e6e4d824e55abd09fc9a69d5 100644 --- a/stratovirt.spec +++ b/stratovirt.spec @@ -5,38 +5,14 @@ %define _unpackaged_files_terminate_build 0 Name: stratovirt -Version: 2.1.0 -Release: 5 +Version: 2.2.0 +Release: 1 Summary: StratoVirt is an opensource VMM(Virtual Machine Manager) which aims to perform next generation virtualization. License: Mulan PSL v2 URL: https://gitee.com/openeuler/StratoVirt Source0: %{name}-%{version}.tar.gz -Patch001: 0001-docs-update-the-document-remove-the-other-features-t.patch -Patch002: 0002-legacy-fwcfg-fix-bug-of-wrong-size-judgment.patch -Patch003: 0003-standard_vm-add-FACS-acpi-table-on-x86-plantform.patch -Patch004: 0004-docs-build_guide-Update-suggested-rustc-version.patch -Patch005: 0005-standard_vm-syscall-Add-new-seccomp-rules.patch -Patch006: 0006-Implement-a-safe-offset_of-macro-function.patch -Patch007: 0007-loop_context-fix-the-bug-that-parked-event-not-remov.patch -Patch008: 0008-migration-use-device-id-as-snapshot-id.patch -Patch009: 0009-tests-fix-the-test_standvm_quickstart.patch -Patch010: 0010-root_port-correct-the-log-of-printing-device-info-du.patch -Patch011: 0011-tests-add-stand-kata-testcases.patch -Patch012: 0012-net-fix-the-bug-when-tap-is-abnormally-removed.patch -Patch013: 0013-docs-boot-update-detailed-usage-for-standard-boot.patch -Patch014: 0014-virtio-queue-fix-error-access-queue-s-host-virtual-a.patch -Patch015: 0015-vfio-doc-create-a-new-document-for-using-vfio.patch -Patch016: 0016-docs-correct-the-command-for-booting-with-the-raw-im.patch -Patch017: 0017-pci-no-need-to-delete-the-unmapped-region.patch -Patch018: 0018-arm-use-the-HighPcieEcam-region.patch -Patch019: 0019-vfio-fix-hot-plug-the-same-device-multiple-times-pro.patch -Patch020: 0020-machine-update-seccomp-rules.patch -Patch021: 0021-console-fix-the-bug-of-delete-park-fd.patch -Patch022: 0022-docs-add-the-description-of-hot-plug-of-PCI-devices.patch -Patch023: 0023-Modify-cargo-cllippy-warning-when-compiling-cargo-cl.patch -Patch024: 0024-machine-clear-some-warnings.patch ExclusiveArch: x86_64 aarch64 @@ -91,6 +67,9 @@ chmod 555 ${RPM_BUILD_ROOT}/usr/bin/stratovirt chmod 555 ${RPM_BUILD_ROOT}/usr/bin/ozone %changelog +* Sat Jul 30 2022 yezengruan - 2.2.0-1 +- Update to StratoVirt 2.2.0-rc1 + * Wed Mar 16 2022 zhouli57 - 2.1.0-5 - Clear some warnings.