Skip to content

Commit

Permalink
Modify example to serve one page at a time to trigger bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maggie-lou committed Aug 29, 2023
1 parent 807e566 commit 570eb69
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/firecracker/examples/uffd/uffd_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,24 @@ impl UffdPfHandler {
}
}

fn populate_from_file(&self, region: &MemRegion) -> (u64, u64) {
let src = self.backing_buffer as u64 + region.mapping.offset;
fn populate_from_file(&self, region: &MemRegion, dst: u64) -> (u64, u64) {
let start_addr = region.mapping.base_host_virt_addr;
let len = region.mapping.size;
// Populate whole region from backing mem-file.
let offset = dst - start_addr;
let src = self.backing_buffer as u64 + offset;
let len = get_page_size().unwrap();
// Populate one page from backing mem-file.
// This offers an example of how memory can be loaded in RAM,
// however this can be adjusted to accommodate use case needs.
let ret = unsafe {
self.uffd
.copy(src as *const _, start_addr as *mut _, len, true)
.copy(src as *const _, dst as *mut _, len, true)
.expect("Uffd copy failed")
};

// Make sure the UFFD copied some bytes.
assert!(ret > 0);

return (start_addr, start_addr + len as u64);
return (dst, dst + len as u64);
}

fn zero_out(&mut self, addr: u64) -> (u64, u64) {
Expand Down Expand Up @@ -151,7 +152,7 @@ impl UffdPfHandler {
// event was received. This can be a consequence of guest reclaiming back its
// memory from the host (through balloon device)
Some(MemPageState::Uninitialized) | Some(MemPageState::FromFile) => {
let (start, end) = self.populate_from_file(region);
let (start, end) = self.populate_from_file(region, fault_page_addr);
self.update_mem_state_mappings(start, end, &MemPageState::FromFile);
return;
}
Expand Down

0 comments on commit 570eb69

Please sign in to comment.