Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5.8 kernel compilation #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions sgx_encl.c
Original file line number Diff line number Diff line change
@@ -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);
up_read(&encl->mm->mmap_sem);
#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(&current->mm->mmap_sem);
#endif
ret = sgx_encl_find(current->mm, secs->base, &vma);
if (ret != -ENOENT) {
if (!ret)
ret = -EINVAL;
up_read(&current->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(&current->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(&current->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(&current->mm->mmap_sem);
#endif

out:
if (encl)
kref_put(&encl->refcount, sgx_encl_release);
19 changes: 18 additions & 1 deletion sgx_encl2.c
Original file line number Diff line number Diff line change
@@ -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;
}

9 changes: 9 additions & 0 deletions sgx_ioctl.c
Original file line number Diff line number Diff line change
@@ -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;
}

11 changes: 10 additions & 1 deletion sgx_page_cache.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is provided under a dual BSD/GPLv2 license. When using or
* redistributing this file, you may do so under either license.
*
@@ -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: