From 7205dd7463dbef7c9f9390aa2da4e55e4d3eac14 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 12 Apr 2022 20:17:27 -0600 Subject: [PATCH] Unmap xAPIC page if already mapped --- src/arch/x86_64/device/local_apic.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/arch/x86_64/device/local_apic.rs b/src/arch/x86_64/device/local_apic.rs index ab2c784..913781e 100644 --- a/src/arch/x86_64/device/local_apic.rs +++ b/src/arch/x86_64/device/local_apic.rs @@ -48,8 +48,16 @@ impl LocalApic { if ! self.x2 { let page = Page::containing_address(VirtualAddress::new(self.address)); let frame = Frame::containing_address(PhysicalAddress::new(self.address - crate::PHYS_OFFSET)); + log::info!("Detected xAPIC at {:#x}", frame.start_address().data()); + if active_table.translate_page(page).is_some() { + // Unmap xAPIC page if already mapped + let (result, _frame) = active_table.unmap_return(page, true); + result.flush(); + } let result = active_table.map_to(page, frame, PageFlags::new().write(true)); result.flush(); + } else { + log::info!("Detected x2APIC"); } self.init_ap();