Lines Matching full:encl

17 #include "encl.h"
20 struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl, bool reclaim) in sgx_encl_grow() argument
28 if (!(encl->page_cnt % SGX_VA_SLOT_COUNT)) { in sgx_encl_grow()
40 WARN_ON_ONCE(encl->page_cnt % SGX_VA_SLOT_COUNT); in sgx_encl_grow()
42 encl->page_cnt++; in sgx_encl_grow()
46 void sgx_encl_shrink(struct sgx_encl *encl, struct sgx_va_page *va_page) in sgx_encl_shrink() argument
48 encl->page_cnt--; in sgx_encl_shrink()
57 static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs) in sgx_encl_create() argument
67 va_page = sgx_encl_grow(encl, true); in sgx_encl_create()
71 list_add(&va_page->list, &encl->va_pages); in sgx_encl_create()
84 encl->backing = backing; in sgx_encl_create()
86 secs_epc = sgx_alloc_epc_page(&encl->secs, true); in sgx_encl_create()
92 encl->secs.epc_page = secs_epc; in sgx_encl_create()
107 set_bit(SGX_ENCL_DEBUG, &encl->flags); in sgx_encl_create()
109 encl->secs.encl = encl; in sgx_encl_create()
110 encl->secs.type = SGX_PAGE_TYPE_SECS; in sgx_encl_create()
111 encl->base = secs->base; in sgx_encl_create()
112 encl->size = secs->size; in sgx_encl_create()
113 encl->attributes = secs->attributes; in sgx_encl_create()
114 encl->attributes_mask = SGX_ATTR_UNPRIV_MASK; in sgx_encl_create()
116 /* Set only after completion, as encl->lock has not been taken. */ in sgx_encl_create()
117 set_bit(SGX_ENCL_CREATED, &encl->flags); in sgx_encl_create()
122 sgx_encl_free_epc_page(encl->secs.epc_page); in sgx_encl_create()
123 encl->secs.epc_page = NULL; in sgx_encl_create()
126 fput(encl->backing); in sgx_encl_create()
127 encl->backing = NULL; in sgx_encl_create()
130 sgx_encl_shrink(encl, va_page); in sgx_encl_create()
137 * @encl: An enclave pointer.
147 static long sgx_ioc_enclave_create(struct sgx_encl *encl, void __user *arg) in sgx_ioc_enclave_create() argument
153 if (test_bit(SGX_ENCL_CREATED, &encl->flags)) in sgx_ioc_enclave_create()
166 ret = sgx_encl_create(encl, secs); in sgx_ioc_enclave_create()
199 static int __sgx_encl_add_page(struct sgx_encl *encl, in __sgx_encl_add_page() argument
221 pginfo.secs = (unsigned long)sgx_get_epc_virt_addr(encl->secs.epc_page); in __sgx_encl_add_page()
239 static int __sgx_encl_extend(struct sgx_encl *encl, in __sgx_encl_extend() argument
246 ret = __eextend(sgx_get_epc_virt_addr(encl->secs.epc_page), in __sgx_encl_extend()
259 static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long src, in sgx_encl_add_page() argument
268 encl_page = sgx_encl_page_alloc(encl, offset, secinfo->flags); in sgx_encl_add_page()
278 va_page = sgx_encl_grow(encl, true); in sgx_encl_add_page()
285 mutex_lock(&encl->lock); in sgx_encl_add_page()
288 * Adding to encl->va_pages must be done under encl->lock. Ditto for in sgx_encl_add_page()
292 list_add(&va_page->list, &encl->va_pages); in sgx_encl_add_page()
299 ret = xa_insert(&encl->page_array, PFN_DOWN(encl_page->desc), in sgx_encl_add_page()
304 ret = __sgx_encl_add_page(encl, encl_page, epc_page, secinfo, in sgx_encl_add_page()
314 encl_page->encl = encl; in sgx_encl_add_page()
317 encl->secs_child_cnt++; in sgx_encl_add_page()
320 ret = __sgx_encl_extend(encl, epc_page); in sgx_encl_add_page()
326 mutex_unlock(&encl->lock); in sgx_encl_add_page()
331 xa_erase(&encl->page_array, PFN_DOWN(encl_page->desc)); in sgx_encl_add_page()
334 sgx_encl_shrink(encl, va_page); in sgx_encl_add_page()
335 mutex_unlock(&encl->lock); in sgx_encl_add_page()
349 static int sgx_validate_offset_length(struct sgx_encl *encl, in sgx_validate_offset_length() argument
362 if (offset + length - PAGE_SIZE >= encl->size) in sgx_validate_offset_length()
370 * @encl: an enclave pointer
407 static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg) in sgx_ioc_enclave_add_pages() argument
414 if (!test_bit(SGX_ENCL_CREATED, &encl->flags) || in sgx_ioc_enclave_add_pages()
415 test_bit(SGX_ENCL_INITIALIZED, &encl->flags)) in sgx_ioc_enclave_add_pages()
424 if (sgx_validate_offset_length(encl, add_arg.offset, add_arg.length)) in sgx_ioc_enclave_add_pages()
445 ret = sgx_encl_add_page(encl, add_arg.src + c, add_arg.offset + c, in sgx_ioc_enclave_add_pages()
484 static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct, in sgx_encl_init() argument
496 if (encl->attributes & ~encl->attributes_mask) in sgx_encl_init()
523 mutex_lock(&encl->lock); in sgx_encl_init()
533 addr = sgx_get_epc_virt_addr(encl->secs.epc_page); in sgx_encl_init()
569 set_bit(SGX_ENCL_INITIALIZED, &encl->flags); in sgx_encl_init()
573 mutex_unlock(&encl->lock); in sgx_encl_init()
579 * @encl: an enclave pointer
592 static long sgx_ioc_enclave_init(struct sgx_encl *encl, void __user *arg) in sgx_ioc_enclave_init() argument
599 if (!test_bit(SGX_ENCL_CREATED, &encl->flags) || in sgx_ioc_enclave_init()
600 test_bit(SGX_ENCL_INITIALIZED, &encl->flags)) in sgx_ioc_enclave_init()
637 ret = sgx_encl_init(encl, sigstruct, token); in sgx_ioc_enclave_init()
646 * @encl: an enclave pointer
656 static long sgx_ioc_enclave_provision(struct sgx_encl *encl, void __user *arg) in sgx_ioc_enclave_provision() argument
663 return sgx_set_attribute(&encl->attributes_mask, params.fd); in sgx_ioc_enclave_provision()
671 static int sgx_ioc_sgx2_ready(struct sgx_encl *encl) in sgx_ioc_sgx2_ready() argument
676 if (!test_bit(SGX_ENCL_INITIALIZED, &encl->flags)) in sgx_ioc_sgx2_ready()
693 static int sgx_enclave_etrack(struct sgx_encl *encl) in sgx_enclave_etrack() argument
698 epc_virt = sgx_get_epc_virt_addr(encl->secs.epc_page); in sgx_enclave_etrack()
711 on_each_cpu_mask(sgx_encl_cpumask(encl), sgx_ipi_cb, NULL, 1); in sgx_enclave_etrack()
719 on_each_cpu_mask(sgx_encl_cpumask(encl), sgx_ipi_cb, NULL, 1); in sgx_enclave_etrack()
726 * @encl: Enclave to which the pages belong.
735 sgx_enclave_restrict_permissions(struct sgx_encl *encl, in sgx_enclave_restrict_permissions() argument
749 addr = encl->base + modp->offset + c; in sgx_enclave_restrict_permissions()
753 mutex_lock(&encl->lock); in sgx_enclave_restrict_permissions()
755 entry = sgx_encl_load_page(encl, addr); in sgx_enclave_restrict_permissions()
802 ret = sgx_enclave_etrack(encl); in sgx_enclave_restrict_permissions()
808 mutex_unlock(&encl->lock); in sgx_enclave_restrict_permissions()
815 mutex_unlock(&encl->lock); in sgx_enclave_restrict_permissions()
825 * @encl: an enclave pointer
842 static long sgx_ioc_enclave_restrict_permissions(struct sgx_encl *encl, in sgx_ioc_enclave_restrict_permissions() argument
848 ret = sgx_ioc_sgx2_ready(encl); in sgx_ioc_enclave_restrict_permissions()
855 if (sgx_validate_offset_length(encl, params.offset, params.length)) in sgx_ioc_enclave_restrict_permissions()
872 ret = sgx_enclave_restrict_permissions(encl, &params); in sgx_ioc_enclave_restrict_permissions()
882 * @encl: Enclave to which the pages belong.
890 static long sgx_enclave_modify_types(struct sgx_encl *encl, in sgx_enclave_modify_types() argument
916 addr = encl->base + modt->offset + c; in sgx_enclave_modify_types()
920 mutex_lock(&encl->lock); in sgx_enclave_modify_types()
922 entry = sgx_encl_load_page(encl, addr); in sgx_enclave_modify_types()
970 * Do not keep encl->lock because of dependency on in sgx_enclave_modify_types()
973 mutex_unlock(&encl->lock); in sgx_enclave_modify_types()
975 sgx_zap_enclave_ptes(encl, addr); in sgx_enclave_modify_types()
977 mutex_lock(&encl->lock); in sgx_enclave_modify_types()
1004 ret = sgx_enclave_etrack(encl); in sgx_enclave_modify_types()
1012 mutex_unlock(&encl->lock); in sgx_enclave_modify_types()
1021 mutex_unlock(&encl->lock); in sgx_enclave_modify_types()
1030 * @encl: an enclave pointer
1051 static long sgx_ioc_enclave_modify_types(struct sgx_encl *encl, in sgx_ioc_enclave_modify_types() argument
1057 ret = sgx_ioc_sgx2_ready(encl); in sgx_ioc_enclave_modify_types()
1064 if (sgx_validate_offset_length(encl, params.offset, params.length)) in sgx_ioc_enclave_modify_types()
1073 ret = sgx_enclave_modify_types(encl, &params); in sgx_ioc_enclave_modify_types()
1083 * @encl: Enclave to which the pages belong
1090 static long sgx_encl_remove_pages(struct sgx_encl *encl, in sgx_encl_remove_pages() argument
1104 addr = encl->base + params->offset + c; in sgx_encl_remove_pages()
1108 mutex_lock(&encl->lock); in sgx_encl_remove_pages()
1110 entry = sgx_encl_load_page(encl, addr); in sgx_encl_remove_pages()
1142 * Do not keep encl->lock because of dependency on in sgx_encl_remove_pages()
1145 mutex_unlock(&encl->lock); in sgx_encl_remove_pages()
1147 sgx_zap_enclave_ptes(encl, addr); in sgx_encl_remove_pages()
1149 mutex_lock(&encl->lock); in sgx_encl_remove_pages()
1152 encl->secs_child_cnt--; in sgx_encl_remove_pages()
1154 xa_erase(&encl->page_array, PFN_DOWN(entry->desc)); in sgx_encl_remove_pages()
1155 sgx_encl_shrink(encl, NULL); in sgx_encl_remove_pages()
1158 mutex_unlock(&encl->lock); in sgx_encl_remove_pages()
1165 mutex_unlock(&encl->lock); in sgx_encl_remove_pages()
1174 * @encl: an enclave pointer
1198 static long sgx_ioc_enclave_remove_pages(struct sgx_encl *encl, in sgx_ioc_enclave_remove_pages() argument
1204 ret = sgx_ioc_sgx2_ready(encl); in sgx_ioc_enclave_remove_pages()
1211 if (sgx_validate_offset_length(encl, params.offset, params.length)) in sgx_ioc_enclave_remove_pages()
1217 ret = sgx_encl_remove_pages(encl, &params); in sgx_ioc_enclave_remove_pages()
1227 struct sgx_encl *encl = filep->private_data; in sgx_ioctl() local
1230 if (test_and_set_bit(SGX_ENCL_IOCTL, &encl->flags)) in sgx_ioctl()
1235 ret = sgx_ioc_enclave_create(encl, (void __user *)arg); in sgx_ioctl()
1238 ret = sgx_ioc_enclave_add_pages(encl, (void __user *)arg); in sgx_ioctl()
1241 ret = sgx_ioc_enclave_init(encl, (void __user *)arg); in sgx_ioctl()
1244 ret = sgx_ioc_enclave_provision(encl, (void __user *)arg); in sgx_ioctl()
1247 ret = sgx_ioc_enclave_restrict_permissions(encl, in sgx_ioctl()
1251 ret = sgx_ioc_enclave_modify_types(encl, (void __user *)arg); in sgx_ioctl()
1254 ret = sgx_ioc_enclave_remove_pages(encl, (void __user *)arg); in sgx_ioctl()
1261 clear_bit(SGX_ENCL_IOCTL, &encl->flags); in sgx_ioctl()