Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942459AbcJ1R6G (ORCPT ); Fri, 28 Oct 2016 13:58:06 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:41298 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941855AbcJ1R6E (ORCPT ); Fri, 28 Oct 2016 13:58:04 -0400 Date: Fri, 28 Oct 2016 11:57:49 -0600 From: Jason Gunthorpe To: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [ARM] Fix stack alignment when processing backtraces Message-ID: <20161028175749.GB28451@obsidianresearch.com> References: <20161018170510.GA12248@obsidianresearch.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161018170510.GA12248@obsidianresearch.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1727 Lines: 49 On Tue, Oct 18, 2016 at 11:05:10AM -0600, Jason Gunthorpe wrote: > 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 Since there are no comments, I will send this to RMK's patch system.. Thanks, Jason > diff --git a/arch/arm/lib/backtrace.S b/arch/arm/lib/backtrace.S > index fab5a50503ae..25e1cce19991 100644 > +++ 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"