From patchwork Sun Oct 17 13:17:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12564305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFD65C433EF for ; Sun, 17 Oct 2021 13:19:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A862B60F9E for ; Sun, 17 Oct 2021 13:19:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A862B60F9E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=a11bHHHdrQQjqcLOODWRVVtwTotjvpU7bSPjLX4Zgpg=; b=Cm8EkieHxkGTr8 j6wg8hEuJdPHX2H7AasYz2SVy4wGyU2P8S2/JzYLCRUIzDc6OZFlb5f4TUcgikDzb2jhHA9a9fvd0 yS9MvY1MTHk2D+ulDXYVjCLsrZel2/4hL34mOwjiEKIKnWrHf/hhMdSYyktNkQjz+acApdvGA/vhB h8598s53YsVdjfhiVmGD5eILj99CmgPoRqYFdSk7IrL7u2+vW2uxK3xqp2o/DUTFUy/gT+Gj+6+Zm dDEBU1jVymRJ53e8UxgPc1Go2CWdLozwmgR8zTO8REdf2wK+0mZOZDwqtDYhrQavWs5TLOkqC6t4T ODCiXfo34dEmX+8+mOxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc62j-00CaaL-51; Sun, 17 Oct 2021 13:17:37 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc62e-00CaZ6-GM for linux-arm-kernel@lists.infradead.org; Sun, 17 Oct 2021 13:17:34 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6FB6C60F9E; Sun, 17 Oct 2021 13:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634476651; bh=9JWk7bxaDn6/awM0IOtDa11zB6iCwk/xP36AZ2OQFI8=; h=From:To:Cc:Subject:Date:From; b=rR1lcKuxgASO8hZlvhuFfrrT9yt2mwSs4z4cnX74xtdAKbpMETV3Vd76/Eg5ZIOfk 9WgPGKrFg79nO+mPNv5QZXyyu+K9FDYmCsSdE7ych6dl7dRqRez7/+0HB30vXFBQmw 1xhKsv4xhwH72r5nrzK8aG6Kxfdccx/458PzjOikB7dN6ertsXntN9m60LJIRWrRcK SM8KJN2/liNvsE9eLVHVanqoKdgzE1k1ByBr+eqC3ftZGlQ1/9SrQ4ca6jwK75TPrD zio1MXqBRrBkOS2CCCPYaNS8Oq/XzOOSRLn37IDcqcd2FLJaa7IFgZyr9PYmdjZ7w6 ilnTJPECs+6RQ== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Russell King , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Nicolas Pitre Subject: [PATCH v3 00/10] ARM: add support for IRQ stacks Date: Sun, 17 Oct 2021 15:17:13 +0200 Message-Id: <20211017131723.4034662-1-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5131; h=from:subject; bh=9JWk7bxaDn6/awM0IOtDa11zB6iCwk/xP36AZ2OQFI8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhbCJPUQqe0lSCAnrlPXP7+swp1zQ4/yCJMgQ25NIe LqhN7neJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYWwiTwAKCRDDTyI5ktmPJC8PDA CGg8uEocBNxh2VfqCLmt1VnR5uV/X2V+f7fW0ssqHabW6dAzde/BS98HnIDNXl/mV8NXCrXFcsZPMF RWU1cRgkh9LFh8ZhTbS1lrWh0RnWO+WodvkblWYcVLmBDh8HrR2WvajXGfQtKXk8hcc5FbaEQpLS15 cPd2LoRXheRhDeq3VdVp5TyoAvBwCESouer/WcIua0hiRHCwkMmUTM9rR0e2Gjrkf94VcCqouCsWaU A1EASfTVl8rNMNrpvgZp604Ox9EVbEk95p8AzrvXUVf2MJaUPoSdSRSp0T5GvrRdmEX/RqE/Vragmi zY7fwAufEHITR1NvcKz0cYrM+1f1DNFf7DZOCyVLS5eDYRCZmaRDvv4HEvXzHzFP5xOSmF6zsNK4GS 3teIUw53UG4YMeYabaxUDt8pZVasMA7a/pwbBoiwlE7D4Uo2cFojspdVMTAeglx4QzUb369Qy6c0uG H+cnUhJz59b2eBN8lADhkQz3CVoaSzAdBvKT/6T1BzWQI= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_061732_633937_34FA0B97 X-CRM114-Status: GOOD ( 21.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Cc: Arnd Bergmann Cc: Kees Cook Cc: Keith Packard Cc: Linus Walleij Cc: Nick Desaulniers Cc: Nicolas Pitre 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(-)