change mmap_sem to mmap_lock for the differences between kernel 4.19 and 5.8
Signed-off-by: chenmaodong <chenmaodong@huawei.com>
This commit is contained in:
parent
e1ab7c1391
commit
81c0778cd7
207
0001-Fix-compilation-on-5.8-kernel-120.patch
Normal file
207
0001-Fix-compilation-on-5.8-kernel-120.patch
Normal file
@ -0,0 +1,207 @@
|
||||
From 276c5c6a064d22358542f5e0aa96b1c0ace5d695 Mon Sep 17 00:00:00 2001
|
||||
From: Don Porter <porter@cs.unc.edu>
|
||||
Date: Wed, 2 Sep 2020 14:26:40 -0400
|
||||
Subject: [PATCH 1/1] Fix compilation on 5.8 kernel (#120)
|
||||
|
||||
* Fix compilation on 5.8 kernel
|
||||
|
||||
Signed-off-by: Don Porter <porter@cs.unc.edu>
|
||||
|
||||
* Address review comments
|
||||
|
||||
* Address review comments
|
||||
|
||||
Signed-off-by: chenmaodong <chenmaodong@huawei.com>
|
||||
---
|
||||
sgx_encl.c | 30 ++++++++++++++++++++++++++----
|
||||
sgx_encl2.c | 19 ++++++++++++++++++-
|
||||
sgx_ioctl.c | 9 +++++++++
|
||||
sgx_page_cache.c | 9 +++++++++
|
||||
4 files changed, 62 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/sgx_encl.c b/sgx_encl.c
|
||||
index 44439c8..04a1b9c 100644
|
||||
--- a/sgx_encl.c
|
||||
+++ b/sgx_encl.c
|
||||
@@ -316,7 +316,11 @@ static void sgx_add_page_worker(struct work_struct *work)
|
||||
goto next;
|
||||
}
|
||||
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_lock(encl->mm);
|
||||
+#else
|
||||
down_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
mutex_lock(&encl->lock);
|
||||
|
||||
if (!sgx_process_add_page_req(req, epc_page)) {
|
||||
@@ -325,7 +329,11 @@ static void sgx_add_page_worker(struct work_struct *work)
|
||||
}
|
||||
|
||||
mutex_unlock(&encl->lock);
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(encl->mm);
|
||||
+#else
|
||||
up_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
|
||||
next:
|
||||
kfree(req);
|
||||
@@ -639,31 +647,45 @@ int sgx_encl_create(struct sgx_secs *secs)
|
||||
goto out;
|
||||
}
|
||||
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_lock(current->mm);
|
||||
+#else
|
||||
down_read(¤t->mm->mmap_sem);
|
||||
+#endif
|
||||
ret = sgx_encl_find(current->mm, secs->base, &vma);
|
||||
if (ret != -ENOENT) {
|
||||
if (!ret)
|
||||
ret = -EINVAL;
|
||||
- up_read(¤t->mm->mmap_sem);
|
||||
- goto out;
|
||||
+ goto out_locked;
|
||||
}
|
||||
|
||||
if (vma->vm_start != secs->base ||
|
||||
vma->vm_end != (secs->base + secs->size)
|
||||
/* vma->vm_pgoff != 0 */) {
|
||||
ret = -EINVAL;
|
||||
- up_read(¤t->mm->mmap_sem);
|
||||
- goto out;
|
||||
+ goto out_locked;
|
||||
}
|
||||
|
||||
vma->vm_private_data = encl;
|
||||
+
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(current->mm);
|
||||
+#else
|
||||
up_read(¤t->mm->mmap_sem);
|
||||
+#endif
|
||||
|
||||
mutex_lock(&sgx_tgid_ctx_mutex);
|
||||
list_add_tail(&encl->encl_list, &encl->tgid_ctx->encl_list);
|
||||
mutex_unlock(&sgx_tgid_ctx_mutex);
|
||||
|
||||
return 0;
|
||||
+out_locked:
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(current->mm);
|
||||
+#else
|
||||
+ up_read(¤t->mm->mmap_sem);
|
||||
+#endif
|
||||
+
|
||||
out:
|
||||
if (encl)
|
||||
kref_put(&encl->refcount, sgx_encl_release);
|
||||
diff --git a/sgx_encl2.c b/sgx_encl2.c
|
||||
index 2f5064f..0122efd 100644
|
||||
--- a/sgx_encl2.c
|
||||
+++ b/sgx_encl2.c
|
||||
@@ -234,12 +234,22 @@ static int isolate_range(struct sgx_encl *encl,
|
||||
|
||||
address = rg->start_addr;
|
||||
end = address + rg->nr_pages * PAGE_SIZE;
|
||||
+
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_lock(encl->mm);
|
||||
+#else
|
||||
down_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
+
|
||||
|
||||
for (; address < end; address += PAGE_SIZE) {
|
||||
ret = sgx_encl_find(encl->mm, address, &vma);
|
||||
if (ret || encl != vma->vm_private_data) {
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(encl->mm);
|
||||
+#else
|
||||
up_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -250,7 +260,11 @@ static int isolate_range(struct sgx_encl *encl,
|
||||
SGX_FAULT_RESERVE, NULL);
|
||||
|
||||
if (IS_ERR(encl_page)) {
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(encl->mm);
|
||||
+#else
|
||||
up_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
sgx_err(encl, "sgx: No page found at address 0x%lx\n",
|
||||
address);
|
||||
return PTR_ERR(encl_page);
|
||||
@@ -264,8 +278,11 @@ static int isolate_range(struct sgx_encl *encl,
|
||||
encl_page->flags &= ~SGX_ENCL_PAGE_RESERVED;
|
||||
mutex_unlock(&encl->lock);
|
||||
}
|
||||
-
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(encl->mm);
|
||||
+#else
|
||||
up_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff --git a/sgx_ioctl.c b/sgx_ioctl.c
|
||||
index 0b3476d..56ab1e6 100644
|
||||
--- a/sgx_ioctl.c
|
||||
+++ b/sgx_ioctl.c
|
||||
@@ -82,7 +82,11 @@ int sgx_get_encl(unsigned long addr, struct sgx_encl **encl)
|
||||
if (addr & (PAGE_SIZE - 1))
|
||||
return -EINVAL;
|
||||
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_lock(mm);
|
||||
+#else
|
||||
down_read(&mm->mmap_sem);
|
||||
+#endif
|
||||
|
||||
ret = sgx_encl_find(mm, addr, &vma);
|
||||
if (!ret) {
|
||||
@@ -94,7 +98,12 @@ int sgx_get_encl(unsigned long addr, struct sgx_encl **encl)
|
||||
kref_get(&(*encl)->refcount);
|
||||
}
|
||||
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(mm);
|
||||
+#else
|
||||
up_read(&mm->mmap_sem);
|
||||
+#endif
|
||||
+
|
||||
return ret;
|
||||
}
|
||||
|
||||
diff --git a/sgx_page_cache.c b/sgx_page_cache.c
|
||||
index 3770ad4..77bea6e 100644
|
||||
--- a/sgx_page_cache.c
|
||||
+++ b/sgx_page_cache.c
|
||||
@@ -376,10 +376,19 @@ static void sgx_swap_pages(unsigned long nr_to_scan)
|
||||
if (!encl)
|
||||
goto out;
|
||||
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_lock(encl->mm);
|
||||
+#else
|
||||
down_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
+
|
||||
sgx_isolate_pages(encl, &cluster, nr_to_scan);
|
||||
sgx_write_pages(encl, &cluster);
|
||||
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
|
||||
+ mmap_read_unlock(encl->mm);
|
||||
+#else
|
||||
up_read(&encl->mm->mmap_sem);
|
||||
+#endif
|
||||
|
||||
kref_put(&encl->refcount, sgx_encl_release);
|
||||
out:
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: linux-sgx-driver
|
||||
Version: 2.11
|
||||
Release: 2
|
||||
Release: 3
|
||||
Summary: Intel SGX Linux* Driver
|
||||
ExclusiveArch: x86_64
|
||||
License: BSD-3-Clause and GPL-2.0 License
|
||||
@ -8,6 +8,7 @@ URL: https://github.com/intel/linux-sgx-driver
|
||||
Source0: https://github.com/intel/linux-sgx-driver/archive/sgx_driver_%{version}.tar.gz
|
||||
|
||||
BuildRequires: gcc kernel-devel make module-init-tools glibc
|
||||
Patch0: 0001-Fix-compilation-on-5.8-kernel-120.patch
|
||||
|
||||
Requires: kernel
|
||||
|
||||
@ -26,7 +27,7 @@ software stack, which will be used until the driver upstreaming process is compl
|
||||
|
||||
|
||||
%prep
|
||||
%autosetup -n %{name}-sgx_driver_2.11
|
||||
%autosetup -n %{name}-sgx_driver_2.11 -p1
|
||||
|
||||
%build
|
||||
make
|
||||
@ -57,6 +58,9 @@ sed -i '/^isgx$/d' /etc/modules
|
||||
|
||||
|
||||
%changelog
|
||||
* Mon Dec 28 2020 chenmaodong <chenmaodong@huawei.com> - 2.11.3
|
||||
- Fix compilation on 5.8 kernel
|
||||
|
||||
* Wed Oct 21 2020 chenmaodong <chenmaodong@huawei.com> - 2.11.2
|
||||
- specify x86_64 as the building architecure
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user