* [PATCH] tracing: check field variable references before removing histograms
@ 2026-12-04 5:12 Kyuwon Cho
2026-12-04 5:34 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-04 5:12 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Mathieu Desnoyers, Tom Zanussi, linux-kernel, linux-trace-kernel
A field variable creates an auxiliary source histogram owned by its target
histogram. Another histogram can reference a variable in that auxiliary
histogram. Removing the target checks only references to the target's own
variables, then proceeds even though removal of the auxiliary histogram is
busy. Unregistering the target's field variable histogram consequently
warns and leaves a stale variable registration:
WARNING: kernel/trace/trace_events_hist.c:6379 at
unregister_field_var_hists
RIP: 0010:unregister_field_var_hists
(kernel/trace/trace_events_hist.c:6379)
Call Trace:
event_hist_trigger_free (kernel/trace/trace_events_hist.c:6400)
event_hist_trigger_parse (kernel/trace/trace_events_hist.c:6961)
trigger_process_regex (kernel/trace/trace_events_trigger.c:388)
event_trigger_write (kernel/trace/trace_events_trigger.c:418)
Keep the auxiliary histogram pointer with each field variable histogram.
Before single-trigger or file-wide removal, check its variables for
external references while excluding the owning target's expected reference.
Fixes: 02205a6752f2 ("tracing: Add support for 'field variables'")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
This issue was found by an LLM-guided test generator used in our research prototype.
A reproducer is available on request.
kernel/trace/trace_events_hist.c | 38 ++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 7f5ec9ff19e5..b581909bad98 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -558,6 +558,7 @@ struct field_var {
struct field_var_hist {
struct trace_event_file *file;
+ struct hist_trigger_data *hist_data;
char *cmd;
};
@@ -966,6 +967,7 @@ static struct hist_field *find_var_ref(struct hist_trigger_data *hist_data,
* find_any_var_ref - Check if there is a reference to a given trigger variable
* @hist_data: The hist trigger
* @var_idx: The trigger variable identifier
+ * @exclude: An additional trigger to ignore
*
* Check to see whether the given variable is currently referenced by
* any other trigger.
@@ -977,14 +979,16 @@ static struct hist_field *find_var_ref(struct hist_trigger_data *hist_data,
* Return: The VAR_REF field referencing the variable if so, NULL if not
*/
static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
- unsigned int var_idx)
+ unsigned int var_idx,
+ struct hist_trigger_data *exclude)
{
struct trace_array *tr = hist_data->event_file->tr;
struct hist_field *found = NULL;
struct hist_var_data *var_data;
list_for_each_entry(var_data, &tr->hist_vars, list) {
- if (var_data->hist_data == hist_data)
+ if (var_data->hist_data == hist_data ||
+ var_data->hist_data == exclude)
continue;
found = find_var_ref(var_data->hist_data, hist_data, var_idx);
if (found)
@@ -997,6 +1001,7 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
/**
* check_var_refs - Check if there is a reference to any of trigger's variables
* @hist_data: The hist trigger
+ * @exclude: An additional trigger to ignore
*
* A trigger can define one or more variables. If any one of them is
* currently referenced by any other trigger, this function will
@@ -1007,7 +1012,8 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
*
* Return: True if there is a reference to any of trigger's variables
*/
-static bool check_var_refs(struct hist_trigger_data *hist_data)
+static bool check_var_refs(struct hist_trigger_data *hist_data,
+ struct hist_trigger_data *exclude)
{
struct hist_field *field;
bool found = false;
@@ -1016,7 +1022,7 @@ static bool check_var_refs(struct hist_trigger_data *hist_data)
for_each_hist_field(i, hist_data) {
field = hist_data->fields[i];
if (field && field->flags & HIST_FIELD_FL_VAR) {
- if (find_any_var_ref(hist_data, field->var.idx)) {
+ if (find_any_var_ref(hist_data, field->var.idx, exclude)) {
found = true;
break;
}
@@ -1026,6 +1032,21 @@ static bool check_var_refs(struct hist_trigger_data *hist_data)
return found;
}
+static bool check_field_var_refs(struct hist_trigger_data *hist_data)
+{
+ unsigned int i;
+
+ for (i = 0; i < hist_data->n_field_var_hists; i++) {
+ if (!hist_data->field_var_hists[i]->hist_data)
+ continue;
+ if (check_var_refs(hist_data->field_var_hists[i]->hist_data,
+ hist_data))
+ return true;
+ }
+
+ return false;
+}
+
static struct hist_var_data *find_hist_vars(struct hist_trigger_data *hist_data)
{
struct trace_array *tr = hist_data->event_file->tr;
@@ -1114,7 +1135,7 @@ static void remove_hist_vars(struct hist_trigger_data *hist_data)
if (!var_data)
return;
- if (WARN_ON(check_var_refs(hist_data)))
+ if (WARN_ON(check_var_refs(hist_data, NULL)))
return;
list_del(&var_data->list);
@@ -3160,6 +3181,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data,
hist_err(tr, HIST_ERR_SYNTH_VAR_NOT_FOUND, errpos(field_name));
return ERR_PTR(-EINVAL);
}
+ var_hist->hist_data = event_var->var.hist_data;
return event_var;
}
@@ -6760,7 +6782,8 @@ static bool hist_trigger_check_refs(struct event_trigger_data *data,
if (!hist_trigger_match(data, test, named_data, false))
continue;
hist_data = test->private_data;
- if (check_var_refs(hist_data))
+ if (check_var_refs(hist_data, NULL) ||
+ check_field_var_refs(hist_data))
return true;
break;
}
@@ -6823,7 +6846,8 @@ static bool hist_file_check_refs(struct trace_event_file *file)
list_for_each_entry(test, &file->triggers, list) {
if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
hist_data = test->private_data;
- if (check_var_refs(hist_data))
+ if (check_var_refs(hist_data, NULL) ||
+ check_field_var_refs(hist_data))
return true;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] tracing: check field variable references before removing histograms
2026-12-04 5:12 [PATCH] tracing: check field variable references before removing histograms Kyuwon Cho
@ 2026-12-04 5:34 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 5:34 UTC (permalink / raw)
To: Kyuwon Cho; +Cc: linux-trace-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing: check_field_var_refs() fails to exclude sibling
auxiliary hists
--
commit 341ded2e2cce86f2db2302bd7321ebea20e6b91e
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
tracing: check field variable references before removing histograms
This commit stores each auxiliary field-variable histogram pointer in
struct field_var_hist and checks its variables for external references,
excluding the owning target histogram, before removing a histogram trigger
or truncating a trigger file.
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index d4702ad4e0036..a711bc2bf0bba 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
[ ... ]
> @@ -977,14 +979,16 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
> * Return: The VAR_REF field referencing the variable if so, NULL if not
> */
> static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
> - unsigned int var_idx)
> + unsigned int var_idx,
> + struct hist_trigger_data *exclude)
> {
> struct trace_array *tr = hist_data->event_file->tr;
> struct hist_field *found = NULL;
> struct hist_var_data *var_data;
>
> list_for_each_entry(var_data, &tr->hist_vars, list) {
> - if (var_data->hist_data == hist_data)
> + if (var_data->hist_data == hist_data ||
> + var_data->hist_data == exclude)
> continue;
> found = find_var_ref(var_data->hist_data, hist_data, var_idx);
> if (found)
[ ... ]
> @@ -1026,6 +1032,21 @@ static bool check_var_refs(struct hist_trigger_data *hist_data)
> return found;
> }
>
> +static bool check_field_var_refs(struct hist_trigger_data *hist_data)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < hist_data->n_field_var_hists; i++) {
> + if (!hist_data->field_var_hists[i]->hist_data)
> + continue;
> + if (check_var_refs(hist_data->field_var_hists[i]->hist_data,
> + hist_data))
> + return true;
> + }
> +
> + return false;
> +}
[Severity: Medium]
Can check_field_var_refs() permanently block removal of a target histogram
when one of its auxiliary field-variable histograms references a sibling
auxiliary histogram?
In a multi-parameter action such as mysynth(prio, prio+$synthetic_prio),
create_field_var_hist() creates a first auxiliary histogram defining
synthetic_prio and then a second auxiliary histogram whose expression
resolves $synthetic_prio against the first.
Because find_any_var_ref() skips only hist_data and the single exclude
pointer, the sibling reference makes removal return -EBUSY. Neither
auxiliary histogram can be removed directly while the target references
both, leaving the triggers and synthetic event stuck until reboot.
Excluding sibling entries in hist_data->field_var_hists[] and tearing them
down in reverse order in unregister_field_var_hists() would avoid this
deadlock.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179634936693.931432.2335780990204797817@skku.edu?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 5:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 5:12 [PATCH] tracing: check field variable references before removing histograms Kyuwon Cho
2026-12-04 5:34 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox