diff --git a/penglai-enclave-driver/penglai-enclave-driver.c b/penglai-enclave-driver/penglai-enclave-driver.c index 30c0c3cd2..07e2b012b 100644 --- a/penglai-enclave-driver/penglai-enclave-driver.c +++ b/penglai-enclave-driver/penglai-enclave-driver.c @@ -11,6 +11,13 @@ MODULE_DESCRIPTION("enclave_ioctl"); MODULE_AUTHOR("LuXu"); MODULE_VERSION("enclave_ioctl"); +// #define PENGLAI_DEBUG +#ifdef PENGLAI_DEBUG +#define dprint(...) printk(__VA_ARGS__) +#else +#define dprint(...) +#endif + static int enclave_mmap(struct file* f,struct vm_area_struct *vma) { return 0; @@ -78,38 +85,38 @@ int enclave_ioctl_init(void) void enclave_ioctl_exit(void) { unsigned long addr, order, count; - unsigned long *size = kmalloc(sizeof(unsigned long), GFP_KERNEL); - ; + unsigned long *size_ptr = kmalloc(sizeof(unsigned long), GFP_KERNEL); + struct sbiret sbiret; printk("enclave_ioctl_exit...\n"); - sbiret = SBI_CALL_2(SBI_SM_FREE_ENCLAVE_MEM, __pa(size), FREE_MAX_MEMORY); + sbiret = SBI_CALL_2(SBI_SM_FREE_ENCLAVE_MEM, __pa(size_ptr), FREE_MAX_MEMORY); addr = (unsigned long)(sbiret.value); while (addr) { - order = ilog2((*size) - 1) + 1; + order = ilog2((*size_ptr) - 1) + 1; count = 0x1 << order; - if (count != (*size) && (*size > 0)) + if (count != (*size_ptr) && (*size_ptr > 0)) { printk("KERNEL MODULE: the number of free pages is not exponential times of two\n"); - kfree(size); + kfree(size_ptr); return; } printk("KERNEL MODULE: free secmem:paddr:%lx, vaddr:%lx, order:%lu\n", addr, __va(addr), order); - if ((*size) > 0) + if ((*size_ptr) > 0) { free_pages((long unsigned int)__va(addr), (order - RISCV_PGSHIFT)); } - - sbiret = SBI_CALL_2(SBI_SM_FREE_ENCLAVE_MEM, __pa(size), FREE_MAX_MEMORY); + *size_ptr = 0; + sbiret = SBI_CALL_2(SBI_SM_FREE_ENCLAVE_MEM, __pa(size_ptr), FREE_MAX_MEMORY); addr = (unsigned long)(sbiret.value); } deregister_device: - kfree(size); + kfree(size_ptr); misc_deregister(&enclave_dev); return; } diff --git a/penglai-enclave-driver/penglai-enclave-elfloader.c b/penglai-enclave-driver/penglai-enclave-elfloader.c index 56af6fb7f..d09e7d83a 100644 --- a/penglai-enclave-driver/penglai-enclave-elfloader.c +++ b/penglai-enclave-driver/penglai-enclave-elfloader.c @@ -1,4 +1,21 @@ #include "penglai-enclave-elfloader.h" +#define ROUND_TO(x, align) (((x) + ((align)-1)) & ~((align)-1)) + +// Function to print hex data +static void print_hex(const void *data, size_t size) { + const unsigned char *byte_data = data; + size_t i; + + for (i = 0; i < size; ) { + printk("%02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x\n%02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x", + byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++], + byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++], + byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++], + byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++],byte_data[i++]); + } + if (i % 16 != 0) + printk("\n"); +} int penglai_enclave_load_NOBITS_section(enclave_mem_t* enclave_mem, void * elf_sect_addr, int elf_sect_size) { @@ -25,8 +42,9 @@ int penglai_enclave_load_program(enclave_mem_t* enclave_mem, vaddr_t elf_prog_in { vaddr_t addr; vaddr_t enclave_new_page; + vaddr_t begin_page = 0; int size; - int r; + unsigned long r = 0; for(addr = (vaddr_t)elf_prog_addr; addr < (vaddr_t)elf_prog_addr + elf_prog_size; addr += RISCV_PGSIZE) { @@ -35,8 +53,17 @@ int penglai_enclave_load_program(enclave_mem_t* enclave_mem, vaddr_t elf_prog_in size = elf_prog_size % RISCV_PGSIZE; else size = RISCV_PGSIZE; - r = copy_from_user((void* )enclave_new_page, (void *)(elf_prog_infile_addr + addr - (vaddr_t)elf_prog_addr), size); + r += copy_from_user((void* )enclave_new_page, (void *)(elf_prog_infile_addr + addr - (vaddr_t)elf_prog_addr), size); + if (r) + { + printk("KERNEL MODULE: load_program copy_from_user failed r=0x%lx\n",r); + } + + // dprint("[Penglai Driver@%s]copy segment 0x%lx to va:0x%lx -pa:0x%lx \n",__func__ ,(unsigned long)((void *)(elf_prog_addr + addr - (vaddr_t)elf_prog_addr)) ,(vaddr_t)enclave_new_page ,__pa((vaddr_t)enclave_new_page)); + if(!begin_page)begin_page = enclave_new_page; + // print_hex(enclave_new_page, size); } + dprint("[Penglai Driver@%s] SUCCESS! from 0x%lx to 0x%lx r=0x%x\n",__func__,(unsigned long)elf_prog_addr,(unsigned long)(elf_prog_addr + elf_prog_size) ,r); return 0; } @@ -109,8 +136,8 @@ int penglai_enclave_loadelf(enclave_mem_t*enclave_mem, void* __user elf_ptr, uns printk("KERNEL MODULE: penglai enclave load program failed\n"); return -1; } - printk("[Penglai Driver@%s] elf_prog_addr:0x%lx elf_prog_size:0x%x, infile_addr:0x%lx", __func__, - elf_prog_addr, elf_prog_size, elf_prog_infile_addr); + // printk("[Penglai Driver@%s] elf_prog_addr:0x%lx elf_prog_size:0x%x, infile_addr:0x%lx", __func__, + // elf_prog_addr, elf_prog_size, elf_prog_infile_addr); elf_prog_ptr += sizeof(struct elf_phdr); } return 0; diff --git a/penglai-enclave-driver/penglai-enclave-ioctl.c b/penglai-enclave-driver/penglai-enclave-ioctl.c index 4bc02b677..b1b740705 100644 --- a/penglai-enclave-driver/penglai-enclave-ioctl.c +++ b/penglai-enclave-driver/penglai-enclave-ioctl.c @@ -10,13 +10,13 @@ DEFINE_SPINLOCK(enclave_big_lock); void acquire_big_lock(const char * str) { spin_lock(&enclave_big_lock); - printk("[PENGLAI Driver@%s] %s get lock\n", __func__, str); + dprint("[PENGLAI Driver@%s] %s get lock\n", __func__, str); } void release_big_lock(const char * str) { spin_unlock(&enclave_big_lock); - printk("[PENGLAI Driver@%s] %s release lock\n", __func__, str); + dprint("[PENGLAI Driver@%s] %s release lock\n", __func__, str); } unsigned int total_enclave_page(int elf_size, int stack_size) @@ -28,7 +28,7 @@ unsigned int total_enclave_page(int elf_size, int stack_size) int create_sbi_param(enclave_t* enclave, struct penglai_enclave_sbi_param * enclave_sbi_param, unsigned long paddr, unsigned long size, unsigned long entry_point, - unsigned long untrusted_ptr, unsigned long untrusted_size, unsigned long free_mem) + unsigned long untrusted_ptr, unsigned long untrusted_ptr_paddr, unsigned long untrusted_size, unsigned long free_mem, unsigned long kbuffer_ptr, unsigned long kbuffer_paddr) { enclave_sbi_param -> eid_ptr = (unsigned int* )__pa(&enclave -> eid); enclave_sbi_param -> ecall_arg0 = (unsigned long* )__pa(&enclave -> ocall_func_id); @@ -39,10 +39,13 @@ int create_sbi_param(enclave_t* enclave, struct penglai_enclave_sbi_param * encl enclave_sbi_param -> size = size; enclave_sbi_param -> entry_point = entry_point; enclave_sbi_param -> untrusted_ptr = untrusted_ptr; - enclave_sbi_param -> untrusted_size = untrusted_size; + enclave_sbi_param->untrusted_paddr = untrusted_ptr_paddr; + enclave_sbi_param->untrusted_size = untrusted_size; enclave_sbi_param -> free_mem = free_mem; //enclave share mem with kernel - enclave_sbi_param->kbuffer = ENCLAVE_DEFAULT_KBUFFER; + // enclave_sbi_param->kbuffer = ENCLAVE_DEFAULT_KBUFFER; + enclave_sbi_param->kbuffer = kbuffer_ptr; + enclave_sbi_param->kbuffer_paddr = kbuffer_paddr; enclave_sbi_param->kbuffer_size = enclave->kbuffer_size; return 0; } @@ -105,7 +108,7 @@ int penglai_enclave_create(struct file * filep, unsigned long args) return -1; } long stack_size = enclave_param->stack_size; //DEFAULT_STACK_SIZE=1MB - long untrusted_mem_size = enclave_param->untrusted_mem_size; //DEFAULT_UNTRUSTED_SIZE=8KB + long untrusted_mem_size = enclave_param->untrusted_mem_size; //DEFAULT_UNTRUSTED_SIZE=8KB MAX=16MB unsigned long untrusted_mem_ptr = enclave_param->untrusted_mem_ptr; //0 unsigned long kbuffer_ptr = ENCLAVE_DEFAULT_KBUFFER; struct penglai_enclave_sbi_param *enclave_sbi_param = kmalloc(sizeof(struct penglai_enclave_sbi_param), GFP_KERNEL); @@ -122,7 +125,7 @@ int penglai_enclave_create(struct file * filep, unsigned long args) return -1; } - + acquire_big_lock(__func__); enclave = create_enclave(total_pages); //May sleep if(!enclave) { @@ -150,31 +153,65 @@ int penglai_enclave_create(struct file * filep, unsigned long args) } enclave->untrusted_mem->addr = (vaddr_t)untrusted_mem_ptr; enclave->untrusted_mem->size = untrusted_mem_size; - printk("[Penglai Driver@%s] untrusted_mem->addr:0x%lx untrusted_mem->size:0x%lx\n", - __func__, (vaddr_t)untrusted_mem_ptr, untrusted_mem_size); + dprint("[Penglai Driver@%s] untrusted_mem->addr:0x%lx ,paddr:%lx, untrusted_mem->size:0x%lx\n", + __func__, (vaddr_t)untrusted_mem_ptr, __pa(untrusted_mem_ptr), untrusted_mem_size); alloc_kbuffer(ENCLAVE_DEFAULT_KBUFFER_SIZE, &kbuffer_ptr, enclave); //May sleep enclave->kbuffer = (vaddr_t)kbuffer_ptr; enclave->kbuffer_size = ENCLAVE_DEFAULT_KBUFFER_SIZE; free_mem = get_free_mem(&(enclave->enclave_mem->free_mem)); - acquire_big_lock(__func__); create_sbi_param(enclave, enclave_sbi_param, - (unsigned long)(enclave->enclave_mem->paddr), - enclave->enclave_mem->size, elf_entry, DEFAULT_UNTRUSTED_PTR, - untrusted_mem_size, __pa(free_mem)); + (unsigned long)(enclave->enclave_mem->paddr), + enclave->enclave_mem->size, elf_entry, DEFAULT_UNTRUSTED_PTR, __pa(untrusted_mem_ptr), + untrusted_mem_size, __pa(free_mem), ENCLAVE_DEFAULT_KBUFFER, __pa(kbuffer_ptr)); - printk("[Penglai Driver@%s] enclave_mem->paddr:0x%lx, size:0x%lx\n", + dprint("[Penglai Driver@%s] enclave_mem->paddr:0x%lx, size:0x%lx\n", __func__, (unsigned long)(enclave->enclave_mem->paddr), enclave->enclave_mem->size); - ret = SBI_CALL_1(SBI_SM_CREATE_ENCLAVE, __pa(enclave_sbi_param)); + ret = SBI_CALL_2(SBI_SM_CREATE_ENCLAVE, __pa(enclave_sbi_param), false); //if(ret < 0) if(ret.error) { printk("KERNEL MODULE: SBI_SM_CREATE_ENCLAVE is failed \n"); - goto destroy_enclave; + if(ret.value == ENCLAVE_NO_MEMORY){ + //TODO: allocate certain memory region like sm_init + unsigned long addr; + int retry = 5; + addr = __get_free_pages(GFP_ATOMIC, DEFAULT_SECURE_PAGES_ORDER); + if(!addr) + { + printk("KERNEL MODULE: can not get free page which order is 0x%d", DEFAULT_SECURE_PAGES_ORDER); + goto destroy_enclave; + } + dprint("[Penglai Driver@%s] new alloc paddr:0x%lx\n",__func__, addr); + ret = SBI_CALL_2(SBI_SM_MEMORY_EXTEND, __pa(addr), (1 << (DEFAULT_SECURE_PAGES_ORDER + RISCV_PGSHIFT)) ); + + while (ret.value == RETRY_SPIN_LOCK && retry) + { + retry--; + ret = SBI_CALL_2(SBI_SM_MEMORY_EXTEND, __pa(addr), (1 << (DEFAULT_SECURE_PAGES_ORDER + RISCV_PGSHIFT))); + } + + if(ret.error) + { + printk("KERNEL MODULE: sbi call extend memory is failed\n"); + goto destroy_enclave; + } + + ret = SBI_CALL_2(SBI_SM_CREATE_ENCLAVE, __pa(enclave_sbi_param), true); + if (ret.error) + { + printk("KERNEL MODULE: sbi call create enclave is failed\n"); + goto destroy_enclave; + } + + } + else{ + goto destroy_enclave; + } } enclave_param->eid = enclave_idr_alloc(enclave); @@ -183,7 +220,7 @@ int penglai_enclave_create(struct file * filep, unsigned long args) release_big_lock(__func__); kfree(enclave_sbi_param); - + dprint("[Penglai Driver@%s] create enclave success!\t\n",__func__); return ret.value; destroy_enclave: @@ -221,6 +258,8 @@ int penglai_enclave_destroy(struct file * filep, unsigned long args) destroy_enclave(enclave); enclave_idr_remove(eid); } //otherwise, the run interfaces will destroy the enclave + + // ret = SBI_CALL_1(SBI_SM_FREE_ENCLAVE_MEM,); out: release_big_lock(__func__); return retval; @@ -293,6 +332,7 @@ int penglai_enclave_run(struct file *filep, unsigned long args) int retval = 0; int resume_id = 0; + dprint("[Penglai Driver@%s] begin get_enclave_by_id\n", __func__); acquire_big_lock(__func__); enclave = get_enclave_by_id(eid); @@ -307,7 +347,7 @@ int penglai_enclave_run(struct file *filep, unsigned long args) enclave->is_running = 1; //set the flag - release_big_lock(__func__); + /* Use untrusted mem as in_out_buf*/ if((void*)untrusted_mem_ptr != NULL && untrusted_mem_size > 0){ @@ -316,11 +356,14 @@ int penglai_enclave_run(struct file *filep, unsigned long args) return -EINVAL; } memset((void*)enclave->untrusted_mem->addr, 0, enclave->untrusted_mem->size); - if(copy_from_user((void*)enclave->untrusted_mem->addr, (void*)untrusted_mem_ptr, untrusted_mem_size)) + if (copy_from_user((void *)enclave->untrusted_mem->addr, (void *)untrusted_mem_ptr, untrusted_mem_size)) + { + printk("KERNEL MODULE: copy_from_user failed \n"); return -EFAULT; + } } - printk("[Penglai Driver@%s] goto infinite run loop\n", __func__); + dprint("[Penglai Driver@%s] goto infinite run loop\n", __func__); // In the (infinite loop), we do not need to acquire the lock // The monitor is responsible to check the authentication // It will only exit when either: @@ -331,6 +374,7 @@ int penglai_enclave_run(struct file *filep, unsigned long args) // the enclave (as resume_from_timer_irq will check status of an enclave) ret = SBI_CALL_1(SBI_SM_RUN_ENCLAVE, enclave_eid); resume_id = enclave->eid; + release_big_lock(__func__); while((ret.value == ENCLAVE_TIMER_IRQ) || (ret.value == ENCLAVE_OCALL)) { @@ -417,7 +461,8 @@ int penglai_enclave_attest(struct file * filep, unsigned long args) enclave_t * enclave; struct sbiret ret = {0}; int retval; - + dprint("[Penglai Driver@%s] begin attest\n", + __func__); acquire_big_lock(__func__); enclave = get_enclave_by_id(eid); if (!enclave) @@ -547,7 +592,7 @@ int penglai_enclave_resume(struct file * filep, unsigned long args) if (copy_to_user((void*)untrusted_mem_ptr, (void*)enclave->untrusted_mem->addr, ocall_buf_size)) return -EFAULT; } - printk("[Penglai Driver@%s] return user for ocall \n", __func__); + dprint("[Penglai Driver@%s] return user for ocall,enclave->untrusted_mem:%lx\n\t kbuffer:%lx kbuffer_val:%s \n", __func__, (void *)(enclave->untrusted_mem->addr), enclave->kbuffer, (void *)(enclave->kbuffer)); return RETURN_USER_FOR_OCALL; } default: @@ -595,6 +640,30 @@ int penglai_enclave_resume(struct file * filep, unsigned long args) return retval; } +int penglai_enclave_memory_reclaim(struct file * filep, unsigned long args){ + int retval; + struct sbiret ret = {0}; + struct mm_reclaim_arg_t* mm_reclaim; + + struct penglai_enclave_user_param * enclave_param = (struct penglai_enclave_user_param*) args; + unsigned long eid = enclave_param ->eid; + enclave_t * enclave; + + enclave = get_enclave_by_id(eid); + + mm_reclaim = kmalloc(sizeof(struct mm_reclaim_arg_t), GFP_KERNEL); + + acquire_big_lock(__func__); + ret = SBI_CALL_2(SBI_SM_MEMORY_RECLAIM, __pa(mm_reclaim), enclave->eid); + retval = ret.value; + + release_big_lock(__func__); + + dprint("[Penglai Driver@%s]A total of %lx enclave memory was reclaimed\n",__func__, mm_reclaim->resp_size); + kfree(mm_reclaim); + return retval; +} + long penglai_enclave_ioctl(struct file* filep, unsigned int cmd, unsigned long args) { char ioctl_data[1024]; @@ -634,6 +703,9 @@ long penglai_enclave_ioctl(struct file* filep, unsigned int cmd, unsigned long a case PENGLAI_ENCLAVE_IOC_DESTROY_ENCLAVE: ret = penglai_enclave_destroy(filep, (unsigned long)ioctl_data); break; + case PENGLAI_ENCLAVE_MEMORY_RECLAIM: + ret = penglai_enclave_memory_reclaim(filep, (unsigned long)ioctl_data); + break; case PENGLAI_ENCLAVE_IOC_DEBUG_PRINT: sbiret = SBI_CALL_1(SBI_SM_DEBUG_PRINT, 0); ret = sbiret.value; diff --git a/penglai-enclave-driver/penglai-enclave-ioctl.h b/penglai-enclave-driver/penglai-enclave-ioctl.h index 83ec088ce..1d97eda57 100644 --- a/penglai-enclave-driver/penglai-enclave-ioctl.h +++ b/penglai-enclave-driver/penglai-enclave-ioctl.h @@ -20,8 +20,10 @@ _IOW(PENGLAI_ENCLAVE_IOC_MAGIC, 0x05, struct penglai_enclave_user_param) #define PENGLAI_ENCLAVE_IOC_DEBUG_PRINT \ _IOW(PENGLAI_ENCLAVE_IOC_MAGIC, 0x06, struct penglai_enclave_user_param) +#define PENGLAI_ENCLAVE_MEMORY_RECLAIM \ + _IOW(PENGLAI_ENCLAVE_IOC_MAGIC, 0x07, struct penglai_enclave_user_param) - +#define DEFAULT_SECURE_PAGES_ORDER 10 #define DEFAULT_CLOCK_DELAY 100000 #define DEFAULT_UNTRUSTED_PTR 0x0000001000000000 #define ENCLAVE_DEFAULT_KBUFFER_SIZE 0x1000UL @@ -48,10 +50,12 @@ struct penglai_enclave_sbi_param unsigned long size; unsigned long entry_point; unsigned long untrusted_ptr; + unsigned long untrusted_paddr; unsigned long untrusted_size; unsigned long free_mem; //enclave shared mem with kernel unsigned long kbuffer; + unsigned long kbuffer_paddr; unsigned long kbuffer_size; unsigned long *ecall_arg0; unsigned long *ecall_arg1; @@ -108,6 +112,13 @@ struct penglai_enclave_ioctl_attest_enclave struct report_t report; }; +struct mm_reclaim_arg_t +{ + unsigned long req_size; + unsigned long req_addr; + unsigned long resp_size; +}; + long penglai_enclave_ioctl(struct file* filep, unsigned int cmd, unsigned long args); #endif diff --git a/penglai-enclave-driver/penglai-enclave-page.h b/penglai-enclave-driver/penglai-enclave-page.h index 5575c96ef..1c3052d4e 100644 --- a/penglai-enclave-driver/penglai-enclave-page.h +++ b/penglai-enclave-driver/penglai-enclave-page.h @@ -22,6 +22,13 @@ typedef uintptr_t vaddr_t; typedef uintptr_t paddr_t; typedef unsigned long pt_entry_t; +// #define PENGLAI_DEBUG +#ifdef PENGLAI_DEBUG +#define dprint(...) printk(__VA_ARGS__) +#else +#define dprint(...) +#endif + #define RISCV_PT_SHIFT 12 #define RISCV_PT_LEVEL 3 #define RISCV_PT_LEVELBITS 9 diff --git a/penglai-enclave-driver/penglai-enclave.c b/penglai-enclave-driver/penglai-enclave.c index 3e270f83f..ded917821 100644 --- a/penglai-enclave-driver/penglai-enclave.c +++ b/penglai-enclave-driver/penglai-enclave.c @@ -62,10 +62,12 @@ enclave_t* create_enclave(int total_pages) goto free_enclave; } - printk("[Penglai Driver@%s] total_pages:%d order:%ld\n", + dprint("[Penglai Driver@%s] total_pages:%d order:%ld\n", __func__, total_pages, order); //Note: SBI_SM_ALLOC_ENCLAVE_MEM's arg is the num of bytes instead of pages - require_sec_memory->size = total_pages << RISCV_PGSHIFT; + require_sec_memory->size = total_pages << RISCV_PGSHIFT;//0x200000 + dprint("[Penglai Driver@%s] require_sec_memory va: %lx, pa: %lx, __va(pa): %lx, size:%lx\n", + __func__, (unsigned long)require_sec_memory, __pa(require_sec_memory), (unsigned long)__va(__pa(require_sec_memory)),(unsigned long)require_sec_memory->size); ret = SBI_CALL_1(SBI_SM_ALLOC_ENCLAVE_MEM, __pa(require_sec_memory)); pa = require_sec_memory->paddr; @@ -83,7 +85,7 @@ enclave_t* create_enclave(int total_pages) goto free_enclave; } - ret = SBI_CALL_2(SBI_SM_MEMORY_EXTEND, __pa(addr), 4096 * (1 << order) ); + ret = SBI_CALL_2(SBI_SM_MEMORY_EXTEND, __pa(addr), (1 << (order+RISCV_PGSHIFT)) ); if(ret.error) { printk("KERNEL MODULE: sbi call extend memory is failed\n"); @@ -125,7 +127,7 @@ enclave_t* create_enclave(int total_pages) if(enclave_mem) kfree(enclave_mem); if(untrusted_mem) kfree(untrusted_mem); if(require_sec_memory) kfree(require_sec_memory); - + spin_unlock_bh(&kmalloc_enclave_lock); return NULL; } diff --git a/penglai-enclave-driver/penglai-enclave.h b/penglai-enclave-driver/penglai-enclave.h index 02d68ac64..2415638e3 100644 --- a/penglai-enclave-driver/penglai-enclave.h +++ b/penglai-enclave-driver/penglai-enclave.h @@ -28,11 +28,12 @@ #define SBI_SM_DESTROY_ENCLAVE 94 #define SBI_SM_ALLOC_ENCLAVE_MEM 93 #define SBI_SM_MEMORY_EXTEND 92 -#define SBI_SM_MEMORY_RECLAIM 91 +#define SBI_SM_MEMORY_RECLAIM 91 #define SBI_SM_FREE_ENCLAVE_MEM 90 #define SBI_SM_DEBUG_PRINT 88 //Error codes of SBI_SM_ALLOC_ENCLAVE_MEM +#define RETRY_SPIN_LOCK -3 #define ENCLAVE_NO_MEMORY -2 #define ENCLAVE_UNKNOWN_ERROR -1 #define ENCLAVE_SUCCESS 0 @@ -88,6 +89,13 @@ typedef struct require_sec_memory unsigned long resp_size; } require_sec_memory_t; +typedef struct reclaim_sec_memory +{ + unsigned long size; + unsigned long paddr; + unsigned long resp_size; +} reclaim_sec_memory_t; + enclave_t* create_enclave(int total_pages); int destroy_enclave(enclave_t* enclave); unsigned int enclave_idr_alloc(enclave_t* enclave);