Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp493383imm; Wed, 17 Oct 2018 03:44:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV60fymxVSd+WMCeL6wFynpAVXJkfuQUB4PxBCMXb2eb+Xu+IziOQmIgqGMPtp0rBUK672X8Q X-Received: by 2002:a62:d717:: with SMTP id b23-v6mr17334961pfh.238.1539773076211; Wed, 17 Oct 2018 03:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539773076; cv=none; d=google.com; s=arc-20160816; b=Wy4GkXPv+RCNlAbuHD0/yvNiVY2jeBh9KGn8J+mPstcRlQHcaerooI4Hd3FLRXMDwS ZkLrDHArXCWavLWd8CzW4c+h90/kyTrUuF1EpOWxaQcXSyk/sT4gFpjwnwMuOndtS+P5 NwhKjY1JOi++fPM+pnBWqPmZ3MMgTGvHTznLEBrhp8j9Vhy0f43TF4h4ttS2+mbyu064 nIAaML/n6ZiCL75oBpTk53cHC5FONS9ewYH8B4LTlfr4wg9WQ50uKUVsOGw9lLOLL6q4 WYtD6WSDgcxuFy1Ns2E4LlNWcjpi6JNsnWOp9/RXzxPGZT1OeP/YSc9qV6DtLFMMH/Tf 4oiQ== 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; bh=lFXY/VIIfk+G8BNGkRSy6SwyKB8uVz9hn5swAdqfgmA=; b=PhEy5mIVKZtvpvJDq7fc3XM9t3Bdi92Gb27Z3KPiFv5trw7fnPxCLLyvbSUsMxN6js ja6rE/P8mfA46eh7OFL57prpS1zJhcZdeBT4/xDdyofclzvi0jlD3iDpJ9q9VezW8K3v 2U74mLWH2UYlMfVGA7+9GzTpDVH5piKgBMQ7L3/0OTlHNKa71tHm7RBpzaL05j8T+SxR kkbhHj9G7XXYqv7ZaSsIyhPk7lNqMxk6+OB6t8F8fqBkWQVavI0s3IeCZnVhf1cUcExt 01twaUvUlmsadlPJDsrHvO1+SVwoyGi+2Ug/XN24+FB2J8C8TdRH+5DqVqOWUbHx5bFy fKvw== ARC-Authentication-Results: i=1; mx.google.com; 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 f3-v6si16540501plf.415.2018.10.17.03.44.20; Wed, 17 Oct 2018 03:44:36 -0700 (PDT) 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; 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 S1727159AbeJQShK (ORCPT + 99 others); Wed, 17 Oct 2018 14:37:10 -0400 Received: from mail.skyhub.de ([5.9.137.197]:45772 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbeJQShK (ORCPT ); Wed, 17 Oct 2018 14:37:10 -0400 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Ijdcz5t17VPH; Wed, 17 Oct 2018 12:41:44 +0200 (CEST) Received: from zn.tnic (p200300EC2BC91B00329C23FFFEA6A903.dip0.t-ipconnect.de [IPv6:2003:ec:2bc9:1b00:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 6D1C21EC0104; Wed, 17 Oct 2018 12:41:44 +0200 (CEST) Date: Wed, 17 Oct 2018 12:41:37 +0200 From: Borislav Petkov To: Yu-cheng Yu Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , 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" , Vedvyas Shanbhogue Subject: Re: [PATCH v5 03/27] x86/fpu/xstate: Introduce XSAVES system states Message-ID: <20181017104137.GE22535@zn.tnic> References: <20181011151523.27101-1-yu-cheng.yu@intel.com> <20181011151523.27101-4-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181011151523.27101-4-yu-cheng.yu@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 11, 2018 at 08:14:59AM -0700, Yu-cheng Yu wrote: > Control Flow Enforcement (CET) MSRs are XSAVES system states. That sentence needs massaging. MSRs are system states?!?! > To support CET, we introduce XSAVES system states first. Pls drop the "we" in all commit messages and convert the tone to impartial and passive. Also, this commit message needs to explain *why* you're doing this - it is too laconic. > Signed-off-by: Yu-cheng Yu > --- > arch/x86/include/asm/fpu/internal.h | 3 +- > arch/x86/include/asm/fpu/xstate.h | 4 +- > arch/x86/kernel/fpu/core.c | 6 +- > arch/x86/kernel/fpu/init.c | 10 ---- > arch/x86/kernel/fpu/xstate.c | 86 ++++++++++++++++++----------- > 5 files changed, 62 insertions(+), 47 deletions(-) > > diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h > index 02c4296478c8..9a5db5a63f60 100644 > --- a/arch/x86/include/asm/fpu/internal.h > +++ b/arch/x86/include/asm/fpu/internal.h > @@ -45,7 +45,6 @@ extern void fpu__init_cpu_xstate(void); > extern void fpu__init_system(struct cpuinfo_x86 *c); > extern void fpu__init_check_bugs(void); > extern void fpu__resume_cpu(void); > -extern u64 fpu__get_supported_xfeatures_mask(void); > > /* > * Debugging facility: > @@ -93,7 +92,7 @@ static inline void fpstate_init_xstate(struct xregs_state *xsave) > * XRSTORS requires these bits set in xcomp_bv, or it will > * trigger #GP: > */ > - xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xfeatures_mask_user; > + xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xfeatures_mask_all; > } > > static inline void fpstate_init_fxstate(struct fxregs_state *fx) > diff --git a/arch/x86/include/asm/fpu/xstate.h b/arch/x86/include/asm/fpu/xstate.h > index 76f83d2ac10e..d8e2ec99f635 100644 > --- a/arch/x86/include/asm/fpu/xstate.h > +++ b/arch/x86/include/asm/fpu/xstate.h > @@ -19,9 +19,6 @@ > #define XSAVE_YMM_SIZE 256 > #define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET) > > -/* Supervisor features */ > -#define XFEATURE_MASK_SUPERVISOR (XFEATURE_MASK_PT) > - > /* All currently supported features */ > #define SUPPORTED_XFEATURES_MASK (XFEATURE_MASK_FP | \ > XFEATURE_MASK_SSE | \ > @@ -40,6 +37,7 @@ > #endif > > extern u64 xfeatures_mask_user; > +extern u64 xfeatures_mask_all; You have a bunch of places where you generate the system mask by doing ~xfeatures_mask_user. Why not define xfeatures_mask_system instead and generate the _all mask at the places you need it by doing xfeatures_mask_user | xfeatures_mask_system ? We are differentiating user and system states now so it is only logical to have that mirrored in the variables, right? You even do that in fpu__init_system_xstate(). ... > @@ -225,20 +230,19 @@ void fpu__init_cpu_xstate(void) > * set here. > */ > > - xfeatures_mask_user &= ~XFEATURE_MASK_SUPERVISOR; > - > cr4_set_bits(X86_CR4_OSXSAVE); > xsetbv(XCR_XFEATURE_ENABLED_MASK, xfeatures_mask_user); <---- newline here. > + /* > + * MSR_IA32_XSS sets which XSAVES system states to be managed by Improve: "MSR_IA32_XSS controls which system (not user) states are going to be managed by XSAVES." > @@ -702,6 +703,7 @@ static int init_xstate_size(void) > */ > static void fpu__init_disable_system_xstate(void) > { > + xfeatures_mask_all = 0; > xfeatures_mask_user = 0; > cr4_clear_bits(X86_CR4_OSXSAVE); > fpu__xstate_clear_all_cpu_caps(); > @@ -717,6 +719,8 @@ void __init fpu__init_system_xstate(void) > static int on_boot_cpu __initdata = 1; > int err; > int i; > + u64 cpu_user_xfeatures_mask; > + u64 cpu_system_xfeatures_mask; Please sort function local variables declaration in a reverse christmas tree order: longest_variable_name; shorter_var_name; even_shorter; i; > > WARN_ON_FPU(!on_boot_cpu); > on_boot_cpu = 0; ... -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.