Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1124195imm; Fri, 8 Jun 2018 10:23:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJrs7gYGK7GrVp2ZAZcmu3uMpB92kctoN2/NF59SH9ALnAZ1h/RHvEGIGT8zXHUV4Muqvnz X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr2808589pli.314.1528478585943; Fri, 08 Jun 2018 10:23:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528478585; cv=none; d=google.com; s=arc-20160816; b=luP0IIW0FvwGlSF3FnDTdMIrPX3AUayeHGU24qs6jlxRaferqBFzRagGSx3PgOOrTz 8szozoiDwzH96xvvURGEj7SQKFCK85zo3jNyLPrXuk/zNvjNN/mc9ZADKl90+lQ9OPMT Ve/qXv3pEaGABEVegEabI/0FKUN9EudbBu2jZzr9wa8lD3tcSV8fvTt5UEnS+766X7b9 7cdbx0XTHRmRqDKy5k49266oBSNFS4nWQsdvTAwJkoy+0bGVVAWmaTW//ATjUmXp/Lx4 OYtSFdmFQ2yk4I0VKnIuZhAYng1VTF84Hv89nf/g7m6hM/+i20hsMkfxb7cHeVvpScUk 40Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=9xmdMLKouj/Mg1SrDrrGC084Qm2sxBCcO11nu0KZBZc=; b=sT5FE5SVsmTEaedVs6u2e1jlYVa5e+QY0gCdBkrAjgqULbM6kOvk//62GaMO9Dty8+ SBFOQ/gHFuq1g1Luv6rs/6xbSMygdwh5QyKw3dy9GSf5NhGwzR1hW3g5/sYzwYSn08av 9CULgXI2aLs3TrKlmpsBn0L7XG00hG8IREYhw2TC5+8aJlWCtKaksFYmMXb/8QhOTzBO QgP+41oTZRPyFzDK4GRlvaZF2MGYLfWk95d2xND6nqJsv1IchYooIrGONME7D9cimkwN 67B1jPCS/10WPTc2KaZRfGm+XlSJcXj/C+UsAjsE3ssanABcaQ11fU2uUNVaWj9ppOko 60BA== 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 l3-v6si21571904pgp.345.2018.06.08.10.22.51; Fri, 08 Jun 2018 10:23:05 -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 S1753159AbeFHRUx (ORCPT + 99 others); Fri, 8 Jun 2018 13:20:53 -0400 Received: from mga01.intel.com ([192.55.52.88]:12634 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932130AbeFHRUv (ORCPT ); Fri, 8 Jun 2018 13:20:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2018 10:20:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,490,1520924400"; d="scan'208";a="231035296" Received: from nzou1-mobl1.ccr.corp.intel.com (HELO localhost) ([10.249.254.60]) by orsmga005.jf.intel.com with ESMTP; 08 Jun 2018 10:20:42 -0700 From: Jarkko Sakkinen To: x86@kernel.org, platform-driver-x86@vger.kernel.org Cc: dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, Jarkko Sakkinen , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "Rafael J. Wysocki" , Vikas Shivappa , Greg Kroah-Hartman , Andi Kleen , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), intel-sgx-kernel-dev@lists.01.org (open list:INTEL SGX) Subject: [PATCH v11 07/13] x86, sgx: detect Intel SGX Date: Fri, 8 Jun 2018 19:09:42 +0200 Message-Id: <20180608171216.26521-8-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180608171216.26521-1-jarkko.sakkinen@linux.intel.com> References: <20180608171216.26521-1-jarkko.sakkinen@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. This commit adds the check for SGX to arch/x86 and a new config option, INTEL_SGX_CORE. Exposes a boolean variable 'sgx_enabled' to query whether or not the SGX support is available. Signed-off-by: Sean Christopherson Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- arch/x86/Kconfig | 19 ++++++++++++ arch/x86/include/asm/sgx.h | 25 ++++++++++++++++ arch/x86/include/asm/sgx_pr.h | 20 +++++++++++++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/intel_sgx.c | 53 +++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 arch/x86/include/asm/sgx.h create mode 100644 arch/x86/include/asm/sgx_pr.h create mode 100644 arch/x86/kernel/cpu/intel_sgx.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index c07f492b871a..42015d5366ef 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1925,6 +1925,25 @@ config X86_INTEL_MEMORY_PROTECTION_KEYS If unsure, say y. +config INTEL_SGX_CORE + prompt "Intel SGX core functionality" + def_bool n + depends on X86_64 && CPU_SUP_INTEL + help + Intel Software Guard eXtensions (SGX) is a set of CPU instructions + that allows ring 3 applications to create enclaves; private regions + of memory that are protected, by hardware, from unauthorized access + and/or modification. + + This option enables kernel recognition of SGX, high-level management + of the Enclave Page Cache (EPC), tracking and writing of SGX Launch + Enclave Hash MSRs, and allows for virtualization of SGX via KVM. By + iteslf, this option does not provide SGX support to userspace. + + For details, see Documentation/x86/intel_sgx.rst + + If unsure, say N. + config EFI bool "EFI runtime service support" depends on ACPI diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h new file mode 100644 index 000000000000..fa3e6e0eb8af --- /dev/null +++ b/arch/x86/include/asm/sgx.h @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// Copyright(c) 2016-18 Intel Corporation. +// +// Authors: +// +// Jarkko Sakkinen +// Suresh Siddha +// Sean Christopherson + +#ifndef _ASM_X86_SGX_H +#define _ASM_X86_SGX_H + +#include + +#define SGX_CPUID 0x12 + +enum sgx_cpuid { + SGX_CPUID_CAPABILITIES = 0, + SGX_CPUID_ATTRIBUTES = 1, + SGX_CPUID_EPC_BANKS = 2, +}; + +extern bool sgx_enabled; + +#endif /* _ASM_X86_SGX_H */ diff --git a/arch/x86/include/asm/sgx_pr.h b/arch/x86/include/asm/sgx_pr.h new file mode 100644 index 000000000000..876dc44c2ccc --- /dev/null +++ b/arch/x86/include/asm/sgx_pr.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// Copyright(c) 2016-17 Intel Corporation. +// +// Authors: +// +// Jarkko Sakkinen +// Suresh Siddha +// Serge Ayoun +// Shay Katz-zamir + +#ifndef _ASM_X86_SGX_PR_H +#define _ASM_X86_SGX_PR_H + +#include +#include + +#undef pr_fmt +#define pr_fmt(fmt) "intel_sgx: " fmt + +#endif /* _ASM_X86_SGX_PR_H */ diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index a66229f51b12..9552ff5b4ec3 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_CPU_SUP_TRANSMETA_32) += transmeta.o obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o obj-$(CONFIG_INTEL_RDT) += intel_rdt.o intel_rdt_rdtgroup.o intel_rdt_monitor.o intel_rdt_ctrlmondata.o +obj-$(CONFIG_INTEL_SGX_CORE) += intel_sgx.o obj-$(CONFIG_X86_MCE) += mcheck/ obj-$(CONFIG_MTRR) += mtrr/ diff --git a/arch/x86/kernel/cpu/intel_sgx.c b/arch/x86/kernel/cpu/intel_sgx.c new file mode 100644 index 000000000000..db6b315334f4 --- /dev/null +++ b/arch/x86/kernel/cpu/intel_sgx.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// Copyright(c) 2016-17 Intel Corporation. +// +// Authors: +// +// Jarkko Sakkinen +// Suresh Siddha +// Serge Ayoun +// Shay Katz-zamir +// Sean Christopherson + +#include +#include +#include +#include +#include +#include +#include +#include + +bool sgx_enabled __ro_after_init = false; +EXPORT_SYMBOL(sgx_enabled); + +static __init bool sgx_is_enabled(void) +{ + unsigned long fc; + + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) + return false; + + 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)) + return false; + + if (!(fc & FEATURE_CONTROL_SGX_ENABLE)) + return false; + + return true; +} + +static __init int sgx_init(void) +{ + sgx_enabled = sgx_is_enabled(); + return 0; +} + +arch_initcall(sgx_init); -- 2.17.0