From 1b87f332b02361ec1948552b8d9068b2da7315bf Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Tue, 25 May 2021 13:35:36 -0700 Subject: [PATCH] block_util: Mark dirty pages manually with "VolatileSlice::as_ptr()" As discussed in the working PR in the upstream vm-memory crate repo, some special functions (e.g. return raw pointers to the wrapped guest memory) require manual dirty page tracking from their users (e.g.the VMM). One of the special functions is `VolatileSlice::as_ptr(), which is used in our code base for supporting async block I/O. This patch manually mark dirty for guest pages touched while reading from block devices. Signed-off-by: Bo Chen --- block_util/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/block_util/src/lib.rs b/block_util/src/lib.rs index 9c582696e..f57ad1661 100644 --- a/block_util/src/lib.rs +++ b/block_util/src/lib.rs @@ -36,7 +36,8 @@ use versionize::{VersionMap, Versionize, VersionizeResult}; use versionize_derive::Versionize; use virtio_bindings::bindings::virtio_blk::*; use vm_memory::{ - bitmap::AtomicBitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, + bitmap::AtomicBitmap, bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, + GuestMemoryError, }; use vm_virtio::DescriptorChain; use vmm_sys_util::eventfd::EventFd; @@ -335,6 +336,12 @@ impl Request { // Queue operations expected to be submitted. match request_type { RequestType::In => { + for (data_addr, data_len) in &self.data_descriptors { + mem.get_slice(*data_addr, *data_len as usize) + .map_err(ExecuteError::GetHostAddress)? + .bitmap() + .mark_dirty(0, *data_len as usize); + } disk_image .read_vectored(offset, iovecs, user_data) .map_err(ExecuteError::AsyncRead)?;