What happens when a user mode task is interrupted ? I know for a fact that the CPU switches to the kernel mode stack by refring the TSS. But when and how does the kernel switches to the IRQ stack?

  • Note that "Linux" doesn't exclusively mean "i386". Read up on how the various CPU architectures handle it (usually, on receiving an IRQ, they'll switch to supervisor mode/ring 0, and use this stack). – dirkt Dec 29 '18 at 10:36

On the x86_64, kernel code switches to the interrupt stack on an interrupt. There is one interrupt stack per CPU. If the interrupt happens when running in user mode, actually two stack switches occur: first from the user stack to the kernel stack for that thread/process (this is done automatically by the hardware), then the switch to the interrupt stack. See https://www.kernel.org/doc/Documentation/x86/kernel-stacks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.