Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2115759pxp; Mon, 21 Mar 2022 11:39:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxS5IDzgrquai/T7mc5v6UA4l0BArZveWPiuzCiSgeRvWYJwinlsL2Bg0PlvJ+wmrmeNx4J X-Received: by 2002:a63:6645:0:b0:382:65eb:1215 with SMTP id a66-20020a636645000000b0038265eb1215mr7668493pgc.337.1647887945227; Mon, 21 Mar 2022 11:39:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647887945; cv=none; d=google.com; s=arc-20160816; b=Uj9PWoV8WJhAKWth2YdDlnO9kTB0aDBB/B3h+fIXi3uOfvodp3SbCJcrbKxk70SF08 /Kc6g4/TK/LfPA1IUVVp0ZcMicF+f3RxmRgvkyHqnfMN4HUxbzL29LTumXG8oap3yvFE sTfEcjU0zfhrhmEFJEkrh41Z+6haBI5tpDOfZ5MhoZjSaVdxpeeJTAczwsXuoN5Y3lQU Z5SQfcbDINEJeNG6WO8HBkEpztc2cJ8WbERNuAleKn4E1YphWiXQnle9EZAfp/K/1tSr uLNWRFjiYo6bqQDKUP1L8WoeR3rasJPHkL7gv/7KkG1b9td+7Ad4Vc9/FZNUAMr9CpDt hJvQ== 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=KewD06Vu0nsX23vq307ezHIhVg7q/YW1qUsCXfY0+3M=; b=P+01ELV6kV4LHPK7XT+4L4OsIm8Mp8d7Migs6/iaazP1ekin8E41JxwRSZei4JY4zT oDCYMVYw06C5diTSN+HAqr+L2WyY40dhwAdmADLfpWlhGw6/HESj3GSgvTOMk7eIiu3r HG2DEnvuUCALiU9lwmBGm0R1u2fYCr6Sp9r99vb1eXsLuhL+4sDUz+JUH77UGb0zcG0T 2CyEj6olcL5X9b8qyq9yGDXtko+ZBF3S05eiig48PYkpEra4Rmj2WR/9CKFshgDwU+/8 Bxv6JUoSBDy8uX4j68o79Jq6A2bDi+AyN4ZrNEkw5zGmqaDoSs9Lr1AezSFfKyCOtQrJ JIFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=O31GPd4+; 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 k4-20020a170902760400b00153b2d16402si11618828pll.10.2022.03.21.11.38.51; Mon, 21 Mar 2022 11:39:05 -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=O31GPd4+; 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 S241702AbiCSBPK (ORCPT + 99 others); Fri, 18 Mar 2022 21:15:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241693AbiCSBPI (ORCPT ); Fri, 18 Mar 2022 21:15:08 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756A22BAE77 for ; Fri, 18 Mar 2022 18:13:48 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id bt26so16572709lfb.3 for ; Fri, 18 Mar 2022 18:13:48 -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=KewD06Vu0nsX23vq307ezHIhVg7q/YW1qUsCXfY0+3M=; b=O31GPd4+a0dW/sfSFVN0SwhJZgZt45sr6T7Z4Ng79tgRtYB8w8KRyTai2p60eBV9gT tcbw6Ny+Q/TkhccY9Fv3508KsvjxQWdbRgWksssxaccMi0rt7/bhQcRLGGgqLJRupW4n VTasQHX/wzxA2xr2mC7BP2QpKgTAK1TvGaN4Y= 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=KewD06Vu0nsX23vq307ezHIhVg7q/YW1qUsCXfY0+3M=; b=IQxKXcmKCb1ONU87iJCqfWVBMSdj3oC+4z4q7GhXkm8CV+7h/2hdxQP6qLBdowwYqx ozInqO3vVPiW3rR2EwgWdIlFpNe4mFGE9gGNnmJd+msEFexcSynaUl7c2kNIAEbPO4cc l31Ftc/ZPS8eO3UJokm7AAmpdFtCgQoIM/rbETa2c9WF8b9qGdj8eT5l+SXV0czz0YmV bp8hWk8Liz+dZXXGyyewaLjSC0kDnHQr4uPEGSEG2UHjkKMpUXp84yEJ5/2Ew0ZCOOBk QBalhLLjFNQfBwx6gzdfuph5Cwj7OBtUi2NpVHy8dsg7tlZfgUkLUpJG7qbTMxABBlIs RN6w== X-Gm-Message-State: AOAM5328FQYaXDzUtgIgKaW9JxRNsSuxN/+WO/sc/U75lHqGqH/VrQs3 92D44NP3qA6jHpFxvYOMP7xt1QZCBKf8rTHSKV4= X-Received: by 2002:ac2:4a61:0:b0:448:1d0b:b6fb with SMTP id q1-20020ac24a61000000b004481d0bb6fbmr7334565lfp.321.1647652426511; Fri, 18 Mar 2022 18:13:46 -0700 (PDT) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com. [209.85.167.42]) by smtp.gmail.com with ESMTPSA id bq42-20020a056512152a00b00447431cc768sm1079608lfb.170.2022.03.18.18.13.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Mar 2022 18:13:43 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id bu29so16649605lfb.0 for ; Fri, 18 Mar 2022 18:13:42 -0700 (PDT) X-Received: by 2002:a05:6512:b13:b0:448:90c6:dc49 with SMTP id w19-20020a0565120b1300b0044890c6dc49mr7786949lfu.542.1647652421984; Fri, 18 Mar 2022 18:13:41 -0700 (PDT) MIME-Version: 1.0 References: <83b33afc-8502-0065-60bc-3a91528632d8@kernel.org> <9a97330b-e5ee-7b7e-4c7a-cfdf15032094@citrix.com> <20220318234212.GU614@gate.crashing.org> In-Reply-To: <20220318234212.GU614@gate.crashing.org> From: Linus Torvalds Date: Fri, 18 Mar 2022 18:13:25 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5] x86: use builtins to read eflags To: Segher Boessenkool , Josh Poimboeuf 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 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 Fri, Mar 18, 2022 at 4:47 PM Segher Boessenkool 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