From 27e55dab3e92815134151588e9f984fef281ef0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Mon, 4 Oct 2021 18:01:48 +0200 Subject: [PATCH] platform_drv: check quota before allocating buffer The platform driver uses a 'Constrained_ram_allocator' to allocate meta-data on behave of a client. It uses the PD session as 'Ram_allocator' back end that in return is implemented via the 'Expanding_pd_session_client'. Whenever the PD client itselft comes into resource shortage it will ask its parent unconditionally. However, depending on the integration, such a request may be left unanswered. This commit introduces a check to prevent that situation from occurring. In case the platform driver notices the resource shortage it will reflect that back to the client. Issue #4284. --- .../platform/spec/x86/pci_session_component.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h index 733592ff01..534dfee9a2 100644 --- a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h +++ b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h @@ -822,6 +822,19 @@ class Platform::Session_component : public Rpc_object Ram_dataspace_capability alloc_dma_buffer(size_t const size, Cache cache) override { + /* + * 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(); + Ram_dataspace_capability ram_cap = _env_ram.alloc(size, cache); addr_t const dma_addr = Dataspace_client(ram_cap).phys_addr();