linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>, Kees Cook <keescook@chromium.org>,
	Keith Packard <keithpac@amazon.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nicolas Pitre <nico@fluxnic.net>
Subject: [PATCH v3 00/10] ARM: add support for IRQ stacks
Date: Sun, 17 Oct 2021 15:17:13 +0200	[thread overview]
Message-ID: <20211017131723.4034662-1-ardb@kernel.org> (raw)

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.

Changes since v2:
- improve Clang support, by emitting code that is compatible with its
  frame pointer unwinder if that is the unwinder being used;
- add acks from Arnd and Linus (thanks!)

Changes since v1:
- drop the first bugfix patch, which has been queued as a fix in the
  meantime;
- preserve/restore FP in the irq_handler entry code;
- add missing include to arch/arm/kernel/irq.c to silence warnings about
  missing prototypes.

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

Patch #2 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 #3 tweaks the IRQ asm entry point to generate better code for v7
CPUs.

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

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

Patch #6 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 #7 fixes an issue in the Clang frame pointer unwinder, which may
get into an endless recursive fault if any of the stack frames have a
bogus value for the link register.

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. A pull request is outstanding for those changes.

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

Cc: Russell King <linux@armlinux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Keith Packard <keithpac@amazon.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nicolas Pitre <nico@fluxnic.net>

Ard Biesheuvel (10):
  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: backtrace-clang: avoid crash on bogus frame pointer
  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         | 41 +++++++++++++
 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             | 60 +++++++++++++++++---
 arch/arm/kernel/irq.c                    | 37 ++++++++++++
 arch/arm/kernel/smp.c                    |  5 --
 arch/arm/kernel/traps.c                  | 25 ++++++--
 arch/arm/kernel/unwind.c                 | 33 +++++++----
 arch/arm/lib/backtrace-clang.S           | 14 ++++-
 arch/arm/lib/backtrace.S                 |  8 +++
 arch/arm/lib/call_with_stack.S           | 33 ++++++++---
 13 files changed, 236 insertions(+), 68 deletions(-)

-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2021-10-17 13:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-17 13:17 Ard Biesheuvel [this message]
2021-10-17 13:17 ` [PATCH v3 01/10] ARM: remove some dead code Ard Biesheuvel
2021-10-17 13:17 ` [PATCH v3 02/10] ARM: assembler: introduce bl_r and bl_m macros Ard Biesheuvel
2021-10-17 13:17 ` [PATCH v3 03/10] ARM: optimize indirect call to handle_arch_irq for v7 cores Ard Biesheuvel
2021-10-17 13:17 ` [PATCH v3 04/10] ARM: unwind: support unwinding across multiple stacks Ard Biesheuvel
2021-10-17 13:17 ` [PATCH v3 05/10] ARM: export dump_mem() to other objects Ard Biesheuvel
2021-10-17 13:17 ` [PATCH v3 06/10] ARM: unwind: dump exception stack from calling frame Ard Biesheuvel
2021-10-17 13:17 ` [PATCH v3 07/10] ARM: backtrace-clang: avoid crash on bogus frame pointer Ard Biesheuvel
2021-10-18 19:58   ` Nick Desaulniers
2021-10-17 13:17 ` [PATCH v3 08/10] ARM: implement IRQ stacks Ard Biesheuvel
2021-10-18 20:43   ` Nick Desaulniers
2021-10-18 20:59     ` Ard Biesheuvel
2021-10-18 21:03       ` Nick Desaulniers
2021-10-17 13:17 ` [PATCH v3 09/10] ARM: call_with_stack: add unwind support Ard Biesheuvel
2021-10-18 20:50   ` Nick Desaulniers
2021-10-17 13:17 ` [PATCH v3 10/10] ARM: run softirqs on the per-CPU IRQ stack Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211017131723.4034662-1-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=keescook@chromium.org \
    --cc=keithpac@amazon.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=ndesaulniers@google.com \
    --cc=nico@fluxnic.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).