From c06612e43e8a9293e11d3be75b9a220df0cc2056 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 16 May 2024 03:53:07 +0800 Subject: [PATCH] lock down some key pages - no swapping of kernel pages - mark L1 PT's properly in the memory allocation table (was accidentally marking them with the VA of the first address allocated) --- kernel/src/arch/riscv/mem.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/src/arch/riscv/mem.rs b/kernel/src/arch/riscv/mem.rs index 822948fc8..6f472b666 100644 --- a/kernel/src/arch/riscv/mem.rs +++ b/kernel/src/arch/riscv/mem.rs @@ -368,7 +368,7 @@ impl MemoryMapping { #[cfg(not(feature = "swap"))] let l0pt_phys = mm.alloc_page(pid)?; #[cfg(feature = "swap")] - let l0pt_phys = mm.alloc_page(pid, Some(addr))?; + let l0pt_phys = mm.alloc_page(pid, None)?; // Mark this entry as a leaf node (WRX as 0), and indicate // it is a valid page by setting "V". @@ -630,7 +630,7 @@ pub fn map_page_inner( #[cfg(not(feature = "swap"))] let l0_pt_phys = mm.alloc_page(pid)?; #[cfg(feature = "swap")] - let l0_pt_phys = mm.alloc_page(pid, Some(virt))?; + let l0_pt_phys = mm.alloc_page(pid, None)?; // Mark this entry as a leaf node (WRX as 0), and indicate // it is a valid page by setting "V". @@ -1127,6 +1127,19 @@ pub fn evict_page_inner(target_pid: PID, vaddr: usize) -> Result> 10) << 12; + #[cfg(feature = "debug-swap")] + println!( + "-- evict: {:08x} -> {:08x} (flags: {:?}), count {}", + vaddr, + target_paddr, + MMUFlags::from_bits(target_pte & 0x3ff).unwrap(), + unsafe { MemoryManager::with(|mm| mm.get_timestamp(target_paddr)) } + ); + + // mark the page as "touched" even if the eviction checks fail: the page is definitely not LRU if + // it's not swappable. + MemoryManager::with(|mm| mm.touch(target_paddr)); + // sanity check if (target_pte & MMUFlags::VALID.bits() == 0) || (target_pte & MMUFlags::P.bits() != 0) { // return us to the swapper PID -- this call can only originate in the swapper @@ -1135,6 +1148,13 @@ pub fn evict_page_inner(target_pid: PID, vaddr: usize) -> Result Result