From caf5fa955bd4de8889f388cabc4dc33bd4a5f9f1 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 6 Jul 2025 16:08:38 +0200 Subject: [PATCH] Fix freeing of phys_contiguous frames Previously the deallocation would be rounded to the next power of two preventing partial deallocation. But more importantly previously trying to free phys_contiguous frames while another processes still borrows them. Now this should just cause the deallocation to be delayed. --- src/context/memory.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/context/memory.rs b/src/context/memory.rs index 890eb5b21e..6234d67399 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -15,8 +15,8 @@ use crate::{ context::arch::setup_new_utable, cpu_set::LogicalCpuSet, memory::{ - deallocate_frame, deallocate_p2frame, get_page_info, init_frame, the_zeroed_frame, - AddRefError, Enomem, Frame, PageInfo, RaiiFrame, RefCount, RefKind, + deallocate_frame, get_page_info, init_frame, the_zeroed_frame, AddRefError, Enomem, Frame, + PageInfo, RaiiFrame, RefCount, RefKind, }, paging::{Page, PageFlags, PageMapper, RmmA, TableKind, VirtualAddress}, percpu::PercpuBlock, @@ -2719,15 +2719,17 @@ impl GenericFlusher for NopFlusher { fn handle_free_action(base: Frame, phys_contiguous_count: Option) { if let Some(count) = phys_contiguous_count { for i in 0..count.get() { - let new_rc = get_page_info(base.next_by(i)) + let frame = base.next_by(i); + let new_rc = get_page_info(frame) .expect("phys_contiguous frames all need PageInfos") .remove_ref(); - assert_eq!(new_rc, None); - } - unsafe { - let order = count.get().next_power_of_two().trailing_zeros(); - deallocate_p2frame(base, order); + if new_rc.is_none() { + // FIXME use a single deallocate_p2frame when possible + unsafe { + deallocate_frame(frame); + } + } } } else { let Some(info) = get_page_info(base) else {