Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp901844oof; Tue, 25 Sep 2018 06:12:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Hn3ZtvmeWWlRCsM6vj12EVZ7CDgShiXa3jZAOITLVkm/JnkxMtrqj8iwmVBXNlnwbz/vl X-Received: by 2002:a62:798f:: with SMTP id u137-v6mr1114517pfc.23.1537881179801; Tue, 25 Sep 2018 06:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537881179; cv=none; d=google.com; s=arc-20160816; b=P0dZlKSVT2TZssY0rxBTxwtJx4FiwGdBPwAwTyUoWAtZzOYbZKfm/J2Ebm17Ud1IBX aM3y5Z9eWz2aLF0w7LyZcupnlPYYM3cSmnW9P+7+y6N9DfVR5vW5nGrNUCGLGPxu2c8n BPEtYzZeNEjpvUmrIDpYW49b3GjfgZkEz4wfz/fOp/ETZQcxOsNOJU1eDky//obTLiuG DNbZ1P1JdumjDmO9whfC9wYJN6nY/FysEbKXsejwZtHHWn+HWAbsSCwYk+YCkNAW066I UghK7Jy68z2S4+BBo0RSs3Iajk28it1gdhBQCNxHppsZWIB9TAyIZGpu0J8mRC5BUPG6 13CA== 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; bh=D9N6/hqcWhNtnw6lzZErqCNVbEAuhgvuQ2DzXOZh2n4=; b=S5xzOTKprAt3TCS5LYjerDnVN82jmpE4dKZhcppVSAslNhvlOq3/rvym1hg0F+PhU3 0lQqEHXwWBQkbhp3jfgraTFiMq3wZcA2U3zyA6Hk6Zu1YKD9Vb4EUfzRNPnlxCFKrw/U 3bkG353qrwoZ7kyDVm/sQRVBqwz6px+dtqW9TrIUoBwnZorXmyKn/T65lFJoDhENLHUx J8EoT1ZBYjhIWgjAhut1POuFmHXnXcm/2TdJuywKkeWWNGDEgzJSDcdC/1KSVO2L5EVK qsF5kaZR2LNY9qm2pQ/tFrtunAitrgUsnFqRKP11pOiNrsd1OJ6vcJuP0qcquqYU20A3 ayeQ== 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 p13-v6si2341621pgi.317.2018.09.25.06.12.44; Tue, 25 Sep 2018 06:12:59 -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 S1729241AbeIYTUA (ORCPT + 99 others); Tue, 25 Sep 2018 15:20:00 -0400 Received: from mga14.intel.com ([192.55.52.115]:53075 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729112AbeIYTTs (ORCPT ); Tue, 25 Sep 2018 15:19:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 06:12:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,302,1534834800"; d="scan'208";a="93546703" Received: from thomasvo-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.53.212]) by orsmga001.jf.intel.com with ESMTP; 25 Sep 2018 06:09:58 -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, serge.ayoun@intel.com, shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, andriy.shevchenko@linux.intel.com, Jarkko Sakkinen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Konrad Rzeszutek Wilk , David Woodhouse , David Wang , "Kirill A. Shutemov" , "Levin, Alexander (Sasha Levin)" , Jia Zhang , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v14 04/19] x86/cpufeatures: Add SGX feature bits Date: Tue, 25 Sep 2018 16:06:41 +0300 Message-Id: <20180925130845.9962-5-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> References: <20180925130845.9962-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 Add SGX feature bits as part of the Linux defined leaf 8, which currently contains virtualization flags. There are currently four documented SGX feature bits, with more expected in the not-too-distant future. Signed-off-by: Sean Christopherson Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- arch/x86/include/asm/cpufeatures.h | 8 +++++- arch/x86/kernel/cpu/intel.c | 40 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 7bb647f57d42..d6f4abe6d0b0 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -233,6 +233,12 @@ #define X86_FEATURE_XENPV ( 8*32+16) /* "" Xen paravirtual guest */ #define X86_FEATURE_EPT_AD ( 8*32+17) /* Intel Extended Page Table access-dirty bit */ +/* SGX flags: Linux defined, word 8 */ +#define X86_FEATURE_SGX1 ( 8*32+24) /* SGX1 leaf functions */ +#define X86_FEATURE_SGX2 ( 8*32+25) /* SGX2 leaf functions */ +#define X86_FEATURE_SGX_ENCLV ( 8*32+26) /* SGX ENCLV instruction, leafs E[INC|DEC]VIRTCHILD, ESETCONTEXT */ +#define X86_FEATURE_SGX_ENCLS_C ( 8*32+27) /* SGX ENCLS leafs ERDINFO, ETRACK, ELDBC and ELDUC */ + /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/ #define X86_FEATURE_TSC_ADJUST ( 9*32+ 1) /* TSC adjustment MSR 0x3B */ @@ -332,7 +338,7 @@ #define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */ #define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */ #define X86_FEATURE_CLDEMOTE (16*32+25) /* CLDEMOTE instruction */ -#define X86_FEATURE_SGX_LC (16*32+30) /* supports SGX launch configuration */ +#define X86_FEATURE_SGX_LC (16*32+30) /* supports SGX launch control */ /* AMD-defined CPU features, CPUID level 0x80000007 (EBX), word 17 */ #define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0) /* MCA overflow recovery support */ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index fc3c07fe7df5..fcf188d5f9df 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef CONFIG_X86_64 #include @@ -512,6 +513,42 @@ static void detect_vmx_virtcap(struct cpuinfo_x86 *c) } } +static void detect_sgx(struct cpuinfo_x86 *c) +{ +#define _X86_FEATURE_SGX1 BIT(0) +#define _X86_FEATURE_SGX2 BIT(1) +#define _X86_FEATURE_SGX_ENCLV BIT(5) +#define _X86_FEATURE_SGX_ENCLS_C BIT(6) + + unsigned int eax; + + clear_cpu_cap(c, X86_FEATURE_SGX1); + clear_cpu_cap(c, X86_FEATURE_SGX2); + clear_cpu_cap(c, X86_FEATURE_SGX_ENCLV); + clear_cpu_cap(c, X86_FEATURE_SGX_ENCLS_C); + + if (c->cpuid_level < SGX_CPUID) { + pr_err_once("x86/sgx: cannot enumerate CPUID leaf (0x%x)\n", + SGX_CPUID); + clear_cpu_cap(c, X86_FEATURE_SGX); + return; + } + + eax = cpuid_eax(SGX_CPUID); + + if (eax & _X86_FEATURE_SGX1) + set_cpu_cap(c, X86_FEATURE_SGX1); + + if (eax & _X86_FEATURE_SGX2) + set_cpu_cap(c, X86_FEATURE_SGX2); + + if (eax & _X86_FEATURE_SGX_ENCLV) + set_cpu_cap(c, X86_FEATURE_SGX_ENCLV); + + if (eax & _X86_FEATURE_SGX_ENCLS_C) + set_cpu_cap(c, X86_FEATURE_SGX_ENCLS_C); +} + #define MSR_IA32_TME_ACTIVATE 0x982 /* Helpers to access TME_ACTIVATE MSR */ @@ -760,6 +797,9 @@ static void init_intel(struct cpuinfo_x86 *c) if (cpu_has(c, X86_FEATURE_VMX)) detect_vmx_virtcap(c); + if (cpu_has(c, X86_FEATURE_SGX)) + detect_sgx(c); + if (cpu_has(c, X86_FEATURE_TME)) detect_tme(c); -- 2.17.1