From patchwork Tue Oct 18 17:05:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9382725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 85F5A607D0 for ; Tue, 18 Oct 2016 17:07:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 700022958B for ; Tue, 18 Oct 2016 17:07:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6293A29627; Tue, 18 Oct 2016 17:07:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4E3272958B for ; Tue, 18 Oct 2016 17:07:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwXpY-00031U-P5; Tue, 18 Oct 2016 17:05:36 +0000 Received: from quartz.orcorp.ca ([184.70.90.242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwXpV-0002XD-Qq for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2016 17:05:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=Content-Type:MIME-Version:Message-ID:Subject:To:From:Date; bh=XGYafXsAsRDEnE0VP8iW3lkc3oeAOSU/rnxvG0rVuEQ=; b=zgoKuWFvub5JDD85PfMblq0nLmhO+W4EcB3HVCfYGDTGoh31brsHkID16yyFfGq17QJr744/1sBf3hJMl+gA9eAui5vg+s3g5cB+Aq0vmAhRMuwh9i0zTzp//vwBEQLIyvLyHpPzkQ3+vL+G1SIhJ5EewBS+9WRhMVUgbCvo/0s=; Received: from [10.0.0.151] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bwXp8-0005Gi-Lc; Tue, 18 Oct 2016 11:05:10 -0600 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.84) (envelope-from ) id 1bwXp8-0003Cm-Hj; Tue, 18 Oct 2016 11:05:10 -0600 Date: Tue, 18 Oct 2016 11:05:10 -0600 From: Jason Gunthorpe To: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] [ARM] Fix stack alignment when processing backtraces Message-ID: <20161018170510.GA12248@obsidianresearch.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161018_100534_009311_5DC37D6A X-CRM114-Status: UNSURE ( 9.83 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The dumpstm helper within c_backtrace pushed 5 dwords onto the stack causing the stack to become unaligned and then calls printk. This causes memory corruption in the kernel which assumes AAPCS calling convention. Since this bit of asm doesn't use the standard prologue just add another register to restore alignment. Fixes: 7ab3f8d595a1b ("[ARM] Add ability to dump exception stacks to kernel backtraces") Signed-off-by: Jason Gunthorpe --- arch/arm/lib/backtrace.S | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) In my case the kernel was hitting a WARN_ON during boot and then reliably failed to start the compiled-in initramfs. I'm inferring that the stack misalignment caused some kind of memory corruption which wiped out the unpacked initramfs. Saw with gcc 5.4.0 on a kirkwood armv5te diff --git a/arch/arm/lib/backtrace.S b/arch/arm/lib/backtrace.S index fab5a50503ae..25e1cce19991 100644 --- a/arch/arm/lib/backtrace.S +++ b/arch/arm/lib/backtrace.S @@ -116,7 +116,8 @@ ENDPROC(c_backtrace) #define reg r5 #define stack r6 -.Ldumpstm: stmfd sp!, {instr, reg, stack, r7, lr} + /* Must maintain 8 byte stack alignment */ +.Ldumpstm: stmfd sp!, {r3, instr, reg, stack, r7, lr} mov stack, r0 mov instr, r1 mov reg, #10 @@ -140,7 +141,7 @@ ENDPROC(c_backtrace) teq r7, #0 adrne r0, .Lcr blne printk - ldmfd sp!, {instr, reg, stack, r7, pc} + ldmfd sp!, {r3, instr, reg, stack, r7, pc} .Lfp: .asciz " r%d:%08x%s" .Lcr: .asciz "\n"