[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9a97330b-e5ee-7b7e-4c7a-cfdf15032094@citrix.com>
Date: Fri, 18 Mar 2022 21:48:14 +0000
From: Andrew Cooper <Andrew.Cooper3@...rix.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>,
Andy Lutomirski <luto@...nel.org>
CC: 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 18/03/2022 18:19, Linus Torvalds wrote:
> Side note and kind of related: we do have this in the kernel:
>
> register unsigned long current_stack_pointer asm(_ASM_SP);
> #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
>
> which *might* also solve the redzoning issue.
Sadly not. https://godbolt.org/z/cGx74sKE3
Given:
int pushf(void)
{
unsigned long register sp asm("rsp");
unsigned long x, y;
asm ("movq $1, %0" : "=m" (x));
asm ("pushf\n\tpop %0": "=r" (y), "+r" (sp));
return x + y;
}
the generated code is:
pushf:
movq $1, -8(%rsp)
pushf
pop %rax
addl -8(%rsp), %eax
ret
so the rsp clobber doesn't prevent the push/pop pair from trashing x in
the red zone.
The builtin does cause a stack frame to be fully set up, and x to be
allocated within it, rather than in the red zone.
Experimenting with rsp clobbers leads to https://godbolt.org/z/s9scxre19
which demonstrates (for gcc at least) it does change the position of
when a stack frame gets set up (in the case that there is a path not
otherwise needing a stack frame) but doesn't unilaterally force a stack
frame to be set up.
As such, I'm not sure how current_stack_pointer can work as intended in
all cases...
~Andrew
Powered by blists - more mailing lists