Dynamic growing of ring 0 stacks
Posted: Tue Nov 09, 2010 3:17 pm
Hello,
I'm trying to dynamically grow my kernel thread stacks. I create a stack which has an initial size of one page. As soon as a page fault occurs, I want to grow the stack or report a stack overflow for this thread if the stack already reached the maximum size.
The problem is, that kernel threads are running in ring 0. As soon as a an instruction tries to write to an unmapped page of the stack a page fault occurs which then tries to push the error code, eflags, cs and eip to the stack which consequently results in a double fault which also cannot push these values to the stack which leads to a triple fault. Sad thing!
OK, so I need to switch the stack as soon as a fault occurs in any of the kernel threads as you would do in userspace using a TSS.
But since the kernel threads are already running in ring 0 there is no need for the CPU to change the stacksegment and stackpointer to the SS0 and ESP0 values in the TSS. At least that's how I understand the usage of the TSS when using software scheduling.
Is there any way to handle this without moving the kernel threads to a lower privileged level?
I'm trying to dynamically grow my kernel thread stacks. I create a stack which has an initial size of one page. As soon as a page fault occurs, I want to grow the stack or report a stack overflow for this thread if the stack already reached the maximum size.
The problem is, that kernel threads are running in ring 0. As soon as a an instruction tries to write to an unmapped page of the stack a page fault occurs which then tries to push the error code, eflags, cs and eip to the stack which consequently results in a double fault which also cannot push these values to the stack which leads to a triple fault. Sad thing!
OK, so I need to switch the stack as soon as a fault occurs in any of the kernel threads as you would do in userspace using a TSS.
But since the kernel threads are already running in ring 0 there is no need for the CPU to change the stacksegment and stackpointer to the SS0 and ESP0 values in the TSS. At least that's how I understand the usage of the TSS when using software scheduling.
Is there any way to handle this without moving the kernel threads to a lower privileged level?