mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +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:
parent
c0ed656c94
commit
3fb289e27d
14 changed files with 69 additions and 42 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/Try.h>
|
||||
#include <AK/UBSanitizer.h>
|
||||
#include <Kernel/Arch/x86/InterruptDisabler.h>
|
||||
#include <Kernel/Arch/x86/ProcessorInfo.h>
|
||||
|
@ -680,7 +681,7 @@ private:
|
|||
{
|
||||
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
||||
ErrorOr<void> result; // FIXME: Make this nicer
|
||||
PCI::enumerate([&array, &result](PCI::DeviceIdentifier const& device_identifier) {
|
||||
TRY(PCI::enumerate([&array, &result](PCI::DeviceIdentifier const& device_identifier) {
|
||||
if (result.is_error())
|
||||
return;
|
||||
result = ([&]() -> ErrorOr<void> {
|
||||
|
@ -699,7 +700,7 @@ private:
|
|||
TRY(obj.finish());
|
||||
return {};
|
||||
})();
|
||||
});
|
||||
}));
|
||||
TRY(result);
|
||||
TRY(array.finish());
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue