Skip to content

Commit c379d50

Browse files
committed
Restructure signal-based dirty page tracker to be part of SharedMemory
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent b9679ac commit c379d50

File tree

9 files changed

+363
-819
lines changed

9 files changed

+363
-819
lines changed

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ pub(crate) mod tests {
512512
#[cfg(gdb)]
513513
use crate::hypervisor::DbgMemAccessHandlerCaller;
514514
use crate::mem::ptr::RawPtr;
515+
use crate::mem::shared_mem::SharedMemory;
515516
use crate::sandbox::uninitialized::GuestBinary;
516517
#[cfg(any(crashdump, gdb))]
517518
use crate::sandbox::uninitialized::SandboxRuntimeConfig;
@@ -581,6 +582,10 @@ pub(crate) mod tests {
581582
GuestPtr::try_from(Offset::from(0))
582583
}?;
583584

585+
// We need to stop tracking dirty pages from the host side before we start the guest
586+
gshm.shared_mem
587+
.with_exclusivity(|e| e.stop_tracking_dirty_pages())??;
588+
584589
let mut vm = set_up_hypervisor_partition(
585590
&mut gshm,
586591
&config,

src/hyperlight_host/src/mem/dirty_page_tracking.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,46 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
use std::sync::Arc;
18+
1719
use tracing::{Span, instrument};
1820

1921
#[cfg(target_os = "linux")]
2022
pub use super::linux_dirty_page_tracker::LinuxDirtyPageTracker as PlatformDirtyPageTracker;
21-
use super::shared_mem::SharedMemory;
23+
use super::shared_mem::HostMapping;
2224
#[cfg(target_os = "windows")]
2325
pub use super::windows_dirty_page_tracker::WindowsDirtyPageTracker as PlatformDirtyPageTracker;
2426
use crate::Result;
2527

2628
/// Trait defining the interface for dirty page tracking implementations
2729
pub trait DirtyPageTracking {
28-
fn get_dirty_pages(self) -> Result<Vec<usize>>;
30+
#[cfg(test)]
31+
fn get_dirty_pages(&self) -> Result<Vec<usize>>;
32+
fn uninstall(self) -> Result<Vec<usize>>;
2933
}
3034

3135
/// Cross-platform dirty page tracker that delegates to platform-specific implementations
36+
#[derive(Debug)]
3237
pub struct DirtyPageTracker {
3338
inner: PlatformDirtyPageTracker,
3439
}
3540

3641
impl DirtyPageTracker {
3742
/// Create a new dirty page tracker for the given shared memory
3843
#[instrument(skip_all, parent = Span::current(), level = "Trace")]
39-
pub fn new<T: SharedMemory>(shared_memory: &T) -> Result<Self> {
40-
let inner = PlatformDirtyPageTracker::new(shared_memory)?;
44+
pub fn new(mapping: Arc<HostMapping>) -> Result<Self> {
45+
let inner = PlatformDirtyPageTracker::new(mapping)?;
4146
Ok(Self { inner })
4247
}
4348
}
4449

4550
impl DirtyPageTracking for DirtyPageTracker {
46-
fn get_dirty_pages(self) -> Result<Vec<usize>> {
51+
fn uninstall(self) -> Result<Vec<usize>> {
52+
self.inner.stop_tracking_and_get_dirty_pages()
53+
}
54+
55+
#[cfg(test)]
56+
fn get_dirty_pages(&self) -> Result<Vec<usize>> {
4757
self.inner.get_dirty_pages()
4858
}
4959
}

0 commit comments

Comments
 (0)