Skip to content

Commit ee56a28

Browse files
kaccardisuryasaimadhu
authored andcommitted
x86/sgx: Improve comments for sgx_encl_lookup/alloc_backing()
Modify the comments for sgx_encl_lookup_backing() and for sgx_encl_alloc_backing() to indicate that they take a reference which must be dropped with a call to sgx_encl_put_backing(). Make sgx_encl_lookup_backing() static for now, and change the name of sgx_encl_get_backing() to __sgx_encl_get_backing() to make it more clear that sgx_encl_get_backing() is an internal function. Signed-off-by: Kristen Carlson Accardi <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/all/[email protected]/
1 parent 568035b commit ee56a28

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "encls.h"
1313
#include "sgx.h"
1414

15+
static int sgx_encl_lookup_backing(struct sgx_encl *encl, unsigned long page_index,
16+
struct sgx_backing *backing);
17+
1518
#define PCMDS_PER_PAGE (PAGE_SIZE / sizeof(struct sgx_pcmd))
1619
/*
1720
* 32 PCMD entries share a PCMD page. PCMD_FIRST_MASK is used to
@@ -914,7 +917,7 @@ static struct page *sgx_encl_get_backing_page(struct sgx_encl *encl,
914917
}
915918

916919
/**
917-
* sgx_encl_get_backing() - Pin the backing storage
920+
* __sgx_encl_get_backing() - Pin the backing storage
918921
* @encl: an enclave pointer
919922
* @page_index: enclave page index
920923
* @backing: data for accessing backing storage for the page
@@ -926,7 +929,7 @@ static struct page *sgx_encl_get_backing_page(struct sgx_encl *encl,
926929
* 0 on success,
927930
* -errno otherwise.
928931
*/
929-
static int sgx_encl_get_backing(struct sgx_encl *encl, unsigned long page_index,
932+
static int __sgx_encl_get_backing(struct sgx_encl *encl, unsigned long page_index,
930933
struct sgx_backing *backing)
931934
{
932935
pgoff_t page_pcmd_off = sgx_encl_get_backing_page_pcmd_offset(encl, page_index);
@@ -1001,15 +1004,17 @@ static struct mem_cgroup *sgx_encl_get_mem_cgroup(struct sgx_encl *encl)
10011004
}
10021005

10031006
/**
1004-
* sgx_encl_alloc_backing() - allocate a new backing storage page
1007+
* sgx_encl_alloc_backing() - create a new backing storage page
10051008
* @encl: an enclave pointer
10061009
* @page_index: enclave page index
10071010
* @backing: data for accessing backing storage for the page
10081011
*
10091012
* When called from ksgxd, sets the active memcg from one of the
10101013
* mms in the enclave's mm_list prior to any backing page allocation,
10111014
* in order to ensure that shmem page allocations are charged to the
1012-
* enclave.
1015+
* enclave. Create a backing page for loading data back into an EPC page with
1016+
* ELDU. This function takes a reference on a new backing page which
1017+
* must be dropped with a corresponding call to sgx_encl_put_backing().
10131018
*
10141019
* Return:
10151020
* 0 on success,
@@ -1022,7 +1027,7 @@ int sgx_encl_alloc_backing(struct sgx_encl *encl, unsigned long page_index,
10221027
struct mem_cgroup *memcg = set_active_memcg(encl_memcg);
10231028
int ret;
10241029

1025-
ret = sgx_encl_get_backing(encl, page_index, backing);
1030+
ret = __sgx_encl_get_backing(encl, page_index, backing);
10261031

10271032
set_active_memcg(memcg);
10281033
mem_cgroup_put(encl_memcg);
@@ -1040,15 +1045,17 @@ int sgx_encl_alloc_backing(struct sgx_encl *encl, unsigned long page_index,
10401045
* It is the caller's responsibility to ensure that it is appropriate to use
10411046
* sgx_encl_lookup_backing() rather than sgx_encl_alloc_backing(). If lookup is
10421047
* not used correctly, this will cause an allocation which is not accounted for.
1048+
* This function takes a reference on an existing backing page which must be
1049+
* dropped with a corresponding call to sgx_encl_put_backing().
10431050
*
10441051
* Return:
10451052
* 0 on success,
10461053
* -errno otherwise.
10471054
*/
1048-
int sgx_encl_lookup_backing(struct sgx_encl *encl, unsigned long page_index,
1055+
static int sgx_encl_lookup_backing(struct sgx_encl *encl, unsigned long page_index,
10491056
struct sgx_backing *backing)
10501057
{
1051-
return sgx_encl_get_backing(encl, page_index, backing);
1058+
return __sgx_encl_get_backing(encl, page_index, backing);
10521059
}
10531060

10541061
/**

arch/x86/kernel/cpu/sgx/encl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ bool current_is_ksgxd(void);
107107
void sgx_encl_release(struct kref *ref);
108108
int sgx_encl_mm_add(struct sgx_encl *encl, struct mm_struct *mm);
109109
const cpumask_t *sgx_encl_cpumask(struct sgx_encl *encl);
110-
int sgx_encl_lookup_backing(struct sgx_encl *encl, unsigned long page_index,
111-
struct sgx_backing *backing);
112110
int sgx_encl_alloc_backing(struct sgx_encl *encl, unsigned long page_index,
113111
struct sgx_backing *backing);
114112
void sgx_encl_put_backing(struct sgx_backing *backing);

0 commit comments

Comments
 (0)