From 65448c2d4875ca5a1f1f58b79d4407c8e1923591 Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Thu, 21 Jan 2021 11:41:26 +0000 Subject: [PATCH] aarch64: context: memory: Grant::map_inactive: Bugfix When mapping one (from) virtual address range to another (to) virtual address range, be mindful of which mapper type to use for each range. Before this, the same mapper type was used for both ranges. This meant that if from and to were different (as in not both kernel virtual addresses or user virtual addresses) then it would appear that either from or to was not mapped previously and the kernel would panic. --- src/context/memory.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/context/memory.rs b/src/context/memory.rs index e050467..f61c1e9 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -371,7 +371,7 @@ impl Grant { } pub fn map_inactive(from: VirtualAddress, to: VirtualAddress, size: usize, flags: EntryFlags, desc_opt: Option, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) -> Grant { - let mut active_table = match to.get_type() { + let mut active_table = match from.get_type() { VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) }, VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) } }; @@ -386,6 +386,11 @@ impl Grant { frames.push_back(frame); } + let mut active_table = match to.get_type() { + VirtualAddressType::User => unsafe { ActivePageTable::new(PageTableType::User) }, + VirtualAddressType::Kernel => unsafe { ActivePageTable::new(PageTableType::Kernel) } + }; + active_table.with(new_table, temporary_page, |mapper| { let start_page = Page::containing_address(to); let end_page = Page::containing_address(VirtualAddress::new(to.data() + size - 1));