From patchwork Wed Jan 8 08:29:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 11323061 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D379E1398 for ; Wed, 8 Jan 2020 08:29:48 +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 A7C6F206F0 for ; Wed, 8 Jan 2020 08:29:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hRdAJxUa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7C6F206F0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject: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=2cQL+BVX9vw0Bn+dFHlz6wwSn++UHI9rCVGkzp3yUPo=; b=hRdAJxUawP4KDc ecp86a7Apw3B/mBDR5bEwE7N2PbJ/q2HmDyG1Tnywgx9weREtCddVSB6yzleIy4OqFn5kaK2+lrtu 4ecTSx+1Fad2sjGgf5z2wmpHiouirs0BIWUrDitfkqhH33BGpvVM28hFZtp4QdHLVncuIuIB6eBXU MWrJj5wRBKZecIguzh4uqE3hE6EV+awPGSHgmfiTbMYgZsoDtnRfv50AqdQs934rFj8e/lC4JSZVY uUPib2szZKLY9YOKdWwisqQF2JE7F8DSPYB73xQafgSdjWaIc4fGw1XnlIW83cV3TIQdt56f0HXTW U9DdG0Tn1HS9EkiIkxtw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ip6ik-0007aD-1u; Wed, 08 Jan 2020 08:29:42 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ip6ih-0007ZK-LG for linux-arm-kernel@lists.infradead.org; Wed, 08 Jan 2020 08:29:40 +0000 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ip6iZ-00023c-6i; Wed, 08 Jan 2020 09:29:31 +0100 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1ip6iY-0005QD-6Y; Wed, 08 Jan 2020 09:29:30 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Russell King , Arnd Bergmann Subject: [PATCH] ARM: add support for DEBUG_STACKOVERFLOW Date: Wed, 8 Jan 2020 09:29:13 +0100 Message-Id: <20200108082913.29710-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200108_002939_696575_D7E0559A X-CRM114-Status: GOOD ( 12.47 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@pengutronix.de, Marc Zyngier , Thomas Gleixner , Dietmar Eggemann , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This is similar to the checks done for mips that were introduced in 334c86c494b9 ("MIPS: IRQ: Add stackoverflow detection") and helps detecting stack overflows in combination with interrupts. Signed-off-by: Uwe Kleine-König --- Hello, this is for now only lightly tested (it compiles and doesn't trigger on my test machine). Best regards Uwe arch/arm/Kconfig | 1 + arch/arm/kernel/irq.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index ba75e3661a41..f6c534f41914 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -74,6 +74,7 @@ config ARM select HAVE_CONTEXT_TRACKING select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_KMEMLEAK + select HAVE_DEBUG_STACKOVERFLOW select HAVE_DMA_CONTIGUOUS if MMU select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c index ee514034c0a1..dfd5fdc0e565 100644 --- a/arch/arm/kernel/irq.c +++ b/arch/arm/kernel/irq.c @@ -41,6 +41,7 @@ #include #include #include +#include unsigned long irq_err_count; @@ -56,6 +57,23 @@ int arch_show_interrupts(struct seq_file *p, int prec) return 0; } +#ifdef CONFIG_DEBUG_STACKOVERFLOW +#define STACK_WARN (THREAD_SIZE / 8) +static inline void check_stack_overflow(void) +{ + unsigned long remaining_stack = + current_stack_pointer & (THREAD_SIZE - 1); + + if (remaining_stack < sizeof(struct thread_info) + STACK_WARN) { + pr_err("handle_IRQ: stack overflow: %ld\n", + remaining_stack - sizeof(struct thread_info)); + dump_stack(); + } +} +#else +static inline void check_stack_overflow(void) {} +#endif + /* * handle_IRQ handles all hardware IRQ's. Decoded IRQs should * not come via this function. Instead, they should provide their @@ -64,6 +82,7 @@ int arch_show_interrupts(struct seq_file *p, int prec) */ void handle_IRQ(unsigned int irq, struct pt_regs *regs) { + check_stack_overflow(); __handle_domain_irq(NULL, irq, false, regs); }