From 7f3bef01193137e3227fcf88bece86f5234b9bc5 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Thu, 26 Sep 2024 15:43:17 -0700 Subject: [PATCH] Enable CBOs (but upgrade inval to flush for safety) --- machine/minit.c | 2 +- pk/pk.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/machine/minit.c b/machine/minit.c index ceae9f0..3174409 100644 --- a/machine/minit.c +++ b/machine/minit.c @@ -246,7 +246,7 @@ void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1 mstatus = INSERT_FIELD(mstatus, MSTATUS_MPIE, 0); write_csr(mstatus, mstatus); write_csr(mscratch, MACHINE_STACK_TOP() - MENTRY_FRAME_SIZE); - write_csr(menvcfg, MENVCFG_SSE); + write_csr(menvcfg, MENVCFG_SSE | MENVCFG_CBCFE | INSERT_FIELD(0, MENVCFG_CBIE, 1)); #ifndef __riscv_flen uintptr_t *p_fcsr = (uintptr_t*)(MACHINE_STACK_TOP() - MENTRY_FRAME_SIZE); // the x0's save slot *p_fcsr = 0; diff --git a/pk/pk.c b/pk/pk.c index 64d8d57..bc41308 100644 --- a/pk/pk.c +++ b/pk/pk.c @@ -122,6 +122,8 @@ static void run_loaded_program(size_t argc, char** argv, uintptr_t kstack_top) write_csr(ssp, shadow_stack_top); } + set_csr(senvcfg, SENVCFG_CBCFE | INSERT_FIELD(0, SENVCFG_CBIE, 1)); + // copy phdrs to user stack size_t stack_top = current.stack_top - current.phdr_size; memcpy_to_user((void*)stack_top, (void*)current.phdr, current.phdr_size);