[PATCH 11/17] tapsets: lock the inline function index when collecting suggestions

Aaron Merey amerey@redhat.com
Mon Nov 23 04:14:25 GMT 2026


suggest_dwarf_functions copies inline names while update_symtab
inserts into the same module's inlined_funcs set. Find the module
under the session lock and copy its names under symtab_mutex.

  WARNING: ThreadSanitizer: data race
    Read of size 8 at 0xffff7c605ce0 by thread T1:
      #2 suggest_dwarf_functions ... stl_set.h:628
    Previous write of size 8 at 0xffff7c605ce0 by thread T2
      (mutexes: write M0):
      #3 module_info::update_symtab ... tapsets.cxx:11140

Helgrind also reported the reader held no lock in this two-thread
lookup test.

  Possible data race during read of size 8 at 0x7C24808 by thread #2
  Locks held: none
  This conflicts with a previous write of size 8 by thread #3

Assisted-by: Codex <noreply@openai.com>
---
 tapsets.cxx | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tapsets.cxx b/tapsets.cxx
index 0ca618fad..ff2fd7253 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -9934,7 +9934,7 @@ suggest_dwarf_functions(systemtap_session& sess,
   if (pos != string::npos)
     func.erase(pos);
 
-  if (func.empty() || modules.empty() || sess.module_cache == NULL || sess.suppress_costly_diagnostics)
+  if (func.empty() || modules.empty() || sess.suppress_costly_diagnostics)
     return "";
 
   // PR18577: There isn't any point in generating a suggestion list if
@@ -9946,13 +9946,16 @@ suggest_dwarf_functions(systemtap_session& sess,
 
   // We must first aggregate all the functions from the cache
   set<interned_string> funcs;
-  const auto &cache = sess.module_cache->cache;
 
   for (auto itmod = modules.begin();
        itmod != modules.end(); ++itmod)
     {
       module_info *module;
 
+      unique_lock<recursive_mutex> cache_lock (sess.session_data_mutex);
+      if (!sess.module_cache)
+        return "";
+      const auto &cache = sess.module_cache->cache;
       // retrieve module_info from cache
       auto itcache = cache.find(*itmod);
       if (itcache != cache.end())
@@ -9960,6 +9963,8 @@ suggest_dwarf_functions(systemtap_session& sess,
       else // module not found
         continue;
 
+      cache_lock.unlock ();
+      lock_guard<recursive_mutex> module_lock (module->symtab_mutex);
       // add inlines
       funcs.insert(module->inlined_funcs.begin(),
                    module->inlined_funcs.end());
-- 
2.56.1



More information about the Systemtap mailing list