From c8b4b83b71caefc65279cf57733e9b1d9986d4ec Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 12 Sep 2022 16:55:18 +0200 Subject: [PATCH] base-linux: inhibit tracing in region-map attach/detach Tracing must be inhibited in attach/detach as RPC trace points may trigger attachment of trace dataspaces, which would result in nested mutex acquisition. This prevents errors in test-trace_logger like follows. [init -> depot_autopilot] 0.140 [init -> dynamic_rom] Error: deadlock ahead, mutex=0x500e6f00, return ip=0x50053ed7 Fixes #4607 --- .../src/lib/base/region_map_mmap.cc | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/repos/base-linux/src/lib/base/region_map_mmap.cc b/repos/base-linux/src/lib/base/region_map_mmap.cc index 01946e4204..46b34ae66b 100644 --- a/repos/base-linux/src/lib/base/region_map_mmap.cc +++ b/repos/base-linux/src/lib/base/region_map_mmap.cc @@ -172,6 +172,24 @@ void Region_map_mmap::_add_to_rmap(Region const ®ion) } +/* + * Tracing must be inhibited in attach/detach as RPC trace points may trigger + * attachment of trace dataspaces, which would result in nested mutex + * acquisition. + */ + +namespace Genode { extern bool inhibit_tracing; } + +struct Inhibit_tracing_guard +{ + bool old_value = inhibit_tracing; + + Inhibit_tracing_guard() { inhibit_tracing = true; } + + ~Inhibit_tracing_guard() { inhibit_tracing = old_value; } +}; + + Region_map::Local_addr Region_map_mmap::attach(Dataspace_capability ds, size_t size, off_t offset, bool use_local_addr, @@ -180,6 +198,8 @@ Region_map::Local_addr Region_map_mmap::attach(Dataspace_capability ds, { Mutex::Guard mutex_guard(mutex()); + Inhibit_tracing_guard it_guard { }; + /* only support attach_at for sub RM sessions */ if (_sub_rm && !use_local_addr) { error("Region_map_mmap::attach: attaching w/o local addr not supported"); @@ -325,6 +345,8 @@ void Region_map_mmap::detach(Region_map::Local_addr local_addr) { Mutex::Guard mutex_guard(mutex()); + Inhibit_tracing_guard it_guard { }; + /* * Cases *