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
This commit is contained in:
Sebastian Sumpf 2022-10-19 17:29:02 +02:00 committed by Christian Helmuth
parent 03a142174f
commit 1b66b1bd7c

View File

@ -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) { }