[PATCH 02/17] tapsets: serialize visits to shared helper bodies
Aaron Merey
amerey@redhat.com
Mon Nov 23 04:14:16 GMT 2026
An @defined retry can rewrite a shared helper's return expression
while another worker scans the same body for context operators.
Serialize visits to shared bodies. Release the lock before expanding
a private clone.
WARNING: ThreadSanitizer: data race
Write of size 8 at 0xffff80015930 by thread T19:
#0 void update_visitor::replace<expression> ... staptree.h:1433
#8 var_expanding_visitor::visit_functioncall ... tapsets.cxx:4136
Previous read of size 8 at 0xffff80015930 by thread T18:
#0 traversing_visitor::visit_return_statement ... staptree.cxx:2086
#4 var_expanding_visitor::visit_functioncall ... tapsets.cxx:4034
Assisted-by: Codex <noreply@openai.com>
---
session.h | 3 +++
staptree.cxx | 1 +
tapsets.cxx | 6 ++++--
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/session.h b/session.h
index 39717b8d6..6ca6fe214 100644
--- a/session.h
+++ b/session.h
@@ -462,6 +462,9 @@ public:
// concurrent derive_probes() (files, unwindsym_modules, etc.).
std::recursive_mutex session_data_mutex;
+ // Protect shared helper bodies. Take this before session_data_mutex.
+ std::recursive_mutex function_body_mutex;
+
// resource limits
std::map<int, struct rlimit> rlimits;
int apply_rlimits ();
diff --git a/staptree.cxx b/staptree.cxx
index dcbda1d13..97784009c 100644
--- a/staptree.cxx
+++ b/staptree.cxx
@@ -2767,6 +2767,7 @@ varuse_collecting_visitor::visit_functioncall (functioncall* e)
// but function body shouldn't all be marked used
current_lvalue_read = false;
+ lock_guard<recursive_mutex> bodies (session.function_body_mutex);
functioncall_traversing_visitor::enter_functioncall(e);
current_lvalue_read = last_lvalue_read;
diff --git a/tapsets.cxx b/tapsets.cxx
index ec88f2ae9..fe8ff17e8 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -4009,8 +4009,7 @@ var_expanding_visitor::visit_functioncall (functioncall* e)
sess.symbol_resolver && // from some sort of symbol-resolution context
cur_probe) // prevent being called from semantic_pass_symbols function-only loop
{
- // Hold session_data_mutex only around table lookups/mutations so
- // parallel $$parms expand can overlap deep_copy/require work.
+ unique_lock<recursive_mutex> bodies (sess.function_body_mutex);
vector<functiondecl*> refs;
{
timed_recursive_lock gl (sess.session_data_mutex,
@@ -4083,9 +4082,11 @@ var_expanding_visitor::visit_functioncall (functioncall* e)
// deep_copy the body then process it recursively (no session lock)
nf->body = deep_copy_visitor::deep_copy(r->body);
+ bodies.unlock ();
early_resolution_in_progress.insert(r);
require (nf->body, false); // process it recursively
early_resolution_in_progress.erase(r);
+ bodies.lock ();
{
timed_recursive_lock gl (sess.session_data_mutex,
@@ -4132,6 +4133,7 @@ var_expanding_visitor::visit_functioncall (functioncall* e)
continue;
}
+ lock_guard<recursive_mutex> bodies (sess.function_body_mutex);
early_resolution_in_progress.insert(r);
require (r->body, false); // process it recursively
early_resolution_in_progress.erase(r);
--
2.56.1
More information about the Systemtap
mailing list