@@ -160,6 +160,10 @@ int __init sgx_drv_init(void)
return -ENODEV;
}
+ ret = misc_register(&sgx_dev_enclave);
+ if (ret)
+ return ret;
+
sgx_misc_reserved_mask = ~ebx | SGX_MISC_RESERVED_MASK;
cpuid_count(SGX_CPUID, 1, &eax, &ebx, &ecx, &edx);
@@ -172,9 +176,10 @@ int __init sgx_drv_init(void)
sgx_xfrm_reserved_mask = ~xfrm_mask;
}
- ret = misc_register(&sgx_dev_enclave);
- if (ret)
- return ret;
-
return 0;
}
+
+bool sgx_drv_inited(void)
+{
+ return !!sgx_attributes_reserved_mask;
+}
@@ -25,5 +25,6 @@ extern const struct file_operations sgx_provision_fops;
long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
int sgx_drv_init(void);
+bool sgx_drv_inited(void);
#endif /* __ARCH_X86_SGX_DRIVER_H__ */
@@ -403,6 +403,14 @@ static int ksgxd(void *p)
__sgx_sanitize_pages(&sgx_dirty_page_list);
WARN_ON(__sgx_sanitize_pages(&sgx_dirty_page_list));
+ /*
+ * EPC pages assigned to KVM guests cannot be reclaimed. There's
+ * no reason to run the reclaimer if the native SGX driver isn't
+ * initialized successfully (i.e. on the machines w/o SGX_LC).
+ */
+ if (!sgx_drv_inited())
+ return 0;
+
while (!kthread_should_stop()) {
if (try_to_freeze())
continue;
@@ -940,7 +948,8 @@ static int __init sgx_init(void)
ksgxd_tsk = NULL;
__sgx_sanitize_pages(&sgx_dirty_page_list);
WARN_ON(__sgx_sanitize_pages(&sgx_dirty_page_list));
- pr_info("Running SGX w/o EPC page reclaimer.\n");
+ if (sgx_drv_inited())
+ pr_info("Running native SGX driver w/o EPC page reclaimer.\n");
}
return 0;
Currently the EPC pages assigned to KVM guests cannot be reclaimed, so there's no point to run the reclaimer when the native SGX driver is not enabled. Add a function to indicate whether the native SGX driver has been initialized, and in ksgxd(), avoid running the reclaimer when it is false. In sgx_drv_init(), move the register of "/dev/sgx_enclave" misc device before initializing sgx_attributes_reserved_mask (and the other two masks) so that the new function can just use it to determine whether the SGX driver has been initialized w/o introducing a new boolean. Signed-off-by: Kai Huang <kai.huang@intel.com> --- arch/x86/kernel/cpu/sgx/driver.c | 13 +++++++++---- arch/x86/kernel/cpu/sgx/driver.h | 1 + arch/x86/kernel/cpu/sgx/main.c | 11 ++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-)