Re: Issues moving to the "one kernel stack per CPU" approach
Posted: Fri Apr 06, 2012 9:31 pm
Hi,
The only "bullet-proof" way to handle NMI is to cope with nested NMI. This implies that using a task gate (in protected mode) or using the "IST" (in long mode) for the NMI handler is a bad idea (as they can't handle nesting).
Cheers,
Brendan
As far as I can tell; after the CPU has started the NMI handler but before the CPU has had a chance to execute the NMI handler's very first instruction, a machine check exception or an SMI could occur and do IRET; and immediately after the IRET (or after a return from SMM) a second NMI can occur before you've managed to execute one instruction for the first NMI.cyr1x wrote:Yes, just don't use IRET, use RETF, etc...gerryg400 wrote: Is it possible to return from an NMI without enabling further NMIs ?
The only "bullet-proof" way to handle NMI is to cope with nested NMI. This implies that using a task gate (in protected mode) or using the "IST" (in long mode) for the NMI handler is a bad idea (as they can't handle nesting).
For "one kernel stack per CPU" you can't store a thread's state the thread's kernel stack (it'd be a massive nightmare). The easiest/best way to get around that is to store the thread's state in a "thread control block" (or TCB) when you enter the kernel, and then restore a thread's state (not necessarily the same thread) when you leave the kernel. Interrupt handlers have to check the interrupted code's CPL to determine if they have to store the interrupted thread's state.turdus wrote:In long mode you can skip the CPL check, as CPU can switch stacks with consistent data regardless to CPL change.
In general, task gates (in protected mode) and "IST" (in long mode) just complicate things more without solving anything...turdus wrote:IST also allows separate stacks for NMI, exception handlers and irq handlers for example (up to 7 stacks).
Cheers,
Brendan