From f2d5ec4c9d385cf452796322fb70e347303776a9 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Tue, 3 Aug 2021 20:06:43 +0800 Subject: [PATCH 1/2] volatile: fix a race window in test case There's a race window in observe_mutate() and we have observed it breaking the coverage test several times. So fix it by using Barrier. Signed-off-by: Liu Jiang --- src/volatile_memory.rs | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/volatile_memory.rs b/src/volatile_memory.rs index bc33c164..244af45c 100644 --- a/src/volatile_memory.rs +++ b/src/volatile_memory.rs @@ -1368,9 +1368,8 @@ mod tests { use std::mem::size_of_val; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering}; - use std::sync::Arc; - use std::thread::{sleep, spawn}; - use std::time::Duration; + use std::sync::{Arc, Barrier}; + use std::thread::spawn; use matches::assert_matches; use vmm_sys_util::tempfile::TempFile; @@ -1563,36 +1562,20 @@ mod tests { let a = VecMem::new(1); let a_clone = a.clone(); let v_ref = a.get_ref::(0).unwrap(); + let barrier = Arc::new(Barrier::new(2)); + let barrier1 = barrier.clone(); + v_ref.store(99); spawn(move || { - sleep(Duration::from_millis(10)); + barrier1.wait(); let clone_v_ref = a_clone.get_ref::(0).unwrap(); clone_v_ref.store(0); + barrier1.wait(); }); - // Technically this is a race condition but we have to observe the v_ref's value changing - // somehow and this helps to ensure the sleep actually happens before the store rather then - // being reordered by the compiler. assert_eq!(v_ref.load(), 99); - - // Granted we could have a machine that manages to perform this many volatile loads in the - // amount of time the spawned thread sleeps, but the most likely reason the retry limit will - // get reached is because v_ref.load() is not actually performing the required volatile read - // or v_ref.store() is not doing a volatile write. A timer based solution was avoided - // because that might use a syscall which could hint the optimizer to reload v_ref's pointer - // regardless of volatile status. Note that we use a longer retry duration for optimized - // builds. - #[cfg(debug_assertions)] - const RETRY_MAX: usize = 500_000_000; - #[cfg(not(debug_assertions))] - const RETRY_MAX: usize = 10_000_000_000; - - let mut retry = 0; - while v_ref.load() == 99 && retry < RETRY_MAX { - retry += 1; - } - - assert_ne!(retry, RETRY_MAX, "maximum retry exceeded"); + barrier.wait(); + barrier.wait(); assert_eq!(v_ref.load(), 0); } From 51ccf05936eb57a578fbb8912cc1e33d9e8a5e78 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Mon, 15 Feb 2021 01:57:44 +0800 Subject: [PATCH 2/2] Release v0.6 Release vm-memory v0.6, with latest dirty track bitmap implementation. Signed-off-by: Liu Jiang --- CHANGELOG.md | 2 ++ Cargo.toml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90396600..ac25d464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +## [v0.6.0] + ### Added - [[#160]](https://github.com/rust-vmm/vm-memory/pull/160): Add `ArcRef` and `AtomicBitmapArc` bitmap diff --git a/Cargo.toml b/Cargo.toml index bc6b4f1f..fbb26bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "vm-memory" -version = "0.5.0" +version = "0.6.0" description = "Safe abstractions for accessing the VM physical memory" keywords = ["memory"] +categories = ["memory-management"] authors = ["Liu Jiang "] repository = "https://github.com/rust-vmm/vm-memory" readme = "README.md"