Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1048760imm; Wed, 4 Jul 2018 10:30:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeEnHkIWmb/XIZ/nXksXcz/Ng/7PvD1gYPT1TDakV1gLaKAN8DFRCJ+c/bZET+L0oyW3Ghr X-Received: by 2002:a65:5004:: with SMTP id f4-v6mr2728218pgo.54.1530725419275; Wed, 04 Jul 2018 10:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530725419; cv=none; d=google.com; s=arc-20160816; b=Umx24BuPo14RPocr7Vl5itusMGVt846ZoP5YKgBfe5QJAWBhNHFD2Zj9OsvcHKiYE9 KBOeNFEBBAGRGtmEDpByRcyMapgLENlOpdEZhpqEI2jQuQM34J8/DdHAziRv3nC/BCTc iUNGOuertihdoERUP2cqJsTuRh+dWVAHhYK3sW6msJKUoNtDGDdx1kx3A2DS+Yvwupko TZPMKAB0kH73Hwl+G5j6mWKYSqF5FtP3/bRZDWYV2kwLzElFKU1X2AnxxxMd9F50xfsx bh00x0SckLk0T0Ky5mlCi76ssElUyTePu/c5hU0ZloHzw/hIahhvCXyb/aEN+m3tM2wy Fv6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=umc50AY5jmp9YX9JaddXnb0uG/57Qz5NwqwhzKFiMQQ=; b=ujYZOjgfV62HoffoahIjUoB1JT2kO7MEOudv1OIrirHZWdpzYrDoF0Bv+pa1ByIRgz /D9a4gsNvVHc/RkNe3QAppV3ymWBf9IZVWV6uE3a9mMPfThi+rASfJ5T43jN7Z7zVp7z GUH7vSFx6jQhP1udOgzYhTkz1wAx+po2rghfjpIxKnbsIMXHAnbOrVaL65s0mI949ame uHnHqjvxpnNPZgDlojIFpWlZ8dX5rBb9S8P1zpTPd0ddOFgvl4OzoZmk9tU7OrV1HHp8 mgiyVwwCwLgchc0A4d83IdO+PRlLjPPjybL9o11sy3LBzD8VVVcpMgTcie6V3JW4fepg jN9Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21-v6si3762293pgl.148.2018.07.04.10.30.04; Wed, 04 Jul 2018 10:30:19 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753220AbeGDR2Y (ORCPT + 99 others); Wed, 4 Jul 2018 13:28:24 -0400 Received: from mga18.intel.com ([134.134.136.126]:23283 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752158AbeGDR2X (ORCPT ); Wed, 4 Jul 2018 13:28:23 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 10:28:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,306,1526367600"; d="scan'208";a="72262493" Received: from saamir-mobl.ger.corp.intel.com (HELO localhost) ([10.252.34.242]) by orsmga002.jf.intel.com with ESMTP; 04 Jul 2018 10:28:15 -0700 Date: Wed, 4 Jul 2018 20:28:14 +0300 From: Jarkko Sakkinen To: Thomas Gleixner Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org, dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, linux-sgx@vger.kernel.org, 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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