Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1891782pxp; Thu, 17 Mar 2022 20:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB5MsAyUtnYkwEy9yBDUrqB5kKgFf4x/bGwaLNFvrzgL32XT3lVab6J7RgfIQJIsYLrS2B X-Received: by 2002:a05:6402:50cb:b0:418:d750:9cba with SMTP id h11-20020a05640250cb00b00418d7509cbamr7741351edb.16.1647574563715; Thu, 17 Mar 2022 20:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647574563; cv=none; d=google.com; s=arc-20160816; b=n1jEOvubSNpMmH1NSRZYHptJKzug6oBIKGHtUZkLPGZlld5ObLYXeLRoe/vBpPddTx VMSKNIhZiInmgKyHfNxME/xs5ixN/HNIqrVxIoIyJAszF6B0dyzAijMpvBrfNJkfzSy9 /7R2uxeMov2fgt6yS/qN7WavFxsWYHrnziJAm3JTx9/FIjBmeAxYJQ1FQOUFgkj8fN4M LphMphIqsOpxbIdMvvk4xsKskT497qWeBSrDUf6ai4RJwwiH+2SG3RYfho2aJYIzWmfg KLXHQxCH8JLiO0VismTkma8zKvfHLr8Ax6w4S8rFYxEhdP//hkQjTRaxXDAuBcatLZ3v Zwqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RzHOurcRZLEPdx5A8AtvMQus3L3vLI1jvcmAUoK7M3M=; b=UTLtImOpe5mMKDzrVuMfAurtukNJE+B124TjgyoogxtKYDvWrNyZXWACw2fjRyIIaN 5bUHc6dOtgq175SESBZDuGmDvuujMEHtiU1+21CCX0usK75amBB2ujBDJlk4KVy12cwF HtNADDZXXmmakwqWSDjW8yq4hkXX6kulordxjzm/nepJdTZIZB8N4YX9MBA5xX8uSXvc fQRjxdwIORjkdLZkciI6O4SuvVCITbD0vcjtpuLvkSwP6kaXzdtBDSsjl87teD+zLqbK 5Mk1lGoehldzo+rIgRLzDING2ilGpX+BdyhxD0YRv+rwC2mdHjNDj6SjUBN1SIPD3f0a NNMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QipcaPze; 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 r28-20020a056402235c00b00418c2b5bed0si3063359eda.434.2022.03.17.20.35.36; Thu, 17 Mar 2022 20:36:03 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QipcaPze; 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 S231561AbiCRBw2 (ORCPT + 99 others); Thu, 17 Mar 2022 21:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiCRBw0 (ORCPT ); Thu, 17 Mar 2022 21:52:26 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 051C4196091 for ; Thu, 17 Mar 2022 18:51:06 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id h14so11869725lfk.11 for ; Thu, 17 Mar 2022 18:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RzHOurcRZLEPdx5A8AtvMQus3L3vLI1jvcmAUoK7M3M=; b=QipcaPzemhcgIfEJYN144w0FnjRfqRUr/lWiEGEPhGe/qWrPlffischpqBrRPHT5m3 Qe3ydqH/K9tObWP9AdmckmHt49bsCYrU9T+CBDF9fX8Zs8e9aORdJWAYCX4yUAPM9H/j m9xf6179ufuVV3J1o5iE6xXJG7Ck51v7CCX+0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RzHOurcRZLEPdx5A8AtvMQus3L3vLI1jvcmAUoK7M3M=; b=O5Bko5Yh2iTx1LrWhmMe43gGCKDW3gX5kQXMGVm43gXIEV9g6N7jgg/Le4FbbVcRm8 EbBcDJPJtnMYsZlDm1++RX4a8jCVrZ3mCmVZnEXog2i0JosZfAvAskP6218nTHHExr5/ /f+lDXLql10nthGHGckpoqs6FLUOhnut4OS6L1z3ANnLkjN0WR17Syv1N0THw7Prb0q3 eKCPgkQk4bR78eAMh+OdhElxV9YGp+LdqX616nGz+UGfym/jHRYQUzRDtxjOZMbmWwi+ bFGo3KEY9YDqae2YVtuoFCBgzXo0PxoP18tg7mH+OYjXPxQ7FBt+zOkKgLiHvDo0VCeB LXAw== X-Gm-Message-State: AOAM532CK2+QZ3bDvaFYxaobiRHGv2Po/RX6zqd+RXQeviKadaezcUzB PU9/Wnn2ZqH3SDEfZikt5pZaLCFiC+yX4bzCyeA= X-Received: by 2002:a05:6512:34d2:b0:44a:b81:85c2 with SMTP id w18-20020a05651234d200b0044a0b8185c2mr674454lfr.689.1647568263931; Thu, 17 Mar 2022 18:51:03 -0700 (PDT) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com. [209.85.208.173]) by smtp.gmail.com with ESMTPSA id i27-20020a198c5b000000b004487eabc006sm612491lfj.253.2022.03.17.18.51.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Mar 2022 18:51:03 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id h11so9585601ljb.2 for ; Thu, 17 Mar 2022 18:51:02 -0700 (PDT) X-Received: by 2002:a05:651c:1509:b0:249:6cd6:96d8 with SMTP id e9-20020a05651c150900b002496cd696d8mr685036ljf.358.1647568262431; Thu, 17 Mar 2022 18:51:02 -0700 (PDT) MIME-Version: 1.0 References: <20220210223134.233757-1-morbo@google.com> <20220301201903.4113977-1-morbo@google.com> <878rt8gwxa.fsf@oldenburg.str.redhat.com> <20220318002555.GP614@gate.crashing.org> In-Reply-To: From: Linus Torvalds Date: Thu, 17 Mar 2022 18:50:46 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5] x86: use builtins to read eflags To: Segher Boessenkool Cc: Florian Weimer , 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 , Andy Lutomirski , llvm@lists.linux.dev, LKML , linux-toolchains Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 6:21 PM Linus Torvalds wrote: > > Now, compare that to just using inline asm: it's trivial, and we've > used it basically unchanged for three decades. Ok, so going _really_ far back, we used to have them literally written out: __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags)); in random code, and then in October 1992 switched those nasty things to instead use #define cli() __asm__ __volatile__ ("cli"::) #define save_flags(x) \ __asm__ __volatile__("pushfl ; popl %0":"=r" (x)) and the code was changed to actually use save_flags(flags); cli(); instead of that open-coded raw asm. And the "memory" clobber was added early June, 1993: #define save_flags(x) \ -__asm__ __volatile__("pushfl ; popl %0":"=r" (x)) +__asm__ __volatile__("pushfl ; popl %0":"=r" (x)::"memory") so that thing really has existed in pretty much that exact form for almost 30 years. There's been tweaks since (the "=r" became "=g" before becoming "=rm", comments have been added, "pushfl" became just "pushf" with x86-64, and the thing has moved around and is now called "native_save_fl()" in a completely different header file etc) But at no point was it ever as buggy as the actual gcc intrinsic seems to be today, nor have we needed to check for compiler versions etc. Linus