mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Fix deadlock when unicasting/broadcasting SMP message
When two processors send each others a SMP message at the same time they need to process messages while waiting for delivery of the message they just sent, or they will deadlock.
This commit is contained in:
parent
3ee7c21fae
commit
dc9ddf8104
Notes:
sideshowbarker
2024-07-19 01:26:39 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/dc9ddf8104d Pull-request: https://github.com/SerenityOS/serenity/pull/4042
1 changed files with 8 additions and 10 deletions
|
@ -1884,11 +1884,10 @@ void Processor::smp_broadcast_message(ProcessorMessage& msg, bool async)
|
|||
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.load(AK::MemoryOrder::memory_order_relaxed))
|
||||
halt_this();
|
||||
// We need to process any messages that may have been sent to
|
||||
// us while we're waiting. This also checks if another processor
|
||||
// may have requested us to halt.
|
||||
cur_proc.smp_process_pending_messages();
|
||||
}
|
||||
|
||||
smp_cleanup_message(msg);
|
||||
|
@ -1934,11 +1933,10 @@ void Processor::smp_unicast_message(u32 cpu, ProcessorMessage& msg, bool async)
|
|||
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.load(AK::MemoryOrder::memory_order_relaxed))
|
||||
halt_this();
|
||||
// We need to process any messages that may have been sent to
|
||||
// us while we're waiting. This also checks if another processor
|
||||
// may have requested us to halt.
|
||||
cur_proc.smp_process_pending_messages();
|
||||
}
|
||||
|
||||
smp_cleanup_message(msg);
|
||||
|
|
Loading…
Reference in a new issue