From bf03b1f1f95eeb68aaebbdd3fa160c5dfd9d8141 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Tue, 7 May 2019 14:32:17 +0000 Subject: [PATCH] Disable interrupts first and then set spinlock_count to 1. Otherwise interrupt can be generated just after setting spinlock_count and before disabling interrupts. Sponsored by: DARPA, AFRL --- sys/riscv/riscv/machdep.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index ae4c040dc47..417373744ae 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -457,11 +457,13 @@ void spinlock_enter(void) { struct thread *td; + register_t reg; td = curthread; if (td->td_md.md_spinlock_count == 0) { + reg = intr_disable(); td->td_md.md_spinlock_count = 1; - td->td_md.md_saved_sstatus_ie = intr_disable(); + td->td_md.md_saved_sstatus_ie = reg; } else td->td_md.md_spinlock_count++; critical_enter();