Kernel: Make disk IO blocking thread safe

This was causing a lot of deadlocks on vms without kvm accel
This commit is contained in:
Bananymous 2023-06-12 18:57:47 +03:00
parent bf617036c7
commit 32e1473c94
2 changed files with 2 additions and 6 deletions

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <BAN/Errors.h> #include <BAN/Errors.h>
#include <kernel/Semaphore.h>
#include <kernel/SpinLock.h> #include <kernel/SpinLock.h>
#include <kernel/Storage/ATAController.h> #include <kernel/Storage/ATAController.h>
@ -56,7 +55,6 @@ namespace Kernel
const uint16_t m_base; const uint16_t m_base;
const uint16_t m_ctrl; const uint16_t m_ctrl;
SpinLock m_lock; SpinLock m_lock;
Semaphore m_semaphore;
bool m_has_got_irq { false }; bool m_has_got_irq { false };

View File

@ -151,14 +151,12 @@ namespace Kernel
if (io_read(ATA_PORT_STATUS) & ATA_STATUS_ERR) if (io_read(ATA_PORT_STATUS) & ATA_STATUS_ERR)
dprintln("ATA Error: {}", error()); dprintln("ATA Error: {}", error());
m_has_got_irq = true; m_has_got_irq = true;
m_semaphore.unblock();
} }
void ATABus::block_until_irq() void ATABus::block_until_irq()
{ {
if (!m_has_got_irq) while (!__sync_bool_compare_and_swap(&m_has_got_irq, true, false))
m_semaphore.block(); __builtin_ia32_pause();
m_has_got_irq = false;
} }
uint8_t ATABus::io_read(uint16_t port) uint8_t ATABus::io_read(uint16_t port)