Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A653C10F0E for ; Thu, 18 Apr 2019 14:26:33 +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 69098206B6 for ; Thu, 18 Apr 2019 14:26:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cTJBYO6Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69098206B6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9cpRG5vKL0ON+O7pYe9OHp9jxQaatpBzppYMdP/ZpM8=; b=cTJBYO6ZEdJ7vJ xeMUrKWi2i0l0CH/O+tryNm1rXBdaM59TKThJGu7rYqIthc6buUs6Qc2/xDo4xWX7iTGqL8g8OLo/ DO0/xbv4byPQoiqbmaiJFuZ6Fx/tSNBnfPS2c8FP95TVkCcnWw2NsCha0vX8POvGTir4nD3coBlJo tADTGGG/KtY1uwEfxyQ/p37gnV9pC8Z5JcaP9oYgQd0alZoKELVlzw6Oo9MXwT65YeveU//xsoEdc l68oISFdMuLVK4BhRzUnz0KOrfQlt9nCnvCmAl7HN1JEPeKIGYbHEv6ragIxHBf503ojtTHo9s4Eq eRVEk1xlzJEY5ozhRCZw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH7zi-0005sI-Ba; Thu, 18 Apr 2019 14:26:30 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hH7ze-0005r3-R1 for linux-arm-kernel@lists.infradead.org; Thu, 18 Apr 2019 14:26:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 620D980D; Thu, 18 Apr 2019 07:26:22 -0700 (PDT) Received: from [10.1.197.45] (e112298-lin.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 960473F5AF; Thu, 18 Apr 2019 07:26:20 -0700 (PDT) Subject: Re: [PATCH] arm64: fix kernel stack overflow in kdump capture kernel To: Wei Li , catalin.marinas@arm.com, will.deacon@arm.com References: <20190418140251.31218-1-liwei391@huawei.com> From: Julien Thierry Message-ID: <401bab0b-88f6-02ea-c49d-08947a337244@arm.com> Date: Thu, 18 Apr 2019 15:26:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190418140251.31218-1-liwei391@huawei.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190418_072626_884205_7DF37F76 X-CRM114-Status: GOOD ( 27.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, daniel.thompson@linaro.org, marc.zyngier@arm.com, christoffer.dall@arm.com, james.morse@arm.com, joel@joelfernandes.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Wei, On 18/04/2019 15:02, Wei Li wrote: > When enabling ARM64_PSEUDO_NMI feature in kdump capture kernel, it will > report a kernel stack overflow exception: > > [ 0.000000] CPU features: detected: IRQ priority masking > [ 0.000000] alternatives: patching kernel code > [ 0.000000] Insufficient stack space to handle exception! > [ 0.000000] ESR: 0x96000044 -- DABT (current EL) > [ 0.000000] FAR: 0x0000000000000040 > [ 0.000000] Task stack: [0xffff0000097f0000..0xffff0000097f4000] > [ 0.000000] IRQ stack: [0x0000000000000000..0x0000000000004000] > [ 0.000000] Overflow stack: [0xffff80002b7cf290..0xffff80002b7d0290] > [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.34-lw+ #3 Can you reproduce this on a recent kernel? > [ 0.000000] pstate: 400003c5 (nZcv DAIF -PAN -UAO) > [ 0.000000] pc : el1_sync+0x0/0xb8 > [ 0.000000] lr : el1_irq+0xb8/0x140 > [ 0.000000] sp : 0000000000000040 > [ 0.000000] pmr_save: 00000070 > [ 0.000000] x29: ffff0000097f3f60 x28: ffff000009806240 > [ 0.000000] x27: 0000000080000000 x26: 0000000000004000 > [ 0.000000] x25: 0000000000000000 x24: ffff000009329028 > [ 0.000000] x23: 0000000040000005 x22: ffff000008095c6c > [ 0.000000] x21: ffff0000097f3f70 x20: 0000000000000070 > [ 0.000000] x19: ffff0000097f3e30 x18: ffffffffffffffff > [ 0.000000] x17: 0000000000000000 x16: 0000000000000000 > [ 0.000000] x15: ffff0000097f9708 x14: ffff000089a382ef > [ 0.000000] x13: ffff000009a382fd x12: ffff000009824000 > [ 0.000000] x11: ffff0000097fb7b0 x10: ffff000008730028 > [ 0.000000] x9 : ffff000009440018 x8 : 000000000000000d > [ 0.000000] x7 : 6b20676e69686374 x6 : 000000000000003b > [ 0.000000] x5 : 0000000000000000 x4 : ffff000008093600 > [ 0.000000] x3 : 0000000400000008 x2 : 7db2e689fc2b8e00 > [ 0.000000] x1 : 0000000000000000 x0 : ffff0000097f3e30 > [ 0.000000] Kernel panic - not syncing: kernel stack overflow > [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.34-lw+ #3 > [ 0.000000] Call trace: > [ 0.000000] dump_backtrace+0x0/0x1b8 > [ 0.000000] show_stack+0x24/0x30 > [ 0.000000] dump_stack+0xa8/0xcc > [ 0.000000] panic+0x134/0x30c > [ 0.000000] __stack_chk_fail+0x0/0x28 > [ 0.000000] handle_bad_stack+0xfc/0x108 > [ 0.000000] __bad_stack+0x90/0x94 > [ 0.000000] el1_sync+0x0/0xb8 > [ 0.000000] init_gic_priority_masking+0x4c/0x70 > [ 0.000000] smp_prepare_boot_cpu+0x60/0x68 > [ 0.000000] start_kernel+0x1e8/0x53c > [ 0.000000] ---[ end Kernel panic - not syncing: kernel stack overflow ]--- > > The reason is init_gic_priority_masking() may unmask PSR.I while the > irq stacks are not inited yet. Some "NMI" could be raised unfortunately > and it will just go into this exception. > > In this patch, we just write the PMR in smp_prepare_boot_cpu(), and delay > unmasking PSR.I after irq stacks inited in init_IRQ(). > > Fixes: e79321883842 ("arm64: Switch to PMR masking when starting CPUs") > Signed-off-by: Wei Li > --- > arch/arm64/include/asm/smp.h | 2 ++ > arch/arm64/kernel/irq.c | 2 ++ > arch/arm64/kernel/smp.c | 8 ++++---- > 3 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h > index 18553f399e08..4d8eb35f4cdd 100644 > --- a/arch/arm64/include/asm/smp.h > +++ b/arch/arm64/include/asm/smp.h > @@ -158,6 +158,8 @@ bool cpus_are_stuck_in_kernel(void); > extern void crash_smp_send_stop(void); > extern bool smp_crash_stop_failed(void); > > +extern void init_gic_priority_masking(bool enable); > + > #endif /* ifndef __ASSEMBLY__ */ > > #endif /* ifndef __ASM_SMP_H */ > diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c > index 92fa81798fb9..7e65280f2ebd 100644 > --- a/arch/arm64/kernel/irq.c > +++ b/arch/arm64/kernel/irq.c > @@ -75,4 +75,6 @@ void __init init_IRQ(void) > irqchip_init(); > if (!handle_arch_irq) > panic("No interrupt controller found."); > + if (system_uses_irq_prio_masking()) > + init_gic_priority_masking(true); > } > diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c > index 824de7038967..07b6e9df151a 100644 > --- a/arch/arm64/kernel/smp.c > +++ b/arch/arm64/kernel/smp.c > @@ -181,7 +181,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) > return ret; > } > > -static void init_gic_priority_masking(void) > +void init_gic_priority_masking(bool enable) > { > u32 cpuflags; > > @@ -195,7 +195,7 @@ static void init_gic_priority_masking(void) > gic_write_pmr(GIC_PRIO_IRQOFF); > > /* We can only unmask PSR.I if we can take aborts */ > - if (!(cpuflags & PSR_A_BIT)) > + if (enable && !(cpuflags & PSR_A_BIT)) > write_sysreg(cpuflags & ~PSR_I_BIT, daif); > } > > @@ -226,7 +226,7 @@ asmlinkage notrace void secondary_start_kernel(void) > cpu_uninstall_idmap(); > > if (system_uses_irq_prio_masking()) > - init_gic_priority_masking(); > + init_gic_priority_masking(true); > > preempt_disable(); > trace_hardirqs_off(); > @@ -451,7 +451,7 @@ void __init smp_prepare_boot_cpu(void) > > /* Conditionally switch to GIC PMR for interrupt masking */ > if (system_uses_irq_prio_masking()) > - init_gic_priority_masking(); > + init_gic_priority_masking(false); The assumption is that PSR.A should be set at this point (the kernel is not more ready to take async exceptions than it is ready to take interrupts) and we shouldn't be unmasking PSR.I. PSR.A should be set when booting Linux (requirement in Documentation/arm64/booting.txt), do you know what is clearing it and why? Thanks, -- Julien Thierry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel