Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1356827pxb; Wed, 4 Nov 2020 06:57:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8LLCAZaXWnDclY0PBJROevnM4GYmGLvO0lLnzh1dQOFqGL9N0ZonHsScBwUtaT9Z7j4OR X-Received: by 2002:a50:9fc1:: with SMTP id c59mr7518738edf.59.1604501822769; Wed, 04 Nov 2020 06:57:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604501822; cv=none; d=google.com; s=arc-20160816; b=T57S6WeD58x003TgPvrl2IWy0vpEflfBIoiCig5ypfyV5Criv684stw5ktGz/1+7mK h1QqbkIzUk1o8Y+kLyffPunddGjB0OkYfX9vTj2LsE71ODTBTxka1ygKT/MYEGv/0k/C AZPaJB6e65qYpgk9dyMwSR3yW3Oc2Kpk389qQmkj41+i9UFV43v4QqyBEM+UPnGDYOwn y+V1hugS30qhPbRMiA5Kophky5BIYKyLkzTbxL8v1I/gTrZ9Vimgi0AGJC1xMHg+TtIq 9Lbp4WaQhVpZaMURN7hznDZas3/acXF5X4B8faQ1fceE2uGeD3ELT0IWTUKyQ06VjGkF H3SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=duBkevPZEcpbG+ADvG7aSPyncyhess0MpZYq+Yg+cBc=; b=QYqIav3PfxnfJLDYvu0la8moLdA3J2gn+vQMlws0ZYdnnvCUnZlcuyyVnFWa7F3wth F7ds4sVHTAyZMXYZNS40ssYKi2naqTN+5OlyTL2Lct7uJLAl8XeGkcbc5csyYZ/vjVM5 TrjTojWt0SwpF7bHQKaq5dslo0PbnlPn7VZo/EDvl4R2I0JvlDSev7YTrztuE3no/I+L HUkw1G5okXQ2zNb2o6gU/G993MSOP+Sypm0pteXpKkeRUHZ77FUHdD9l9vVkn3vzh16Z /SpyG7RZcZWO+TaOUT6KXrxuj/iu2CTXgoD7rSCwPYb6X5nGYOidY6BICCKzmJmbHHBU nNng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id g10si1515326edy.201.2020.11.04.06.56.39; Wed, 04 Nov 2020 06:57:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730183AbgKDOzH (ORCPT + 99 others); Wed, 4 Nov 2020 09:55:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:48796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730367AbgKDOzD (ORCPT ); Wed, 4 Nov 2020 09:55:03 -0500 Received: from suppilovahvero.lan (83-245-197-237.elisa-laajakaista.fi [83.245.197.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 755D9221FA; Wed, 4 Nov 2020 14:54:57 +0000 (UTC) From: Jarkko Sakkinen To: x86@kernel.org, linux-sgx@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Borislav Petkov , Jethro Beekman , Darren Kenny , Jarkko Sakkinen , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com, mikko.ylinen@intel.com Subject: [PATCH v40 04/24] x86/cpufeatures: x86/msr: Add Intel SGX hardware bits Date: Wed, 4 Nov 2020 16:54:10 +0200 Message-Id: <20201104145430.300542-5-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201104145430.300542-1-jarkko.sakkinen@linux.intel.com> References: <20201104145430.300542-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Populate X86_FEATURE_SGX feature from CPUID and tie it to the Kconfig option with disabled-features.h. IA32_FEATURE_CONTROL.SGX_ENABLE must be examined in addition to the CPUID bits to enable full SGX support. The BIOS must both set this bit and lock IA32_FEATURE_CONTROL for SGX to be supported (Intel SDM section 36.7.1). The setting or clearing of this bit has no impact on the CPUID bits above, which is why it needs to be detected separately. Reviewed-by: Borislav Petkov Acked-by: Jethro Beekman Reviewed-by: Darren Kenny Signed-off-by: Sean Christopherson Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- Changes from v39: * Remove X86_FEATURE_SGX{1, 2}. They were only mistakenly being used for model-specific errata detection. Further, the errata does not occur on any processors that this implementation supports. Later patches ignore the errata, so remove the CPUID bits. arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/disabled-features.h | 8 +++++++- arch/x86/include/asm/msr-index.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index dad350d42ecf..1181f5c7bbef 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -241,6 +241,7 @@ /* 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 */ +#define X86_FEATURE_SGX ( 9*32+ 2) /* Software Guard Extensions */ #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */ #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */ #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */ diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index 5861d34f9771..7947cb1782da 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -62,6 +62,12 @@ # define DISABLE_ENQCMD (1 << (X86_FEATURE_ENQCMD & 31)) #endif +#ifdef CONFIG_X86_SGX +# define DISABLE_SGX 0 +#else +# define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31)) +#endif + /* * Make sure to add features to the correct mask */ @@ -74,7 +80,7 @@ #define DISABLED_MASK6 0 #define DISABLED_MASK7 (DISABLE_PTI) #define DISABLED_MASK8 0 -#define DISABLED_MASK9 (DISABLE_SMAP) +#define DISABLED_MASK9 (DISABLE_SMAP|DISABLE_SGX) #define DISABLED_MASK10 0 #define DISABLED_MASK11 0 #define DISABLED_MASK12 0 diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 972a34d93505..258d555d22f2 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -609,6 +609,7 @@ #define FEAT_CTL_LOCKED BIT(0) #define FEAT_CTL_VMX_ENABLED_INSIDE_SMX BIT(1) #define FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX BIT(2) +#define FEAT_CTL_SGX_ENABLED BIT(18) #define FEAT_CTL_LMCE_ENABLED BIT(20) #define MSR_IA32_TSC_ADJUST 0x0000003b -- 2.27.0