Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v21 08/11] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers
Date: Tue, 01 Dec 2026 14:31:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-243489@kernel.org> (raw)
In-Reply-To: <20261130020252.32126-9-mhiramat@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] tracing/wprobe: active wprobe not disabled in
  wprobe_trigger_free()
- [Medium] tracing/wprobe: missing trigger_ref check in
  enable_trace_wprobe()
--

commit b34209141a2f57610f24f8dfae5fab61ea9cb031
Author: Masami Hiramatsu (Google) <mhiramat@kernel.org>

tracing/wprobe: Add set_wprobe and clear_wprobe event triggers

This commit adds set_wprobe and clear_wprobe event triggers to dynamically
attach and detach hardware watchpoint address monitoring based on event
field values.

Link: https://lore.kernel.org/all/59637b96946653393a7ad3c7de094094796b39c2.1785067572.git.wangjinchao600@gmail.com/

> diff --git a/kernel/trace/trace_wprobe.c b/kernel/trace/trace_wprobe.c
> index 90073c9471e94..0d40082462a2d 100644
> --- a/kernel/trace/trace_wprobe.c
> +++ b/kernel/trace/trace_wprobe.c

[ ... ]

> @@ -826,9 +1015,717 @@ static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev)

[ ... ]

> +static void wprobe_trigger_free(struct event_trigger_data *data)
> +{
> +	struct wprobe_trigger_data *wprobe_data = data->private_data;
> +	struct trace_wprobe *tw = wprobe_data->tw;
> +
> +	if (WARN_ON_ONCE(data->ref <= 0))
> +		return;
> +
> +	data->ref--;
> +	if (!data->ref) {
> +		tw->trigger_ref--;
> +		if (tw->trigger_ref > 0) {
> +			/*
> +			 * Other triggers remain attached to this wprobe, so
> +			 * tw->bp_event and the event reference stay alive.
> +			 * Batch-free trigger data asynchronously via
> +			 * trigger_kthread; free_private_wprobe_trigger_data()
> +			 * does not touch tw or file.
> +			 */
> +			trace_event_enable_disable(wprobe_data->file, 0, 1);
> +			trigger_data_free(data);
> +			return;
> +		}
> +
> +		/*
> +		 * Last trigger on this wprobe: synchronize once so all
> +		 * in-flight wprobe_trigger() callbacks exit before tearing
> +		 * down tw->bp_event and releasing the dynamic event ref.
> +		 */
> +		tw->trigger_file = NULL;
> +		if (rcu_access_pointer(data->filter) && data->cmd_ops->set_filter)
> +			data->cmd_ops->set_filter(NULL, data, NULL);
> +		else if (system_state != SYSTEM_BOOTING)
> +			tracepoint_synchronize_unregister();
> +
> +		/* Remove the SOFT_MODE flag */
> +		trace_event_enable_disable(wprobe_data->file, 0, 1);
> +		trace_event_put_ref(trace_probe_event_call(&tw->tp));
> +		free_wprobe_trigger_data(wprobe_data);
> +		kfree(data);
> +	}
> +}

[Severity: High]
Does removing the last trigger after a set_wprobe trigger has fired leave
tw->bp_event armed and the wprobe event enabled?

When set_wprobe fires, wprobe_trigger() clears
EVENT_FILE_FL_SOFT_DISABLED_BIT on wprobe_data->file->flags.  If the last
trigger is removed while the watchpoint is still set,
trace_event_enable_disable(wprobe_data->file, 0, 1) decrements
file->sm_ref to 0, but __ftrace_event_enable_disable() only unregisters
the event when EVENT_FILE_FL_SOFT_DISABLED is set:

kernel/trace/trace_events.c:__ftrace_event_enable_disable() {
    ...
		if (soft_disable) {
			if (atomic_dec_return(&file->sm_ref) > 0)
				break;
			disable = file->flags & EVENT_FILE_FL_SOFT_DISABLED;
			soft_mode = false;
    ...
		if (disable && (file->flags & EVENT_FILE_FL_ENABLED)) {
    ...
}

As a result, disable_trace_wprobe() and __unregister_trace_wprobe() are
skipped, leaving tw->bp_event active in CPU debug registers on the captured
address and leaving the wprobe event hard-enabled (so deleting the wprobe
or attaching new triggers fails with -EBUSY).  Setting
EVENT_FILE_FL_SOFT_DISABLED_BIT on wprobe_data->file->flags in the final
tw->trigger_ref == 0 teardown path before trace_event_enable_disable()
would ensure the wprobe is unregistered.

> +
> +static int wprobe_trigger_cmd_parse(struct event_command *cmd_ops,
> +				    struct trace_event_file *file,
> +				    char *glob, char *cmd,
> +				    char *param_and_filter)
> +{

[ ... ]

> +	/*
> +	 * Reject attaching triggers to a manually enabled wprobe, or
> +	 * sharing one wprobe across different trace instances.
> +	 */
> +	if (!remove) {
> +		if (tw->trigger_ref) {
> +			if (tw->trigger_file != wprobe_file) {
> +				wprobe_trigger_log_err(file, orig_cmd,
> +						       event_str - glob,
> +						       WPROBE_BUSY);
> +				return -EBUSY;
> +			}
> +		} else if (trace_probe_is_enabled(&tw->tp)) {
> +			wprobe_trigger_log_err(file, orig_cmd,
> +					       event_str - glob, WPROBE_BUSY);
> +			return -EBUSY;
> +		}
> +	}

[Severity: Medium]
Can a wprobe already managed by triggers in one trace instance still be
enabled from another trace instance?

wprobe_trigger_cmd_parse() checks tw->trigger_ref and
trace_probe_is_enabled() when attaching a trigger, but
enable_trace_wprobe() does not check tw->trigger_ref.  If a user attaches a
trigger in instance A and then enables the same wprobe in instance B,
enable_trace_wprobe() links instance B's trace_event_file onto tw->tp.
When the triggers in instance A are later removed,
disable_trace_wprobe() sees !trace_probe_has_single_file(tp) and skips
__unregister_trace_wprobe(), leaving tw->addr at the trigger-modified
address instead of restoring tw->orig_addr.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130020252.32126-1-mhiramat@kernel.org?part=8

  reply	other threads:[~2026-12-01 14:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  2:02 [PATCH v21 00/11] tracing: wprobe: x86: Add wprobe for watchpoint Masami Hiramatsu (Google)
2026-11-30  2:02 ` [PATCH v21 01/11] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-11-30  2:02 ` [PATCH v21 02/11] HWBP: Add modify_local_hw_breakpoint_addr() API Masami Hiramatsu (Google)
2026-11-30  2:02 ` [PATCH v21 03/11] perf/hw_breakpoint: Add register_wide_hw_breakpoint_cpuslocked() API Masami Hiramatsu (Google)
2026-11-30  2:02 ` [PATCH v21 04/11] tracing/wprobe: Add wprobe (watchpoint probe) trace event support Masami Hiramatsu (Google)
2026-11-30  2:02 ` [PATCH v21 05/11] x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires Masami Hiramatsu (Google)
2026-12-01 14:21   ` sashiko-bot
2026-11-30  2:02 ` [PATCH v21 06/11] selftests: tracing: Add a basic testcase for wprobe Masami Hiramatsu (Google)
2026-11-30  2:02 ` [PATCH v21 07/11] selftests: tracing: Add syntax " Masami Hiramatsu (Google)
2026-11-30  2:03 ` [PATCH v21 08/11] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers Masami Hiramatsu (Google)
2026-12-01 14:31   ` sashiko-bot [this message]
2026-11-30  2:03 ` [PATCH v21 09/11] selftests: tracing: Add wprobe trigger testcases Masami Hiramatsu (Google)
2026-12-01 14:25   ` sashiko-bot
2026-11-30  2:03 ` [PATCH v21 10/11] tracing/wprobe: Support BTF typecast in fetchargs Masami Hiramatsu (Google)
2026-11-30  2:03 ` [PATCH v21 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger Masami Hiramatsu (Google)
2026-12-01 14:31 ` [PATCH v21 00/11] tracing: wprobe: x86: Add wprobe for watchpoint sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-243489@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox