OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:28 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Converting from physical to linear addresses
PostPosted: Tue Aug 06, 2019 5:44 am 
Offline

Joined: Sun Jul 14, 2019 4:27 pm
Posts: 22
Hi guys,

One of the issues I've just run into is what happens when you exit identity mapping mode. Essentially when in identity mapping you can just convert page table look ups from physical to linear as they are 1:1. When in any kind of real OS you won't have this property. When you look up an address in a hierarchy table that is a physical address according to the Intel manual and might not map to the linear address you need to edit the table.

How do people typically manage reverse mapping? Going from the physical address to the linear. I was planning on just explicitly capturing P4 but it seems this is inadequate.

Thanks,


Top
 Profile  
 
 Post subject: Re: Converting from physical to linear addresses
PostPosted: Tue Aug 06, 2019 7:56 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
As I understand it, you are asking how to discover what virtaul address corresponds to a particular physical address. The answer is that there is not necessarily any such address, or there may be several.

I presume the reason that you need this is so that you can alter page tables, and other structures that must use physical addresses. The answer is that you have to set up your own mapping to do this. A simple solution is to map all physical memory to a particular range of virtual addresses - this only really makes sense in a 64-bit environment where you have a practically unlimited address space. Another answer is to use recursive page tables ( https://wiki.osdev.org/Page_Tables#Recursive_mapping ), although it can be a bit difficult getting your head around this. Or you can reserve a small range of virtual addresses and map individual pages as needed - but this is relatively inefficient. I use the first method - it does use up some available memory, but probably not as much as you might imagine, particularly if you are not working with a huge amount of RAM. If you do this you have to ensure that this mapping is only available to the kernel, not to user programs.


Top
 Profile  
 
 Post subject: Re: Converting from physical to linear addresses
PostPosted: Tue Aug 06, 2019 9:23 am 
Offline

Joined: Sun Jul 14, 2019 4:27 pm
Posts: 22
Thanks.

I'm going with the offset map solution as frankly I can just use the entire kernel space from P4[1] on. It requires a table switch to modify any pages but the TLB is unlikely to have the relevant pages hot anyway. I will never use 512gb for a kernel.

I'll also need to check that this works for arm 64 but even if it doesn't, nothing is forcing me to use the same scheme. I'll try to wrap the table management to keep a consistent interface.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 61 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group