From 3fb289e27d3e0ca171438f178ea6750e25ce6f32 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 4 Feb 2022 19:48:13 +0200 Subject: Kernel/PCI: Don't hold spinlocks when doing fast device enumeration Instead, hold the lock while we copy the contents to a stack-based Vector then iterate on it without any locking. Because we rely on heap allocations, we need to propagate errors back in case of OOM condition, therefore, both PCI::enumerate API function and PCI::Access::add_host_controller_and_enumerate_attached_devices use now a ErrorOr return value to propagate errors. OOM Error can only occur when enumerating the m_device_identifiers vector under a spinlock and trying to expand the temporary Vector which will be used locklessly to actually iterate over the PCI::DeviceIdentifiers objects. --- Kernel/Bus/PCI/Access.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Kernel/Bus/PCI/Access.h') diff --git a/Kernel/Bus/PCI/Access.h b/Kernel/Bus/PCI/Access.h index 8444b80c18..fa1dc16fb2 100644 --- a/Kernel/Bus/PCI/Access.h +++ b/Kernel/Bus/PCI/Access.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -21,7 +22,7 @@ public: static bool initialize_for_multiple_pci_domains(PhysicalAddress mcfg_table); static bool initialize_for_one_pci_domain(); - void fast_enumerate(Function&) const; + ErrorOr fast_enumerate(Function&) const; void rescan_hardware(); static Access& the(); @@ -39,7 +40,7 @@ public: Spinlock const& scan_lock() const { return m_scan_lock; } RecursiveSpinlock const& access_lock() const { return m_access_lock; } - void add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr, Function callback); + ErrorOr add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr, Function callback); private: u8 read8_field(Address address, RegisterOffset field); -- cgit v1.2.3