Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2558877pxp; Fri, 18 Mar 2022 13:12:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwWSO2ELOWlfearnrSb8Yn4ofHJtWuvkMRZ5S6+QZxTOKnokx09xPElfW9N5Fl+hxU2Bhn X-Received: by 2002:aa7:cc0a:0:b0:413:a674:7d33 with SMTP id q10-20020aa7cc0a000000b00413a6747d33mr11268601edt.369.1647634369637; Fri, 18 Mar 2022 13:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647634369; cv=none; d=google.com; s=arc-20160816; b=0trhd8zwtYpEJapQOB2lTdqThioKErPrA5XunB45/5y451o+7zel0Es8WVw1ybXXgz /CxveQ9D9F9adkhi1gSdeivLWYOzqJCqENOT+3XpNKGUMt3NbWoveJ3tW0J3nyLzpLIN I5hBMj99cqXffZngYGLol2jQB3/k+IHPKmzjDqzhUfkk1uD3lDyVCHuRyH8dyZ+hlXrK TU7mjSRfojsqMWGMGbBjjM7bUnTooPukEt8rHGRAb34fKywCCYF1Kk5gFoBBe6QBiRoP mMQYRmmab4X0sSGdbR53TPfyb63swx3gJ3nvgAzHMD4lA1VPrJSLINTngs2QrMjRYRRR n4ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=/QnefjPh08KFWOn77TmM3Mi24nSaZplkq9LrwNEDPBQ=; b=ke1lgFERei7sGhJUFwKTVgqNpvRVn9k6oo5sWzlbmFu77yo5DS1dyjcZBGj/NuRVOU 8zkxqHKcgiDpjfa339lTYdp4/go/Emo4f2aSbtDZs6Z1qEsVbmlbyLHfCVdkBlAN7YTq YhT2HLLZdXB1UrSdEpO41ggK4pvSfyhddoPGaUov1i6NFY3ISH90tbmktWLBk9zs5doO MTlqEQrmhAUsT0aKEEkrDTREyPZB/3twK4g+ZKt/2LHNxjzigaEJS7hBkn9FrpgVualc M2HpYQkDg/1xiiCfGBT33imQIwe9CNf3PstK9laBYDMUq6ZoE+IGlIv3wi6SXjlAKqUS lASA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F9SpeWsT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a170906518a00b006df76385cfasi1622661ejk.410.2022.03.18.13.12.12; Fri, 18 Mar 2022 13:12:49 -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=@kernel.org header.s=k20201202 header.b=F9SpeWsT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239851AbiCRSA7 (ORCPT + 99 others); Fri, 18 Mar 2022 14:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239745AbiCRSA4 (ORCPT ); Fri, 18 Mar 2022 14:00:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9EBE52B26; Fri, 18 Mar 2022 10:59:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 63987B82456; Fri, 18 Mar 2022 17:59:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61796C340E8; Fri, 18 Mar 2022 17:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647626374; bh=DnhgQQxVOH3bMKPDnLoNfQArYffddzQ5u6wFD2OnS6A=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=F9SpeWsTgjwsMojrDShOq/mHAJGifN2wkANWsbgJ5J69nrPcQfMG+Tu9TLWR3uaB4 ta1BDkDp+cZwCgTRfw3ExVP0aWmzmaAVmmnDRfRNuU3kGvtAjbJo6MZ65QTh7v+I1m P9OJu9Z35IX4Dena4O85hCVin3RURminpfbXVFpIWfSIm6kQLOWlKZwa9dGVYgnKfZ 3h3AAzpimeLKScsd6/Wvqfd8oUNx91kh5LhwMC4y84hpghXP9TyuN867eslGQHgKHi KqvqshCoHabejArvOhEKFd13KCLxOfXBCayrrbUuVhH6Qy8oFiYrBlbQrjFyjvpTWv xUL3ifm9OsPHA== Message-ID: <83b33afc-8502-0065-60bc-3a91528632d8@kernel.org> Date: Fri, 18 Mar 2022 10:59:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v5] x86: use builtins to read eflags Content-Language: en-US To: Linus Torvalds , Andrew Cooper Cc: 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 References: <20220210223134.233757-1-morbo@google.com> <20220301201903.4113977-1-morbo@google.com> From: Andy Lutomirski In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,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 3/17/22 14:39, Linus Torvalds wrote: > On Thu, Mar 17, 2022 at 2:06 PM Andrew Cooper wrote: >> >> I was idly playing with this builtin in response to the thread, and >> found that GCC has a far more serious bug than Clang had. > > Heh. Yeah, that's bad. > > But it kind of fits my argument: compiler intrinsics aren't > necessarily such a wonderful thing. They hardly get any testing at all > unless they are some very very core thing. > > I will personally *always* prefer some generic "escape clause" over a > compiler that thinks it knows better. > > I think compiler people should see inline asm as a really *good* > thing, because it allows people to have that "I'm going to do > something that nobody normal does, look away now" kind of escape > clause, letting the compiler concentrate on the things it does best. > > Yes, I realize inline asm isn't something compiler people love. And > yes, I realize that it might not give optimal code. > > But think of it a bit like casts - it adds complexity to the language, > and it might make some optimizations harder or even impossible - but > it makes the language much more powerful and allows you to do things > that you simply couldn't do without it. > > There's a reason people use C instead of Pascal or FORTRAN. Those > casts, and that pointer arithmetic - the bane of many optimizations - > are really really good things. > > Intrinsics should generally be shunned, not seen as a "this is an > alternative to inline asm". They should only exist for situations > where you can show "look, I can do so much better", and have a > test-suite for it and a real-life case where it gives you a clear and > undeniable uplift on a meaningful load. > > (And here I separate 'intrinsic' and generic compiler builtins. I love > the builtins that allow me to tell the compiler something, or the > compiler to tell me something about the code: __builtin_unreachable() > and __builtin_constant_p() are both wonderful examples of those kinds > of things) > > But an intrinsic for some odd target-specific thing that can't even be > portably generalized? Give me inline asm any day. > > We can do things with inline asms that the compiler can't even _dream_ > of, like the whole instruction rewriting thing we use. > > I'd much rather have a powerful generic concept (eg "asm goto" is > lovely) than a specialized intrinsic that does only one thing, and > doesn't even do it well because it's untested and badly defined. > I generally agree. In this particular case, though, I will keep using the builtin in tools/testing/selftests/x86/helpers.h unless we actually hit breakage. This is because this is *user* code, it is compiled with the redzone enabled, and the asm code to do the right thing when the redzone is enabled is too hairy for me to want to deal with it. The builtins have their share of problems, but they do seem to work in this context. This isn't at all an argument that we should do the same thing in actual kernel code.