From 32e1473c94896b4e84c263132d98518d718547dd Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 12 Jun 2023 18:57:47 +0300 Subject: [PATCH] Kernel: Make disk IO blocking thread safe This was causing a lot of deadlocks on vms without kvm accel --- kernel/include/kernel/Storage/ATABus.h | 2 -- kernel/kernel/Storage/ATABus.cpp | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/include/kernel/Storage/ATABus.h b/kernel/include/kernel/Storage/ATABus.h index c9c2db0c..baf83bb8 100644 --- a/kernel/include/kernel/Storage/ATABus.h +++ b/kernel/include/kernel/Storage/ATABus.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -56,7 +55,6 @@ namespace Kernel const uint16_t m_base; const uint16_t m_ctrl; SpinLock m_lock; - Semaphore m_semaphore; bool m_has_got_irq { false }; diff --git a/kernel/kernel/Storage/ATABus.cpp b/kernel/kernel/Storage/ATABus.cpp index 3251c340..158f5370 100644 --- a/kernel/kernel/Storage/ATABus.cpp +++ b/kernel/kernel/Storage/ATABus.cpp @@ -151,14 +151,12 @@ namespace Kernel if (io_read(ATA_PORT_STATUS) & ATA_STATUS_ERR) dprintln("ATA Error: {}", error()); m_has_got_irq = true; - m_semaphore.unblock(); } void ATABus::block_until_irq() { - if (!m_has_got_irq) - m_semaphore.block(); - m_has_got_irq = false; + while (!__sync_bool_compare_and_swap(&m_has_got_irq, true, false)) + __builtin_ia32_pause(); } uint8_t ATABus::io_read(uint16_t port)