From: "Huang, Kai" <kai.huang@intel.com>
To: "linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
"Hansen, Dave" <dave.hansen@intel.com>
Cc: "jarkko@kernel.org" <jarkko@kernel.org>, "Christopherson,,
Sean" <seanjc@google.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Subject: Re: [PATCH] x86/intel: Clear SGX bit if both SGX driver and KVM SGX are not enabled
Date: Mon, 12 Sep 2022 03:09:42 +0000 [thread overview]
Message-ID: <4e1e76f93cda5799fa5eab6fb23ef6fa216ea9eb.camel@intel.com> (raw)
In-Reply-To: <8d7a22f3-6677-1438-84d2-68a56211ad11@intel.com>
On Fri, 2022-09-09 at 05:11 -0700, Dave Hansen wrote:
> On 9/9/22 01:08, Kai Huang wrote:
> > Currently on platform which has SGX enabled, if CONFIG_X86_SGX is not
> > enabled, the X86_FEATURE_SGX is not cleared, resulting in /proc/cpuinfo
> > shows "sgx" feature. This is not desired.
>
> Why is it not desired?
My understanding is if a feature is present in /proc/cpuinfo, that feature
should be supported by the kernel and should be usable to the userspace. For
example, it seems AMD's SME was always present in /proc/cpuinfo at the very
beginning, but later it was cleared if SME is not activated by the kernel in
below commit:
commit 08f253ec3767bcfafc5d32617a92cee57c63968e (tag: x86_cpu_for_v5.18_rc1)
Author: Mario Limonciello <mario.limonciello@amd.com>
Date: Tue Feb 15 21:44:46 2022 -0600
x86/cpu: Clear SME feature flag when not in use
Currently, the SME CPU feature flag is reflective of whether the CPU
supports the feature but not whether it has been activated by the
kernel.
Change this around to clear the SME feature flag if the kernel is not
using it so userspace can determine if it is available and in use
from /proc/cpuinfo.
As the feature flag is cleared on systems where SME isn't active, use
CPUID 0x8000001f to confirm SME availability before calling
native_wbinvd().
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Link:
https://lore.kernel.org/r/20220216034446.2430634-1-mario.limonciello@amd.com
I am not 100% sure whether this rule should always be applied to other features,
though. But for SGX even the current upstream code clears SGX feature in some
conditions, for example, when SGX_LC is disabled by BIOS (in which case only KVM
SGX can be supported) and KVM SGX is also disabled, i.e. due to
CONFIG_X86_SGX_KVM isn't set:
if (!(msr & FEAT_CTL_SGX_LC_ENABLED) && enable_sgx_driver) {
if (!enable_sgx_kvm) {
pr_err_once("SGX Launch Control is locked. Disable SGX.\n");
clear_cpu_cap(c, X86_FEATURE_SGX);
else {
...
}
}
So I think it makes sense to clear SGX if both SGX driver and KVM SGX are not
enabled by the kernel.
--
Thanks,
-Kai
next prev parent reply other threads:[~2022-09-12 3:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-09 8:08 [PATCH] x86/intel: Clear SGX bit if both SGX driver and KVM SGX are not enabled Kai Huang
2022-09-09 11:05 ` Huang, Kai
2022-09-09 12:11 ` Dave Hansen
2022-09-12 3:09 ` Huang, Kai [this message]
2022-09-12 10:47 ` Jarkko Sakkinen
2022-09-12 14:31 ` Reinette Chatre
2022-09-12 14:34 ` Dave Hansen
2022-09-12 20:54 ` Huang, Kai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4e1e76f93cda5799fa5eab6fb23ef6fa216ea9eb.camel@intel.com \
--to=kai.huang@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=jarkko@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox