Page protection in kernel mode or not?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Page protection in kernel mode or not?

Post by OSwhatever »

How do you setup your text and data for the kernel? Do you setup separate text and data region with different protections (execute for the text and read write for data) or do you just put it as one big region.

The advantage of having it one region is that you can use large pages without wasting too much memory and let kernel heap continue on the pages. For example you let the kernel heap expand upwards in large steps of 2MB for example. The benefit is that you get less TLB misses with large pages and have the option to lock one or more TLB entries. The disadvantage is that you get less protection in the kernel and more errors might slip through. Also once you allocate a new large page you will probably never get rid of it because of fragmentation.

You can also do the traditional and split code and data with different protection settings. Litter 4KB pages around but not waste RAM as much.

What do you think? Is the advantage of only using large pages that way in the kernel pages really worth it?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Page protection in kernel mode or not?

Post by gerryg400 »

Both methods seem to have advantages. So why not use big pages, and if you suspect a bug that caught be caught by having finer grained protection then switch temporarily to 4k pages until the bug is fixed.
If a trainstation is where trains stop, what is a workstation ?
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Page protection in kernel mode or not?

Post by Tosi »

I prefer smaller pages, but I don't know if I can explain why.
What I am planning on doing is marking pages which contain only code or constant strings as read-only, as it would make debugging easier and help keep things more stable. Having an ELF kernel makes this easier, as I can make all my sections page-aligned and then use the base addresses and length of the sections to allocate pages initially.
Post Reply