Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2235054pxp; Mon, 21 Mar 2022 14:34:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE3SfGmBo6l/EiGMGaL4va9whUHQ0wq5ySxKvU4fU92FdVf161TPK+TZ/2Gq1nYwG9sOzR X-Received: by 2002:a17:902:d888:b0:151:6fe8:6e68 with SMTP id b8-20020a170902d88800b001516fe86e68mr14773312plz.158.1647898446541; Mon, 21 Mar 2022 14:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647898446; cv=none; d=google.com; s=arc-20160816; b=UEfNcxekODGKp2TpJGk7ArpdBW2y7M3ZxGBTkawiwROvv905FYo8d03wrir/8gMnPX U62ZvGhvLEFiS7jESIEtExaaFCGLYMqVqNlh0Jpe66rRnnbLagUx6MiYnN0Wr6B7CcyQ Z5BMgBV7nHV7wJ5VLt8+jjmaSMlqMbbgXW6bbhQsmVoLTA+3N6pN0mIt2qJVU9cVAYKY f2dhW54QEhTVH48HQvvzrJZu3t1gR9D5n9gVAmNgqwfB61DewLHOvVHsaeKVWt/On7T0 +DFCcmK6Rodqc8y9XCYSLjtO4UIO+XWvTNmax4Q51GAIrMOC+oGDV7/hu+paCG7U2yVG Sgmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:cc:to:from :date:references:in-reply-to:message-id:mime-version:user-agent :dkim-signature; bh=9srphtZo2CcGfBnXZ3gsqq4/SoHU6MwS7UxQ1aJdlCo=; b=ghrAeQzKAnz7iTOyl0Cr0ZsmXrWfnzAOsGegFWazp1y/JvotwcWpfEDJaQzdaZHnPZ icviNLBStWzHLOroDxZhbRHs3PmuRM2zMWPjVPZmHNtvvGIAW1zeQ3qmbQQGwTV9dDaO RMxSlzRybhi+moD3Chro/v2beAF8Be02aJGuSqvQ7VJC/Txrg2kwcy1Q52lX1S/Do/Xn jWk3Mp5l6UXJC+kl9YaMXvzfkPT0x9GebfFNagprBaok5TIIiQDGQvrob3f1aOQO1t7D QFnSBFq9lg7bPbersGDA81jyufwyYkKV7fgcXO/xOnSaMDIj40zOFe5SLRaZXU7h3AD7 Qviw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wq1hjfa7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z2-20020a170902ccc200b00153b2d1642esi12261838ple.54.2022.03.21.14.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 14:34:06 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wq1hjfa7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D20F22498AD; Mon, 21 Mar 2022 14:12:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244363AbiCSXR2 (ORCPT + 99 others); Sat, 19 Mar 2022 19:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244359AbiCSXR0 (ORCPT ); Sat, 19 Mar 2022 19:17:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EB0E25CB81; Sat, 19 Mar 2022 16:16:03 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 708D060F00; Sat, 19 Mar 2022 23:16:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EF71C340EC; Sat, 19 Mar 2022 23:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647731762; bh=lXASBNwBr/agrF4UaO6l9n/8WnFBciFHOoJgMWOR/D8=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=Wq1hjfa7y/igW9QymqOYJjyfybgc+aBBUV1zfz40VpkOCVeQWN2XgIy1ARil6vVdu YhV2ZzCCE4pGYNa5HeYGI0gfSHjtWYnX/FjfVZ272cApFGidsqjbK+qXP6tRFg56zW 1BHYBKs6GfJDO9jcR6WWxKpWcuK3G37TWKXnumUe70S3kuv4tEngxia9dHgWqrAXex KqZSeZ53k2uD69iFe3pjtK62jSuoai0guFvRMMy6tBFlbecW/SYZfvA6GGlmWzKA1M WLVyYnygNwNRVe0TXMqo+/Xni1uyoRJY6x8cpE1YIJgTMwLHmPxt7+GxC/TUXzoZpA c8AcWAgV19cNA== Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 2A21027C0054; Sat, 19 Mar 2022 19:16:01 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute5.internal (MEProxy); Sat, 19 Mar 2022 19:16:01 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefledgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedftehn ugihucfnuhhtohhmihhrshhkihdfuceolhhuthhosehkvghrnhgvlhdrohhrgheqnecugg ftrfgrthhtvghrnhepvdelheejjeevhfdutdeggefftdejtdffgeevteehvdfgjeeiveei ueefveeuvdetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheprghnugihodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudeiudek heeifedvqddvieefudeiiedtkedqlhhuthhopeepkhgvrhhnvghlrdhorhhgsehlihhnuh igrdhluhhtohdruhhs X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 805FA21E006E; Sat, 19 Mar 2022 19:15:59 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4907-g25ce6f34a9-fm-20220311.001-g25ce6f34 Mime-Version: 1.0 Message-Id: <4ac71b88-4848-456f-8b34-518ca7622fee@www.fastmail.com> In-Reply-To: <20220318234212.GU614@gate.crashing.org> References: <83b33afc-8502-0065-60bc-3a91528632d8@kernel.org> <9a97330b-e5ee-7b7e-4c7a-cfdf15032094@citrix.com> <20220318234212.GU614@gate.crashing.org> Date: Sat, 19 Mar 2022 16:15:39 -0700 From: "Andy Lutomirski" To: "Segher Boessenkool" , "Linus Torvalds" Cc: "Andrew Cooper" , "Nick Desaulniers" , "H. Peter Anvin" , "Bill Wendling" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , "the arch/x86 maintainers" , "Nathan Chancellor" , "Juergen Gross" , "Peter Zijlstra (Intel)" , "llvm@lists.linux.dev" , "Linux Kernel Mailing List" , linux-toolchains Subject: Re: [PATCH v5] x86: use builtins to read eflags Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Fri, Mar 18, 2022, at 4:42 PM, Segher Boessenkool wrote: > On Fri, Mar 18, 2022 at 04:10:55PM -0700, Linus Torvalds wrote: >> It would be lovely to have some explicit model for "I want the frame >> to have been set up for backtraces", but here we are. > > So please define exactly what that *means*? Preferably portably, but I > reckon at least some of it will have to be machine-specific (and ABI- > specific). But it needs to be well-defined, clearly defined, defined = at > all, and *documented* :-) > >> 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! > >> And while we have other uses for it that then use the actual value, >> those don't care about the exact value of the stack pointer register, >> they just want "give me a pointer that is contained within the current >> stack", because we control the stack allocation and do funky things >> there. So "any random stack pointer value in this function" is >> perfectly fine and expected. > > You can use %rsp as *input* operand just fine, which is all you need f= or > that. > >> But for user mode, it would probably be a great idea to also have a "I >> cannot use a redzone in this function" thing. The kernel can't use it >> because we have nested exceptions, but maybe some day even the kernel >> could make use of (controlled) red-zoning. > > Yes. We just have to figure out what the exact semantics we want is, > and how to express that in a target-independent way, and then relatedly > what a good name for it would be ("redzone" in the clobber list is the > best I can come up with right now, but that may have to change). Here=E2=80=99s the semantics I want: I want to tell the compiler that an asm statement makes a function call.= I want to specify the stack alignment and offset I need. I want the co= mpiler to make it work. Something like this, but preferably with better = syntax: asm("asm here" ::: "call" (align=3D16, offset=3D0)); This means that the asm in question wants rsp to be 0 more than a multip= le of 16 and that it wants precisely the setup needed for a call to be d= one. If frame pointers are enabled, a frame should be set up. If there i= s a redzone then either the compiler needs to not use it or needs to adv= ance rsp past it. > > > Segher