x86/sgx: Warn explicitly if X86_FEATURE_SGX_LC is not enabled
PATCH v2 1/1 x86/sgx: Warn explicitly if X86_FEATURE_SGX_LC is not enabled
A kernel requires X86_FEATURE_SGX_LC to be able to create SGX enclaves. There is quite a number of hardware which has X86_FEATURE_SGX but not X86_FEATURE_SGX_LC. A kernel running on such a hardware does not create /dev/sgx_enclave file silently. Explicitly warn if X86_FEATURE_SGX_LC is not enabled to properly nofity a user about this condition.
The X86_FEATURE_SGX_LC is a CPU feature that enables LE hash MSRs to be writable when running native enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.
---
an out-of-commit-message note:
I've hit this issue myself and have spent some time researching where is my /dev/sgx_enclave file on an SGX-enabled hardware, so this is a bit personal.
Links related:
https://github.com/intel/linux-sgx/issues/837
https://patchwork.kernel.org/project/platform-driver-x86/patch/[email protected]/
arch/x86/kernel/cpu/sgx/driver.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/driver.c +3 -1
@@ -150,8 +150,10 @@ int __init sgx_drv_init(void)u64 xfrm_mask;int ret; -if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) +if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) { +pr_err ("SGX disabled: SGX launch control is not available.\n" );return -ENODEV ; + }cpuid_count (SGX_CPUID ,0 , &eax, &ebx, &ecx, &edx);
Signature · 1 line
2.48.1
Quoted 1 line · Vladis Dronov
A kernel requires
X86_FEATURE_SGX_LCto be able to create SGX enclaves.
The kernel requires ...
Quoted 4 lines
There is quite a number of hardware which has
X86_FEATURE_SGXbut notX86_FEATURE_SGX_LC. A kernel running on such a hardware does not create/dev/sgx_enclavefile silently. Explicitly warn ifX86_FEATURE_SGX_LCis not enabled to properly nofity a user about this condition.
^ notify
And I don't think "notify" is correct because the reality is the kernel only prints some error message so that the user can check and see when it wants.
How about:
Explicitly print error message if X86_FEATURE_SGX_LC is not present so that the users can be aware of this condition which results in SGX driver being disabled.
Quoted 4 lines
The
X86_FEATURE_SGX_LCis a CPU feature that enables LE hash MSRs to be writable when running native enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.
Using "root key" can be controversial. Let's just say "key" instead.
And the X86_FEATURE_SGX_LC feature itself doesn't automatically enable LE MSRs to be writable. We still need to opt-in in the 'feature control' MSR.
How about:
The X86_FEATURE_SGX_LC, a.k.a. SGX Launch Control, is a CPU feature that enables LE (Launch Enclave) hash MSRs to be writable (with additional opt-in required in the 'feature control' MSR) when running enclaves, i.e., using a custom key rather than the Intel proprietary key for enclave signing.
Quoted 2 lines
Signed-off-by Vladis Dronov <[email protected]>
I think this message will be useful for someone who knows SGX in general but doesn't know that Linux SGX driver requires the LE MSRs to be writable, thus requires the CPU supports SGX_LC feature bit.
With the above addressed, feel free to add:
Quoted 31 lines
---
an out-of-commit-message note:
I've hit this issue myself and have spent some time researching where is my
/dev/sgx_enclavefile on an SGX-enabled hardware, so this is a bit personal.Links related:
https://github.com/intel/linux-sgx/issues/837
https://patchwork.kernel.org/project/platform-driver-x86/patch/[email protected]/arch/x86/kernel/cpu/sgx/driver.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/x86/kernel/cpu/sgx/driver.c +3
-1@@ -150,8 +150,10 @@ int __init sgx_drv_init(void)u64 xfrm_mask;int ret; -if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) +if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) { +pr_err ("SGX disabled: SGX launch control is not available.\n" );return -ENODEV ; + }cpuid_count (SGX_CPUID ,0 , &eax, &ebx, &ecx, &edx);
PATCH 1/1 x86/sgx: Warn explicitly if X86_FEATURE_SGX_LC is not enabled
Quoted 23 lines · Huang, Kai
Quoted 1 line · Vladis Dronov
A kernel requires
X86_FEATURE_SGX_LCto be able to create SGX enclaves.The kernel requires ...
Quoted 4 lines
There is quite a number of hardware which has
X86_FEATURE_SGXbut notX86_FEATURE_SGX_LC. A kernel running on such a hardware does not create/dev/sgx_enclavefile silently. Explicitly warn ifX86_FEATURE_SGX_LCis not enabled to properly nofity a user about this condition.^ notifyAnd I don't think "notify" is correct because the reality is the kernel only prints some error message so that the user can check and see when it wants.
How about:
Explicitly print error message if
X86_FEATURE_SGX_LCis not present so that the users can be aware of this condition which results in SGX driver being disabled.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
The
X86_FEATURE_SGX_LCis a CPU feature that enables LE hash MSRs to be writable when running native enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.Using "root key" can be controversial. Let's just say "key" instead.
And the
X86_FEATURE_SGX_LCfeature itself doesn't automatically enable LE MSRs to be writable. We still need to opt-in in the 'feature control' MSR.
Why would it be controversial?
Quoted 11 lines
How about:
The
X86_FEATURE_SGX_LC, a.k.a. SGX Launch Control, is a CPU feature that enables LE (Launch Enclave) hash MSRs to be writable (with additional opt-in required in the 'feature control' MSR) when running enclaves, i.e., using a custom key rather than the Intel proprietary key for enclave signing.Quoted 1 line
Signed-off-by Vladis Dronov <[email protected]>
Quoted 7 lines
I think this message will be useful for someone who knows SGX in general but doesn't know that Linux SGX driver requires the LE MSRs to be writable, thus requires the CPU supports
SGX_LCfeature bit.With the above addressed, feel free to add:
Acked-by Kai Huang <[email protected]>
Thanks, I've edited the changelog to be a bit clearer.
I also added an error message when the driver fails to register, and made all 3 failure error messages consistent and refer back to the /dev/sgx_enclave device node name.
I also included part of this commit message note:
Quoted 9 lines
Quoted 9 lines
an out-of-commit-message note:
I've hit this issue myself and have spent some time researching where is my
/dev/sgx_enclavefile on an SGX-enabled hardware, so this is a bit personal.Links related:
https://github.com/intel/linux-sgx/issues/837
https://patchwork.kernel.org/project/platform-driver-x86/patch/[email protected]/
Because this experience reflects arguably poor usability: people see 'SGX' in their /proc/cpuinfo file, think that their hardware is 'SGX enabled' and are wondering why the hell the /dev/sgx_enclave device node is not created, right?
I also Cc:-ed more SGX people.
See the full -v3 patch below.
Is the device node misnamed, should it be /dev/sgx_lc_enclave? Should we hide the SGX feature bit from cpuinfo when SGX_LC is not present, so that people don't go on a wild goose chase?
Thanks,
Ingo
======================================>
From: Vladis Dronov <[email protected]>
Date: Sun, 9 Mar 2025 18:22:16 +0100
Subject: [PATCH] x86/sgx: Warn explicitly if X86_FEATURE_SGX_LC is not enabled
The kernel requires X86_FEATURE_SGX_LC to be able to create SGX enclaves, not just X86_FEATURE_SGX.
There is quite a number of hardware which has X86_FEATURE_SGX but not X86_FEATURE_SGX_LC. A kernel running on such hardware does not create the /dev/sgx_enclave file and does so silently.
Explicitly warn if X86_FEATURE_SGX_LC is not enabled to properly notify users that the kernel disabled the SGX driver.
The X86_FEATURE_SGX_LC, a.k.a. SGX Launch Control, is a CPU feature that enables LE (Launch Enclave) hash MSRs to be writable (with additional opt-in required in the 'feature control' MSR) when running enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.
I've hit this issue myself and have spent some time researching where my /dev/sgx_enclave file went on SGX-enabled hardware.
Related links:
https://github.com/intel/linux-sgx/issues/837
https://patchwork.kernel.org/project/platform-driver-x86/patch/[email protected]/
[ mingo: Made the error message a bit more verbose, and added other cases
where the kernel fails to create the /dev/sgx_enclave device node. ]
--- arch/x86/kernel/cpu/sgx/driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/sgx/driver.c +7 -3
@@ -150,13 +150,15 @@ int __init sgx_drv_init(void)u64 xfrm_mask;int ret; -if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) +if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) { +pr_err ("SGX disabled: SGX launch control CPU feature is not available, /dev/sgx_enclave disabled.\n" );return -ENODEV ; + }cpuid_count (SGX_CPUID ,0 , &eax, &ebx, &ecx, &edx);if (!(eax &1 )) { -pr_err ("SGX disabled: SGX1 instruction support not available.\n" ); +pr_err ("SGX disabled: SGX1 instruction support not available, /dev/sgx_enclave disabled.\n" );return -ENODEV ; }
@@ -173,8 +175,10 @@ int __init sgx_drv_init(void) } ret =misc_register (&sgx_dev_enclave); -if (ret) +if (ret) { +pr_err ("SGX disabled: Unable to register the /dev/sgx_enclave driver (%d).\n" , ret);return ret; + }return 0 ; }
Quoted 29 lines · Ingo Molnar
Quoted 27 lines · Huang, Kai
Quoted 1 line · Vladis Dronov
A kernel requires
X86_FEATURE_SGX_LCto be able to create SGX enclaves.The kernel requires ...
Quoted 4 lines
There is quite a number of hardware which has
X86_FEATURE_SGXbut notX86_FEATURE_SGX_LC. A kernel running on such a hardware does not create/dev/sgx_enclavefile silently. Explicitly warn ifX86_FEATURE_SGX_LCis not enabled to properly nofity a user about this condition.^ notifyAnd I don't think "notify" is correct because the reality is the kernel only prints some error message so that the user can check and see when it wants.
How about:
Explicitly print error message if
X86_FEATURE_SGX_LCis not present so that the users can be aware of this condition which results in SGX driver being disabled.Quoted 4 lines
The
X86_FEATURE_SGX_LCis a CPU feature that enables LE hash MSRs to be writable when running native enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.
Quoted 6 lines
Quoted 4 lines
Using "root key" can be controversial. Let's just say "key" instead.
And the
X86_FEATURE_SGX_LCfeature itself doesn't automatically enable LE MSRs to be writable. We still need to opt-in in the 'feature control' MSR.Why would it be controversial?
If we are talking out from key derivation's perspective, I think the "root key" refers to something that sits at the bottom of the key hierarchy and is involved in the key derivation of other keys.
If we are talking about asymmetric key signing and verification, then I think the "root key" means the private key of the last level of the certificate-chain.
Here the key used to sign the enclave fits neither of above:
It's not the root of any certificate chain. The MRSIGNER (the hash of the enclave signing key) is not involved in all SGX key derivations either (e.g., the derivation of REPORT_KEY doesn't use it, and the SEAL_KEY can choose to not use it).
Quoted 34 lines
Quoted 12 lines
How about:
The
X86_FEATURE_SGX_LC, a.k.a. SGX Launch Control, is a CPU feature that enables LE (Launch Enclave) hash MSRs to be writable (with additional opt-in required in the 'feature control' MSR) when running enclaves, i.e., using a custom key rather than the Intel proprietary key for enclave signing.Quoted 1 line
Signed-off-by Vladis Dronov <[email protected]>Quoted 7 lines
I think this message will be useful for someone who knows SGX in general but doesn't know that Linux SGX driver requires the LE MSRs to be writable, thus requires the CPU supports
SGX_LCfeature bit.With the above addressed, feel free to add:
Acked-by Kai Huang <[email protected]>Thanks, I've edited the changelog to be a bit clearer.
I also added an error message when the driver fails to register, and made all 3 failure error messages consistent and refer back to the
/dev/sgx_enclavedevice node name.I also included part of this commit message note:
Quoted 6 lines
Quoted 6 lines
an out-of-commit-message note:
I've hit this issue myself and have spent some time researching where is my
/dev/sgx_enclavefile on an SGX-enabled hardware, so this is a bit personal.
Quoted 8 lines
Quoted 3 lines
Because this experience reflects arguably poor usability: people see 'SGX' in their
/proc/cpuinfofile, think that their hardware is 'SGX enabled' and are wondering why the hell the/dev/sgx_enclavedevice node is not created, right?
Yes I believe so.
Quoted 7 lines
I also Cc:-ed more SGX people.
See the full -v3 patch below.
Is the device node misnamed, should it be
/dev/sgx_lc_enclave?
No. Form SGX hardware's perspective, LC (Launch Control) is a control mechanism to allow running 3rd party's Launch Enclave (LE), which is a special enclave used to control running other enclaves.
Linux SGX driver doesn't distinguish whether the enclave is LE or not, it just treat all enclaves the same. So the name should be /dev/sgx_enclave.
Quoted 3 lines
Should
we hide the SGX feature bit from cpuinfo whenSGX_LCis not present, so that people don't go on a wild goose chase?
No. KVM SGX virtualization can still work without the SGX_LC flag (only SGX flag is needed).
Hi, Jarkko, Kai,
Thanks a ton for your suggestions and edits!
Hi, Ingo,
Thank you many tons for your help and attention to this small patch and a TIP submission! I wasn't expecting such an... immediate response to my small suggestion, honestly.
Best regards,
Vladis
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: baf6a4fdb5ead6be10aa0a0e620d6078a669fc75 Gitweb: https://git.kernel.org/tip/baf6a4fdb5ead6be10aa0a0e620d6078a669fc75 Author: Vladis Dronov <[email protected]> AuthorDate: Sun, 09 Mar 2025 18:22:16 +01:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 10 Mar 2025 09:40:38 +01:00
x86/sgx: Warn explicitly if X86_FEATURE_SGX_LC is not enabled
The kernel requires X86_FEATURE_SGX_LC to be able to create SGX enclaves, not just X86_FEATURE_SGX.
There is quite a number of hardware which has X86_FEATURE_SGX but not X86_FEATURE_SGX_LC. A kernel running on such hardware does not create the /dev/sgx_enclave file and does so silently.
Explicitly warn if X86_FEATURE_SGX_LC is not enabled to properly notify users that the kernel disabled the SGX driver.
The X86_FEATURE_SGX_LC, a.k.a. SGX Launch Control, is a CPU feature that enables LE (Launch Enclave) hash MSRs to be writable (with additional opt-in required in the 'feature control' MSR) when running enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.
I've hit this issue myself and have spent some time researching where my /dev/sgx_enclave file went on SGX-enabled hardware.
Related links:
https://github.com/intel/linux-sgx/issues/837
https://patchwork.kernel.org/project/platform-driver-x86/patch/[email protected]/
[ mingo: Made the error message a bit more verbose, and added other cases
where the kernel fails to create the /dev/sgx_enclave device node. ]
--- arch/x86/kernel/cpu/sgx/driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/sgx/driver.c +7 -3
@@ -150,13 +150,15 @@ int __init sgx_drv_init(void)u64 xfrm_mask;int ret; -if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) +if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) { +pr_err ("SGX disabled: SGX launch control CPU feature is not available, /dev/sgx_enclave disabled.\n" );return -ENODEV ; + }cpuid_count (SGX_CPUID ,0 , &eax, &ebx, &ecx, &edx);if (!(eax &1 )) { -pr_err ("SGX disabled: SGX1 instruction support not available.\n" ); +pr_err ("SGX disabled: SGX1 instruction support not available, /dev/sgx_enclave disabled.\n" );return -ENODEV ; }
@@ -173,8 +175,10 @@ int __init sgx_drv_init(void) } ret =misc_register (&sgx_dev_enclave); -if (ret) +if (ret) { +pr_err ("SGX disabled: Unable to register the /dev/sgx_enclave driver (%d).\n" , ret);return ret; + }return 0 ; }
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 65be5c95d08eedda570a6c888a12384c77fe7614 Gitweb: https://git.kernel.org/tip/65be5c95d08eedda570a6c888a12384c77fe7614 Author: Vladis Dronov <[email protected]> AuthorDate: Sun, 09 Mar 2025 18:22:16 +01:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 10 Mar 2025 12:29:18 +01:00
x86/sgx: Warn explicitly if X86_FEATURE_SGX_LC is not enabled
The kernel requires X86_FEATURE_SGX_LC to be able to create SGX enclaves, not just X86_FEATURE_SGX.
There is quite a number of hardware which has X86_FEATURE_SGX but not X86_FEATURE_SGX_LC. A kernel running on such hardware does not create the /dev/sgx_enclave file and does so silently.
Explicitly warn if X86_FEATURE_SGX_LC is not enabled to properly notify users that the kernel disabled the SGX driver.
The X86_FEATURE_SGX_LC, a.k.a. SGX Launch Control, is a CPU feature that enables LE (Launch Enclave) hash MSRs to be writable (with additional opt-in required in the 'feature control' MSR) when running enclaves, i.e. using a custom root key rather than the Intel proprietary key for enclave signing.
I've hit this issue myself and have spent some time researching where my /dev/sgx_enclave file went on SGX-enabled hardware.
Related links:
https://github.com/intel/linux-sgx/issues/837
https://patchwork.kernel.org/project/platform-driver-x86/patch/[email protected]/
[ mingo: Made the error message a bit more verbose, and added other cases
where the kernel fails to create the /dev/sgx_enclave device node. ]
--- arch/x86/kernel/cpu/sgx/driver.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/sgx/driver.c +7 -3
@@ -150,13 +150,15 @@ int __init sgx_drv_init(void)u64 xfrm_mask;int ret; -if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) +if (!cpu_feature_enabled (X86_FEATURE_SGX_LC )) { +pr_info ("SGX disabled: SGX launch control CPU feature is not available, /dev/sgx_enclave disabled.\n" );return -ENODEV ; + }cpuid_count (SGX_CPUID ,0 , &eax, &ebx, &ecx, &edx);if (!(eax &1 )) { -pr_err ("SGX disabled: SGX1 instruction support not available.\n" ); +pr_info ("SGX disabled: SGX1 instruction support not available, /dev/sgx_enclave disabled.\n" );return -ENODEV ; }
@@ -173,8 +175,10 @@ int __init sgx_drv_init(void) } ret =misc_register (&sgx_dev_enclave); -if (ret) +if (ret) { +pr_info ("SGX disabled: Unable to register the /dev/sgx_enclave driver (%d).\n" , ret);return ret; + }return 0 ; }