From 5a6c4d6ff2db965199d7063d23f3bd21bcb694e1 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 25 Jun 2024 17:14:27 +0200 Subject: [PATCH] base-hw: handle cap-slab exhaust in Thread::start This interim solution for issue #5256 solves the problem for the thread.run script. Issue #5256 --- repos/base-hw/include/hw_native_pd/client.h | 3 +++ repos/base-hw/include/hw_native_pd/hw_native_pd.h | 4 +++- repos/base-hw/src/core/native_pd_component.cc | 6 ++++++ repos/base-hw/src/core/native_pd_component.h | 1 + repos/base-hw/src/core/platform_pd.h | 2 ++ repos/base-hw/src/include/base/internal/native_env.h | 4 ++++ repos/base-hw/src/lib/base/capability_slab.cc | 6 ++++++ repos/base-hw/src/lib/base/thread_start.cc | 4 ++++ 8 files changed, 29 insertions(+), 1 deletion(-) diff --git a/repos/base-hw/include/hw_native_pd/client.h b/repos/base-hw/include/hw_native_pd/client.h index 06089c05f2..10f2c86973 100644 --- a/repos/base-hw/include/hw_native_pd/client.h +++ b/repos/base-hw/include/hw_native_pd/client.h @@ -27,6 +27,9 @@ struct Genode::Hw_native_pd_client : Rpc_client void upgrade_cap_slab() override { call(); } + + size_t avail_cap_slab() override { + return call(); } }; #endif /* _INCLUDE__HW_NATIVE_PD__CLIENT_H_ */ diff --git a/repos/base-hw/include/hw_native_pd/hw_native_pd.h b/repos/base-hw/include/hw_native_pd/hw_native_pd.h index 884344cd19..c27cdef142 100644 --- a/repos/base-hw/include/hw_native_pd/hw_native_pd.h +++ b/repos/base-hw/include/hw_native_pd/hw_native_pd.h @@ -21,6 +21,7 @@ struct Genode::Pd_session::Native_pd : Interface { virtual void upgrade_cap_slab() = 0; + virtual size_t avail_cap_slab() = 0; /********************* @@ -29,7 +30,8 @@ struct Genode::Pd_session::Native_pd : Interface GENODE_RPC_THROW(Rpc_upgrade_cap_slab, void, upgrade_cap_slab, GENODE_TYPE_LIST(Out_of_ram, Out_of_caps)); - GENODE_RPC_INTERFACE(Rpc_upgrade_cap_slab); + GENODE_RPC(Rpc_avail_cap_slab, size_t, avail_cap_slab); + GENODE_RPC_INTERFACE(Rpc_upgrade_cap_slab, Rpc_avail_cap_slab); }; #endif /* _INCLUDE__HW_NATIVE_PD__HW_NATIVE_PD_H_ */ diff --git a/repos/base-hw/src/core/native_pd_component.cc b/repos/base-hw/src/core/native_pd_component.cc index 7b8291e083..658209e340 100644 --- a/repos/base-hw/src/core/native_pd_component.cc +++ b/repos/base-hw/src/core/native_pd_component.cc @@ -23,6 +23,12 @@ void Native_pd_component::upgrade_cap_slab() } +size_t Native_pd_component::avail_cap_slab() +{ + return _pd_session._pd->avail_slab(); +} + + Native_pd_component::Native_pd_component(Pd_session_component &pd, char const *) : _pd_session(pd) diff --git a/repos/base-hw/src/core/native_pd_component.h b/repos/base-hw/src/core/native_pd_component.h index 64cc1e41c7..b5cca69601 100644 --- a/repos/base-hw/src/core/native_pd_component.h +++ b/repos/base-hw/src/core/native_pd_component.h @@ -41,6 +41,7 @@ class Core::Native_pd_component : public Rpc_object ~Native_pd_component(); void upgrade_cap_slab() override; + size_t avail_cap_slab() override; }; #endif /* _CORE__INCLUDE__NATIVE_PD_COMPONENT_H_ */ diff --git a/repos/base-hw/src/core/platform_pd.h b/repos/base-hw/src/core/platform_pd.h index 5438f069db..003756df46 100644 --- a/repos/base-hw/src/core/platform_pd.h +++ b/repos/base-hw/src/core/platform_pd.h @@ -163,6 +163,7 @@ class Core::Cap_space Cap_slab & capability_slab() { return _slab; } void upgrade_slab(Allocator &alloc); + size_t avail_slab() { return _slab.avail_entries(); } }; @@ -208,6 +209,7 @@ class Core::Platform_pd : public Hw::Address_space, private Cap_space using Cap_space::capability_slab; using Cap_space::upgrade_slab; + using Cap_space::avail_slab; /** * Bind thread to protection domain diff --git a/repos/base-hw/src/include/base/internal/native_env.h b/repos/base-hw/src/include/base/internal/native_env.h index fb2802498a..bf1a849081 100644 --- a/repos/base-hw/src/include/base/internal/native_env.h +++ b/repos/base-hw/src/include/base/internal/native_env.h @@ -14,12 +14,16 @@ #ifndef _INCLUDE__BASE__INTERNAL__NATIVE_ENV_H_ #define _INCLUDE__BASE__INTERNAL__NATIVE_ENV_H_ +#include + namespace Genode { /** * Upgrade quota of the PD session's capability slab allocator */ void upgrade_capability_slab(); + + size_t avail_capability_slab(); }; #endif /* _INCLUDE__BASE__INTERNAL__NATIVE_ENV_H_ */ diff --git a/repos/base-hw/src/lib/base/capability_slab.cc b/repos/base-hw/src/lib/base/capability_slab.cc index f28252983d..0dafd3ca1c 100644 --- a/repos/base-hw/src/lib/base/capability_slab.cc +++ b/repos/base-hw/src/lib/base/capability_slab.cc @@ -32,6 +32,12 @@ void Genode::init_cap_slab(Pd_session &pd, Parent &parent) } +size_t Genode::avail_capability_slab() +{ + return native_pd_ptr ? native_pd_ptr->avail_cap_slab() : 0UL; +} + + void Genode::upgrade_capability_slab() { if (!native_pd_ptr || !parent_ptr) { diff --git a/repos/base-hw/src/lib/base/thread_start.cc b/repos/base-hw/src/lib/base/thread_start.cc index 96150760ee..4416750504 100644 --- a/repos/base-hw/src/lib/base/thread_start.cc +++ b/repos/base-hw/src/lib/base/thread_start.cc @@ -22,6 +22,7 @@ /* base-internal includes */ #include #include +#include #include using namespace Genode; @@ -106,6 +107,9 @@ void Thread::_deinit_platform_thread() Thread::Start_result Thread::start() { + while (avail_capability_slab() < 5) + upgrade_capability_slab(); + return _thread_cap.convert( [&] (Thread_capability cap) { Cpu_thread_client cpu_thread(cap);