Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1493611imm; Tue, 3 Jul 2018 12:11:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc18TPC4orv6r9L3NwyQiD7FuprbwqX1vSm4mqZ+ceVkj42ZxjEejRzTJT6idE0yHbHrZHP X-Received: by 2002:a62:c00c:: with SMTP id x12-v6mr20931299pff.216.1530645117392; Tue, 03 Jul 2018 12:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530645117; cv=none; d=google.com; s=arc-20160816; b=Ym8jf26YF8GxqU8i+6OwRyy45U2S0y0/3LPFScNmFQ3o2GhPta4U67Tu3UqZJA4uGr tq7vV1/BGsTCvnBgiwFLdPIrx6Q62lnIhdnAhIogjcFMWH77T1jVm4N0X4S34DaMi6RG K/XKAHb1JclzLCAfPtenSVxeIm5+4LkYRhiVzbPsJ/gPUUWlDjbgJn2JGZNWFGbv9R59 dBCGZNEb7OXerCiq84TUCTxz2pP3ef5dpT4Vk2e/P9oc7RmEtH/MFWOW7qfWVXKYE9NM 9MQboXvbR/RcFTlT5j3KUcSRhpL9opcBj37cIC6PGpt5ifVD8neaCJ8237NY5H2ro4dm vX2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=2W7TXEde8kctrdq/CX940DzC1hZNRTJZ4dvKjqS8DpU=; b=mMN1+yjKgkou9FBbpX33WQnNovNX1kDNictXLmUOhh6YPQfX/FQOry+N2LSwpiT+oK WzCNPVH91ldScYVe6Gb2zzU9D6mfKYI61HsvgVEKcuyPIMy7lg+LQy+ii1PFTSUzopOL fqb5UVomxNdAaw/mkVGWJDZHWPU+z3CI3Z0F5UNZ7sJx/vrF78MpMyjoDkd10/5RmkP1 NxRNnfeS/O1e3wqfcLwKoobx/a5BlgdH0tVkuSZZUlh3a6krsicGriZIh6vwlD8BkIuO ne0q6MGG5RajXfyN3sIbaSWEAjPaXWBX3FGTPfT8RcwG5mkja1MZF9WUps0kHyoD+YGu mGMw== 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 bb7-v6si211176plb.305.2018.07.03.12.11.43; Tue, 03 Jul 2018 12:11:57 -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 S934535AbeGCTKE (ORCPT + 99 others); Tue, 3 Jul 2018 15:10:04 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:45244 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932698AbeGCTKD (ORCPT ); Tue, 3 Jul 2018 15:10:03 -0400 Received: from p4fea482e.dip0.t-ipconnect.de ([79.234.72.46] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1faQgT-0001Ep-2g; Tue, 03 Jul 2018 21:09:53 +0200 Date: Tue, 3 Jul 2018 21:09:52 +0200 (CEST) From: Thomas Gleixner To: Jarkko Sakkinen 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 In-Reply-To: <20180703182118.15024-7-jarkko.sakkinen@linux.intel.com> Message-ID: References: <20180703182118.15024-1-jarkko.sakkinen@linux.intel.com> <20180703182118.15024-7-jarkko.sakkinen@linux.intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Thanks, tglx