[PATCH 3/8] UBUNTU: SAUCE: ubuntu/sgx: fix a synchronization issue for mmput
Tim Gardner
tim.gardner at canonical.com
Thu Aug 12 12:09:08 UTC 2021
BugLink: https://bugs.launchpad.net/bugs/1936240
https://github.com/intel/SGXDataCenterAttestationPrimitives
0977851177d96aa7859adcafef36f1b3ed5c7ab0 Linux Driver: fix a synchronization issue for mmput
Signed-off-by: Tim Gardner <tim.gardner at canonical.com>
---
ubuntu/sgx/main.c | 13 +++++++++++++
ubuntu/sgx/reclaim.c | 16 +++++++++-------
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/ubuntu/sgx/main.c b/ubuntu/sgx/main.c
index 82c7b77e91806..8d28da9e8331c 100644
--- a/ubuntu/sgx/main.c
+++ b/ubuntu/sgx/main.c
@@ -12,6 +12,7 @@
#include "encls.h"
#include <linux/module.h>
+#include <linux/version.h>
#include "version.h"
#include "dcap.h"
#ifndef MSR_IA32_FEAT_CTL
@@ -21,6 +22,9 @@
#ifndef FEAT_CTL_LOCKED
#define FEAT_CTL_LOCKED FEATURE_CONTROL_LOCKED
#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) )
+void (*k_mmput_async)(struct mm_struct* mm);
+#endif
struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];
int sgx_nr_epc_sections;
@@ -300,6 +304,15 @@ static int __init sgx_init(void)
if (!sgx_page_cache_init())
return -EFAULT;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) )
+ k_mmput_async = (void*)kallsyms_lookup_name("mmput_async");
+ if (!k_mmput_async){
+ pr_err("intel_sgx: mmput_async support missing from kernel.\n");
+ return -EFAULT;
+ }
+#endif
+
+
if (!sgx_page_reclaimer_init())
goto err_page_cache;
diff --git a/ubuntu/sgx/reclaim.c b/ubuntu/sgx/reclaim.c
index 1ba0cec6dba4b..747cfbe4ec6a3 100644
--- a/ubuntu/sgx/reclaim.c
+++ b/ubuntu/sgx/reclaim.c
@@ -14,7 +14,9 @@
#include "driver.h"
#include <linux/version.h>
-
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) )
+extern void (*k_mmput_async)(struct mm_struct* mm);
+#endif
struct task_struct *ksgxswapd_tsk;
DECLARE_WAIT_QUEUE_HEAD(ksgxswapd_waitq);
LIST_HEAD(sgx_active_page_list);
@@ -175,8 +177,8 @@ static bool sgx_reclaimer_age(struct sgx_epc_page *epc_page)
ret = !sgx_encl_test_and_clear_young(encl_mm->mm, page);
up_read(&encl_mm->mm->mmap_sem);
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) || LINUX_VERSION_CODE > KERNEL_VERSION(5, 4, 0) )
- mmput(encl_mm->mm);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
+ k_mmput_async(encl_mm->mm);
#else
mmput_async(encl_mm->mm);
#endif
@@ -226,8 +228,8 @@ static void sgx_reclaimer_block(struct sgx_epc_page *epc_page)
up_read(&encl_mm->mm->mmap_sem);
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) || LINUX_VERSION_CODE > KERNEL_VERSION(5, 4, 0) )
- mmput(encl_mm->mm);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
+ k_mmput_async(encl_mm->mm);
#else
mmput_async(encl_mm->mm);
#endif
@@ -306,8 +308,8 @@ static const cpumask_t *sgx_encl_ewb_cpumask(struct sgx_encl *encl)
cpumask_or(cpumask, cpumask, mm_cpumask(encl_mm->mm));
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) || LINUX_VERSION_CODE > KERNEL_VERSION(5, 4, 0) )
- mmput(encl_mm->mm);
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
+ k_mmput_async(encl_mm->mm);
#else
mmput_async(encl_mm->mm);
#endif
--
2.32.0
More information about the kernel-team
mailing list