Page 1 of 1

Page protection in kernel mode or not?

Posted: Wed Jan 12, 2011 8:11 pm
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?

Re: Page protection in kernel mode or not?

Posted: Wed Jan 12, 2011 9:17 pm
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.

Re: Page protection in kernel mode or not?

Posted: Thu Jan 13, 2011 8:19 am
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.