From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Wed, 4 Jul 2018 20:28:14 +0300 From: Jarkko Sakkinen To: Thomas Gleixner CC: , , , , , , , Ingo Molnar , "H. Peter Anvin" , "Vikas Shivappa" , "Rafael J. Wysocki" , Andi Kleen , "Kirill A. Shutemov" , Greg Kroah-Hartman , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v12 06/13] x86/sgx: detect Intel SGX Message-ID: <20180704172814.GH6724@linux.intel.com> References: <20180703182118.15024-1-jarkko.sakkinen@linux.intel.com> <20180703182118.15024-7-jarkko.sakkinen@linux.intel.com> Content-Type: text/plain; charset="us-ascii" In-Reply-To: Sender: Return-Path: platform-driver-x86-owner@vger.kernel.org MIME-Version: 1.0 List-ID: On Tue, Jul 03, 2018 at 09:09:52PM +0200, Thomas Gleixner wrote: > On Tue, 3 Jul 2018, Jarkko Sakkinen wrote: > > @@ -0,0 +1,54 @@ > > +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) > > +// Copyright(c) 2016-17 Intel Corporation. > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > The common include ordering is > > include linux/.... > > include asm/... > > > + > > +bool sgx_enabled __ro_after_init; > > +EXPORT_SYMBOL(sgx_enabled); > > > > +bool sgx_lc_enabled __ro_after_init; > > +EXPORT_SYMBOL(sgx_lc_enabled); > > + > > +static __init bool sgx_is_enabled(bool *lc_enabled) > > +{ > > + unsigned long fc; > > + > > + if (!boot_cpu_has(X86_FEATURE_SGX)) > > + return false; > > + > > + if (!boot_cpu_has(X86_FEATURE_SGX1)) > > + return false; > > + > > + rdmsrl(MSR_IA32_FEATURE_CONTROL, fc); > > + if (!(fc & FEATURE_CONTROL_LOCKED)) { > > + pr_info("IA32_FEATURE_CONTROL MSR is not locked\n"); > > + return false; > > + } > > + > > + if (!(fc & FEATURE_CONTROL_SGX_ENABLE)) { > > + pr_info("disabled by the firmware\n"); > > + return false; > > + } > > + > > + if (!(fc & FEATURE_CONTROL_SGX_LE_WR)) { > > + pr_info("IA32_SGXLEPUBKEYHASHn MSRs are not writable\n"); > > + return false; > > + } > > + > > + *lc_enabled = !!(fc & FEATURE_CONTROL_SGX_LE_WR); > > + return true; > > +} > > + > > +static __init int sgx_init(void) > > +{ > > + sgx_enabled = sgx_is_enabled(&sgx_lc_enabled); > > This is horrible, really. Both variables are global. So what the heck is > wrong with assigning them directly in the function? Fully agreed, does not make any sense. > Thanks, > > tglx /Jarkko