[PATCH 17/17] elaborate: read kernel configuration without inserting missing keys
Aaron Merey
amerey@redhat.com
Mon Nov 23 04:14:31 GMT 2026
Looking up a missing CONFIG_ARCH_SUPPORTS_UPROBES key with
map::operator[] inserts a node while another worker searches the same
map. Use find() for reads and return an empty value on a miss.
WARNING: ThreadSanitizer: data race
Read of size 8 at 0xffff94804528 by thread T18:
#8 std::map<...>::operator[] ... stl_map.h:556
#9 kernel_supports_inode_uprobes ... tapsets.cxx:6803
Previous write of size 8 at 0xffff94804528 by thread T17:
#2 std::map<...>::operator[] ... stl_map.h:559
Assisted-by: Codex <noreply@openai.com>
---
parse.cxx | 2 +-
session.cxx | 4 ++--
session.h | 12 +++++++++++-
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/parse.cxx b/parse.cxx
index 1d850b421..2193f8e67 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -855,7 +855,7 @@ parser::parse_library_macros ()
bool eval_pp_conditional (systemtap_session& s,
const token* l, const token* op, const token* r)
{
- lock_guard<recursive_mutex> s_lock (session_lock); // because s.kernel_config[] accesses etc. might mutate
+ lock_guard<recursive_mutex> s_lock (session_lock);
if (l->type == tok_identifier && (l->content == "kernel_v" ||
l->content == "kernel_vr" ||
diff --git a/session.cxx b/session.cxx
index b175d0cff..564b7ea02 100644
--- a/session.cxx
+++ b/session.cxx
@@ -2140,12 +2140,12 @@ systemtap_session::parse_kernel_config ()
if (off == string::npos) continue;
string key = line.substr(0, off);
string value = line.substr(off+1, string::npos);
- kernel_config[key] = value;
+ kernel_config.values[key] = value;
}
if (verbose > 2)
clog << _F("Parsed kernel \"%s\", ", kernel_config_file.c_str())
<< _NF("containing %zu tuple", "containing %zu tuples",
- kernel_config.size(), kernel_config.size()) << endl;
+ kernel_config.values.size(), kernel_config.values.size()) << endl;
kcf.close();
diff --git a/session.h b/session.h
index 6ca6fe214..beb0f642e 100644
--- a/session.h
+++ b/session.h
@@ -194,7 +194,17 @@ public:
std::string kernel_build_tree;
std::string kernel_source_tree;
std::vector<std::string> kernel_extra_cflags;
- std::map<interned_string,interned_string> kernel_config;
+ struct kernel_configuration
+ {
+ std::map<interned_string,interned_string> values;
+
+ const interned_string& operator[] (const interned_string& key) const
+ {
+ static const interned_string empty;
+ auto it = values.find (key);
+ return it == values.end () ? empty : it->second;
+ }
+ } kernel_config;
std::set<interned_string> kernel_exports;
std::set<interned_string> kernel_functions;
int parse_kernel_config ();
--
2.56.1
More information about the Systemtap
mailing list