1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:27:45 +00:00

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.
This commit is contained in:
Timon Kruiper 2023-04-06 12:01:18 +02:00 committed by Linus Groh
parent 7795b7bc17
commit 10030038e9
2 changed files with 2 additions and 9 deletions

View file

@ -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;
}