From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: Re: [PATCH v5 04/27] x86/fpu/xstate: Add XSAVES system states for shadow stack Date: Thu, 8 Nov 2018 15:35:02 -0800 Message-ID: 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=utf-8 Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: <20181108220054.GP3074@bombadil.infradead.org> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Matthew Wilcox 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 List-Id: linux-arch.vger.kernel.org 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 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; 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com ([134.134.136.65]:52518 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726926AbeKIJM6 (ORCPT ); Fri, 9 Nov 2018 04:12:58 -0500 Subject: Re: [PATCH v5 04/27] x86/fpu/xstate: Add XSAVES system states for shadow stack 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> From: Dave Hansen Message-ID: Date: Thu, 8 Nov 2018 15:35:02 -0800 MIME-Version: 1.0 In-Reply-To: <20181108220054.GP3074@bombadil.infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Matthew Wilcox 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" Message-ID: <20181108233502.u23d9ZDdOUBNGAaIe_lL1FsJDfgz9boo4Yionew1kSM@z> 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 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; 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.