OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Can I access unmapped pages from the fault handler?
PostPosted: Thu Aug 29, 2019 9:48 am 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
Can I access unmapped addresses from the page fault handler?

Or do I need to disable paging entirely in CR0 (bit 31==0)?

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Thu Aug 29, 2019 9:53 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
You need to have a mapping or disabled page translation in order to access RAM.


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Thu Aug 29, 2019 10:47 pm 
Offline
Member
Member

Joined: Wed Mar 09, 2011 3:55 am
Posts: 509
~ wrote:
Can I access unmapped addresses from the page fault handler?

Or do I need to disable paging entirely in CR0 (bit 31==0)?


If you mean "When I get a not-present fault for a virtual address, can I access the faulting virtual address from the page fault handler?", then the answer is, by definition, no. You haven't told the MMU what physical page you want mapped to that virtual address, so that address doesn't correspond to any actual memory, so there's nothing at that address to access. Even disabling paging won't help, because all that will do is access a physical address for you, but that physical address won't be related in any way to the faulting virtual address, other than that they happen to be represented by the same string of bits.

If you mean, "Can I access arbitrary pages of physical memory from a page fault handler, such as the page I plan to use for a virtual address that's being swapped in?", the the answer is "not directly by their physical address, but you can map them in the course of handling the page fault, or, if physical memory is much smaller than the available virtual address space, you can premap all of physical memory at some offset in kernelspace".


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Fri Aug 30, 2019 9:08 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
If you want to find out the exact address at which the fault has occurred just look it up in CR2.
If you want to know if you can access that specific faulty address, then it depends. If the address was mapped, it can be done. If the address wasn't mapped, then why would you?

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Fri Aug 30, 2019 11:35 am 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
My page directory and page tables are never mapped in any virtual address (they are invisible to any actual code and data).

It avoids polluting the virtual address space with paging structures that are dummies from the point of view of a process.

If I request a non-existent page table entry, it page faults and I cannot access paging structures in any way without disabling paging because they will never be virtually mapped for any reason. So I need to disable paging to modify the page entries.

For example I map around the first physical 1.5MB for my current kernel, but if I want to malloc(15) a test space at 100MB, it page faults with all paging structures themselves fully unmapped to avoid polluting my virtual address space for nothing.

If paging structures support working from virtually unmapped regions outside page tables, they probably are meant to be kept like that to make more virtual space, and disabling PG bit 31 at CR0 probably doesn't affect the cache.

Just disabling paging is probably faster than having to map new things with a visor page, if priorities are taken into account when requests to allocate or free RAM are made.

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Fri Aug 30, 2019 12:45 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I've got to say that that sounds a particularly inefficient methodology. Also it constrains you to place your kernel in any identity mapped space.

Why not just have a map of all physical memory accessible only to the kernel? That solves a lot of problems and is very versatile.


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Fri Aug 30, 2019 2:33 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
I have a bitmap for all physical RAM that is always identity mapped and will never be swapped to disk.

The page tables are unmapped, but I know which bits to free from the bitmap by inspecting the physical addresses in the paging structures.

Since the page directory and page tables are always unmapped, I need to disable paging to allocate or free pages (mapping them to temporary visor pages probably wouldn't speed up the system in this case compared to remap them fast and disable paging only for instructions that do the trick), but in exchange I don't pollute my virtual space randomly by adding page tables when I can leave them out.

User programs allocate in 4-page blocks, and single-page allocations for paging are individual although affected by 4-page alignment. But having always 4 contiguous pages can speed up by reducing fragmentation. 4 pages are marked at once for application-type allocations, but only 1 page is marked at once for paging structures from the paged memory manager, so I know that a nibble in the memory bitmap with 1's and 0's is from the memory manager, and all 1's nibbles are reserved by actual programs.

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Sat Aug 31, 2019 2:36 am 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
~ wrote:
Since the page directory and page tables are always unmapped, I need to disable paging to allocate or free pages (mapping them to temporary visor pages probably wouldn't speed up the system in this case compared to remap them fast and disable paging only for instructions that do the trick), but in exchange I don't pollute my virtual space randomly by adding page tables when I can leave them out.

Disabling paging flushes the TLB. Flushing the TLB is extremely slow! Using INVLPG to flush single pages from the TLB is much, much faster.

If you're worried about polluting your virtual address space, perhaps you'd like recursive mapping. With recursive mapping, only the currently active page tables are mapped, and they're always mapped to a fixed virtual address.


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Sat Aug 31, 2019 2:55 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
~ wrote:
4 pages are marked at once for application-type allocations, but only 1 page is marked at once for paging structures from the paged memory manager, so I know that a nibble in the memory bitmap with 1's and 0's is from the memory manager, and all 1's nibbles are reserved by actual programs.
How do you know that all 1s isn't 4 pages for paging structures?


Top
 Profile  
 
 Post subject: Re: Can I access unmapped pages from the fault handler?
PostPosted: Sat Aug 31, 2019 1:46 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
iansjack wrote:
~ wrote:
4 pages are marked at once for application-type allocations, but only 1 page is marked at once for paging structures from the paged memory manager, so I know that a nibble in the memory bitmap with 1's and 0's is from the memory manager, and all 1's nibbles are reserved by actual programs.
How do you know that all 1s isn't 4 pages for paging structures?
No pointers point to them other than paging (maybe other hardware things in the future), so nothing will deallocate them (they won't be requested).

The allocator only cares about finding free 4-page blocks marked at once for applications and 1 page for paging (the allocator won't allocate a partially-allocated 4-page block for applications, only for paging).

I only disable paging at the point where an instruction will actually affect unmapped paging structures, and then I reenable it along with interrupts, so other processes and IRQs have a normal chance of running.

I will have to run formal programs to see if the execution speed is normal, but I need to investigate it to the end of implementation.

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: 8infy, Google [Bot] and 51 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