From b8ad4932a9951296056ef39c3e967c01cd983fa7 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 25 Oct 2020 20:07:48 -0600 Subject: [PATCH] Kernel: Fix race condition waiting for IPI while other CPU requested halt It's possible that we broadcast an IPI message right at the same time another processor requests a halt. Rather than spinning forever waiting for that message to be handled, check if we should halt while waiting. --- Kernel/Arch/i386/CPU.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 7bffaf6f5d..73a9e50174 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -1870,6 +1870,12 @@ void Processor::smp_broadcast_message(ProcessorMessage& msg, bool async) // to the pool. Otherwise, the last processor to complete it will return it while (atomic_load(&msg.refs, AK::MemoryOrder::memory_order_consume) != 0) { // TODO: pause for a bit? + + // We need to check here if another processor may have requested + // us to halt before this message could be delivered. Otherwise + // we're just spinning the CPU because msg.refs will never drop to 0. + if (cur_proc.m_halt_requested) + halt_this(); } smp_cleanup_message(msg);