Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6536665ybl; Mon, 23 Dec 2019 07:27:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyXQq2dchgF+usARc/+7tlx8rt0riB7nqUJmIYzi9o1LB2Y/tnke5cKREiKQ07bS7+W8tpU X-Received: by 2002:a05:6830:1487:: with SMTP id s7mr12902390otq.269.1577114872052; Mon, 23 Dec 2019 07:27:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577114872; cv=none; d=google.com; s=arc-20160816; b=opVdiJ9ogLKCwVWKp0aZj3/kQ5UkgQPijiP9+60DbWVQrIRRFvdoevhK5n6+Oa+7n8 9MOaO2N0sYFDXdP53rBqVjbZAboagbHcrlnA2kaDivszPOR4k/ypQUygbf5jlqF99Wi0 P5W78IA4qYUp9LMRGT2ERV1imjiAgoQE4SzC0SuJ2HvDZfxy8DWrq4+hz6OgSL5bhZ+P eSszt5CyL9BLv2LAzTVULdXdopbLsfNEF/kSkZyGR1uKrt8xZQIjkYc4cbm2Jzihw5zU FDvvMZe2PcWpPZWqdxg8G0JkhLV5IC757RVpYQkT5mU0+yv9Fj1j2L93ply/IB5+4nAM dLKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=D3+VKZJ3hPYAS69Fkh6Xu5UkefnPwZgOHwwzmESq47E=; b=Yr6C4x/5wC8a+XDDkxSvCLC3LGEud46PmPs5KtSr0jKsxqGI/XvHeoBf4qe/m3CyQY L4gGDwOuwkXWe7TIDmDvVn6d9NQ+IvWcf4pP13JVQ2bqGO/adG8U2IrVxBghngSpsuFu TEKBLWOaYrCnQHTC5Lgmze077L3dBoI445sIYZTExzg96MIOQ08jniJePKTRyKA1Mlf6 XxVmYcq+78NB+ELWsTOtCwSS5YVJnTfpcfwrYeiMZbL1ruR3buAuw0YpHMdA07yf/whY ZmEBPcdPdJ4NqqcCV2IYQY0C6QVz0S4s1P1hAtIZSuzzx8VR697urFhGOUaviCwtgB1W 1OQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=SVJZ6Mlz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9si9967069otq.68.2019.12.23.07.27.41; Mon, 23 Dec 2019 07:27:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=SVJZ6Mlz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727183AbfLWP0d (ORCPT + 99 others); Mon, 23 Dec 2019 10:26:33 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:13491 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726934AbfLWP0S (ORCPT ); Mon, 23 Dec 2019 10:26:18 -0500 Received: from localhost (mailhub1-ext [192.168.12.233]) by localhost (Postfix) with ESMTP id 47hNVC08mlz9vJyn; Mon, 23 Dec 2019 16:26:11 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=SVJZ6Mlz; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id NMduw6uLKHzc; Mon, 23 Dec 2019 16:26:10 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 47hNVB65gtz9vJyx; Mon, 23 Dec 2019 16:26:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1577114770; bh=D3+VKZJ3hPYAS69Fkh6Xu5UkefnPwZgOHwwzmESq47E=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=SVJZ6MlzwisGMPUrmb7zjVPn5E8ioInBlKV63cjaMHP359fiVDCGeCtBL5c7Aj4ga AF6Jo0GLl1l0ZXQGUUjJidH0sEXKC9h1uHvPP2AbupP4aEkLAv03ie8lEC2Q8n6j+j aIV0/BOVpK5WBNpgm9FZ5rrlbf92caXOOrUkX52s= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0ADF38B7AB; Mon, 23 Dec 2019 16:26:16 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id nedWeDvJrad3; Mon, 23 Dec 2019 16:26:15 +0100 (CET) Received: from po16098vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.100]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E0D5B8B7A1; Mon, 23 Dec 2019 16:26:15 +0100 (CET) Received: by po16098vm.idsi0.si.c-s.fr (Postfix, from userid 0) id E4733637D8; Mon, 23 Dec 2019 15:26:15 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH 5/8] powerpc/irq: move stack overflow verification To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Mon, 23 Dec 2019 15:26:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As we are going to switch to IRQ stack immediately in the exception handler, it won't be possible anymore to check stack overflow by reading stack pointer. Do the verification on regs->gpr[1] which contains the stack pointer at the time the IRQ happended, and move it to __do_irq() so that the verification is also done when calling __do_irq() directly once the exception entry does the stack switch. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/irq.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index 28414c6665cc..4df49f6e9987 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c @@ -596,15 +596,16 @@ u64 arch_irq_stat_cpu(unsigned int cpu) return sum; } -static inline void check_stack_overflow(void) +static inline void check_stack_overflow(struct pt_regs *regs) { #ifdef CONFIG_DEBUG_STACKOVERFLOW + bool is_user = user_mode(regs); long sp; - sp = current_stack_pointer() & (THREAD_SIZE-1); + sp = regs->gpr[1] & (THREAD_SIZE - 1); /* check for stack overflow: is there less than 2KB free? */ - if (unlikely(sp < 2048)) { + if (unlikely(!is_user && sp < 2048)) { pr_err("do_IRQ: stack overflow: %ld\n", sp); dump_stack(); } @@ -654,6 +655,8 @@ void __do_irq(struct pt_regs *regs) trace_irq_entry(regs); + check_stack_overflow(regs); + /* * Query the platform PIC for the interrupt & ack it. * @@ -685,8 +688,6 @@ void do_IRQ(struct pt_regs *regs) irqsp = hardirq_ctx[raw_smp_processor_id()]; sirqsp = softirq_ctx[raw_smp_processor_id()]; - check_stack_overflow(); - /* Already there ? Otherwise switch stack and call */ if (unlikely(cursp == irqsp || cursp == sirqsp)) __do_irq(regs); -- 2.13.3