[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZfxTV+u4UWoRdGpJ@shell.armlinux.org.uk>
Date: Thu, 21 Mar 2024 15:33:43 +0000
From: "Russell King (Oracle)" <linux@...linux.org.uk>
To: David Laight <David.Laight@...lab.com>
Cc: Ard Biesheuvel <ardb@...nel.org>,
'Jiangfeng Xiao' <xiaojiangfeng@...wei.com>,
"arnd@...db.de" <arnd@...db.de>,
"keescook@...omium.org" <keescook@...omium.org>,
"haibo.li@...iatek.com" <haibo.li@...iatek.com>,
"angelogioacchino.delregno@...labora.com" <angelogioacchino.delregno@...labora.com>,
"amergnat@...libre.com" <amergnat@...libre.com>,
"akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
"douzhaolei@...wei.com" <douzhaolei@...wei.com>,
"gustavoars@...nel.org" <gustavoars@...nel.org>,
"jpoimboe@...nel.org" <jpoimboe@...nel.org>,
"kepler.chenxin@...wei.com" <kepler.chenxin@...wei.com>,
"kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
"linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-arm-kernel@...ts.infradead.org" <linux-arm-kernel@...ts.infradead.org>,
"nixiaoming@...wei.com" <nixiaoming@...wei.com>,
"peterz@...radead.org" <peterz@...radead.org>,
"wangbing6@...wei.com" <wangbing6@...wei.com>,
"wangfangpeng1@...wei.com" <wangfangpeng1@...wei.com>,
"jannh@...gle.com" <jannh@...gle.com>,
"willy@...radead.org" <willy@...radead.org>
Subject: Re: [PATCH v2] ARM: unwind: improve unwinders for noreturn case
On Thu, Mar 21, 2024 at 03:20:57PM +0000, David Laight wrote:
> From: Russell King
> > Sent: 21 March 2024 14:56
> >
> > On Thu, Mar 21, 2024 at 02:37:28PM +0000, David Laight wrote:
> > > From: Russell King
> > > > Sent: 21 March 2024 13:08
> > > >
> > > > On Thu, Mar 21, 2024 at 12:57:07PM +0000, David Laight wrote:
> > > > > From: Russell King
> > > > > > Sent: 21 March 2024 12:23
> > > > > ...
> > > > > > > That might mean you can get the BL in the middle of a function
> > > > > > > but where the following instruction is for the 'no stack frame'
> > > > > > > side of the branch.
> > > > > > > That is very likely to break any stack offset calculations.
> > > > > >
> > > > > > No it can't. At any one point in the function, the stack has to be in
> > > > > > a well defined state, so that access to local variables can work, and
> > > > > > also the stack can be correctly unwound. If there exists a point in
> > > > > > the function body which can be reached where the stack could be in two
> > > > > > different states, then the stack can't be restored to the parent
> > > > > > context.
> > > > >
> > > > > Actually you can get there with a function that has a lot of args.
> > > > > So you can have:
> > > > > if (...) {
> > > > > push x
> > > > > bl func
> > > > > add %sp, #8
> > > > > }
> > > > > code;
> > > > > which is fine.
> > > >
> > > > No you can't.... and that isn't even Arm code. Arm doesn't use %sp.
> > > > Moreover, that "bl" will stomp over the link register, meaning this
> > > > function can not return.
> > >
> ...
> >
> > Don't show me Arm64 assembly when we're discussing Arm32.
>
> Oops - I'd assumed no one did 32bit :-)
> In any case it is much the same, see https://godbolt.org/z/7dcbKrs76
>
> f4:
> push {r3, lr}
> subs r3, r0, #0
> ble .L2
> mov r2, r3
> mov r1, r3
> bl f
> .L2:
> pop {r3, pc}
>
> f5:
> subs r3, r0, #0
> ble .L6
> push {lr}
> sub sp, sp, #12
> mov r2, r3
> mov r1, r3
> str r3, [sp]
> bl f
> .L6:
> bx lr
>
> That is with -mno-sched-prolog but with 5+ args they spill to stack
> and the %sp change is pulled into the conditional.
>
> It does look like %lr is being saved (and for arm64 I think).
I see nothing that contradicts anything I've said in your example
output.
You have been previously refering to a "bl" in the prologue, which is
what I thought you were going to give an example of. There is no "bl"
in the prologue of f5, the "ble" instruction is a normal branch for
less-than-or-equal. It's b + le not bl + e.
At .L6, there will be a difference in stack, but as f() is declared
as no-return, anything that comes after it is utterly irrelevant as
control is not expected to reach any following instruction via that
path. If it _were_ to, then in the example you give above, because
"lr" points at the bx lr instruction, the result would be to endlessly
spin executing bx lr instructions.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Powered by blists - more mailing lists