diff options
author | Timon Kruiper <timonkruiper@gmail.com> | 2023-04-06 12:01:18 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-13 20:22:08 +0200 |
commit | 10030038e910237816b6a181deb69a88d15d6550 (patch) | |
tree | c838dff1fcc6d7f23af1638a92d2f520c76b5286 /Kernel/Arch/aarch64 | |
parent | 7795b7bc176c9f131d85cb299ea1b2d54c9bdf2b (diff) | |
download | serenity-10030038e910237816b6a181deb69a88d15d6550.zip |
Kernel/aarch64: Make sure no reordering of DAIF::read is possible
We were crashing on the VERIFY_INTERRUPTS_DISABLED() in
RecursiveSpinlock::unlock, which was caused by the compiler reordering
instructions in `sys$get_root_session_id`. In this function, a SpinLock
is locked and quickly unlocked again, and since the lock and unlock
functions were inlined into `sys$get_root_session_id` and the DAIF::read
was missing the `volatile` keyword, the compiler was free to reorder the
reads from the DAIF register to the top of this function. This caused
the CPU to read the interrupts state at the beginning of the function,
and storing the result on the stack, which in turn caused the
VERIFY_INTERRUPTS_DISABLED() assertion to fail. By adding the `volatile`
modifier to the inline assembly, the compiler will not reorder the
instructions.
In aa40cef2b7, I mistakenly assumed that the crash was related to the
initial interrupts state of the kernel threads, but it turns out that
the missing `volatile` keyword was the actual problem. This commit also
removes that code again.
Diffstat (limited to 'Kernel/Arch/aarch64')
-rw-r--r-- | Kernel/Arch/aarch64/Registers.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Kernel/Arch/aarch64/Registers.h b/Kernel/Arch/aarch64/Registers.h index b84aa9363b..264c4ab177 100644 --- a/Kernel/Arch/aarch64/Registers.h +++ b/Kernel/Arch/aarch64/Registers.h @@ -1287,8 +1287,8 @@ struct DAIF { { DAIF daif; - asm("mrs %[value], daif" - : [value] "=r"(daif)); + asm volatile("mrs %[value], daif" + : [value] "=r"(daif)); return daif; } |