Teach MM to flush individual TLB entries only.

This commit is contained in:
Andreas Kling 2018-10-23 15:53:11 +02:00
parent 3676214a62
commit 44045b258c
Notes: sideshowbarker 2024-07-19 18:39:56 +09:00
2 changed files with 13 additions and 9 deletions

View File

@ -92,8 +92,8 @@ void MemoryManager::protectMap(LinearAddress linearAddress, size_t length)
pte.setUserAllowed(false);
pte.setPresent(false);
pte.setWritable(false);
flushTLB(pteAddress);
}
flushTLB();
}
void MemoryManager::identityMap(LinearAddress linearAddress, size_t length)
@ -106,8 +106,8 @@ void MemoryManager::identityMap(LinearAddress linearAddress, size_t length)
pte.setUserAllowed(true);
pte.setPresent(true);
pte.setWritable(true);
flushTLB(pteAddress);
}
flushTLB();
}
void MemoryManager::initialize()
@ -155,11 +155,11 @@ byte* MemoryManager::quickMapOnePage(PhysicalAddress physicalAddress)
pte.setPhysicalPageBase(physicalAddress.pageBase());
pte.setPresent(true);
pte.setWritable(true);
flushTLB();
flushTLB(LinearAddress(4 * MB));
return (byte*)(4 * MB);
}
void MemoryManager::flushTLB()
void MemoryManager::flushEntireTLB()
{
asm volatile(
"mov %cr3, %eax\n"
@ -167,6 +167,11 @@ void MemoryManager::flushTLB()
);
}
void MemoryManager::flushTLB(LinearAddress laddr)
{
asm volatile("invlpg %0": :"m" (*(char*)laddr.get()));
}
bool MemoryManager::unmapRegion(Task& task, Task::Region& region)
{
auto& zone = *region.zone;
@ -177,10 +182,9 @@ bool MemoryManager::unmapRegion(Task& task, Task::Region& region)
pte.setPresent(false);
pte.setWritable(false);
pte.setUserAllowed(false);
flushTLB(laddr);
// kprintf("MM: >> Unmapped L%x => P%x <<\n", laddr, zone.m_pages[i].get());
}
flushTLB();
return true;
}
@ -203,10 +207,9 @@ bool MemoryManager::mapRegion(Task& task, Task::Region& region)
pte.setPresent(true);
pte.setWritable(true);
pte.setUserAllowed(!task.isRing0());
flushTLB(laddr);
//kprintf("MM: >> Mapped L%x => P%x <<\n", laddr, zone.m_pages[i].get());
}
flushTLB();
return true;
}

View File

@ -60,7 +60,8 @@ private:
~MemoryManager();
void initializePaging();
void flushTLB();
void flushEntireTLB();
void flushTLB(LinearAddress);
void protectMap(LinearAddress, size_t length);
void identityMap(LinearAddress, size_t length);