Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp38180imu; Thu, 8 Nov 2018 13:24:15 -0800 (PST) X-Google-Smtp-Source: AJdET5e+PATm5Mf/Nz2bMAOkuoUH0qex+UnFeaooN49aZNgIPFlBLDaRezfch3e3DPRBpVcWBQhi X-Received: by 2002:a17:902:c03:: with SMTP id 3-v6mr688697pls.141.1541712255354; Thu, 08 Nov 2018 13:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541712255; cv=none; d=google.com; s=arc-20160816; b=pyHEBEZ0P5fgFhGnUG96g/FKogLlQO+5YWT/kIh5VWTP3hI4Xmqo/CQ6z5GFHRWa3L 6pZitZ+U1valCzU4bwGCPoViXJT9BoeaQZvv0gaqSakeYtNmpTPSwx3TN89ooUDtxqE4 jPIl24+AFPJI4q6Ltn6DI53E0Lb8v6hOXpZo+LqOwMDsoMlVJuxYX5CWaSH53zNlKn3S Hw4/nkJIPA90Yw2OHRnHCdnL8vTZKpi83jWra1PKlvrLcBlQafXmpv8uohxEtKNyd3yt Lrp7BjOv5qYEqN5TwRUoW0iMH4P9ovpc89SntzFJ0bCwb7NiUdn66IgQHoBvNuKF4MUO JEgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7Fm+Swwz5U6PYgdF4xz3yvF0Ae+TVaAPPC+XBP1RMAY=; b=Ngv18t0d3ACZKVKGeXquRFNYqotuZ4zyw/fe0ttAvdYQFT0xVmdcrH2d56EwNt+ihx 7j9kVaBHf7rh6lRDPMyjaWyBvd1RbuWG4CC6e3qeldlWEFZqXt/KB+GZpGEFf8ep75D+ hHqLNyFvE7/g5f88kX27UfSfEmxa5SBiBdE/HInFDEpW+zRLy2nDND5VJRrgt2kujagw Q1UaC8Tj8aU4LHnEDzBXVsK0fZ5nNCjeag1WWiCfoOMMrCJy7jLtafFtGD1SusJtQZ2b 6WQbpO4s/sBo765yqBpNyf9/f8hFbDFcpp1y67yYPlYrD02OnX6mtmW79zN5uGaDWIHe rIPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=E706BHL0; 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 u5-v6si5270130plj.98.2018.11.08.13.23.56; Thu, 08 Nov 2018 13:24:15 -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=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=E706BHL0; 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 S1726847AbeKIHA0 (ORCPT + 99 others); Fri, 9 Nov 2018 02:00:26 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38491 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbeKIHA0 (ORCPT ); Fri, 9 Nov 2018 02:00:26 -0500 Received: by mail-wm1-f67.google.com with SMTP id f2-v6so116676wme.3 for ; Thu, 08 Nov 2018 13:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7Fm+Swwz5U6PYgdF4xz3yvF0Ae+TVaAPPC+XBP1RMAY=; b=E706BHL0Td3myb4413EwEA1PhNfwbex5uMj+f31Sv1vypjDGhg3Ry8ZMpr6jUhq7JI Pm1oqp/XMJ7g2jwJUZXRiOH0BhwPq7WEUFskMxiV4QUb8BTVzOItGsNAwDpzbcF9LiAi nM/JyQif/POUtX3zV9LqpeMzmZ1MDjVF8edn/5HIez3tnVH1TSEH1JpeyqCWV1pdrkjH zw77zTBffvybM4PLLRgxhLjKeCNkGDhwNPamR7rFmaYJ0yL7vyQsYPWyIB9zGE/25PrV 5DFkRkEr6rEVkBk16gvVZv6wfT84lVTypKJugSbE14Ue5T3WLoK8Yz2g60amCTLl/O/q +MOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7Fm+Swwz5U6PYgdF4xz3yvF0Ae+TVaAPPC+XBP1RMAY=; b=eCEb0EqdLkuSZRSBRY094FXIc/sxZHCZDLwUsM4FoZEfCcITPlDw+Z7EoNYP+NDoGp OEP8TyZhyAap5tkaXpZ5W82NdvQRU3bqRw3AnLYpd8ibJ2aG9/1iez4BNbuA+urfrdmf ViT4ukgj2fT7HMO4rjODCiO56hvrJDnHMBi2Cb0vlnMcXG2tVCsdnMvTF2WHkPW5YWK4 8hIcB7xaBCt+FSitA+0sz73R0Z1Zg8syF7GABAG68B9fyQczd5604dDtBgK8o6OjyNLr r+IbFKSWqn7WlPNxc3Luh9JSyXtj0FaCTPPO5O0Ar8wMSRjH9Xqke0KNXBQL2of6QbrS sGdw== X-Gm-Message-State: AGRZ1gK7+dn9cvGhxqu9lEHCveZ0hJmFMkWJOLSTA8+yinXCJs+iNjvL OKC1aGVRXRjx+I/oeobRJLGkuddjfqqJzB/77lnTxA== X-Received: by 2002:a1c:4b1a:: with SMTP id y26-v6mr2593259wma.82.1541712184530; Thu, 08 Nov 2018 13:23:04 -0800 (PST) MIME-Version: 1.0 References: <20181011151523.27101-1-yu-cheng.yu@intel.com> <20181011151523.27101-5-yu-cheng.yu@intel.com> <4295b8f786c10c469870a6d9725749ce75dcdaa2.camel@intel.com> In-Reply-To: <4295b8f786c10c469870a6d9725749ce75dcdaa2.camel@intel.com> From: Andy Lutomirski Date: Thu, 8 Nov 2018 13:22:54 -0800 Message-ID: Subject: Re: [PATCH v5 04/27] x86/fpu/xstate: Add XSAVES system states for shadow stack To: Yu-cheng Yu Cc: 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" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 8, 2018 at 1:06 PM Yu-cheng Yu wrote: > > On Thu, 2018-11-08 at 12:46 -0800, Andy Lutomirski wrote: > > On Thu, Oct 11, 2018 at 8:20 AM Yu-cheng Yu wrote: > > > > > > Intel Control-flow Enforcement Technology (CET) introduces the > > > following MSRs into the XSAVES system states. > > > > > > IA32_U_CET (user-mode CET settings), > > > IA32_PL3_SSP (user-mode shadow stack), > > > IA32_PL0_SSP (kernel-mode shadow stack), > > > IA32_PL1_SSP (ring-1 shadow stack), > > > IA32_PL2_SSP (ring-2 shadow stack). > > > > > > Signed-off-by: Yu-cheng Yu > > > --- > > > arch/x86/include/asm/fpu/types.h | 22 +++++++++++++++++++++ > > > arch/x86/include/asm/fpu/xstate.h | 4 +++- > > > arch/x86/include/uapi/asm/processor-flags.h | 2 ++ > > > arch/x86/kernel/fpu/xstate.c | 10 ++++++++++ > > > 4 files changed, 37 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/include/asm/fpu/types.h > > > b/arch/x86/include/asm/fpu/types.h > > > index 202c53918ecf..e55d51d172f1 100644 > > > --- a/arch/x86/include/asm/fpu/types.h > > > +++ b/arch/x86/include/asm/fpu/types.h > > > @@ -114,6 +114,9 @@ enum xfeature { > > > XFEATURE_Hi16_ZMM, > > > XFEATURE_PT_UNIMPLEMENTED_SO_FAR, > > > XFEATURE_PKRU, > > > + XFEATURE_RESERVED, > > > + XFEATURE_SHSTK_USER, > > > + XFEATURE_SHSTK_KERNEL, > > > > > > XFEATURE_MAX, > > > }; > > > @@ -128,6 +131,8 @@ enum xfeature { > > > #define XFEATURE_MASK_Hi16_ZMM (1 << XFEATURE_Hi16_ZMM) > > > #define XFEATURE_MASK_PT (1 << > > > XFEATURE_PT_UNIMPLEMENTED_SO_FAR) > > > #define XFEATURE_MASK_PKRU (1 << XFEATURE_PKRU) > > > +#define XFEATURE_MASK_SHSTK_USER (1 << XFEATURE_SHSTK_USER) > > > +#define XFEATURE_MASK_SHSTK_KERNEL (1 << XFEATURE_SHSTK_KERNEL) > > > > > > #define XFEATURE_MASK_FPSSE (XFEATURE_MASK_FP | > > > XFEATURE_MASK_SSE) > > > #define XFEATURE_MASK_AVX512 (XFEATURE_MASK_OPMASK \ > > > @@ -229,6 +234,23 @@ struct pkru_state { > > > u32 pad; > > > } __packed; > > > > > > +/* > > > + * State component 11 is Control flow Enforcement user states > > > + */ > > > +struct cet_user_state { > > > + u64 u_cet; /* user control flow settings */ > > > + u64 user_ssp; /* user shadow stack pointer */ > > > +} __packed; > > > + > > > +/* > > > + * State component 12 is Control flow Enforcement kernel states > > > + */ > > > +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. > > That prevents any possibility that the compiler will insert padding, although in > 64-bit kernel this should not happen to either struct. Also all xstate > components here are packed. > They both seem like bugs, perhaps. As I understand it, __packed removes padding, but it also forces the compiler to expect the fields to be unaligned even if they are actually aligned.