Skip to content

Commit

Permalink
paging: fix possible deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6D70 committed Sep 18, 2024
1 parent 33a9284 commit 1dc0334
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions xernel/kernel/src/mem/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,19 @@ impl Pagemap {
}

fn deallocate_pt(pt: *mut PageTable, level: u8) {
let mut frame_allocator = FRAME_ALLOCATOR.lock();
if level == 4 {
for i in 0..256 {
unsafe {
if (*pt)[i].flags().contains(PageTableFlags::PRESENT) {
let pt = ((*pt)[i].addr().as_u64() + *HIGHER_HALF_OFFSET) as *mut PageTable;

// FIXME: this will deadlock, because the frame allocator is already locked
Self::deallocate_pt(pt, level - 1);
}
}
}

unsafe {
frame_allocator.deallocate_frame(
FRAME_ALLOCATOR.lock().deallocate_frame(
PhysFrame::<Size4KiB>::from_start_address(PhysAddr::new(pt as u64 - *HIGHER_HALF_OFFSET)).unwrap(),
);
}
Expand All @@ -360,7 +358,7 @@ impl Pagemap {
}

unsafe {
frame_allocator.deallocate_frame(
FRAME_ALLOCATOR.lock().deallocate_frame(
PhysFrame::<Size4KiB>::from_start_address(PhysAddr::new(pt as u64 - *HIGHER_HALF_OFFSET)).unwrap(),
);
}
Expand Down

0 comments on commit 1dc0334

Please sign in to comment.