Skip to content

Commit

Permalink
mm/validate: migrate all pages in bitmap
Browse files Browse the repository at this point in the history
If the number of pages in the bitmap was not a multiple of 64, the
remainder would not be copied over to the new bitmap during
migration, which could lead to tracking validated pages as invalid.

Signed-off-by: Carlos López <carlos.lopez@suse.com>
  • Loading branch information
00xc committed Nov 21, 2023
1 parent 66abf38 commit 2b0162d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/mm/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,26 @@ impl ValidBitmap {
}

fn clear_all(&mut self) {
let (mut i, bit) = self.index(self.region.end());
if bit != 0 {
i += 1;
}
let index: usize = i.try_into().unwrap();

let len = self.bitmap_len();
unsafe {
ptr::write_bytes(self.bitmap, 0, index);
ptr::write_bytes(self.bitmap, 0, len);
}
}

fn alloc_order(&self) -> usize {
bitmap_alloc_order(self.region)
}

fn migrate(&mut self, new_bitmap: *mut u64) {
let (count, _) = self.index(self.region.end());
/// The number of u64's in the bitmap
fn bitmap_len(&self) -> usize {
let num_pages = self.region.len() / PAGE_SIZE;
num_pages.div_ceil(u64::BITS as usize)
}

fn migrate(&mut self, new_bitmap: *mut u64) {
let count = self.bitmap_len();
unsafe {
ptr::copy_nonoverlapping(self.bitmap, new_bitmap, count as usize);
ptr::copy_nonoverlapping(self.bitmap, new_bitmap, count);
}
self.bitmap = new_bitmap;
}
Expand Down

0 comments on commit 2b0162d

Please sign in to comment.