Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp143222imu; Thu, 8 Nov 2018 16:33:11 -0800 (PST) X-Google-Smtp-Source: AJdET5dvIxVny6cAUOk2/gMeIFV+NxZRdRDg4kAdVtK0p0xiPnKG45RVkjXmOWQjOgqmT6Ha4aQV X-Received: by 2002:a17:902:7b91:: with SMTP id w17-v6mr6556778pll.289.1541723591274; Thu, 08 Nov 2018 16:33:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541723591; cv=none; d=google.com; s=arc-20160816; b=Jjk7ID2TDbabDYKHocYN0m/7Rq5hVitVh8kJ5K+8cUiR3f3b8FhrGFkpu62ogI9cgI XjBy5xsjgz/a513bwRKPt2/WQ2ua7iKuxF+JIF6NAq//wct1BQAnurPKKLYjoVEAfrJM CwkKDREgb2hpBMN0nnv2XogX3Zn8YUsZ3VUovx21QPWRJRPRB4Mz5BuwfjF1mptU0Jk/ gZQrotcjyxIQGa4FYwF/dm1ODGRLOz2IwMfijLZWWjSa/SbEjzRPIQC3wbuOHs5uRKu2 6t14MX8ZCxpOmOE9PRLDgpMvXODOadO/ld0ErfB2Tu+A2sexI8k9bYYU8PLaOE9D2OQb 3lyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OsnntpvzRra1bKCuMyJWMzb3tscjWBVS1AEp7qWVZAI=; b=gZf5x7/FsCoyASa/87UY8R0oQrqRhy09CxEdiPeffzoYBt3XIDIjzXDgp95WBi7Kmp VV8EXLdD8uVuqSIhm6N3ELf9M2xmfzMZ4eTq6KglcCXdTol5LP4uXahcCUschRTejI7L JKJuD/Hy2LRJLxlX0IK7LJQRDdF3C44X+j+7TfABu1Ui2WSPXR+O/q5U4J/sn0CzsONX EcdrkdqqeU0dNCSkhUd4qDHnqKdkCK3ENzUtxYC/MlIk+zxtI8snZ9eyroSLefYyaGon VkkHc9XAdDwQHUSxFKkfkiCpjJlJ5ud0FGpF7nA8ARYeKVaa9xfRdX3Kl0hUgRDEtEyp A3Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nC78xKGJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n18-v6si5556438plp.294.2018.11.08.16.32.55; Thu, 08 Nov 2018 16:33:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nC78xKGJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727573AbeKIKKj (ORCPT + 99 others); Fri, 9 Nov 2018 05:10:39 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:34620 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727483AbeKIKKj (ORCPT ); Fri, 9 Nov 2018 05:10:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OsnntpvzRra1bKCuMyJWMzb3tscjWBVS1AEp7qWVZAI=; b=nC78xKGJJftKkq7l3M2+Mh9vu NjTLkICrkMLdnLEY4rAOF0N9bCaOF/3NOIxyd+bGuqiIOzpF7zS3iK3zQlA2C6Z3Jcgue552NcGJn YDxnHgsWZpIFbw0x4iFbpsZAlZ4iJBGcE3tmYgX3/MUlKqVc6La7C+Mmv1mKXwPIZ2/q/lWNZ03Xk gp27cFSGlONLRxdLGEA6i2DMtQhTEOBmyOwykgE3Tf71PGuglZFPpXDUlA3kCuAeHP3LjkHuPtvUr CyrB1ccI9Y8Yp62tX7wSkNhJ7hAXmqFX70TPjxEWgYZZjZ4JmqOroSTCC5VhWSAvNHar4gXwfBIkq YaqUjXooQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKuin-00057a-H8; Fri, 09 Nov 2018 00:32:25 +0000 Date: Thu, 8 Nov 2018 16:32:25 -0800 From: Matthew Wilcox To: Dave Hansen Cc: Andy Lutomirski , Yu-cheng Yu , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , LKML , "open list:DOCUMENTATION" , Linux-MM , linux-arch , Linux API , Arnd Bergmann , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H. J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , "Shanbhogue, Vedvyas" Subject: Re: [PATCH v5 04/27] x86/fpu/xstate: Add XSAVES system states for shadow stack Message-ID: <20181109003225.GQ3074@bombadil.infradead.org> References: <20181011151523.27101-1-yu-cheng.yu@intel.com> <20181011151523.27101-5-yu-cheng.yu@intel.com> <4295b8f786c10c469870a6d9725749ce75dcdaa2.camel@intel.com> <043a17ef-dc9f-56d2-5fba-1a58b7b0fd4d@intel.com> <20181108220054.GP3074@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 08, 2018 at 03:35:02PM -0800, Dave Hansen wrote: > On 11/8/18 2:00 PM, Matthew Wilcox wrote: > > struct a { > > char c; > > struct b b; > > }; > > > > we want struct b to start at offset 8, but with __packed, it will start > > at offset 1. > > You're talking about how we want the struct laid out in memory if we > have control over the layout. I'm talking about what happens if > something *else* tells us the layout, like a hardware specification > which is what is in play with the XSAVE instruction dictated layout > that's in question here. > > What I'm concerned about is a structure like this: > > struct foo { > u32 i1; > u64 i2; > }; > > If we leave that to natural alignment, we end up with a 16-byte > structure laid out like this: > > 0-3 i1 > 3-8 alignment gap > 8-15 i2 I know you actually meant: 0-3 i1 4-7 pad 8-15 i2 > Which isn't what we want. We want a 12-byte structure, laid out like this: > > 0-3 i1 > 4-11 i2 > > Which we get with: > > struct foo { > u32 i1; > u64 i2; > } __packed; But we _also_ get pessimised accesses to i1 and i2. Because gcc can't rely on struct foo being aligned to a 4 or even 8 byte boundary (it might be embedded in "struct a" from above). > Now, looking at Yu-cheng's specific example, it doesn't matter. We've > got 64-bit types and natural 64-bit alignment. Without __packed, we > need to look out for natural alignment screwing us up. With __packed, > it just does what it *looks* like it does. The question is whether Yu-cheng's struct is ever embedded in another struct. And if so, what does the hardware do?