x86/irq: Provide macro for inlining irq stack switching
authorThomas Gleixner <tglx@linutronix.de>
Tue, 9 Feb 2021 23:40:46 +0000 (00:40 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 10 Feb 2021 22:34:14 +0000 (23:34 +0100)
commita0cfc74d0b00c5201e1c09e28b2dc01c8088f809
tree9ff9e88a19413f05a00593a2e8e2d3f9dd7bff8f
parent3c5e0267ec3e6ed7d3f1793273cbf0beb4f86a74
x86/irq: Provide macro for inlining irq stack switching

The effort to make the ASM entry code slim and unified moved the irq stack
switching out of the low level ASM code so that the whole return from
interrupt work and state handling can be done in C and the ASM code just
handles the low level details of entry and exit.

This ended up being a suboptimal implementation for various reasons
(including tooling). The main pain points are:

 - The indirect call which is expensive thanks to retpoline

 - The inability to stay on the irq stack for softirq processing on return
   from interrupt

 - The fact that the stack switching code ends up being an easy to target
   exploit gadget.

Prepare for inlining the stack switching logic into the C entry points by
providing a ASM macro which contains the guts of the switching mechanism:

  1) Store RSP at the top of the irq stack
  2) Switch RSP to the irq stack
  3) Invoke code
  4) Pop the original RSP back

Document the unholy asm() logic while at it to reduce the amount of head
scratching required a half year from now.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210210002512.578371068@linutronix.de
arch/x86/include/asm/irq_stack.h