From b51092c7ec2db8b52c50bafce4fd51e15e090560 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Fri, 27 Jul 2018 16:13:06 +0000 Subject: [PATCH] Use SPP (Supervisor Previous Privilege) bit in the sstatus register to determine if trap is from userspace. Otherwise if we jump to kernel address from userspace, then TRAPF_USERMODE failed to detect usermode and then do_ast triggers a panic "ast in kernel mode". Reviewed by: markj@ Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16469 --- sys/riscv/include/cpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/riscv/include/cpu.h b/sys/riscv/include/cpu.h index 9b488ac9ecb..92c5c67ef59 100644 --- a/sys/riscv/include/cpu.h +++ b/sys/riscv/include/cpu.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2015-2016 Ruslan Bukin + * Copyright (c) 2015-2018 Ruslan Bukin * All rights reserved. * * Portions of this software were developed by SRI International and the @@ -41,7 +41,7 @@ #include #define TRAPF_PC(tfp) ((tfp)->tf_ra) -#define TRAPF_USERMODE(tfp) (((tfp)->tf_sepc & (1ul << 63)) == 0) +#define TRAPF_USERMODE(tfp) (((tfp)->tf_sstatus & SSTATUS_SPP) == 0) #define cpu_getstack(td) ((td)->td_frame->tf_sp) #define cpu_setstack(td, sp) ((td)->td_frame->tf_sp = (sp))