[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wjZhTJJY3WV8=3vjZR6gONReXorRdNtM+T5syFSZqimEA@mail.gmail.com>
Date: Fri, 18 Mar 2022 18:13:25 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Segher Boessenkool <segher@...nel.crashing.org>,
Josh Poimboeuf <jpoimboe@...hat.com>
Cc: Andrew Cooper <Andrew.Cooper3@...rix.com>,
Andy Lutomirski <luto@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
"H. Peter Anvin" <hpa@...or.com>, Bill Wendling <morbo@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Juergen Gross <jgross@...e.com>,
Peter Zijlstra <peterz@...radead.org>,
"llvm@...ts.linux.dev" <llvm@...ts.linux.dev>,
LKML <linux-kernel@...r.kernel.org>,
linux-toolchains <linux-toolchains@...r.kernel.org>
Subject: Re: [PATCH v5] x86: use builtins to read eflags
On Fri, Mar 18, 2022 at 4:47 PM Segher Boessenkool
<segher@...nel.crashing.org> wrote:
>>
> > Marking '%rsp
> > used makes the compiler understand it's not a leaf function.
>
> As I said before, this is explicitly incorrect code. Always was, but
> it is documented since a while (since GCC 9). Clobbering the stack
> pointer can never be correct, the stack pointer after an asm has to be
> identical to the one before that asm!
We've never clobbered the stack register.
We've _marked_ it as an in-out register, but we obviously never
actually change it (as far as the compiler can tell). That would very
obviously never work.
And even that marking must have been some gcc person telling us to do
that, because I don't think we would have come up with it otherwise. I
would guess it's what gcc uses internally to decide "I need this
function to have a stack frame". And once you have a stack frame, the
inline asm will automatically be put inside of it.
I spent a lot of time trying to find the origin of it. Finding the
commit in the kernel where it was first introduced is easy: looks like
commit 0e8e2238b52e ("x86/xen: Add stack frame dependency to hypercall
inline asm calls") was the first to use that trick, although it was a
series of patches from Josh that did that to make objdump happy.
And I found the culprit. It's you, on the gcc lists:
https://gcc.gnu.org/legacy-ml/gcc/2015-07/msg00080.html
Heh.
Linus
Powered by blists - more mailing lists