From c7b3a596dddc96dd40b9f294234872c18c2d1a6e Mon Sep 17 00:00:00 2001 From: Chen Chengjun Date: Fri, 1 Nov 2024 10:15:32 +0800 Subject: [PATCH] Disable IRQ during page allocation --- ostd/src/mm/page/allocator.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ostd/src/mm/page/allocator.rs b/ostd/src/mm/page/allocator.rs index 4f6ca711e..5b7660676 100644 --- a/ostd/src/mm/page/allocator.rs +++ b/ostd/src/mm/page/allocator.rs @@ -65,10 +65,16 @@ pub(in crate::mm) static PAGE_ALLOCATOR: Once> /// /// The metadata of the page is initialized with the given metadata. pub(crate) fn alloc_single(metadata: M) -> Option> { - PAGE_ALLOCATOR.get().unwrap().lock().alloc(1).map(|idx| { - let paddr = idx * PAGE_SIZE; - Page::from_unused(paddr, metadata) - }) + PAGE_ALLOCATOR + .get() + .unwrap() + .disable_irq() + .lock() + .alloc(1) + .map(|idx| { + let paddr = idx * PAGE_SIZE; + Page::from_unused(paddr, metadata) + }) } /// Allocate a contiguous range of pages of a given length in bytes. @@ -88,6 +94,7 @@ where PAGE_ALLOCATOR .get() .unwrap() + .disable_irq() .lock() .alloc(len / PAGE_SIZE) .map(|start| { @@ -113,7 +120,7 @@ where { assert!(len % PAGE_SIZE == 0); let nframes = len / PAGE_SIZE; - let mut allocator = PAGE_ALLOCATOR.get().unwrap().lock(); + let mut allocator = PAGE_ALLOCATOR.get().unwrap().disable_irq().lock(); let mut vector = Vec::new(); for _ in 0..nframes { let paddr = allocator.alloc(1)? * PAGE_SIZE;