From 1b66b1bd7c16c2be93f8d2a5533dffb71b5072d8 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Wed, 19 Oct 2022 17:29:02 +0200 Subject: [PATCH] platform_drv: check quota before dma allocations (taken from legacy) '_env_ram' allocations can lead to 'Expanding_pd_session_client::try_alloc' quota upgrades, which in turn may lead to a resource request by the platform driver. Therefore, we check the available quota within the platform driver before allocations. This is not an optimal solution. issue #4667 related issue #3767 --- repos/os/src/drivers/platform/session_component.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/repos/os/src/drivers/platform/session_component.cc b/repos/os/src/drivers/platform/session_component.cc index 081ab14ed1..68168094fe 100644 --- a/repos/os/src/drivers/platform/session_component.cc +++ b/repos/os/src/drivers/platform/session_component.cc @@ -176,6 +176,19 @@ Session_component::alloc_dma_buffer(size_t const size, Cache cache) { Ram_dataspace_capability ram_cap { }; + /* + * Check available quota beforehand and reflect the state back + * to the client because the 'Expanding_pd_session_client' will + * ask its parent otherwise. + */ + enum { WATERMARK_CAP_QUOTA = 8, }; + if (_env.pd().avail_caps().value < WATERMARK_CAP_QUOTA) + throw Out_of_caps(); + + enum { WATERMARK_RAM_QUOTA = 4096, }; + if (_env.pd().avail_ram().value < WATERMARK_RAM_QUOTA) + throw Out_of_ram(); + try { ram_cap = _env_ram.alloc(size, cache); } catch (Ram_allocator::Denied) { }