Skip to content

Commit

Permalink
[SM] Multicore Security Monitor (keystone-enclave#4)
Browse files Browse the repository at this point in the history
The security monitor supports SMP up to 8 cores

* SMM is protected over all the cores
* Enclave Creation/Destruction: PMP registers are globally synchronized using an IPI
* Enclave Run/Exit: only the local PMP register is set or unset
* Removed unused SBI functions (`copy_to_enclave` and `copy_from_enclave`)
* [BUG] Sanctum bootloader does not work with SMP yet; must debug later
  • Loading branch information
dayeol authored Oct 8, 2018
1 parent eddf486 commit cf355ee
Show file tree
Hide file tree
Showing 11 changed files with 494 additions and 272 deletions.
2 changes: 0 additions & 2 deletions machine/mcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#define SBI_SM_CREATE_ENCLAVE 101
#define SBI_SM_DESTROY_ENCLAVE 102
#define SBI_SM_COPY_TO_ENCLAVE 103
#define SBI_SM_COPY_FROM_ENCLAVE 104
#define SBI_SM_RUN_ENCLAVE 105
#define SBI_SM_EXIT_ENCLAVE 1101
#define SBI_SM_NOT_IMPLEMENTED 1111
Expand Down
18 changes: 17 additions & 1 deletion machine/mentry.S
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trap_table:
.word pmp_trap
.word misaligned_store_trap
.word pmp_trap
.word u_ecall_trap // 8 --> ECALL from U-mode
.word bad_trap
.word mcall_trap // 9 --> ECALL from S-mode
.word bad_trap
.word bad_trap
Expand All @@ -24,6 +24,10 @@ trap_table:
.word __trap_from_machine_mode
.word bad_trap
.word bad_trap
#ifdef SM_ENABLED
# define HANDLE_IPI_PMP_VECTOR 16
.word handle_pmp_ipi
#endif

.option norvc
.section .text.init,"ax",@progbits
Expand Down Expand Up @@ -80,6 +84,7 @@ trap_vector:
lw a0, MENTRY_IPI_PENDING_OFFSET(a0)
sw x0, MENTRY_IPI_PENDING_OFFSET(a0)
#endif

and a1, a0, IPI_SOFT
beqz a1, 1f
csrs mip, MIP_SSIP
Expand All @@ -96,6 +101,11 @@ trap_vector:
beqz a1, 1f
wfi
j 1b
#ifdef SM_ENABLED
1:
andi a1, a0, IPI_PMP
bnez a1, .Lipi_pmp
#endif
1:
j .Lmret

Expand Down Expand Up @@ -190,6 +200,12 @@ restore_regs:
LOAD sp, 2*REGBYTES(sp)
mret

#ifdef SM_ENABLED
.Lipi_pmp:
li a1, HANDLE_IPI_PMP_VECTOR
j .Lhandle_trap_in_machine_mode
#endif

.Ltrap_from_machine_mode:
csrr sp, mscratch
addi sp, sp, -INTEGER_CONTEXT_SIZE
Expand Down
14 changes: 5 additions & 9 deletions machine/mtrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ static uintptr_t mcall_set_timer(uint64_t when)
set_csr(mie, MIP_MTIP);
return 0;
}

static void send_ipi_many(uintptr_t* pmask, int event)
#ifndef SM_ENABLED
static
#endif
void send_ipi_many(uintptr_t* pmask, int event)
{
_Static_assert(MAX_HARTS <= 8 * sizeof(*pmask), "# harts > uintptr_t bits");
uintptr_t mask = hart_mask;
Expand All @@ -109,7 +111,7 @@ static void send_ipi_many(uintptr_t* pmask, int event)

if (event == IPI_SOFT)
return;

// wait until all events have been handled.
// prevent deadlock by consuming incoming IPIs.
uint32_t incoming_ipi = 0;
Expand Down Expand Up @@ -172,12 +174,6 @@ void mcall_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
case SBI_SM_DESTROY_ENCLAVE:
retval = mcall_sm_destroy_enclave(arg0);
break;
case SBI_SM_COPY_TO_ENCLAVE:
retval = mcall_sm_copy_to_enclave(arg0, arg1, arg2, arg3);
break;
case SBI_SM_COPY_FROM_ENCLAVE:
retval = mcall_sm_copy_from_enclave(arg0, arg1, arg2);
break;
case SBI_SM_RUN_ENCLAVE:
retval = mcall_sm_run_enclave(arg0, arg1);
break;
Expand Down
1 change: 1 addition & 0 deletions machine/mtrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static inline void wfi()
#define IPI_FENCE_I 0x2
#define IPI_SFENCE_VMA 0x4
#define IPI_HALT 0x8
#define IPI_PMP 0x10

#define MACHINE_STACK_SIZE RISCV_PGSIZE
#define MENTRY_HLS_OFFSET (INTEGER_CONTEXT_SIZE + SOFT_FLOAT_CONTEXT_SIZE)
Expand Down
Loading

0 comments on commit cf355ee

Please sign in to comment.