main.c (e7e0545299d8cb0fd6fe3ba50401b7f5c3937362) | main.c (d2285493bef310b66b56dfe4eb75c1e2f431ea5c) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright(c) 2016-20 Intel Corporation. */ 3 4#include <linux/freezer.h> 5#include <linux/highmem.h> 6#include <linux/kthread.h> 7#include <linux/pagemap.h> 8#include <linux/ratelimit.h> --- 71 unchanged lines hidden (view full) --- 80 if (IS_ERR(tsk)) 81 return false; 82 83 ksgxd_tsk = tsk; 84 85 return true; 86} 87 | 1// SPDX-License-Identifier: GPL-2.0 2/* Copyright(c) 2016-20 Intel Corporation. */ 3 4#include <linux/freezer.h> 5#include <linux/highmem.h> 6#include <linux/kthread.h> 7#include <linux/pagemap.h> 8#include <linux/ratelimit.h> --- 71 unchanged lines hidden (view full) --- 80 if (IS_ERR(tsk)) 81 return false; 82 83 ksgxd_tsk = tsk; 84 85 return true; 86} 87 |
88static struct sgx_epc_page *__sgx_alloc_epc_page_from_section(struct sgx_epc_section *section) 89{ 90 struct sgx_epc_page *page; 91 92 spin_lock(§ion->lock); 93 94 if (list_empty(§ion->page_list)) { 95 spin_unlock(§ion->lock); 96 return NULL; 97 } 98 99 page = list_first_entry(§ion->page_list, struct sgx_epc_page, list); 100 list_del_init(&page->list); 101 102 spin_unlock(§ion->lock); 103 return page; 104} 105 106/** 107 * __sgx_alloc_epc_page() - Allocate an EPC page 108 * 109 * Iterate through EPC sections and borrow a free EPC page to the caller. When a 110 * page is no longer needed it must be released with sgx_free_epc_page(). 111 * 112 * Return: 113 * an EPC page, 114 * -errno on error 115 */ 116struct sgx_epc_page *__sgx_alloc_epc_page(void) 117{ 118 struct sgx_epc_section *section; 119 struct sgx_epc_page *page; 120 int i; 121 122 for (i = 0; i < sgx_nr_epc_sections; i++) { 123 section = &sgx_epc_sections[i]; 124 125 page = __sgx_alloc_epc_page_from_section(section); 126 if (page) 127 return page; 128 } 129 130 return ERR_PTR(-ENOMEM); 131} 132 133/** 134 * sgx_free_epc_page() - Free an EPC page 135 * @page: an EPC page 136 * 137 * Call EREMOVE for an EPC page and insert it back to the list of free pages. 138 */ 139void sgx_free_epc_page(struct sgx_epc_page *page) 140{ 141 struct sgx_epc_section *section = &sgx_epc_sections[page->section]; 142 int ret; 143 144 ret = __eremove(sgx_get_epc_virt_addr(page)); 145 if (WARN_ONCE(ret, "EREMOVE returned %d (0x%x)", ret, ret)) 146 return; 147 148 spin_lock(§ion->lock); 149 list_add_tail(&page->list, §ion->page_list); 150 spin_unlock(§ion->lock); 151} 152 |
|
88static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, 89 unsigned long index, 90 struct sgx_epc_section *section) 91{ 92 unsigned long nr_pages = size >> PAGE_SHIFT; 93 unsigned long i; 94 95 section->virt_addr = memremap(phys_addr, size, MEMREMAP_WB); --- 95 unchanged lines hidden --- | 153static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, 154 unsigned long index, 155 struct sgx_epc_section *section) 156{ 157 unsigned long nr_pages = size >> PAGE_SHIFT; 158 unsigned long i; 159 160 section->virt_addr = memremap(phys_addr, size, MEMREMAP_WB); --- 95 unchanged lines hidden --- |