OSDev.org
https://forum.osdev.org/

Converting from physical to linear addresses
https://forum.osdev.org/viewtopic.php?f=1&t=33813
Page 1 of 1

Author:  GMorgan [ Tue Aug 06, 2019 5:44 am ]
Post subject:  Converting from physical to linear addresses

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,

Author:  iansjack [ Tue Aug 06, 2019 7:56 am ]
Post subject:  Re: Converting from physical to linear addresses

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.

Author:  GMorgan [ Tue Aug 06, 2019 9:23 am ]
Post subject:  Re: Converting from physical to linear addresses

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/