Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1659491pxp; Thu, 17 Mar 2022 13:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHlTuXaFsThjAlOthGBcPMDyWWqiddEBC38Rry108oyltC/0DxbRYZP4W4t2kub3wmuDiE X-Received: by 2002:a63:f14b:0:b0:374:7b9e:dc8f with SMTP id o11-20020a63f14b000000b003747b9edc8fmr5189313pgk.357.1647550271562; Thu, 17 Mar 2022 13:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647550271; cv=none; d=google.com; s=arc-20160816; b=d9aUfhBO28HLWpObGU1LqKKRMxI61ceBeSZax4jp9fnz5RUxcI3Qsp39ov2fCbvFWV R5r8568BW85h1ZFLtU0JYshuRozaWm04+IqROS8eqtHdgJVSzUD+Hak4I3RI44zOtj0i 1WeVzsBFyVhk+fxB5bj28Qdk5AKAXO3KByupiAOhveFDNrxkBufv/fymwsQEH4TSmg1u nSvYZtfsv65wuKK0cVSlTaUMwUVc987hLRsK2Y5aI/PTPh0pb0W0MHPLVzxmOzzM8ubd 6eSZZiwtBpQrgKzCa9Lvk0V9M2Zd1r3N11A1NpRkJF98LNMGWmj4IZrKvTD0Ll8hxZrF u2Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from:dkim-signature; bh=9qNtFrtkLvPTt+C4lJhyxR9PYkHaXFWorb7+v2VNB60=; b=isdNoB/gYM2WSQLAmQlMWpxFFi4HzNJPLOY87smGVx4jwUhkc3HYoXjrdVD5+nrVAG ukJrDwqwvUja2dkdwJMDLnfg4SwYqpWjIVWGLjZy2hcqkkjdh5oFupLbdIz85h0Z6ZxT L007Ry6o4RDbbeDdXwN/s6Fw50RbS1w+I2YRq5GNmvfoJrs6lZb0VqZnufceq8azmDfS aU0wgqcDvTHE3WyQccfzKksvXSyXLB3MOq97GIi7Oxrg11QldIrz7b2311zDtFD3z49q dffha+DFT90JlTJE4WUxKY6B9Fd9M7JNDQJaAxCtTFrf0cJNKlUA8zktyae9f6jcJnqs QF0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K13O57P+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j4-20020a170902c08400b00153b2d16657si123534pld.607.2022.03.17.13.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:51:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K13O57P+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 617A617A2D6; Thu, 17 Mar 2022 13:14:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229476AbiCQUPM (ORCPT + 99 others); Thu, 17 Mar 2022 16:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbiCQUPI (ORCPT ); Thu, 17 Mar 2022 16:15:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4D915171EFD for ; Thu, 17 Mar 2022 13:13:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647547994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9qNtFrtkLvPTt+C4lJhyxR9PYkHaXFWorb7+v2VNB60=; b=K13O57P+kOOV4fP7twTgvpfPTJHf8aUEEZZ4s98Z3n4/Us9aoMyCCAfXyZxU12MCbIXnSs N/nGqNrPyOcZv63tIdNCirRyKYAYrp8CsIF6xpLbRjclfOouJWnaunSXbJ9Sqc2wrPHKTt a1MohrjuxuF5IntnSAtVPZ+B5Ms2LLE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-199-BvINtsxcOa6wZL1C7IXwhw-1; Thu, 17 Mar 2022 16:13:11 -0400 X-MC-Unique: BvINtsxcOa6wZL1C7IXwhw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E35EE296A613; Thu, 17 Mar 2022 20:13:10 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0662D401E75; Thu, 17 Mar 2022 20:13:06 +0000 (UTC) From: Florian Weimer To: Linus Torvalds 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 , Andy Lutomirski , llvm@lists.linux.dev, LKML , linux-toolchains Subject: Re: [PATCH v5] x86: use builtins to read eflags References: <20220210223134.233757-1-morbo@google.com> <20220301201903.4113977-1-morbo@google.com> Date: Thu, 17 Mar 2022 21:13:05 +0100 In-Reply-To: (Linus Torvalds's message of "Thu, 17 Mar 2022 11:52:26 -0700") Message-ID: <878rt8gwxa.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 * Linus Torvalds: > You can actually operate on EFLAGS at multiple granularities. > > - normal pushf/popf. Don't do it unless you are doing system software. There's one exception: PUSHF/twiddle/POPF/PUSHF/compare is the recommended sequence to detect CPUID support on i386 (in userspace and elsewhere). > - you can use lahf/sahc to load/store only the arithmetic flags > into/from AH. Deprecated, and going away, but historically supported. And these instructions were missing from the original long mode, but they were added back. > Yes, yes, that complete mental breakdown with pushf/popf did get > fixed, but it really makes me very wary of thinking that we should > ever use a built-in that compiler writers really fundamentally got so > wrong before. > > What would make me think that you'd get it right now? In user space, > you'll basically never actually see the whole system flags issues, so > your test-cases would never work or be very contrieved. You'd have to > really work at it to see the problems. I think as the result of the nature of that kind of bug it does not matter whether you use a compiler builtin to access the flags (to put their combined value into a general-purpose register). GCC doesn't have barriers in the built-ins (if we are talking about __builtin_ia32_readeflags_u64 and __builtin_ia32_writeeflags_u64). I expect they are actually pretty useless, and were merely added for completeness of the intrinsics headers. It's not that you can write unsigned a, b, c; // =E2=80=A6 c =3D a + b; and examine __builtin_ia32_readeflags_u64() to see if there was an overflow. Neither GCC nor Clang model the EFLAGS register and arithmetic expression side effects to make this possible. Thanks, Florian