[PATCH 00/10] ARM: add support for IRQ stacks

Ard Biesheuvel ardb at kernel.org
Tue Sep 21 02:53:58 PDT 2021


Compared to user space, the kernel's task stacks are tiny and
inflexible, as we don't grow them dynamically using demand paging. This
is the reason we tend to obsess about functions with disproportionately
large stack frames, given that it is hard to predict statically how
calls to those functions may combine at runtime, and exhaust the stack
and crash the kernel.

This becomes even less predictable when taking interrupt handling into
account, as their handlers are normally executed on the stack of the
task that was interrupted, regardless of how deep its call stack was at
the time of the interruption. To decouple these, and reduce the risk of
hitting a pathological worst case where IRQ handling and the task below
it happen to exhaust the available stack space when combined, we can
switch to a different stack when taking interrupts, similar to how this
is done already on some other architectures. This series implements this
approach for ARM.

Note that a good chunk of the changes below are related to supporting
non-contiguous call stacks, which is also relevant in the context of
vmap'ed stacks, which use a separate overflow stack to handle stack
overflows. The changes preserve all functionality related to walking the
call stack and dumping exception stacks and register contents, with one
small exception: when using CONFIG_UNWINDER_FRAME_POINTER=y with Clang,
(which does not record the SP value at function entry), we cannot dump
the exception stack passed by the IRQ entry code if a stack switch
occurred. All other scenarios have been tested and should work as
before.

Patch #1 fixes a bug that broke the exception stack dumping code.

Patch #2 removes some code that I spotted that is no longer used.

Patch #3 introduces a pair of macros that will be used later in the
series to emit the optimal indirect call sequence for older and newer
cores.

Patch #4 tweaks the IRQ asm entry point to generate better code for v7
CPUs.

Patch #5 updates the unwind info based unwinder so it can deal with call
stacks that are non-contiguous.

Patch #6 exports dump_mem() to other compilation units so the ARM
unwinder can cal it directly. This is needed by the next patch.

Patch #7 refactors the ARM unwinder to dump the exception stack from a
context where it can figure out if it lives on the current stack or on
the task stack.

Patch #8 implements the actual IRQ stacks support, by allocating one for
each CPU, and adding the code to switch to it in the IRQ entry path. It
also contains some related changes to allow the frame pointer based
unwinder to deal with the new situation.

Patch #9 modifies call_with_stack() so both the frame pointer unwinder
as well as the ARM unwinder know how to deal with it.

Patch #10 adds the IRQ stack switching for softIRQ handling initiated
from task context.

The patches are based on my arm32-ti-in-task-v5 branch [0], which is a
prerequisite for these changes, given that we can no longer rely on
thread_info being accessible by masking the stack pointer when we are
jumping between stacks.

Cc: Russell King <linux at armlinux.org.uk>
Cc: Arnd Bergmann <arnd at arndb.de>
Cc: Kees Cook <keescook at chromium.org>
Cc: Keith Packard <keithpac at amazon.com>
Cc: Linus Walleij <linus.walleij at linaro.org>

[0] https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm32-ti-in-task-v5

Ard Biesheuvel (10):
  ARM: fix incorrect use of get_kernel_nofault()
  ARM: remove some dead code
  ARM: assembler: introduce bl_r and bl_m macros
  ARM: optimize indirect call to handle_arch_irq for v7 cores
  ARM: unwind: support unwinding across multiple stacks
  ARM: export dump_mem() to other objects
  ARM: unwind: dump exception stack from calling frame
  ARM: implement IRQ stacks
  ARM: call_with_stack: add unwind support
  ARM: run softirqs on the per-CPU IRQ stack

 arch/arm/Kconfig                         |  6 +++
 arch/arm/include/asm/assembler.h         | 37 ++++++++++++++++
 arch/arm/include/asm/entry-macro-multi.S | 24 ----------
 arch/arm/include/asm/smp.h               |  5 ---
 arch/arm/include/asm/stacktrace.h        | 13 ++++++
 arch/arm/kernel/entry-armv.S             | 46 +++++++++++++++++---
 arch/arm/kernel/irq.c                    | 31 +++++++++++++
 arch/arm/kernel/smp.c                    |  5 ---
 arch/arm/kernel/traps.c                  | 27 +++++++++---
 arch/arm/kernel/unwind.c                 | 33 +++++++++-----
 arch/arm/lib/backtrace-clang.S           |  8 ++++
 arch/arm/lib/backtrace.S                 |  8 ++++
 arch/arm/lib/call_with_stack.S           | 44 ++++++++++++++++---
 13 files changed, 223 insertions(+), 64 deletions(-)

-- 
2.30.2




More information about the linux-arm-kernel mailing list