Kernel/x86: Disable interrupts when leaving critical sections

This fixes an issue where we could get preempted after acquiring the
current Processor pointer, but before calling methods on it.

I strongly suspect this was the cause of "Processor::current() == this"
assertion failures.
This commit is contained in:
Andreas Kling 2022-08-17 19:35:14 +02:00
parent cd348918f9
commit 51bc87d15a

View file

@ -990,7 +990,7 @@ void Processor::exit_trap(TrapFrame& trap)
void Processor::check_invoke_scheduler() void Processor::check_invoke_scheduler()
{ {
InterruptDisabler disabler; VERIFY_INTERRUPTS_DISABLED();
VERIFY(!m_in_irq); VERIFY(!m_in_irq);
VERIFY(!m_in_critical); VERIFY(!m_in_critical);
VERIFY(&Processor::current() == this); VERIFY(&Processor::current() == this);
@ -1667,6 +1667,7 @@ u64 Processor::time_spent_idle() const
void Processor::leave_critical() void Processor::leave_critical()
{ {
InterruptDisabler disabler;
current().do_leave_critical(); current().do_leave_critical();
} }
@ -1688,6 +1689,7 @@ void Processor::do_leave_critical()
u32 Processor::clear_critical() u32 Processor::clear_critical()
{ {
InterruptDisabler disabler;
auto prev_critical = in_critical(); auto prev_critical = in_critical();
write_gs_ptr(__builtin_offsetof(Processor, m_in_critical), 0); write_gs_ptr(__builtin_offsetof(Processor, m_in_critical), 0);
auto& proc = current(); auto& proc = current();