[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210305181628.GW29191@gate.crashing.org>
Date: Fri, 5 Mar 2021 12:16:28 -0600
From: Segher Boessenkool <segher@...nel.crashing.org>
To: Christophe Leroy <christophe.leroy@...roup.eu>
Cc: Nick Desaulniers <ndesaulniers@...gle.com>,
Mark Rutland <mark.rutland@....com>,
Marco Elver <elver@...gle.com>,
Catalin Marinas <catalin.marinas@....com>,
linuxppc-dev <linuxppc-dev@...ts.ozlabs.org>,
LKML <linux-kernel@...r.kernel.org>,
kasan-dev <kasan-dev@...glegroups.com>,
Mark Brown <broonie@...nel.org>,
Paul Mackerras <paulus@...ba.org>,
linux-toolchains@...r.kernel.org, Will Deacon <will@...nel.org>,
Linux ARM <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH v1] powerpc: Include running function as first entry in save_stack_trace() and friends
On Fri, Mar 05, 2021 at 07:38:25AM +0100, Christophe Leroy wrote:
> Le 04/03/2021 à 20:24, Segher Boessenkool a écrit :
> https://github.com/linuxppc/linux/commit/a9a3ed1eff36
>
> >
> >That is much heavier than needed (an mb()). You can just put an empty
> >inline asm after a call before a return, and that call cannot be
> >optimised to a sibling call: (the end of a function is an implicit
> >return:)
> In the commit mentionned at the top, it is said:
>
> The next attempt to prevent compilers from tail-call optimizing
> the last function call cpu_startup_entry(), ... , was to add an empty
> asm("").
>
> This current solution was short and sweet, and reportedly, is supported
> by both compilers but we didn't get very far this time: future (LTO?)
> optimization passes could potentially eliminate this,
This is simply not true. A volatile inline asm (like this is, all
asm without outputs are) is always run on the reel machine exactly like
on the abstract machine. LTO can not eliminate it, not more than any
other optimisation can. The compiler makes no assumption about the
constents of the template of an asm, empty or not.
If you are really scared the compiler violates the rules of GCC inline
asm and thinks it knows what "" means, you can write
asm(";#");
(that is a comment on all supported archs).
> which leads us
> to the third attempt: having an actual memory barrier there which the
> compiler cannot ignore or move around etc.
Why would it not be allowed to delete this, and delete some other asm?
And the compiler *can* move around asm like this. But the point is,
it has to stay in order with other side effects, so there cannot be a
sibling call here, the call has to remain: any call contains a sequence
point, so side effects cannot be reordered over it, so the call (being
before the asm) cannot be transformed to a tail call.
Segher
Powered by blists - more mailing lists