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?
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