Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1808021pxp; Thu, 17 Mar 2022 17:57:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWE9aADlTk4OC2hT1wf/Gw+QgE6hz3I44JRzZpBV1+pKcxWmohCmEhkEJH0/0RP0I936/8 X-Received: by 2002:a17:907:3f12:b0:6d8:bf7c:7672 with SMTP id hq18-20020a1709073f1200b006d8bf7c7672mr7064605ejc.686.1647565056745; Thu, 17 Mar 2022 17:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647565056; cv=none; d=google.com; s=arc-20160816; b=yby/zaoG+m7rdJnJRXs8wn68d760Hdl6hjRXr9bGj3rcIk20AaoAVhogwhSBB2uQj9 u3TcgQsawitWK24hSJ2uuiavc7Mdlnp9xC5O1VmLCNOiyJfq2LgpOj/t9WCEBx2EXyOR HbL/IeMjcvWiVCeGqvy0VQ1PlooqYY5X8ULWPQIc2hglfIOG+Mw6Qq9LnAa6798gs7PD jIVFLAo5sYVz3vDiNh2pPnyOGQ7psB+tIxriPCPYVhkgV/rQ6k9q2f8GmCEjHEAWCyn+ ejsKEg8BeULXrI5elt6jh2FkTLPELhrKddHtyd5DPtYmM0MuchWelgo0AXG69tX0n3z3 V0kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ig/isDTbU7l30Wdmtm2OG66zItf+Nakgo66Ch62uH4Y=; b=gTMx79GqdvItFfaG4GN8dqthP8lnHq4zH/9dBnPglvvaNB654rC5nkMddl7iLuphGg 8Lv64sHc8K0I0ZePA69R5+8fs4dUHkAaT+2a/g+ngBgmpP8gQY0s+q6OggYs5Ja7A47S F6MngYB3VjMO5+5ULWNCloW7QrrJWpqB2vFqdS+Lyo1fvTW6dDz9QgXxyMmJ7lpnPj+h WufRB/GFyWgVMQ62Yzho+W0D9PzcbYVY5ui7EuavjWGJLthwP/J45DN1Ct4r/I4OzTgm Xslwaojx1QSN90JfUvpnFz5jRWY1HhAiWsS5J2TgOhlQvil1401NFTuMG0XW3pdYMIXd 9jBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a1709064a0900b006df76385e09si423350eju.681.2022.03.17.17.57.11; Thu, 17 Mar 2022 17:57:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229818AbiCQX1v (ORCPT + 99 others); Thu, 17 Mar 2022 19:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbiCQX1u (ORCPT ); Thu, 17 Mar 2022 19:27:50 -0400 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DA8728AC7B; Thu, 17 Mar 2022 16:26:32 -0700 (PDT) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 22HNK0JT030658; Thu, 17 Mar 2022 18:20:00 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 22HNJxhb030657; Thu, 17 Mar 2022 18:19:59 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Thu, 17 Mar 2022 18:19:59 -0500 From: Segher Boessenkool To: Linus Torvalds Cc: Bill Wendling , Nick Desaulniers , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Nathan Chancellor , Juergen Gross , Peter Zijlstra , Andy Lutomirski , llvm@lists.linux.dev, LKML , linux-toolchains Subject: Re: [PATCH v5] x86: use builtins to read eflags Message-ID: <20220317231959.GN614@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 17, 2022 at 03:51:28PM -0700, Linus Torvalds wrote: > On Thu, Mar 17, 2022 at 2:45 PM Bill Wendling wrote: > > I'm NOT saying that it WILL change or that it SHOULD change. I'm also > > not saying that your concern isn't justified. What I am saying is that > > unless you're using a compiler feature that's DEFINED as having a > > certain effect, then you are not using that feature correctly, > > regardless of how it's acted in the past. And it has the potential to > > bite you in the ass sooner or later. We've all seen such things happen > > before. > > So I think most of inline asm constraints are fairly well defined. > Certainly "memory" clobbers are. > > The unfortunate exception to this is, I think, "volatile". It has > always had somewhat undefined semantics (iirc originally gcc talked > about it not being "moved significantly" etc), and it ends up getting > mixed reasons for existing. "asm volatile" has always meant "has some unspecified side effect", in parallel with what a volatile object is in C (there, all *accesses* to such objects have the side effects). All such side effects have to happen on the real machine in the same order (and exactly as often) as on the abstract C machine. This is all it means, nothing more, nothing less. This is a little hard to understand, certainly for most users, who do not often have heard of the abstract machine before (which is a shame, because *all* of C semantics are defined wrt that). > The *natural* semantics would be to literally make it have the same > rules as volatile data accesses: something like "'volatile' marks the > asm as having visible side effects in the virtual machine". Not necessarily visible, that is the point even, but yes :-) > So I think natural semantics for "asm volatile" - and the ones that > would be simple to document - would literally be to compare it to > those volatile memory accesses, and say that it can't be optimized > away, and it's ordered wrt other volatile operations (whether volatile > data accesses or other volatile asm instructions). "Cannot be optimised away" means something else to everyone, and almost all of those meanings do not correspond to the truth very well. > And then we in the kernel have then also co-opted 'asm volatile' to > just fix some compiler bugs, so we end up using "asm volatile goto" > because of > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 > > although *that* particular issue is probably historical now that we > require more modern compiler versions. Thankfully. The barrier_before_unreachable() thing in compiler-gcc.h needs some newer GCC 7 (.3 or .4 I think?), so that is still needed for a while more. The barrier() one in compiler.h is probably not a bug anymore since decades, it is from before the kernel started documenting what versions of required tools have what known bugs, apparently ;-) > I still think that from a sanity standpoint, it would be good to > actually strengthen the semantics of "asm volatile" to literally act > as - and be ordered with - volatile memory accesses. > > But I guess that's water under the bridge. That is what it has actually done since forever. See C 5.1.2.3. For GCC, "asm volatile" has a side effect like in /2 there as well, as does unspec_volatile (an internal GCC thing used to implement certain builtins, among other things). "asm volatile" does not mean, and has never meant, anything like "can not be deleted" or "can not be cloned". "Cannot be moved significantly" is vague enough that it isn't untrue (but isn't very helpful either). Segher