1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

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<void> 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.
This commit is contained in:
Liav A 2022-02-04 19:48:13 +02:00 committed by Andreas Kling
parent c0ed656c94
commit 3fb289e27d
14 changed files with 69 additions and 42 deletions

View file

@ -27,7 +27,7 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
if (kernel_command_line().disable_usb())
return;
PCI::enumerate([this](PCI::DeviceIdentifier const& device_identifier) {
MUST(PCI::enumerate([this](PCI::DeviceIdentifier const& device_identifier) {
if (!(device_identifier.class_code().value() == 0xc && device_identifier.subclass_code().value() == 0x3))
return;
if (device_identifier.prog_if().value() == 0x0) {
@ -56,7 +56,7 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
}
dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", device_identifier.address(), device_identifier.prog_if().value());
});
}));
}
bool USBManagement::initialized()