Skip to contentSkip to conversation

tracing: wprobe: Add wprobe for watchpoint

RFC PATCH Superseded Masami Hiramatsu (Google) 3 participants 16 messages Sep 1, 2025 – Sep 10, 2025

Subsystems (5)

v1 of 20 Superseded Latest is v20 →

lore
Share & tools
lore

Masami Hiramatsu (Google)

author maintainer
#0 lore raw

cover tracing: wprobe: Add wprobe for watchpoint

Hi,

Here is an RFC series for adding new wprobe (watch probe) which provides memory access tracing event. Moreover, this can be used via event trigger. Thus it can trace memory access on a dynamically allocated objects too.

In this version, I reuse Jinchao's arch_reinstall_hw_breakpoint() patch[1].

[1] https://lore.kernel.org/all/[email protected]/

The basic usage of this wprobe is similar to other probes;

w:[GRP/][EVENT] [r|w|rw]@<ADDRESS|SYMBOL[+OFFS]> [FETCHARGS]

This defines a new wprobe event. For example, to trace jiffies update, you can do;

echo 'w:my_jiffies w@jiffies:8 value=+0($addr)' >> dynamic_events echo 1 > events/wprobes/my_jiffies/enable

Moreover, this can be combined with event trigger to trace the memory accecss on slab objects. The trigger syntax is;

set_wprobe:WPROBE_EVENT:FIELD[+ADJUST]
clear_wprobe:WPROBE_EVENT

For example, trace the first 8 byte of the dentry data structure passed to do_truncate() until it is deleted by __dentry_kill(). (Note: all tracefs setup uses '>>' so that it does not kick do_truncate())

  # echo 'w:watch rw@0:8 address=$addr value=+0($addr)' > dynamic_events
  # echo 'f:truncate do_truncate dentry=$arg2' >> dynamic_events
  # echo 'set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
  # echo 'f:dentry_kill __dentry_kill dentry=$arg1' >> dynamic_events
  # echo 'clear_wprobe:watch' >> events/fprobes/dentry_kill/trigger
  # echo 1 >> events/fprobes/truncate/enable
  # echo 1 >> events/fprobes/dentry_kill/enable
  # echo aaa > /tmp/hoge
  # echo bbb > /tmp/hoge
  # echo ccc > /tmp/hoge
  # rm /tmp/hoge

Then, the trace data will show;

# tracer: nop
#
# entries-in-buffer/entries-written: 16/16 #P:8
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched

#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| / _-=> migrate-disable
#                              |||| /     delay
#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
#    [    7.026136] sh (113) used greatest stack depth: 12912 bytes left
          | |         |   |||||     |         |
              sh-113     [002] .....     7.024402: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
              sh-113     [002] ..Zff     7.024822: watch: (lookup_fast+0xaa/0x150) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024830: watch: (step_into+0x82/0x360) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024834: watch: (step_into+0x9f/0x360) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024839: watch: (path_openat+0xb3a/0xe70) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024843: watch: (path_openat+0xb9a/0xe70) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] .....     7.024847: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
              sh-113     [002] ...1.     7.025364: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888006919380
              sh-113     [002] ...1.     7.025511: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069195f0
              rm-118     [003] ...1.     7.027543: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069194b8
              sh-113     [002] ...2.     7.027825: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880044429c0
              sh-113     [002] ...2.     7.027833: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888004442270

Thank you,

---

Jinchao Wang (1):
x86/HWBP: introduce arch_reinstall_hw_breakpoint() for atomic context

Masami Hiramatsu (Google) (5):
tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
HWBP: Add modify_wide_hw_breakpoint_local() API
tracing: wprobe: Add wprobe event trigger
selftests: tracing: Add a basic testcase for wprobe
selftests: tracing: Add syntax testcase for wprobe

 Documentation/trace/index.rst                      |    1 
 Documentation/trace/wprobetrace.rst                |  129 ++
 arch/Kconfig                                       |   10 
 arch/x86/Kconfig                                   |    1 
 arch/x86/include/asm/hw_breakpoint.h               |    3 
 arch/x86/kernel/hw_breakpoint.c                    |   61 +
 include/linux/hw_breakpoint.h                      |    6 
 include/linux/trace_events.h                       |    3 
 kernel/events/hw_breakpoint.c                      |   36 +
 kernel/trace/Kconfig                               |   24 
 kernel/trace/Makefile                              |    1 
 kernel/trace/trace.c                               |    9 
 kernel/trace/trace.h                               |    5 
 kernel/trace/trace_probe.c                         |   20 
 kernel/trace/trace_probe.h                         |    8 
 kernel/trace/trace_wprobe.c                        | 1111 ++++++++++++++++++++
 .../ftrace/test.d/dynevent/add_remove_wprobe.tc    |   68 +
 .../test.d/dynevent/wprobes_syntax_errors.tc       |   20 
 18 files changed, 1513 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/trace/wprobetrace.rst
 create mode 100644 kernel/trace/trace_wprobe.c
 create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc

--
Masami Hiramatsu (Google) <[email protected]>

author maintainer
#1 lore raw

RFC PATCH 1/6 tracing: wprobe: Add watchpoint probe event based on hardware breakpoint

From: Masami Hiramatsu (Google) <[email protected]>

Add a new probe event for the hardware breakpoint called wprobe-event. This wprobe allows user to trace (watch) the memory access at the specified memory address.
The new syntax is;

w[:[GROUP/]EVENT] [r|w|rw]@[ADDR|SYM][:SIZE] [FETCH_ARGs]

User also can use $addr to fetch the accessed address. But no other variables are supported. To record updated value, use '+0($addr)'.

For example, tracing updates of the jiffies;

/sys/kernel/tracing # echo 'w:my_jiffies w@jiffies' >> dynamic_events /sys/kernel/tracing # cat dynamic_events w:wprobes/my_jiffies w@jiffies:4
/sys/kernel/tracing # echo 1 > events/wprobes/my_jiffies/enable /sys/kernel/tracing # head -n 20 trace | tail -n 5

 #           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
 #              | |         |   |||||     |         |
          <idle>-0       [000] d.Z1.   206.547317: my_jiffies: (tick_do_update_jiffies64+0xbe/0x130)
          <idle>-0       [000] d.Z1.   206.548341: my_jiffies: (tick_do_update_jiffies64+0xbe/0x130)
          <idle>-0       [000] d.Z1.   206.549346: my_jiffies: (tick_do_update_jiffies64+0xbe/0x130)
---
 Documentation/trace/index.rst       |    1 
 Documentation/trace/wprobetrace.rst |   69 ++++
 include/linux/trace_events.h        |    2 
 kernel/trace/Kconfig                |   14 +
 kernel/trace/Makefile               |    1 
 kernel/trace/trace.c                |    9 
 kernel/trace/trace.h                |    5 
 kernel/trace/trace_probe.c          |   20 +
 kernel/trace/trace_probe.h          |    8 
 kernel/trace/trace_wprobe.c         |  685 +++++++++++++++++++++++++++++++++++
 10 files changed, 811 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/trace/wprobetrace.rst
 create mode 100644 kernel/trace/trace_wprobe.c
Documentation/trace/index.rst +1 -0
index b4a429dc4f7a..14de6858ae1b 100644
@@ -36,6 +36,7 @@ the Linux kernel.
    kprobes
    kprobetrace
    fprobetrace
+   wprobetrace
    eprobetrace
    fprobe
    ring-buffer-design
Documentation/trace/wprobetrace.rst new file +69 -0

69 lines not on this page · raw message

include/linux/trace_events.h +2 -0
index 04307a19cde3..7c65f2f73ff4 100644
@@ -324,6 +324,7 @@ enum {
 	TRACE_EVENT_FL_UPROBE_BIT,
 	TRACE_EVENT_FL_EPROBE_BIT,
 	TRACE_EVENT_FL_FPROBE_BIT,
+	TRACE_EVENT_FL_WPROBE_BIT,
 	TRACE_EVENT_FL_CUSTOM_BIT,
 	TRACE_EVENT_FL_TEST_STR_BIT,
 };
@@ -354,6 +355,7 @@ enum {
 	TRACE_EVENT_FL_UPROBE		= (1 << TRACE_EVENT_FL_UPROBE_BIT),
 	TRACE_EVENT_FL_EPROBE		= (1 << TRACE_EVENT_FL_EPROBE_BIT),
 	TRACE_EVENT_FL_FPROBE		= (1 << TRACE_EVENT_FL_FPROBE_BIT),
+	TRACE_EVENT_FL_WPROBE		= (1 << TRACE_EVENT_FL_WPROBE_BIT),
 	TRACE_EVENT_FL_CUSTOM		= (1 << TRACE_EVENT_FL_CUSTOM_BIT),
 	TRACE_EVENT_FL_TEST_STR		= (1 << TRACE_EVENT_FL_TEST_STR_BIT),
 };
kernel/trace/Kconfig +14 -0
index d2c79da81e4f..dd8919386425 100644
@@ -807,6 +807,20 @@ config EPROBE_EVENTS
 	  convert the type of an event field. For example, turn an
 	  address into a string.
 
+config WPROBE_EVENTS
+	bool "Enable wprobe-based dynamic events"
+	depends on TRACING
+	depends on HAVE_HW_BREAKPOINT
+	select PROBE_EVENTS
+	select DYNAMIC_EVENTS
+	default y
+	help
+	  This allows the user to add watchpoint tracing events based on
+	  hardware breakpoints on the fly via the ftrace interface.
+
+	  Those events can be inserted wherever hardware breakpoints can be
+	  set, and record various register and memory values.
+
 config BPF_EVENTS
 	depends on BPF_SYSCALL
 	depends on (KPROBE_EVENTS || UPROBE_EVENTS) && PERF_EVENTS
kernel/trace/Makefile +1 -0
index dcb4e02afc5f..1d57bb36c5fc 100644
@@ -106,6 +106,7 @@ obj-$(CONFIG_FTRACE_RECORD_RECURSION) += trace_recursion_record.o
 obj-$(CONFIG_FPROBE) += fprobe.o
 obj-$(CONFIG_RETHOOK) += rethook.o
 obj-$(CONFIG_FPROBE_EVENTS) += trace_fprobe.o
+obj-$(CONFIG_WPROBE_EVENTS) += trace_wprobe.o
 
 obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o
 obj-$(CONFIG_RV) += rv/
kernel/trace/trace.c +8 -1
index 4283ed4e8f59..ac2fc6d768ad 100644
@@ -5506,8 +5506,12 @@ static const char readme_msg[] =
 	"  uprobe_events\t\t- Create/append/remove/show the userspace dynamic events\n"
 	"\t\t\t  Write into this file to define/undefine new trace events.\n"
 #endif
+#ifdef CONFIG_WPROBE_EVENTS
+	"  wprobe_events\t\t- Create/append/remove/show the hardware breakpoint dynamic events\n"
+	"\t\t\t  Write into this file to define/undefine new trace events.\n"
+#endif
 #if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS) || \
-    defined(CONFIG_FPROBE_EVENTS)
+    defined(CONFIG_FPROBE_EVENTS) || defined(CONFIG_WPROBE_EVENTS)
 	"\t  accepts: event-definitions (one definition per line)\n"
 #if defined(CONFIG_KPROBE_EVENTS) || defined(CONFIG_UPROBE_EVENTS)
 	"\t   Format: p[:[<group>/][<event>]] <place> [<args>]\n"
@@ -5517,6 +5521,9 @@ static const char readme_msg[] =
 	"\t           f[:[<group>/][<event>]] <func-name>[%return] [<args>]\n"
 	"\t           t[:[<group>/][<event>]] <tracepoint> [<args>]\n"
 #endif
+#ifdef CONFIG_WPROBE_EVENTS
+	"\t           w[:[<group>/][<event>]] [r|w|rw]@<addr>[:<len>]\n"
+#endif
 #ifdef CONFIG_HIST_TRIGGERS
 	"\t           s:[synthetic/]<event> <field> [<field>]\n"
 #endif
kernel/trace/trace.h +5 -0
index 1dbf1d3cf2f1..ae175ddc3f58 100644
@@ -173,6 +173,11 @@ struct fexit_trace_entry_head {
 	unsigned long		ret_ip;
 };
 
+struct wprobe_trace_entry_head {
+	struct trace_entry	ent;
+	unsigned long		ip;
+};
+
 #define TRACE_BUF_SIZE		1024
 
 struct trace_array;
kernel/trace/trace_probe.c +19 -1
index 5b92376a58fc..ef500c373f3c 100644
@@ -968,6 +968,24 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t,
 		goto inval;
 	}
 
+	/* wprobe only support "$addr" and "$value" variable */
+	if (ctx->flags & TPARG_FL_WPROBE) {
+		if (!strcmp(arg, "addr")) {
+			code->op = FETCH_OP_BADDR;
+			return 0;
+		}
+		if (!strcmp(arg, "value")) {
+			code->op = FETCH_OP_BADDR;
+			code++;
+			code->op = FETCH_OP_DEREF;
+			code->offset = 0;
+			*pcode = code;
+			return 0;
+		}
+		err = TP_ERR_BAD_VAR;
+		goto inval;
+	}
+
 	if (str_has_prefix(arg, "retval")) {
 		if (!(ctx->flags & TPARG_FL_RETURN)) {
 			err = TP_ERR_RETVAL_ON_PROBE;
@@ -1098,7 +1116,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
 		break;
 
 	case '%':	/* named register */
-		if (ctx->flags & (TPARG_FL_TEVENT | TPARG_FL_FPROBE)) {
+		if (ctx->flags & (TPARG_FL_TEVENT | TPARG_FL_FPROBE | TPARG_FL_WPROBE)) {
 			/* eprobe and fprobe do not handle registers */
 			trace_probe_log_err(ctx->offset, BAD_VAR);
 			break;
kernel/trace/trace_probe.h +7 -1
index 76bf2dee8071..13c9dbc4d0e2 100644
@@ -89,6 +89,7 @@ enum fetch_op {
 	FETCH_OP_STACK,		/* Stack : .param = index */
 	FETCH_OP_STACKP,	/* Stack pointer */
 	FETCH_OP_RETVAL,	/* Return value */
+	FETCH_OP_BADDR,		/* Break address */
 	FETCH_OP_IMM,		/* Immediate : .immediate */
 	FETCH_OP_COMM,		/* Current comm */
 	FETCH_OP_ARG,		/* Function argument : .param */
@@ -396,6 +397,7 @@ static inline int traceprobe_get_entry_data_size(struct trace_probe *tp)
 #define TPARG_FL_USER   BIT(4)
 #define TPARG_FL_FPROBE BIT(5)
 #define TPARG_FL_TPOINT BIT(6)
+#define TPARG_FL_WPROBE BIT(7)
 #define TPARG_FL_LOC_MASK	GENMASK(4, 0)
 
 static inline bool tparg_is_function_entry(unsigned int flags)
@@ -556,7 +558,11 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
 	C(BAD_TYPE4STR,		"This type does not fit for string."),\
 	C(NEED_STRING_TYPE,	"$comm and immediate-string only accepts string type"),\
 	C(TOO_MANY_ARGS,	"Too many arguments are specified"),	\
-	C(TOO_MANY_EARGS,	"Too many entry arguments specified"),
+	C(TOO_MANY_EARGS,	"Too many entry arguments specified"),	\
+	C(BAD_ACCESS_FMT,	"Access memory address requires @"),	\
+	C(BAD_ACCESS_TYPE,	"Bad memory access type"),	\
+	C(BAD_ACCESS_LEN,	"This memory access length is not supported"), \
+	C(BAD_ACCESS_ADDR,	"Invalid access memory address"),
 
 #undef C
 #define C(a, b)		TP_ERR_##a
kernel/trace/trace_wprobe.c new file +685 -0

685 lines not on this page · raw message

author maintainer
#4 lore raw

RFC PATCH 2/6 x86/HWBP: introduce arch_reinstall_hw_breakpoint() for atomic context

In reply to Masami Hiramatsu (Google)

From: Jinchao Wang <[email protected]>

Introduce arch_reinstall_hw_breakpoint() to update hardware breakpoint parameters (address, length, type) without freeing and reallocating the debug register slot.

This allows atomic updates in contexts where memory allocation is not permitted, such as kprobe handlers.

---
 arch/x86/include/asm/hw_breakpoint.h |    1 +
 arch/x86/kernel/hw_breakpoint.c      |   50 ++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
arch/x86/include/asm/hw_breakpoint.h +1 -0
index 0bc931cd0698..bb7c70ad22fe 100644
@@ -59,6 +59,7 @@ extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
 
 
 int arch_install_hw_breakpoint(struct perf_event *bp);
+int arch_reinstall_hw_breakpoint(struct perf_event *bp);
 void arch_uninstall_hw_breakpoint(struct perf_event *bp);
 void hw_breakpoint_pmu_read(struct perf_event *bp);
 void hw_breakpoint_pmu_unthrottle(struct perf_event *bp);
arch/x86/kernel/hw_breakpoint.c +50 -0

56 lines not on this page · raw message

author maintainer
#5 lore raw

RFC PATCH 3/6 HWBP: Add modify_wide_hw_breakpoint_local() API

In reply to Masami Hiramatsu (Google)

From: Masami Hiramatsu (Google) <[email protected]>

Add modify_wide_hw_breakpoint_local() arch-wide interface which allows hwbp users to update watch address on-line. This is available if the arch supports CONFIG_HAVE_REINSTALL_HW_BREAKPOINT.
Note that this can not change the type because it does not release and reserve the hwbp slot based on type.

---
 arch/Kconfig                         |   10 +++++++++
 arch/x86/Kconfig                     |    1 +
 arch/x86/include/asm/hw_breakpoint.h |    2 ++
 arch/x86/kernel/hw_breakpoint.c      |   11 ++++++++++
 include/linux/hw_breakpoint.h        |    6 ++++++
 kernel/events/hw_breakpoint.c        |   36 ++++++++++++++++++++++++++++++++++
 6 files changed, 66 insertions(+)
arch/Kconfig +10 -0
index d1b4ffd6e085..e4787fc814df 100644
@@ -418,6 +418,16 @@ config HAVE_MIXED_BREAKPOINTS_REGS
 	  Select this option if your arch implements breakpoints under the
 	  latter fashion.
 
+config HAVE_REINSTALL_HW_BREAKPOINT
+	bool
+	depends on HAVE_HW_BREAKPOINT
+	help
+	  Depending on the arch implementation of hardware breakpoints,
+	  some of them are able to update the breakpoint configuration
+	  without release and reserve the hardware breakpoint register.
+	  What configuration is able to update depends on hardware and
+	  software implementation.
+
 config HAVE_USER_RETURN_NOTIFIER
 	bool
 
arch/x86/Kconfig +1 -0
index 58d890fe2100..49d4ce2af94c 100644
@@ -247,6 +247,7 @@ config X86
 	select HAVE_FUNCTION_TRACER
 	select HAVE_GCC_PLUGINS
 	select HAVE_HW_BREAKPOINT
+	select HAVE_REINSTALL_HW_BREAKPOINT
 	select HAVE_IOREMAP_PROT
 	select HAVE_IRQ_EXIT_ON_IRQ_STACK	if X86_64
 	select HAVE_IRQ_TIME_ACCOUNTING
arch/x86/include/asm/hw_breakpoint.h +2 -0
index bb7c70ad22fe..b3db25eb613f 100644
@@ -64,6 +64,8 @@ void arch_uninstall_hw_breakpoint(struct perf_event *bp);
 void hw_breakpoint_pmu_read(struct perf_event *bp);
 void hw_breakpoint_pmu_unthrottle(struct perf_event *bp);
 
+bool hw_breakpoint_arch_same_type(struct arch_hw_breakpoint *hw,
+				  struct perf_event_attr *attr);
 extern void
 arch_fill_perf_breakpoint(struct perf_event *bp);
 
arch/x86/kernel/hw_breakpoint.c +11 -0
index 89135229ed21..7dfc88ff6cd9 100644
@@ -278,6 +278,17 @@ int arch_bp_generic_fields(int x86_len, int x86_type,
 	return 0;
 }
 
+bool hw_breakpoint_arch_same_type(struct arch_hw_breakpoint *hw,
+				  struct perf_event_attr *attr)
+{
+	int glen, gtype;
+
+	if (arch_bp_generic_fields(hw->len, hw->type, &glen, &gtype) < 0)
+		return false;
+
+	return gtype == attr->bp_type;
+}
+
 /*
  * Check for virtual address in kernel space.
  */
include/linux/hw_breakpoint.h +6 -0
index db199d653dd1..ea373f2587f8 100644
@@ -81,6 +81,9 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,
 			    perf_overflow_handler_t triggered,
 			    void *context);
 
+extern int modify_wide_hw_breakpoint_local(struct perf_event *bp,
+					   struct perf_event_attr *attr);
+
 extern int register_perf_hw_breakpoint(struct perf_event *bp);
 extern void unregister_hw_breakpoint(struct perf_event *bp);
 extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
@@ -124,6 +127,9 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,
 			    perf_overflow_handler_t triggered,
 			    void *context)		{ return NULL; }
 static inline int
+modify_wide_hw_breakpoint_local(struct perf_event *bp,
+				struct perf_event_attr *attr) { return -ENOSYS; }
+static inline int
 register_perf_hw_breakpoint(struct perf_event *bp)	{ return -ENOSYS; }
 static inline void unregister_hw_breakpoint(struct perf_event *bp)	{ }
 static inline void
kernel/events/hw_breakpoint.c +36 -0
index 8ec2cb688903..473a5b76941d 100644
@@ -887,6 +887,42 @@ void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events)
 }
 EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint);
 
+/**
+ * modify_wide_hw_breakpoint_local - update breakpoint config for local cpu
+ * @bp: the hwbp perf event for this cpu
+ * @attr: the new attribute for @bp
+ *
+ * This does not release and reserve the slot of HWBP, just reuse the current
+ * slot on local CPU. So the users must update the other CPUs by themselves.
+ * Also, since this does not release/reserve the slot, this can not change the
+ * type of the HWBP.
+ * Return err if attr is invalid or the cpu fails to update debug register
+ * for new @attr.
+ */
+#ifdef CONFIG_HAVE_REINSTALL_HW_BREAKPOINT
+int modify_wide_hw_breakpoint_local(struct perf_event *bp,
+				    struct perf_event_attr *attr)
+{
+	int ret;
+
+	if (!hw_breakpoint_arch_same_type(counter_arch_bp(bp), attr))
+		return -EINVAL;
+
+	ret = hw_breakpoint_arch_parse(bp, attr, counter_arch_bp(bp));
+	if (ret)
+		return ret;
+
+	return arch_reinstall_hw_breakpoint(bp);
+}
+#else
+int modify_wide_hw_breakpoint_local(struct perf_event *bp,
+				    struct perf_event_attr *attr)
+{
+	return -EOPNOTSUPP;
+}
+#endif
+EXPORT_SYMBOL_GPL(modify_wide_hw_breakpoint_local);
+
 /**
  * hw_breakpoint_is_used - check if breakpoints are currently used
  *
author maintainer
#6 lore raw

RFC PATCH 4/6 tracing: wprobe: Add wprobe event trigger

In reply to Masami Hiramatsu (Google)

From: Masami Hiramatsu (Google) <[email protected]>

Add wprobe event trigger to set and clear the watch event dynamically. This allows us to set an watchpoint on a given local variables and a slab object instead of static objects.

The trigger syntax is below;

set_wprobe:WPROBE:FIELD[+offset] [if FILTER]
clear_wprobe:WPROBE

As you can see, this only sets the address of wprobe, not changing type and length. That should be set when a new wprobe is created. Also, the WPROBE event must be disabled when setting the new trigger and it will be busy afterwards. Recommended usage is to add a new wprobe at NULL address and keep disabled.

---
 Documentation/trace/wprobetrace.rst |   60 +++++
 include/linux/trace_events.h        |    1 
 kernel/trace/Kconfig                |   10 +
 kernel/trace/trace_wprobe.c         |  426 +++++++++++++++++++++++++++++++++++
 4 files changed, 497 insertions(+)
Documentation/trace/wprobetrace.rst +60 -0
index 9774f57e2947..67dbf2566289 100644
@@ -67,3 +67,63 @@ Here is an example to add a wprobe event on a variable `jiffies`.
            <idle>-0       [000] d.Z1.  717.026373: my_jiffies: (tick_do_update_jiffies64+0xbe/0x130)
 
 You can see the code which writes to `jiffies` is `do_timer()`.
+
+Combination with trigger action
+-------------------------------
+The event trigger action can extend the utilization of this wprobe.
+
+- set_wprobe:WPEVENT:FIELD[+|-ADJUST]
+- clear_wprobe:WPEVENT
+
+Set these triggers to the target event, then the WPROBE event will be
+setup to trace the memory access at FIELD[+|-ADJUST] address.
+
+For example, trace the first 8 byte of the dentry data structure passed
+to do_truncate() until it is deleted by __dentry_kill().
+(Note: all tracefs setup uses '>>' so that it does not kick do_truncate())
+
+  # echo 'w:watch rw@0:8 address=$addr value=+0($addr)' > dynamic_events
+
+  # echo 'f:truncate do_truncate dentry=$arg2' >> dynamic_events
+  # echo 'set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
+
+  # echo 'f:dentry_kill __dentry_kill dentry=$arg1' >> dynamic_events
+  # echo 'clear_wprobe:watch' >> events/fprobes/dentry_kill/trigger
+
+  # echo 1 >> events/fprobes/truncate/enable
+  # echo 1 >> events/fprobes/dentry_kill/enable
+
+  # echo aaa > /tmp/hoge
+  # echo bbb > /tmp/hoge
+  # echo ccc > /tmp/hoge
+  # rm /tmp/hoge
+
+Then, the trace data will show;
+
+# tracer: nop
+#
+# entries-in-buffer/entries-written: 16/16   #P:8
+#
+#                                _-----=> irqs-off/BH-disabled
+#                               / _----=> need-resched
+#                              | / _---=> hardirq/softirq
+#                              || / _--=> preempt-depth
+#                              ||| / _-=> migrate-disable
+#                              |||| /     delay
+#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
+#    [    7.026136] sh (113) used greatest stack depth: 12912 bytes left
+          | |         |   |||||     |         |
+              sh-113     [002] .....     7.024402: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
+              sh-113     [002] ..Zff     7.024822: watch: (lookup_fast+0xaa/0x150) address=0xffff8880069194b8 value=0x200008
+              sh-113     [002] ..Zff     7.024830: watch: (step_into+0x82/0x360) address=0xffff8880069194b8 value=0x200008
+              sh-113     [002] ..Zff     7.024834: watch: (step_into+0x9f/0x360) address=0xffff8880069194b8 value=0x200008
+              sh-113     [002] ..Zff     7.024839: watch: (path_openat+0xb3a/0xe70) address=0xffff8880069194b8 value=0x200008
+              sh-113     [002] ..Zff     7.024843: watch: (path_openat+0xb9a/0xe70) address=0xffff8880069194b8 value=0x200008
+              sh-113     [002] .....     7.024847: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
+              sh-113     [002] ...1.     7.025364: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888006919380
+              sh-113     [002] ...1.     7.025511: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069195f0
+              rm-118     [003] ...1.     7.027543: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069194b8
+              sh-113     [002] ...2.     7.027825: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880044429c0
+              sh-113     [002] ...2.     7.027833: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888004442270
+
+You can see the watch event is correctly configured on the dentry.
include/linux/trace_events.h +1 -0
index 7c65f2f73ff4..6517c5d7e03e 100644
@@ -720,6 +720,7 @@ enum event_trigger_type {
 	ETT_EVENT_HIST		= (1 << 4),
 	ETT_HIST_ENABLE		= (1 << 5),
 	ETT_EVENT_EPROBE	= (1 << 6),
+	ETT_EVENT_WPROBE	= (1 << 7),
 };
 
 extern int filter_match_preds(struct event_filter *filter, void *rec);
kernel/trace/Kconfig +10 -0
index dd8919386425..7396191ccb4d 100644
@@ -821,6 +821,16 @@ config WPROBE_EVENTS
 	  Those events can be inserted wherever hardware breakpoints can be
 	  set, and record various register and memory values.
 
+config WPROBE_TRIGGERS
+	bool "Enable an event trigger for wprobe"
+	depends on WPROBE_EVENTS
+	depends on HAVE_REINSTALL_HW_BREAKPOINT
+	default y
+	help
+	  This adds an event trigger which will set the wprobe on a specific
+	  field of an event. This allows user to trace the memory access of
+	  an address pointed by the event field.
+
 config BPF_EVENTS
 	depends on BPF_SYSCALL
 	depends on (KPROBE_EVENTS || UPROBE_EVENTS) && PERF_EVENTS
kernel/trace/trace_wprobe.c +426 -0

453 lines not on this page · raw message

author maintainer
#9 lore raw

RFC PATCH 5/6 selftests: tracing: Add a basic testcase for wprobe

In reply to Masami Hiramatsu (Google)

From: Masami Hiramatsu (Google) <[email protected]>

Add 'add_remove_wprobe.tc' testcase for testing wprobe event that tests adding and removing operations of the wprobe event.

---
 .../ftrace/test.d/dynevent/add_remove_wprobe.tc    |   68 ++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc new file +68 -0
new file mode 100644
index 000000000000..20774c7f69f8
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Generic dynamic event - add/remove wprobe events
+# requires: dynamic_events "w[:[<group>/][<event>]] [r|w|rw]@<addr>[:<len>]":README
+
+echo 0 > events/enable
+echo > dynamic_events
+
+# Use jiffies as a variable that is frequently written to.
+TARGET=jiffies
+
+echo "w:my_wprobe w@$TARGET" >> dynamic_events
+
+grep -q my_wprobe dynamic_events
+if [ $? -ne 0 ]; then
+    echo "Failed to create wprobe event"
+    exit_fail
+fi
+
+test -d events/wprobes/my_wprobe
+if [ $? -ne 0 ]; then
+    echo "Failed to create wprobe event directory"
+    exit_fail
+fi
+
+echo 1 > events/wprobes/my_wprobe/enable
+
+# Check if the event is enabled
+cat events/wprobes/my_wprobe/enable | grep -q 1
+if [ $? -ne 0 ]; then
+    echo "Failed to enable wprobe event"
+    exit_fail
+fi
+
+# Let some time pass to trigger the breakpoint
+sleep 1
+
+# Check if we got any trace output
+if !grep -q my_wprobe trace; then
+    echo "wprobe event was not triggered"
+fi
+
+echo 0 > events/wprobes/my_wprobe/enable
+
+# Check if the event is disabled
+cat events/wprobes/my_wprobe/enable | grep -q 0
+if [ $? -ne 0 ]; then
+    echo "Failed to disable wprobe event"
+    exit_fail
+fi
+
+echo "-:my_wprobe" >> dynamic_events
+
+! grep -q my_wprobe dynamic_events
+if [ $? -ne 0 ]; then
+    echo "Failed to remove wprobe event"
+    exit_fail
+fi
+
+! test -d events/wprobes/my_wprobe
+if [ $? -ne 0 ]; then
+    echo "Failed to remove wprobe event directory"
+    exit_fail
+fi
+
+clear_trace
+
+exit 0
author maintainer
#10 lore raw

RFC PATCH 6/6 selftests: tracing: Add syntax testcase for wprobe

In reply to Masami Hiramatsu (Google)

From: Masami Hiramatsu (Google) <[email protected]>

Add "wprobe_syntax_errors.tc" testcase for testing syntax errors of the watch probe events.

---
 .../test.d/dynevent/wprobes_syntax_errors.tc       |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc
tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc new file +20 -0
new file mode 100644
index 000000000000..82a273d9efb4
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Watch probe event parser error log check
+# requires: dynamic_events "w[:[<group>/][<event>]] [r|w|rw]@<addr>[:<len>]":README
+
+check_error() { # command-with-error-pos-by-^
+    ftrace_errlog_check 'event_probe' "$1" 'dynamic_events'
+}
+
+check_error 'w ^symbol'			# BAD_ACCESS_FMT
+check_error 'w ^a@symbol'		# BAD_ACCESS_TYPE
+check_error 'w w@^symbol'		# BAD_ACCESS_ADDR
+check_error 'w w@^jiffies+offset'	# BAD_ACCESS_ADDR
+check_error 'w w@jiffies:^100'		# BAD_ACCESS_LEN
+check_error 'w w@jiffies ^$arg1'	# BAD_VAR
+check_error 'w w@jiffies ^$retval'	# BAD_VAR
+check_error 'w w@jiffies ^$stack'	# BAD_VAR
+check_error 'w w@jiffies ^%ax'		# BAD_VAR
+
+exit 0
#2 lore raw

Re: [RFC PATCH 1/6] tracing: wprobe: Add watchpoint probe event based on hardware breakpoint

In reply to Masami Hiramatsu (Google)
kernel test robot noticed the following build errors:

Hi Masami,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on trace/for-next]
[also build test ERROR on tip/x86/core perf-tools-next/perf-tools-next tip/perf/core perf-tools/perf-tools peterz-queue/sched/core linus/master v6.17-rc4 next-20250902] [cannot apply to acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masami-Hiramatsu-Google/tracing-wprobe-Add-watchpoint-probe-event-based-on-hardware-breakpoint/20250901-225207
base:   https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next
patch link:    https://lore.kernel.org/r/175673788575.478080.17611922836391707019.stgit%40devnote2
patch subject: [RFC PATCH 1/6] tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
config: i386-buildonly-randconfig-001-20250902 (https://download.01.org/0day-ci/archive/20250902/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250902/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> kernel/trace/trace_wprobe.c:562:20: error: use of undeclared identifier '__free_trace_probe_log_clear'; did you mean 'trace_probe_log_clear'?
     562 |         const char *tplog __free(trace_probe_log_clear) = NULL;
         |                           ^
   include/linux/cleanup.h:213:33: note: expanded from macro '__free'
     213 | #define __free(_name)   __cleanup(__free_##_name)
         |                                   ^
   <scratch space>:55:1: note: expanded from here
      55 | __free_trace_probe_log_clear
         | ^
   kernel/trace/trace_probe.h:584:6: note: 'trace_probe_log_clear' declared here
     584 | void trace_probe_log_clear(void);
         |      ^
>> kernel/trace/trace_wprobe.c:562:20: error: 'cleanup' function 'trace_probe_log_clear' must take 1 parameter
     562 |         const char *tplog __free(trace_probe_log_clear) = NULL;
         |                           ^
   include/linux/cleanup.h:213:33: note: expanded from macro '__free'
     213 | #define __free(_name)   __cleanup(__free_##_name)
         |                                   ^
   <scratch space>:55:1: note: expanded from here
      55 | __free_trace_probe_log_clear
         | ^
>> kernel/trace/trace_wprobe.c:574:8: error: assigning to 'const char *' from incompatible type 'void'
     574 |         tplog = trace_probe_log_init("wprobe", argc, argv);
         |               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3 errors generated.

vim +562 kernel/trace/trace_wprobe.c

549
550 static int __trace_wprobe_create(int argc, const char *argv[])
551 {
552 /*
553 * Argument syntax:
554 * b[:[GRP/][EVENT]] SPEC
555 *
556 * SPEC:
557 * [r|w|rw]@[ADDR|SYMBOL[+OFFS]][:LEN]
558 */
559 struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) = NULL;
560 struct trace_wprobe *tw __free(free_trace_wprobe) = NULL;
561 const char *event = NULL, *group = WPROBE_EVENT_SYSTEM;

 > 562		const char *tplog __free(trace_probe_log_clear) = NULL;
   563		char *symbol = NULL;
   564		unsigned long addr;
   565		int len, type, i;
   566		int ret = 0;
   567	
   568		if (argv[0][0] != 'w')
   569			return -ECANCELED;
   570	
   571		if (argc < 2)
   572			return -EINVAL;
   573	
 > 574		tplog = trace_probe_log_init("wprobe", argc, argv);

575
576 if (argv[0][1] != '\0') {
577 if (argv[0][1] != ':') {
578 trace_probe_log_set_index(0);
579 trace_probe_log_err(1, BAD_MAXACT_TYPE);
580 /* Invalid format */
581 return -EINVAL;
582 }
583 event = &argv[0][2];
584 }
585
586 trace_probe_log_set_index(1);
587 ret = parse_address_spec(argv[1], &addr, &type, &len, &symbol);
588 if (ret < 0)
589 return ret;
590
591 if (!event)
592 event = symbol ? symbol : "wprobe";
593
594 argc -= 2; argv += 2;
595 tw = alloc_trace_wprobe(group, event, symbol, addr, len, type, argc);
596 if (IS_ERR(tw))
597 return PTR_ERR(tw);
598
599 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
600 if (!ctx)
601 return -ENOMEM;
602
603 ctx->flags = TPARG_FL_KERNEL | TPARG_FL_WPROBE;
604
605 /* parse arguments */
606 for (i = 0; i < argc; i++) {
607 trace_probe_log_set_index(i + 2);
608 ctx->offset = 0;
609 ret = traceprobe_parse_probe_arg(&tw->tp, i, argv[i], ctx);
610 if (ret)
611 return ret; /* This can be -ENOMEM */
612 }
613
614 ret = traceprobe_set_print_fmt(&tw->tp, PROBE_PRINT_NORMAL);
615 if (ret < 0)
616 return ret;
617
618 ret = register_trace_wprobe_event(tw);
619 if (!ret)
620 tw = NULL; /* To avoid free */
621
622 return ret;
623 }
624

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

Re: [RFC PATCH 4/6] tracing: wprobe: Add wprobe event trigger

In reply to Masami Hiramatsu (Google)
kernel test robot noticed the following build warnings:

Hi Masami,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on trace/for-next]
[also build test WARNING on tip/x86/core perf-tools-next/perf-tools-next tip/perf/core perf-tools/perf-tools peterz-queue/sched/core linus/master v6.17-rc4 next-20250902] [cannot apply to acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masami-Hiramatsu-Google/tracing-wprobe-Add-watchpoint-probe-event-based-on-hardware-breakpoint/20250901-225207
base:   https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next
patch link:    https://lore.kernel.org/r/175673791934.478080.13510585438052558733.stgit%40devnote2
patch subject: [RFC PATCH 4/6] tracing: wprobe: Add wprobe event trigger
config: arm64-randconfig-001-20250902 (https://download.01.org/0day-ci/archive/20250902/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250902/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

kernel/trace/trace_wprobe.c: In function '__trace_wprobe_create':
kernel/trace/trace_wprobe.c:573:2: error: cleanup argument not a function

     const char *tplog __free(trace_probe_log_clear) = NULL;
     ^~~~~
   kernel/trace/trace_wprobe.c:585:8: error: void value not ignored as it ought to be
     tplog = trace_probe_log_init("wprobe", argc, argv);
           ^
   kernel/trace/trace_wprobe.c:573:14: warning: variable 'tplog' set but not used [-Wunused-but-set-variable]
     const char *tplog __free(trace_probe_log_clear) = NULL;
                 ^~~~~
   At top level:
>> kernel/trace/trace_wprobe.c:60:27: warning: 'trace_wprobe_local_perf' defined but not used [-Wunused-function]

static struct perf_event *trace_wprobe_local_perf(struct trace_wprobe *tw)
^~~~~~~~~~~~~~~~~~~~~~~

vim +/trace_wprobe_local_perf +60 kernel/trace/trace_wprobe.c

58
59 /* This must be called under cpu locked (e.g. preempt off, irq off) */

  > 60	static struct perf_event *trace_wprobe_local_perf(struct trace_wprobe *tw)
    61	{
    62		return *this_cpu_ptr(tw->bp_event);
    63	}
    64	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#3 lore raw

Re: [RFC PATCH 1/6] tracing: wprobe: Add watchpoint probe event based on hardware breakpoint

In reply to kernel test robot
Quoted 25 lines · On Tue, 2 Sep 2025 16:58:21 +0800 kernel test robot <[email protected]> wrote:

Hi Masami,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on trace/for-next]
[also build test ERROR on tip/x86/core perf-tools-next/perf-tools-next tip/perf/core perf-tools/perf-tools peterz-queue/sched/core linus/master v6.17-rc4 next-20250902] [cannot apply to acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masami-Hiramatsu-Google/tracing-wprobe-Add-watchpoint-probe-event-based-on-hardware-breakpoint/20250901-225207
base:   https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next
patch link:    https://lore.kernel.org/r/175673788575.478080.17611922836391707019.stgit%40devnote2
patch subject: [RFC PATCH 1/6] tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
config: i386-buildonly-randconfig-001-20250902 (https://download.01.org/0day-ci/archive/20250902/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250902/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 4 lines

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

kernel/trace/trace_wprobe.c:562:20: error: use of undeclared identifier '__free_trace_probe_log_clear'; did you mean 'trace_probe_log_clear'?

     562 |         const char *tplog __free(trace_probe_log_clear) = NULL;

Oops, this series is based on probes/for-next, which already merged [1] which provides this free function. Sorry for confusion.

[1] https://lore.kernel.org/all/175509538609.193596.16646724647358218778.stgit@devnote2/

Quoted 107 lines

| ^
include/linux/cleanup.h:213:33: note: expanded from macro '__free'

     213 | #define __free(_name)   __cleanup(__free_##_name)
         |                                   ^
   <scratch space>:55:1: note: expanded from here
      55 | __free_trace_probe_log_clear
         | ^
   kernel/trace/trace_probe.h:584:6: note: 'trace_probe_log_clear' declared here
     584 | void trace_probe_log_clear(void);
         |      ^
Quoted 1 line
Quoted 1 line

kernel/trace/trace_wprobe.c:562:20: error: 'cleanup' function 'trace_probe_log_clear' must take 1 parameter

     562 |         const char *tplog __free(trace_probe_log_clear) = NULL;
         |                           ^
   include/linux/cleanup.h:213:33: note: expanded from macro '__free'
     213 | #define __free(_name)   __cleanup(__free_##_name)
         |                                   ^
   <scratch space>:55:1: note: expanded from here
      55 | __free_trace_probe_log_clear
         | ^
Quoted 1 line
Quoted 1 line

kernel/trace/trace_wprobe.c:574:8: error: assigning to 'const char *' from incompatible type 'void'

     574 |         tplog = trace_probe_log_init("wprobe", argc, argv);
         |               ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3 errors generated.

vim +562 kernel/trace/trace_wprobe.c

   549	
   550	static int __trace_wprobe_create(int argc, const char *argv[])
   551	{
   552		/*
   553		 * Argument syntax:
   554		 *  b[:[GRP/][EVENT]] SPEC
   555		 *
   556		 * SPEC:
   557		 *  [r|w|rw]@[ADDR|SYMBOL[+OFFS]][:LEN]
   558		 */
   559		struct traceprobe_parse_context *ctx __free(traceprobe_parse_context) = NULL;
   560		struct trace_wprobe *tw __free(free_trace_wprobe) = NULL;
   561		const char *event = NULL, *group = WPROBE_EVENT_SYSTEM;
Quoted 1 line

562 const char *tplog __free(trace_probe_log_clear) = NULL;

   563		char *symbol = NULL;
   564		unsigned long addr;
   565		int len, type, i;
   566		int ret = 0;
   567	
   568		if (argv[0][0] != 'w')
   569			return -ECANCELED;
   570	
   571		if (argc < 2)
   572			return -EINVAL;
   573	
Quoted 1 line

574 tplog = trace_probe_log_init("wprobe", argc, argv);

575

   576		if (argv[0][1] != '\0') {
   577			if (argv[0][1] != ':') {
   578				trace_probe_log_set_index(0);
   579				trace_probe_log_err(1, BAD_MAXACT_TYPE);
   580				/* Invalid format */
   581				return -EINVAL;
   582			}
   583			event = &argv[0][2];
   584		}
   585	
   586		trace_probe_log_set_index(1);
   587		ret = parse_address_spec(argv[1], &addr, &type, &len, &symbol);
   588		if (ret < 0)
   589			return ret;
   590	
   591		if (!event)
   592			event = symbol ? symbol : "wprobe";
   593	
   594		argc -= 2; argv += 2;
   595		tw = alloc_trace_wprobe(group, event, symbol, addr, len, type, argc);
   596		if (IS_ERR(tw))
   597			return PTR_ERR(tw);
   598	
   599		ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
   600		if (!ctx)
   601			return -ENOMEM;
   602	
   603		ctx->flags = TPARG_FL_KERNEL | TPARG_FL_WPROBE;
   604	
   605		/* parse arguments */
   606		for (i = 0; i < argc; i++) {
   607			trace_probe_log_set_index(i + 2);
   608			ctx->offset = 0;
   609			ret = traceprobe_parse_probe_arg(&tw->tp, i, argv[i], ctx);
   610			if (ret)
   611				return ret;	/* This can be -ENOMEM */
   612		}
   613	
   614		ret = traceprobe_set_print_fmt(&tw->tp, PROBE_PRINT_NORMAL);
   615		if (ret < 0)
   616			return ret;
   617	
   618		ret = register_trace_wprobe_event(tw);
   619		if (!ret)
   620			tw = NULL; /* To avoid free */
   621	
   622		return ret;
   623	}
   624	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author maintainer
#8 lore raw

Re: [RFC PATCH 4/6] tracing: wprobe: Add wprobe event trigger

In reply to kernel test robot
Quoted 38 lines · On Tue, 2 Sep 2025 19:34:30 +0800 kernel test robot <[email protected]> wrote:

Hi Masami,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on trace/for-next]
[also build test WARNING on tip/x86/core perf-tools-next/perf-tools-next tip/perf/core perf-tools/perf-tools peterz-queue/sched/core linus/master v6.17-rc4 next-20250902] [cannot apply to acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masami-Hiramatsu-Google/tracing-wprobe-Add-watchpoint-probe-event-based-on-hardware-breakpoint/20250901-225207
base:   https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next
patch link:    https://lore.kernel.org/r/175673791934.478080.13510585438052558733.stgit%40devnote2
patch subject: [RFC PATCH 4/6] tracing: wprobe: Add wprobe event trigger
config: arm64-randconfig-001-20250902 (https://download.01.org/0day-ci/archive/20250902/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250902/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

   kernel/trace/trace_wprobe.c: In function '__trace_wprobe_create':
   kernel/trace/trace_wprobe.c:573:2: error: cleanup argument not a function
     const char *tplog __free(trace_probe_log_clear) = NULL;
     ^~~~~
   kernel/trace/trace_wprobe.c:585:8: error: void value not ignored as it ought to be
     tplog = trace_probe_log_init("wprobe", argc, argv);
           ^
   kernel/trace/trace_wprobe.c:573:14: warning: variable 'tplog' set but not used [-Wunused-but-set-variable]
     const char *tplog __free(trace_probe_log_clear) = NULL;
                 ^~~~~
   At top level:
Quoted 3 lines
Quoted 1 line
Quoted 1 line

kernel/trace/trace_wprobe.c:60:27: warning: 'trace_wprobe_local_perf' defined but not used [-Wunused-function]

static struct perf_event *trace_wprobe_local_perf(struct trace_wprobe *tw)
^~~~~~~~~~~~~~~~~~~~~~~

Indeed, CONFIG_WPROBE_TRIGGERS=n, it is not used. This is a real problem in this version.

Thanks.

Quoted 15 lines

vim +/trace_wprobe_local_perf +60 kernel/trace/trace_wprobe.c

58
59 /* This must be called under cpu locked (e.g. preempt off, irq off) */

Quoted 1 line

60 static struct perf_event *trace_wprobe_local_perf(struct trace_wprobe *tw)

    61	{
    62		return *this_cpu_ptr(tw->bp_event);
    63	}
    64	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author maintainer
#11 lore raw
In reply to Masami Hiramatsu (Google)

(Adding Jinchao)

Quoted 6 lines · On Mon, 1 Sep 2025 23:44:35 +0900 "Masami Hiramatsu (Google)"…

Hi,

Here is an RFC series for adding new wprobe (watch probe) which provides memory access tracing event. Moreover, this can be used via event trigger. Thus it can trace memory access on a dynamically allocated objects too.

BTW, this series is on the top of probes/for-next branch in the linux-trace tree.

Thanks,

Quoted 112 lines

In this version, I reuse Jinchao's arch_reinstall_hw_breakpoint() patch[1].

[1] https://lore.kernel.org/all/[email protected]/

The basic usage of this wprobe is similar to other probes;

w:[GRP/][EVENT] [r|w|rw]@<ADDRESS|SYMBOL[+OFFS]> [FETCHARGS]

This defines a new wprobe event. For example, to trace jiffies update, you can do;

echo 'w:my_jiffies w@jiffies:8 value=+0($addr)' >> dynamic_events echo 1 > events/wprobes/my_jiffies/enable

Moreover, this can be combined with event trigger to trace the memory accecss on slab objects. The trigger syntax is;

set_wprobe:WPROBE_EVENT:FIELD[+ADJUST]
clear_wprobe:WPROBE_EVENT

For example, trace the first 8 byte of the dentry data structure passed to do_truncate() until it is deleted by __dentry_kill(). (Note: all tracefs setup uses '>>' so that it does not kick do_truncate())

  # echo 'w:watch rw@0:8 address=$addr value=+0($addr)' > dynamic_events
  # echo 'f:truncate do_truncate dentry=$arg2' >> dynamic_events
  # echo 'set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
  # echo 'f:dentry_kill __dentry_kill dentry=$arg1' >> dynamic_events
  # echo 'clear_wprobe:watch' >> events/fprobes/dentry_kill/trigger
  # echo 1 >> events/fprobes/truncate/enable
  # echo 1 >> events/fprobes/dentry_kill/enable
  # echo aaa > /tmp/hoge
  # echo bbb > /tmp/hoge
  # echo ccc > /tmp/hoge
  # rm /tmp/hoge

Then, the trace data will show;

# tracer: nop
#
# entries-in-buffer/entries-written: 16/16 #P:8
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched

#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| / _-=> migrate-disable
#                              |||| /     delay
#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
#    [    7.026136] sh (113) used greatest stack depth: 12912 bytes left
          | |         |   |||||     |         |
              sh-113     [002] .....     7.024402: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
              sh-113     [002] ..Zff     7.024822: watch: (lookup_fast+0xaa/0x150) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024830: watch: (step_into+0x82/0x360) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024834: watch: (step_into+0x9f/0x360) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024839: watch: (path_openat+0xb3a/0xe70) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] ..Zff     7.024843: watch: (path_openat+0xb9a/0xe70) address=0xffff8880069194b8 value=0x200008
              sh-113     [002] .....     7.024847: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
              sh-113     [002] ...1.     7.025364: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888006919380
              sh-113     [002] ...1.     7.025511: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069195f0
              rm-118     [003] ...1.     7.027543: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069194b8
              sh-113     [002] ...2.     7.027825: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880044429c0
              sh-113     [002] ...2.     7.027833: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888004442270

Thank you,

---

Jinchao Wang (1):
x86/HWBP: introduce arch_reinstall_hw_breakpoint() for atomic context

Masami Hiramatsu (Google) (5):
tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
HWBP: Add modify_wide_hw_breakpoint_local() API
tracing: wprobe: Add wprobe event trigger
selftests: tracing: Add a basic testcase for wprobe
selftests: tracing: Add syntax testcase for wprobe

 Documentation/trace/index.rst                      |    1 
 Documentation/trace/wprobetrace.rst                |  129 ++
 arch/Kconfig                                       |   10 
 arch/x86/Kconfig                                   |    1 
 arch/x86/include/asm/hw_breakpoint.h               |    3 
 arch/x86/kernel/hw_breakpoint.c                    |   61 +
 include/linux/hw_breakpoint.h                      |    6 
 include/linux/trace_events.h                       |    3 
 kernel/events/hw_breakpoint.c                      |   36 +
 kernel/trace/Kconfig                               |   24 
 kernel/trace/Makefile                              |    1 
 kernel/trace/trace.c                               |    9 
 kernel/trace/trace.h                               |    5 
 kernel/trace/trace_probe.c                         |   20 
 kernel/trace/trace_probe.h                         |    8 
 kernel/trace/trace_wprobe.c                        | 1111 ++++++++++++++++++++
 .../ftrace/test.d/dynevent/add_remove_wprobe.tc    |   68 +
 .../test.d/dynevent/wprobes_syntax_errors.tc       |   20 
 18 files changed, 1513 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/trace/wprobetrace.rst
 create mode 100644 kernel/trace/trace_wprobe.c
 create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc

--
Masami Hiramatsu (Google) <[email protected]>

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#12 lore raw
Quoted 7 lines · Masami Hiramatsu (Google)

(Adding Jinchao)

Quoted 2 lines · On Mon, 1 Sep 2025 23:44:35 +0900 "Masami Hiramatsu (Google)"…

Hi,

Quoted 8 lines
Quoted 4 lines

Here is an RFC series for adding new wprobe (watch probe) which provides memory access tracing event. Moreover, this can be used via event trigger. Thus it can trace memory access on a dynamically allocated objects too.

BTW, this series is on the top of probes/for-next branch in the linux-trace tree.

Hi, Masami

Thanks for including me. I only received the cover letter, so I'm providing my feedback here:

- trigger_data issue:
it appears that the instance being removed is not the same as the one that was originally set.

- the function call issue:
trace_wprobe_update_local() is called twice, once in the trigger callback and again in wprobe_work_func.

I also noticed that the Watchpoint probe and KStackWatch implementations share very similar logic for managing hardware breakpoints/watchpoints (hwbp/watch):
- watch_init(unsigned long &place_holder)
- watch_on(struct perf_event_attr *attr)
- watch_off() (or reset to the place_holder value)
- watch_uninit()

Their primary difference lies in their handler functions, specifically the perf_overflow_handler_t triggered callback.

I believe we could work together to unify this logic. I am open to either approach: I can refactor my watch.c, or you can introduce new helpers. This would help us save duplicated work and review time.

Quoted 116 lines

Thanks,

Quoted 112 lines

In this version, I reuse Jinchao's arch_reinstall_hw_breakpoint() patch[1].

[1] https://lore.kernel.org/all/[email protected]/

The basic usage of this wprobe is similar to other probes;

   w:[GRP/][EVENT] [r|w|rw]@<ADDRESS|SYMBOL[+OFFS]> [FETCHARGS]

This defines a new wprobe event. For example, to trace jiffies update, you can do;

echo 'w:my_jiffies w@jiffies:8 value=+0($addr)' >> dynamic_events echo 1 > events/wprobes/my_jiffies/enable

Moreover, this can be combined with event trigger to trace the memory accecss on slab objects. The trigger syntax is;

set_wprobe:WPROBE_EVENT:FIELD[+ADJUST]
clear_wprobe:WPROBE_EVENT

For example, trace the first 8 byte of the dentry data structure passed to do_truncate() until it is deleted by __dentry_kill(). (Note: all tracefs setup uses '>>' so that it does not kick do_truncate())

   # echo 'w:watch rw@0:8 address=$addr value=+0($addr)' > dynamic_events
   # echo 'f:truncate do_truncate dentry=$arg2' >> dynamic_events
   # echo 'set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
   # echo 'f:dentry_kill __dentry_kill dentry=$arg1' >> dynamic_events
   # echo 'clear_wprobe:watch' >> events/fprobes/dentry_kill/trigger
   # echo 1 >> events/fprobes/truncate/enable
   # echo 1 >> events/fprobes/dentry_kill/enable
   # echo aaa > /tmp/hoge
   # echo bbb > /tmp/hoge
   # echo ccc > /tmp/hoge
   # rm /tmp/hoge

Then, the trace data will show;

# tracer: nop
#
# entries-in-buffer/entries-written: 16/16 #P:8
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched

#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| / _-=> migrate-disable
#                              |||| /     delay
#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
#    [    7.026136] sh (113) used greatest stack depth: 12912 bytes left
           | |         |   |||||     |         |
               sh-113     [002] .....     7.024402: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
               sh-113     [002] ..Zff     7.024822: watch: (lookup_fast+0xaa/0x150) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024830: watch: (step_into+0x82/0x360) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024834: watch: (step_into+0x9f/0x360) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024839: watch: (path_openat+0xb3a/0xe70) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024843: watch: (path_openat+0xb9a/0xe70) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] .....     7.024847: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
               sh-113     [002] ...1.     7.025364: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888006919380
               sh-113     [002] ...1.     7.025511: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069195f0
               rm-118     [003] ...1.     7.027543: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069194b8
               sh-113     [002] ...2.     7.027825: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880044429c0
               sh-113     [002] ...2.     7.027833: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888004442270

Thank you,

---

Jinchao Wang (1):
x86/HWBP: introduce arch_reinstall_hw_breakpoint() for atomic context

Masami Hiramatsu (Google) (5):
tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
HWBP: Add modify_wide_hw_breakpoint_local() API
tracing: wprobe: Add wprobe event trigger
selftests: tracing: Add a basic testcase for wprobe
selftests: tracing: Add syntax testcase for wprobe

  Documentation/trace/index.rst                      |    1
  Documentation/trace/wprobetrace.rst                |  129 ++
  arch/Kconfig                                       |   10
  arch/x86/Kconfig                                   |    1
  arch/x86/include/asm/hw_breakpoint.h               |    3
  arch/x86/kernel/hw_breakpoint.c                    |   61 +
  include/linux/hw_breakpoint.h                      |    6
  include/linux/trace_events.h                       |    3
  kernel/events/hw_breakpoint.c                      |   36 +
  kernel/trace/Kconfig                               |   24
  kernel/trace/Makefile                              |    1
  kernel/trace/trace.c                               |    9
  kernel/trace/trace.h                               |    5
  kernel/trace/trace_probe.c                         |   20
  kernel/trace/trace_probe.h                         |    8
  kernel/trace/trace_wprobe.c                        | 1111 ++++++++++++++++++++
  .../ftrace/test.d/dynevent/add_remove_wprobe.tc    |   68 +
  .../test.d/dynevent/wprobes_syntax_errors.tc       |   20
  18 files changed, 1513 insertions(+), 3 deletions(-)

create mode 100644 Documentation/trace/wprobetrace.rst
create mode 100644 kernel/trace/trace_wprobe.c
create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc

--
Masami Hiramatsu (Google) <[email protected]>

Signature · 2 lines
Best regards,
Jinchao
author maintainer
#13 lore raw
Quoted 13 lines · On Thu, 4 Sep 2025 14:35:33 +0800 Jinchao Wang <[email protected]> wrote:
Quoted 12 lines · Masami Hiramatsu (Google)

(Adding Jinchao)

Quoted 6 lines · On Mon, 1 Sep 2025 23:44:35 +0900 "Masami Hiramatsu (Google)"…

Hi,

Here is an RFC series for adding new wprobe (watch probe) which provides memory access tracing event. Moreover, this can be used via event trigger. Thus it can trace memory access on a dynamically allocated objects too.

Quoted 8 lines
Quoted 3 lines

BTW, this series is on the top of probes/for-next branch in the linux-trace tree.

Hi, Masami

Thanks for including me. I only received the cover letter, so I'm providing my feedback here:

Thanks for your feedback! I'll send v2.

Quoted 4 lines

- trigger_data issue:
it appears that the instance being removed is not the same as the one that was originally set.

Did you mean it will free invalid struct event_trigger_data by wprobe_trigger_free(), or hw_breakpoint instance?

When trace_event_enable_disable(wprobe_data->file, 1, 1) at wprobe_trigger_cmd_parse(), the trace_wprobe is enabled == call enable_trace_wprobe(), which eventually call register_wide_hw_breakpoint() with dummy address. IOW, the (wide)hw_breakpoint is allocated here.

When the trigger is hit, modify_wide_hw_breakpoint_local() is called for updating local target address on the same hw_breakpoint. So latter instance should be the same.

Quoted 4 lines

- the function call issue:
trace_wprobe_update_local() is called twice, once in the trigger callback and again in wprobe_work_func.

Yes, I found it can happen. Maybe I need a cpumask to skip the first one.

Quoted 7 lines

I also noticed that the Watchpoint probe and KStackWatch implementations share very similar logic for managing hardware breakpoints/watchpoints (hwbp/watch):
- watch_init(unsigned long &place_holder)
- watch_on(struct perf_event_attr *attr)
- watch_off() (or reset to the place_holder value)
- watch_uninit()

Hmm, I agree that we are using hwbp in a similar way but I think current interface is enough.

Quoted 7 lines

Their primary difference lies in their handler functions, specifically the perf_overflow_handler_t triggered callback.

I believe we could work together to unify this logic. I am open to either approach: I can refactor my watch.c, or you can introduce new helpers. This would help us save duplicated work and review time.

I'm not sure what you mean. Is there any concern to use the same (current hwbp) interfaces?

Thank you,

Quoted 122 lines
Quoted 117 lines

Thanks,

Quoted 112 lines

In this version, I reuse Jinchao's arch_reinstall_hw_breakpoint() patch[1].

[1] https://lore.kernel.org/all/[email protected]/

The basic usage of this wprobe is similar to other probes;

   w:[GRP/][EVENT] [r|w|rw]@<ADDRESS|SYMBOL[+OFFS]> [FETCHARGS]

This defines a new wprobe event. For example, to trace jiffies update, you can do;

echo 'w:my_jiffies w@jiffies:8 value=+0($addr)' >> dynamic_events echo 1 > events/wprobes/my_jiffies/enable

Moreover, this can be combined with event trigger to trace the memory accecss on slab objects. The trigger syntax is;

set_wprobe:WPROBE_EVENT:FIELD[+ADJUST]
clear_wprobe:WPROBE_EVENT

For example, trace the first 8 byte of the dentry data structure passed to do_truncate() until it is deleted by __dentry_kill(). (Note: all tracefs setup uses '>>' so that it does not kick do_truncate())

   # echo 'w:watch rw@0:8 address=$addr value=+0($addr)' > dynamic_events
   # echo 'f:truncate do_truncate dentry=$arg2' >> dynamic_events
   # echo 'set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
   # echo 'f:dentry_kill __dentry_kill dentry=$arg1' >> dynamic_events
   # echo 'clear_wprobe:watch' >> events/fprobes/dentry_kill/trigger
   # echo 1 >> events/fprobes/truncate/enable
   # echo 1 >> events/fprobes/dentry_kill/enable
   # echo aaa > /tmp/hoge
   # echo bbb > /tmp/hoge
   # echo ccc > /tmp/hoge
   # rm /tmp/hoge

Then, the trace data will show;

# tracer: nop
#
# entries-in-buffer/entries-written: 16/16 #P:8
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched

#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| / _-=> migrate-disable
#                              |||| /     delay
#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
#    [    7.026136] sh (113) used greatest stack depth: 12912 bytes left
           | |         |   |||||     |         |
               sh-113     [002] .....     7.024402: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
               sh-113     [002] ..Zff     7.024822: watch: (lookup_fast+0xaa/0x150) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024830: watch: (step_into+0x82/0x360) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024834: watch: (step_into+0x9f/0x360) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024839: watch: (path_openat+0xb3a/0xe70) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] ..Zff     7.024843: watch: (path_openat+0xb9a/0xe70) address=0xffff8880069194b8 value=0x200008
               sh-113     [002] .....     7.024847: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
               sh-113     [002] ...1.     7.025364: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888006919380
               sh-113     [002] ...1.     7.025511: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069195f0
               rm-118     [003] ...1.     7.027543: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069194b8
               sh-113     [002] ...2.     7.027825: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880044429c0
               sh-113     [002] ...2.     7.027833: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888004442270

Thank you,

---

Jinchao Wang (1):
x86/HWBP: introduce arch_reinstall_hw_breakpoint() for atomic context

Masami Hiramatsu (Google) (5):
tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
HWBP: Add modify_wide_hw_breakpoint_local() API
tracing: wprobe: Add wprobe event trigger
selftests: tracing: Add a basic testcase for wprobe
selftests: tracing: Add syntax testcase for wprobe

  Documentation/trace/index.rst                      |    1
  Documentation/trace/wprobetrace.rst                |  129 ++
  arch/Kconfig                                       |   10
  arch/x86/Kconfig                                   |    1
  arch/x86/include/asm/hw_breakpoint.h               |    3
  arch/x86/kernel/hw_breakpoint.c                    |   61 +
  include/linux/hw_breakpoint.h                      |    6
  include/linux/trace_events.h                       |    3
  kernel/events/hw_breakpoint.c                      |   36 +
  kernel/trace/Kconfig                               |   24
  kernel/trace/Makefile                              |    1
  kernel/trace/trace.c                               |    9
  kernel/trace/trace.h                               |    5
  kernel/trace/trace_probe.c                         |   20
  kernel/trace/trace_probe.h                         |    8
  kernel/trace/trace_wprobe.c                        | 1111 ++++++++++++++++++++
  .../ftrace/test.d/dynevent/add_remove_wprobe.tc    |   68 +
  .../test.d/dynevent/wprobes_syntax_errors.tc       |   20
  18 files changed, 1513 insertions(+), 3 deletions(-)

create mode 100644 Documentation/trace/wprobetrace.rst
create mode 100644 kernel/trace/trace_wprobe.c
create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc

--
Masami Hiramatsu (Google) <[email protected]>

Signature · 2 lines
Best regards,
Jinchao
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#14 lore raw
Quoted 35 lines · Masami Hiramatsu (Google)
Quoted 13 lines · On Thu, 4 Sep 2025 14:35:33 +0800 Jinchao Wang <[email protected]> wrote:
Quoted 12 lines · Masami Hiramatsu (Google)

(Adding Jinchao)

Quoted 6 lines · On Mon, 1 Sep 2025 23:44:35 +0900 "Masami Hiramatsu (Google)"…

Hi,

Here is an RFC series for adding new wprobe (watch probe) which provides memory access tracing event. Moreover, this can be used via event trigger. Thus it can trace memory access on a dynamically allocated objects too.

Quoted 8 lines
Quoted 3 lines

BTW, this series is on the top of probes/for-next branch in the linux-trace tree.

Hi, Masami

Thanks for including me. I only received the cover letter, so I'm providing my feedback here:

Thanks for your feedback! I'll send v2.

Quoted 4 lines

- trigger_data issue:
it appears that the instance being removed is not the same as the one that was originally set.

Did you mean it will free invalid struct event_trigger_data by wprobe_trigger_free(), or hw_breakpoint instance?

Quoted 8 lines

When trace_event_enable_disable(wprobe_data->file, 1, 1) at wprobe_trigger_cmd_parse(), the trace_wprobe is enabled == call enable_trace_wprobe(), which eventually call register_wide_hw_breakpoint() with dummy address. IOW, the (wide)hw_breakpoint is allocated here.

When the trigger is hit, modify_wide_hw_breakpoint_local() is called for updating local target address on the same hw_breakpoint. So latter instance should be the same.

In wprobe_trigger_cmd_parse(), consider removing:
echo '!set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
The trigger_data passed to event_trigger_unregister() is freshly allocated.

Quoted 23 lines
Quoted 5 lines

- the function call issue:
trace_wprobe_update_local() is called twice, once in the trigger callback and again in wprobe_work_func.

Yes, I found it can happen. Maybe I need a cpumask to skip the first one.

Quoted 7 lines

I also noticed that the Watchpoint probe and KStackWatch implementations share very similar logic for managing hardware breakpoints/watchpoints (hwbp/watch):
- watch_init(unsigned long &place_holder)
- watch_on(struct perf_event_attr *attr)
- watch_off() (or reset to the place_holder value)
- watch_uninit()

Hmm, I agree that we are using hwbp in a similar way but I think current interface is enough.

Quoted 4 lines

Their primary difference lies in their handler functions, specifically the perf_overflow_handler_t triggered callback.

Quoted 7 lines
Quoted 3 lines

I believe we could work together to unify this logic. I am open to either approach: I can refactor my watch.c, or you can introduce new helpers. This would help us save duplicated work and review time.

I'm not sure what you mean. Is there any concern to use the same (current hwbp) interfaces?

It is not the _current_ HWBP interface, it needs review. We will write the same logic except for the HWBP interface regarding atomic context watch switch (addr/type/len) and the process to sync with other CPUs.

The only difference is the HWBP handler.

I am not familiar with the process of how we usually do roughly the same thing. Maybe I am thinking about it the wrong way; I will look at it later. > Thank you,

Quoted 125 lines
Quoted 123 lines
Quoted 118 lines

Thanks,

Quoted 112 lines

In this version, I reuse Jinchao's arch_reinstall_hw_breakpoint() patch[1].

[1] https://lore.kernel.org/all/[email protected]/

The basic usage of this wprobe is similar to other probes;

    w:[GRP/][EVENT] [r|w|rw]@<ADDRESS|SYMBOL[+OFFS]> [FETCHARGS]

This defines a new wprobe event. For example, to trace jiffies update, you can do;

echo 'w:my_jiffies w@jiffies:8 value=+0($addr)' >> dynamic_events echo 1 > events/wprobes/my_jiffies/enable

Moreover, this can be combined with event trigger to trace the memory accecss on slab objects. The trigger syntax is;

set_wprobe:WPROBE_EVENT:FIELD[+ADJUST]
clear_wprobe:WPROBE_EVENT

For example, trace the first 8 byte of the dentry data structure passed to do_truncate() until it is deleted by __dentry_kill(). (Note: all tracefs setup uses '>>' so that it does not kick do_truncate())

    # echo 'w:watch rw@0:8 address=$addr value=+0($addr)' > dynamic_events
    # echo 'f:truncate do_truncate dentry=$arg2' >> dynamic_events
    # echo 'set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
    # echo 'f:dentry_kill __dentry_kill dentry=$arg1' >> dynamic_events
    # echo 'clear_wprobe:watch' >> events/fprobes/dentry_kill/trigger
    # echo 1 >> events/fprobes/truncate/enable
    # echo 1 >> events/fprobes/dentry_kill/enable
    # echo aaa > /tmp/hoge
    # echo bbb > /tmp/hoge
    # echo ccc > /tmp/hoge
    # rm /tmp/hoge

Then, the trace data will show;

# tracer: nop
#
# entries-in-buffer/entries-written: 16/16 #P:8
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched

#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| / _-=> migrate-disable
#                              |||| /     delay
#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
#    [    7.026136] sh (113) used greatest stack depth: 12912 bytes left
            | |         |   |||||     |         |
                sh-113     [002] .....     7.024402: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
                sh-113     [002] ..Zff     7.024822: watch: (lookup_fast+0xaa/0x150) address=0xffff8880069194b8 value=0x200008
                sh-113     [002] ..Zff     7.024830: watch: (step_into+0x82/0x360) address=0xffff8880069194b8 value=0x200008
                sh-113     [002] ..Zff     7.024834: watch: (step_into+0x9f/0x360) address=0xffff8880069194b8 value=0x200008
                sh-113     [002] ..Zff     7.024839: watch: (path_openat+0xb3a/0xe70) address=0xffff8880069194b8 value=0x200008
                sh-113     [002] ..Zff     7.024843: watch: (path_openat+0xb9a/0xe70) address=0xffff8880069194b8 value=0x200008
                sh-113     [002] .....     7.024847: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880069194b8
                sh-113     [002] ...1.     7.025364: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888006919380
                sh-113     [002] ...1.     7.025511: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069195f0
                rm-118     [003] ...1.     7.027543: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880069194b8
                sh-113     [002] ...2.     7.027825: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff8880044429c0
                sh-113     [002] ...2.     7.027833: dentry_kill: (__dentry_kill+0x0/0x220) dentry=0xffff888004442270

Thank you,

---

Jinchao Wang (1):
x86/HWBP: introduce arch_reinstall_hw_breakpoint() for atomic context

Masami Hiramatsu (Google) (5):
tracing: wprobe: Add watchpoint probe event based on hardware breakpoint
HWBP: Add modify_wide_hw_breakpoint_local() API
tracing: wprobe: Add wprobe event trigger
selftests: tracing: Add a basic testcase for wprobe
selftests: tracing: Add syntax testcase for wprobe

   Documentation/trace/index.rst                      |    1
   Documentation/trace/wprobetrace.rst                |  129 ++
   arch/Kconfig                                       |   10
   arch/x86/Kconfig                                   |    1
   arch/x86/include/asm/hw_breakpoint.h               |    3
   arch/x86/kernel/hw_breakpoint.c                    |   61 +
   include/linux/hw_breakpoint.h                      |    6
   include/linux/trace_events.h                       |    3
   kernel/events/hw_breakpoint.c                      |   36 +
   kernel/trace/Kconfig                               |   24
   kernel/trace/Makefile                              |    1
   kernel/trace/trace.c                               |    9
   kernel/trace/trace.h                               |    5
   kernel/trace/trace_probe.c                         |   20
   kernel/trace/trace_probe.h                         |    8
   kernel/trace/trace_wprobe.c                        | 1111 ++++++++++++++++++++
   .../ftrace/test.d/dynevent/add_remove_wprobe.tc    |   68 +
   .../test.d/dynevent/wprobes_syntax_errors.tc       |   20
   18 files changed, 1513 insertions(+), 3 deletions(-)

create mode 100644 Documentation/trace/wprobetrace.rst
create mode 100644 kernel/trace/trace_wprobe.c
create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/wprobes_syntax_errors.tc

--
Masami Hiramatsu (Google) <[email protected]>

Signature · 2 lines
Best regards,
Jinchao
Signature · 2 lines
Best regards,
Jinchao
author maintainer
#15 lore raw
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines

- trigger_data issue:
it appears that the instance being removed is not the same as the one that was originally set.

Did you mean it will free invalid struct event_trigger_data by wprobe_trigger_free(), or hw_breakpoint instance?

When trace_event_enable_disable(wprobe_data->file, 1, 1) at wprobe_trigger_cmd_parse(), the trace_wprobe is enabled == call enable_trace_wprobe(), which eventually call register_wide_hw_breakpoint() with dummy address. IOW, the (wide)hw_breakpoint is allocated here.

Quoted 6 lines
Quoted 3 lines

When the trigger is hit, modify_wide_hw_breakpoint_local() is called for updating local target address on the same hw_breakpoint. So latter instance should be the same.

In wprobe_trigger_cmd_parse(), consider removing:
echo '!set_wprobe:watch:dentry' >> events/fprobes/truncate/trigger
The trigger_data passed to event_trigger_unregister() is freshly allocated.

Ah, thanks for pointing it out.
I confused to free newly allocated trigger_data instead of existing one on the list.
Let me fix that.

Thank you,

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>