Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp46587imu; Thu, 8 Nov 2018 14:30:50 -0800 (PST) X-Google-Smtp-Source: AJdET5eg3EXhN/KOM79l8eOIT6I6qo64ClmSVvkIyq/GOZqR8m2oG9P7iilpDsoB1TBsd/jwRwe8 X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr6433580plb.87.1541716250214; Thu, 08 Nov 2018 14:30:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716250; cv=none; d=google.com; s=arc-20160816; b=IIWqIUDstdA0XNsOUWSlaIzDl+Kkr+ufLTy1bWzMlEGTCIxr9cbuSanumRxizYwfoz MBOA9aIebwPeJcb8WkC6QKb+VHuiuW1kU6iVLM81EyTz3pVVs3X3rkNVoxh3rXEyTtn4 QtkM1aZg35CLM47Aw6+u5RVJzgBGFsoonGQYRu7wgCnRCStAaHN84htzJlARQni1N16B Ir08mi549pHIh9NeVmq5xLu/C7svxI9C1DL+RCWbu2CXSM+YiVkOTBNn1LlsA0oF+vbb d2Wu/Z324kqPKJrNd8aywu23EqGFoYBZMgrggSbQjICObl5liyrLVLSI6qJaj0lBwIMV dqjA== 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=hk1JID0w158EIaGcr+HCkYTvTEFZ9mw1TMrwyhEXE3Y=; b=Sh84XwkPD4QKVZe1YITjZxou+A9aS7doIStnnwIHEBDftXn+N+PpqkzUvQ9tzQyhwV sHy3G2tvzkYnJ41i/nt7SvPk8NWPMedUpfHySYSMyT2QDiN29Stwb1UF6aqtepQ85AwL 309yX+k0tkY2booWvQr1xkUW6RR0g/gvSzi7zn/vhZ16wE+ijjAPSFfp2BZLD9ZALCfI Ryz8JNXNcW+V2lkgAjk1wcvn38RSM3H67vSAaWvc58PkkPaDd89hlmxAmOmwe5ipZqZz ZHhO1zEJcXmi4uWyDWwU601GT+XUPgV3/akiVAGq0UOaueEy74a+FSMWMvDwAKREIkJ4 l8Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=BtgqaeN5; 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 k18si5079239pgf.97.2018.11.08.14.30.35; Thu, 08 Nov 2018 14:30:50 -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=BtgqaeN5; 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 S1730765AbeKIHie (ORCPT + 99 others); Fri, 9 Nov 2018 02:38:34 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:34484 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728491AbeKIHic (ORCPT ); Fri, 9 Nov 2018 02:38:32 -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=hk1JID0w158EIaGcr+HCkYTvTEFZ9mw1TMrwyhEXE3Y=; b=BtgqaeN5RxYXE0oy0PLqwjh7r t8QVPwzmJ0q7SL0wFaHgO1ObCjn5rI/5mmcFvxdaR3RRH37tE/4PzZ23IcZnFBTYK6H6UJ25H0fa7 3XTGbeV6la9bTYPN8n/ifIKXsxKmC3ge+wj0hyU378Bsj2KxB3xB5nk96VG/33vndqyPOusmlYvn4 TP0ZF2O7+Wwft6xZ+/YulihwWxhQWA2ncN7h1HlRLQwtfdthqVNTAr5bxYjTePk5DiyzyN5nD4z3P Qu0UtelLBNrCgq+Cei4bWbG235I8j5qbMUQB840PFn9LNax5URVU4AzilITACbFN06pIAc/QUVtxg dDiWwfikg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gKsMA-0005k8-PU; Thu, 08 Nov 2018 22:00:54 +0000 Date: Thu, 8 Nov 2018 14:00:54 -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: <20181108220054.GP3074@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <043a17ef-dc9f-56d2-5fba-1a58b7b0fd4d@intel.com> 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 01:48:54PM -0800, Dave Hansen wrote: > On 11/8/18 1:22 PM, Andy Lutomirski wrote: > >> +struct cet_kernel_state { > >> + u64 kernel_ssp; /* kernel shadow stack */ > >> + u64 pl1_ssp; /* ring-1 shadow stack */ > >> + u64 pl2_ssp; /* ring-2 shadow stack */ > >> +} __packed; > >> + > > Why are these __packed? It seems like it'll generate bad code for no > > obvious purpose. > > It's a hardware-defined in-memory structure. Granted, we'd need a > really wonky compiler to make that anything *other* than a nicely-packed > 24-byte structure, but the __packed makes it explicit. > > It is probably a really useful long-term thing to stop using __packed > and start using "__hw_defined" or something that #defines down to __packed. packed doesn't mean "don't leave gaps". It means: 'packed' The 'packed' attribute specifies that a variable or structure field should have the smallest possible alignment--one byte for a variable, and one bit for a field, unless you specify a larger value with the 'aligned' attribute. So Andy's right. It tells the compiler, "this struct will not be naturally aligned, it will be aligned to a 1-byte boundary". Which is silly. If we have struct b { unsigned long x; } __packed; 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. Delete __packed. It doesn't do what you think it does.