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.
This commit is contained in:
Tom 2020-10-25 20:07:48 -06:00 committed by Andreas Kling
parent fe615e601a
commit b8ad4932a9
Notes: sideshowbarker 2024-07-19 01:43:27 +09:00

View file

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