From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DD556444 for ; Fri, 18 Mar 2022 23:47:43 +0000 (UTC) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 22INgDNB014381; Fri, 18 Mar 2022 18:42:13 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 22INgCLj014380; Fri, 18 Mar 2022 18:42:12 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 18 Mar 2022 18:42:12 -0500 From: Segher Boessenkool To: Linus Torvalds Cc: Andrew Cooper , Andy Lutomirski , Nick Desaulniers , "H. Peter Anvin" , Bill Wendling , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Nathan Chancellor , Juergen Gross , Peter Zijlstra , "llvm@lists.linux.dev" , LKML , linux-toolchains Subject: Re: [PATCH v5] x86: use builtins to read eflags Message-ID: <20220318234212.GU614@gate.crashing.org> References: <83b33afc-8502-0065-60bc-3a91528632d8@kernel.org> <9a97330b-e5ee-7b7e-4c7a-cfdf15032094@citrix.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i On Fri, Mar 18, 2022 at 04:10:55PM -0700, Linus Torvalds wrote: > It would be lovely to have some explicit model for "I want the frame > to have been set up for backtraces", but here we are. So please define exactly what that *means*? Preferably portably, but I reckon at least some of it will have to be machine-specific (and ABI- specific). But it needs to be well-defined, clearly defined, defined at all, and *documented* :-) > 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! > And while we have other uses for it that then use the actual value, > those don't care about the exact value of the stack pointer register, > they just want "give me a pointer that is contained within the current > stack", because we control the stack allocation and do funky things > there. So "any random stack pointer value in this function" is > perfectly fine and expected. You can use %rsp as *input* operand just fine, which is all you need for that. > But for user mode, it would probably be a great idea to also have a "I > cannot use a redzone in this function" thing. The kernel can't use it > because we have nested exceptions, but maybe some day even the kernel > could make use of (controlled) red-zoning. Yes. We just have to figure out what the exact semantics we want is, and how to express that in a target-independent way, and then relatedly what a good name for it would be ("redzone" in the clobber list is the best I can come up with right now, but that may have to change). Segher