Skip to content

Commit 65be5c9

Browse files
nefigtutIngo Molnar
authored andcommitted
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: intel/linux-sgx#837 https://patchwork.kernel.org/project/platform-driver-x86/patch/20180827185507.17087-3-jarkko.sakkinen@linux.intel.com/ [ 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. ] Signed-off-by: Vladis Dronov <vdronov@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Kai Huang <kai.huang@intel.com> Cc: Jarkko Sakkinen <jarkko@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Sean Christopherson <sean.j.christopherson@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20250309172215.21777-2-vdronov@redhat.com
1 parent 80e54e8 commit 65be5c9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

arch/x86/kernel/cpu/sgx/driver.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ int __init sgx_drv_init(void)
150150
u64 xfrm_mask;
151151
int ret;
152152

153-
if (!cpu_feature_enabled(X86_FEATURE_SGX_LC))
153+
if (!cpu_feature_enabled(X86_FEATURE_SGX_LC)) {
154+
pr_info("SGX disabled: SGX launch control CPU feature is not available, /dev/sgx_enclave disabled.\n");
154155
return -ENODEV;
156+
}
155157

156158
cpuid_count(SGX_CPUID, 0, &eax, &ebx, &ecx, &edx);
157159

158160
if (!(eax & 1)) {
159-
pr_err("SGX disabled: SGX1 instruction support not available.\n");
161+
pr_info("SGX disabled: SGX1 instruction support not available, /dev/sgx_enclave disabled.\n");
160162
return -ENODEV;
161163
}
162164

@@ -173,8 +175,10 @@ int __init sgx_drv_init(void)
173175
}
174176

175177
ret = misc_register(&sgx_dev_enclave);
176-
if (ret)
178+
if (ret) {
179+
pr_info("SGX disabled: Unable to register the /dev/sgx_enclave driver (%d).\n", ret);
177180
return ret;
181+
}
178182

179183
return 0;
180184
}

0 commit comments

Comments
 (0)