tracing: wprobe: x86: Add wprobe for watchpoint
Subsystems (5)
Masami Hiramatsu (Google)
maintainerv20 cover tracing: wprobe: x86: Add wprobe for watchpoint
Hi,
Here is the 20th version of the 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 dynamically allocated objects too.
The previous version (v19) is here:
https://lore.kernel.org/all/179101393469.22872.5895666191299551553.stgit@devnote2/
In this version (v20), the series is rebased on the latest probes/core branch and fixes several wprobe event matching, trigger teardown, and selftest coverage issues:
- Remove "Assisted-by: LLM" tags from all patches.
- Match and consume the address specification argument in trace_wprobe_match() before matching fetchargs so removing a wprobe with its full specification works properly, and call trace_probe_dump_args() in trace_wprobe_show().
- Do not set EVENT_FILE_FL_SOFT_DISABLED_BIT in wprobe_trigger_free() so it follows enable_event semantics and does not prematurely silence the watchpoint when removing set_wprobe while clear_wprobe is still active.
- Defer trace_event_put_ref() to the private_data_free callback after trigger_data_free() synchronization.
- Expand selftest coverage across wprobe dynamic events, triggers, BTF typecast fetchargs, and BTF struct offset resolution.
Detailed changes are here.
Changes in v20:
- Rebase on the latest probes/core branch.
- Remove "Assisted-by: LLM" tags from all patches.
[04/11]
- Match and consume the address specification argument in trace_wprobe_match() before matching fetchargs so removing a wprobe with its full specification works properly.
- Call trace_probe_dump_args() in trace_wprobe_show() to support CONFIG_PROBE_EVENTS_DUMP_FETCHARG.
[06/11]
- Verify $addr and $value fetchargs in trace output.
- Add test checks for access modes (r@, rw@), length specifiers, symbol offset, and spec-based event removal ('!w:...' and '-:...').
[07/11]
- Add error_log to requires line in wprobes_syntax_errors.tc.
- Add testcases for unaligned address (BAD_ACCESS_ADDR) and sibling wprobe rejection (WPROBE_NO_SIBLING).
[08/11]
- Do not set EVENT_FILE_FL_SOFT_DISABLED_BIT in wprobe_trigger_free() so it follows enable_event semantics and does not prematurely silence the wprobe when removing set_wprobe while clear_wprobe is still active.
- Defer trace_event_put_ref() to private_data_free callback after trigger_data_free() synchronization, matching enable_event triggers.
[09/11]
- Verify events/wprobes/watch/enable transitions to '0*' after clear_wprobe fires and to '0' after the trigger is removed.
- Add test checks for pointer field offset (timer+16), trigger count limit (:1), and conditional clear_wprobe:watch:timer+16 in trigger-wprobe.tc.
- Use $arg1 instead of BTF argument 't' in trigger-wprobe.tc and trigger-wprobe-hotplug.tc, and drop redundant fprobe README check.
- Add WPROBE_BAD_FIELD, BAD_DEREF_OFFS, and BAD_IMM test cases to trigger-wprobe-syntax-errors.tc.
[10/11]
- Verify BTF typecast fields (counter= and expires=) in trace output in trigger-wprobe-btf-typecast.tc, test direct (STRUCT)$addr->MEMBER and (STRUCT)$value->MEMBER typecasts, and verify watch/enable stays '1' after removing set_wprobe.
- Drop redundant fprobe README check in trigger-wprobe-btf-typecast.tc.
[11/11]
- Verify resolved non-zero BTF offset in trigger file and test clear_wprobe with BTF struct offset resolution in trigger-wprobe-btf-offset.tc.
- Drop redundant fprobe README check in trigger-wprobe-btf-offset.tc.
Public branch
-------------
I will push this branch as topic/wprobe-v2 to my tree so that it can be easily tested.
https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/log/?h=topic/wprobe-v2
This is based on linux-trace tree's linux-trace/probes/core.
Usage
-----
The basic usage of this wprobe is similar to other probes;
w:[GRP/][EVENT] [r|w|rw]@<ADDRESS|SYMBOL[+|-OFFS]>[:LEN] [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 access on slab objects. The trigger syntax is;
set_wprobe:WPROBE_EVENT:FIELD[+|-OFFSET][:COUNT] [if FILTER] clear_wprobe:WPROBE_EVENT[:FIELD[+|-OFFSET][:COUNT]] [if FILTER]
set_wprobe sets WPROBE_EVENT's watch address on FIELD[+|-OFFSET]. clear_wprobe clears WPROBE_EVENT's watch address if it is set to FIELD[+|-OFFSET]. If FIELD is omitted, forcibly clear the watch address when trigger event is hit.
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@-1: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:dentry' >> 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: 32/32 #P:8
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth
# ||| / _-=> migrate-disable
# |||| / delay
# TASK-PID CPU# ||||| TIMESTAMP FUNCTION
# | | | ||||| | |
sh-107 [004] ...1. 9.990418: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004ad6618
sh-107 [004] ...1. 9.990914: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b3de78
sh-107 [004] ...1. 9.993175: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049ddd40
sh-107 [004] ..... 9.995198: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880048083a8
sh-107 [004] ...1. 9.995389: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db998
sh-107 [004] ..Zff 9.997503: watch: (lookup_fast+0xaa/0x150) address=0xffff8880048083a8 value=0x8200080
sh-107 [004] ..Zff 9.997509: watch: (path_openat+0x211/0xda0) address=0xffff8880048083a8 value=0x8200080
sh-107 [004] ..Zff 9.997514: watch: (path_openat+0xa56/0xda0) address=0xffff8880048083a8 value=0x8200080
sh-107 [004] ..Zff 9.997518: watch: (path_openat+0xae2/0xda0) address=0xffff8880048083a8 value=0x8200080
sh-107 [004] ..... 9.997521: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880048083a8
sh-107 [004] ...1. 9.997582: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004808270
sh-107 [004] ...1. 9.999365: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db728
sh-107 [004] ...1. 9.999388: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b1c000
rm-113 [005] ..Zff 10.000965: watch: (lookup_fast+0xaa/0x150) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.000971: watch: (path_lookupat+0x97/0x1e0) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.000984: watch: (lookup_fast+0xaa/0x150) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.000988: watch: (path_lookupat+0x97/0x1e0) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.001010: watch: (lookup_one_qstr_excl+0x28/0x140) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.001014: watch: (lookup_one_qstr_excl+0xd1/0x140) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.001018: watch: (may_delete_dentry+0x1c/0x200) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.001021: watch: (may_delete_dentry+0x195/0x200) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] ..Zff 10.001031: watch: (vfs_unlink+0x5e/0x260) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] d.Z.. 10.001067: watch: (d_make_discardable+0x1b/0x40) address=0xffff8880048083a8 value=0x8200080
rm-113 [005] d.Z.. 10.001071: watch: (d_make_discardable+0x29/0x40) address=0xffff8880048083a8 value=0x200080
rm-113 [005] ...1. 10.001072: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880048083a8
rm-113 [005] ...1. 10.001218: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880048083a8
sh-107 [004] ...1. 10.001416: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db110
sh-107 [004] ...1. 10.001444: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db248
sh-107 [004] ...1. 10.001500: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004ad6618
sh-107 [004] ...1. 10.002067: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b41e78
sh-107 [004] ...1. 10.904920: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b41e78
sh-107 [004] ...1. 10.905129: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004ad6618Thank you,
---
base-commit: 06e0d3b89da12f24ed5ed434acc8e2cb504f5e4f
base-commit: 1499a90b5d18ae93d5a8eb47520e7bed1a2b7a0e
Jinchao Wang (1):
x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
Masami Hiramatsu (Google) (10):
HWBP: Add modify_local_hw_breakpoint_addr() API perf/hw_breakpoint: Add register_wide_hw_breakpoint_cpuslocked() API tracing/wprobe: Add wprobe (watchpoint probe) trace event support
x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires
selftests: tracing: Add a basic testcase for wprobe
selftests: tracing: Add syntax testcase for wprobe tracing/wprobe: Add set_wprobe and clear_wprobe event triggers
selftests: tracing: Add wprobe trigger testcases tracing/wprobe: Support BTF typecast in fetchargs tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger
Documentation/trace/index.rst | 1 Documentation/trace/wprobetrace.rst | 200 ++ arch/Kconfig | 18 arch/x86/Kconfig | 2 arch/x86/include/asm/hw_breakpoint.h | 2 arch/x86/kernel/hw_breakpoint.c | 51 + include/linux/hw_breakpoint.h | 15 include/linux/trace_events.h | 3 kernel/events/hw_breakpoint.c | 86 + kernel/trace/Kconfig | 24 kernel/trace/Makefile | 1 kernel/trace/trace.c | 9 kernel/trace/trace.h | 6 kernel/trace/trace_events_trigger.c | 2 kernel/trace/trace_probe.c | 36 kernel/trace/trace_probe.h | 22 kernel/trace/trace_wprobe.c | 1743 ++++++++++++++++++++ tools/testing/selftests/ftrace/config | 3 .../ftrace/test.d/dynevent/add_remove_wprobe.tc | 81 + .../test.d/dynevent/wprobes_syntax_errors.tc | 28 .../test.d/trigger/trigger-wprobe-btf-offset.tc | 94 + .../test.d/trigger/trigger-wprobe-btf-typecast.tc | 85 + .../test.d/trigger/trigger-wprobe-hotplug.tc | 150 ++ .../test.d/trigger/trigger-wprobe-syntax-errors.tc | 40 .../ftrace/test.d/trigger/trigger-wprobe.tc | 135 ++ 25 files changed, 2824 insertions(+), 13 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 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-btf-offset.tc create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-btf-typecast.tc create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-hotplug.tc create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-syntax-errors.tc create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc
--
Masami Hiramatsu (Google) <[email protected]>
Masami Hiramatsu (Google)
maintainerPATCH v20 1/11 x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
From: Jinchao Wang <[email protected]>
Wprobe needs to move an active per-CPU watchpoint without releasing and reserving its hardware slot.
Add arch_modify_local_hw_breakpoint_addr() as the architecture backend for modify_local_hw_breakpoint_addr(). It validates the new address, finds the installed local slot, and updates the hardware debug register and per-CPU shadow register. The core layer (modify_local_hw_breakpoint_addr()) handles updating bp->attr.bp_addr and counter_arch_bp(bp)->address.
The caller must provide an installed local event and a valid address. Slot ownership, breakpoint type, length, mask and DR7 remain unchanged.
---
Changes in v18:
- Drop perf_guest_in_guest() check and cpu_dr7_seq sequence loop since wprobe does not support updating DR7 in NMI context.
Changes in v17:
- In arch_modify_local_hw_breakpoint_addr(), check perf_guest_in_guest() instead of cpu_dr_in_guest.
Changes in v16:
- Clear breakpoint in shadow cpu_dr7 before setting hardware DR7 so an intervening NMI cannot re-enable the breakpoint via local_db_restore() while the address register is being updated, preventing spurious #DB exceptions.
- Check cpu_dr_in_guest and return -EBUSY to reject modifying local breakpoints while executing a KVM guest.
Changes in v15:
- Temporarily clear the breakpoint enable bit in DR7 before updating the debug address register, and re-enable it afterward, to comply with the x86 hardware specification and avoid spurious #DB exceptions.
Changes in v13:
- Add compiler barrier (barrier()) before checking cpu_dr7_seq to prevent hoisting the sequence check before set_debugreg().
- Clarify in commit log and code comment that the core layer manages updating bp->attr.bp_addr and counter_arch_bp(bp)->address.
Changes in v11:
- Return int error code instead of void.
- Validate the new address using hw_breakpoint_arch_parse() before updating registers.
- Increment cpu_dr7_seq in a sequence loop for NMI protection.
- Return -ENOENT if the breakpoint slot is not found on the local CPU.
--- arch/x86/include/asm/hw_breakpoint.h | 2 + arch/x86/kernel/hw_breakpoint.c | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
arch/x86/include/asm/hw_breakpoint.h +2 -0
@@ -59,6 +59,8 @@ extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,int arch_install_hw_breakpoint (struct perf_event *bp); +int arch_modify_local_hw_breakpoint_addr (struct perf_event *bp, +unsigned long addr);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 +51 -0
57 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 01/11] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] x86/hw_breakpoints: arch_modify_local_hw_breakpoint_addr() corrupts DRs --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] x86/hw_breakpoints: arch_modify_local_hw_breakpoint_addr() corrupts DRs
--
commit 490e341c5679ea8c1cf5b3a39b5b39ecc93de7d0
Author: Jinchao Wang <[email protected]>
x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API
This commit adds arch_modify_local_hw_breakpoint_addr() to update the address of an installed per-CPU hardware breakpoint on the local CPU without releasing and re-allocating its debug register slot.
Quoted 45 lines
arch/x86/kernel/hw_breakpoint.c +37
-0@@ -133,6 +133,57 @@ int arch_install_hw_breakpoint(struct perf_event *bp)return 0 ; } +/* +* Modify the address of an installed perf counter breakpoint on local CPU. +* +* This updates the debug address register and per-CPU shadow state without +* changing slot allocation or DR7. The core layer (modify_local_hw_breakpoint_addr()) +* manages updating bp->attr.bp_addr and counter_arch_bp(bp)->address. +* +* Atomic: called with IRQs disabled and handles variables and registers +* local to this CPU. +*/ +int arch_modify_local_hw_breakpoint_addr (struct perf_event *bp, +unsigned long addr) +{ +struct arch_hw_breakpoint *info =counter_arch_bp (bp); +struct arch_hw_breakpoint hw; +struct perf_event_attr attr = bp->attr; +unsigned long dr7; +int i, ret; + +lockdep_assert_irqs_disabled (); + + attr.bp_addr = addr; + ret =hw_breakpoint_arch_parse (bp, &attr, &hw); +if (ret) +return ret; + +for (i =0 ; i <HBP_NUM ; i++) { +if (this_cpu_read (bp_per_reg[i]) == bp) +break ; + } + +if (WARN_ONCE (i ==HBP_NUM ,"Can't find any breakpoint slot" )) +return -ENOENT ; + +/* +* Temporarily clear the breakpoint enable bit in DR7 before updating the +* debug address register, and re-enable it afterward, to comply with the
arch/x86/kernel/hw_breakpoint.c int arch_install_hw_breakpoint(struct perf_event *bp) · line 182
Quoted 10 lines
arch/x86/kernel/hw_breakpoint.c +10
-0+* x86 hardware specification and avoid spurious #DB exceptions. +*/ + dr7 =this_cpu_read (cpu_dr7); +set_debugreg (dr7 & ~__encode_dr7 (i, info->len, info->type),7 ); + +this_cpu_write (cpu_debugreg[i], addr); +barrier (); +set_debugreg (addr, i); + +set_debugreg (dr7,7 );
[Severity: High]
Can arch_modify_local_hw_breakpoint_addr() corrupt hardware debug registers or prematurely re-enable hardware DR7 when host breakpoints are temporarily disabled or switched to KVM guest state?
Several paths disable hardware DR7 (writing DR7_FIXED_1) or replace hardware DR0-DR3 without clearing the per-CPU shadow cpu_dr7:
arch/x86/kvm/x86.c:vcpu_enter_guest() {
...
if (unlikely(vcpu->arch.switch_db_regs &&
!(vcpu->arch.switch_db_regs & KVM_DEBUGREG_AUTO_SWITCH))) {
set_debugreg(DR7_FIXED_1, 7);
set_debugreg(vcpu->arch.eff_db[0], 0);
set_debugreg(vcpu->arch.eff_db[1], 1);
set_debugreg(vcpu->arch.eff_db[2], 2);
set_debugreg(vcpu->arch.eff_db[3], 3);
}
...
}vcpu_enter_guest() runs in normal context with IRQs disabled and invokes instrumentable functions and tracepoints (such as trace_kvm_entry and trace_kvm_exit) before sync_dirty_debug_regs() and hw_breakpoint_restore(). If a wprobe trigger calls arch_modify_local_hw_breakpoint_addr() in this window, set_debugreg(addr,
i) overwrites the guest's hardware DR[i] with the host kernel address (which sync_dirty_debug_regs() then saves into vcpu->arch.db[i], leaking the host address to the guest), and set_debugreg(dr7, 7) activates host cpu_dr7 while the remaining hardware DR[j] registers still hold guest addresses.
Similarly, if called while use_temporary_mm() -> hw_breakpoint_disable() or local_db_save() has suppressed hardware breakpoints, writing cpu_dr7 back to hardware DR7 re-enables the breakpoints prematurely while temp_mm is loaded (with 0UL in the other DR registers) or while inside a #DB exception context.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=1
Masami Hiramatsu (Google)
maintainerPATCH v20 2/11 HWBP: Add modify_local_hw_breakpoint_addr() API
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Add modify_local_hw_breakpoint_addr() to update only the watched address of an installed hardware breakpoint on the local CPU without releasing and reserving its hardware slot. This is available when the architecture selects CONFIG_HAVE_MODIFY_LOCAL_HW_BREAKPOINT_ADDR.
The caller must provide an installed local event and a valid address, and update other CPUs separately.
---
Changes in v15:
- Use WRITE_ONCE() for counter_arch_bp(bp)->address and bp->attr.bp_addr in both update and rollback paths to prevent data races with concurrent readers (e.g. NMI handlers).
Changes in v13:
- Add comment to modify_local_hw_breakpoint_addr() clarifying the early update behavior of bp->attr.bp_addr during the NMI race window.
Changes in v12:
- Update bp->attr.bp_addr and counter_arch_bp(bp)->address before calling arch_modify_local_hw_breakpoint_addr() to prevent race conditions during interrupt handling.
- Restore counter_arch_bp(bp)->address and bp->attr.bp_addr if arch_modify_local_hw_breakpoint_addr() fails.
Changes in v11:
- Check return value of arch_modify_local_hw_breakpoint_addr() and return error on failure.
- Update bp->attr.bp_addr and counter_arch_bp(bp)->address only after arch modification succeeds.
--- arch/Kconfig | 8 +++++++ arch/x86/Kconfig | 1 + include/linux/hw_breakpoint.h | 6 +++++ kernel/events/hw_breakpoint.c | 48 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+)
arch/Kconfig +8 -0
@@ -474,6 +474,14 @@ config HAVE_MIXED_BREAKPOINTS_REGS Select this option if your arch implements breakpoints under the latter fashion. +config HAVE_MODIFY_LOCAL_HW_BREAKPOINT_ADDR + bool + depends on HAVE_HW_BREAKPOINT + help + Select this if the architecture can modify the address of an + installed hardware breakpoint on the local CPU without releasing + and reserving its hardware slot. + config HAVE_USER_RETURN_NOTIFIER bool
arch/x86/Kconfig +1 -0
@@ -248,6 +248,7 @@ config X86 select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT + select HAVE_MODIFY_LOCAL_HW_BREAKPOINT_ADDR select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING
include/linux/hw_breakpoint.h +6 -0
@@ -81,6 +81,9 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,perf_overflow_handler_t triggered, void *context); +int modify_local_hw_breakpoint_addr (struct perf_event *bp, +unsigned long addr); +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_local_hw_breakpoint_addr (struct perf_event *bp, +unsigned long addr) {return -EOPNOTSUPP ; } +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 +48 -0
54 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 02/11] HWBP: Add modify_local_hw_breakpoint_addr() API
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Masami Hiramatsu (Google) <[email protected]>
Add
modify_local_hw_breakpoint_addr()to update only the watched address of an installed hardware breakpoint on the local CPU without releasing and reserving its hardware slot. This is available when the architecture selectsCONFIG_HAVE_MODIFY_LOCAL_HW_BREAKPOINT_ADDR.
Quoted 7 lines
The caller must provide an installed local event and a valid address, and update other CPUs separately.
Signed-off-by Masami Hiramatsu (Google) <[email protected]>Signed-off-by Jinchao Wang <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=2
Masami Hiramatsu (Google)
maintainerPATCH v20 3/11 perf/hw_breakpoint: Add register_wide_hw_breakpoint_cpuslocked() API
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Add register_wide_hw_breakpoint_cpuslocked() which registers a wide hardware breakpoint across all online CPUs while caller holds cpus_read_lock(). This allows callers who need to perform additional setup under cpus_read_lock() without releasing it to avoid races with CPU hotplug and without triggering recursive lockdep warnings.
Refactor register_wide_hw_breakpoint() as a wrapper around register_wide_hw_breakpoint_cpuslocked().
--- include/linux/hw_breakpoint.h | 9 +++++++++ kernel/events/hw_breakpoint.c | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-)
include/linux/hw_breakpoint.h +9 -0
@@ -76,6 +76,11 @@ register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,void *context, int cpu); +extern struct perf_event *__percpu * +register_wide_hw_breakpoint_cpuslocked (struct perf_event_attr *attr, +perf_overflow_handler_t triggered, +void *context); +extern struct perf_event *__percpu * register_wide_hw_breakpoint(struct perf_event_attr *attr, perf_overflow_handler_t triggered,
@@ -123,6 +128,10 @@ register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,void *context, int cpu) { return NULL; }static inline struct perf_event *__percpu * +register_wide_hw_breakpoint_cpuslocked (struct perf_event_attr *attr, +perf_overflow_handler_t triggered, +void *context) {return NULL ; } +static inline struct perf_event *__percpu *register_wide_hw_breakpoint (struct perf_event_attr *attr,perf_overflow_handler_t triggered,void *context) {return NULL ; }
kernel/events/hw_breakpoint.c +32 -6
@@ -832,27 +832,30 @@ void unregister_hw_breakpoint(struct perf_event *bp)EXPORT_SYMBOL_GPL (unregister_hw_breakpoint);/** -* register_wide_hw_breakpoint - register a wide breakpoint in the kernel +* register_wide_hw_breakpoint_cpuslocked - register a wide breakpoint with cpus locked * @attr: breakpoint attributes * @triggered: callback to trigger when we hit the breakpoint * @context: context data could be used in the triggered callback * +* Same as register_wide_hw_breakpoint(), but caller must hold cpus_read_lock(). +* * @return a set of per_cpu pointers to perf events */ struct perf_event *__percpu * -register_wide_hw_breakpoint (struct perf_event_attr *attr, -perf_overflow_handler_t triggered, -void *context) +register_wide_hw_breakpoint_cpuslocked (struct perf_event_attr *attr, +perf_overflow_handler_t triggered, +void *context) {struct perf_event *__percpu *cpu_events, *bp;long err =0 ;int cpu; +lockdep_assert_cpus_held (); + cpu_events =alloc_percpu (typeof (*cpu_events));if (!cpu_events)return ERR_PTR_PCPU (-ENOMEM ); -cpus_read_lock ();for_each_online_cpu (cpu) { bp =perf_event_create_kernel_counter (attr, cpu,NULL , triggered, context);
@@ -863,7 +866,6 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,per_cpu (*cpu_events, cpu) = bp; } -cpus_read_unlock ();if (likely (!err))return cpu_events;
@@ -871,6 +873,30 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,unregister_wide_hw_breakpoint (cpu_events);return ERR_PTR_PCPU (err); } +EXPORT_SYMBOL_GPL (register_wide_hw_breakpoint_cpuslocked); + +/** +* register_wide_hw_breakpoint - register a wide breakpoint in the kernel +* @attr: breakpoint attributes +* @triggered: callback to trigger when we hit the breakpoint +* @context: context data could be used in the triggered callback +* +* @return a set of per_cpu pointers to perf events +*/ +struct perf_event *__percpu * +register_wide_hw_breakpoint (struct perf_event_attr *attr, +perf_overflow_handler_t triggered, +void *context) +{ +struct perf_event *__percpu *cpu_events; + +cpus_read_lock (); + cpu_events =register_wide_hw_breakpoint_cpuslocked (attr, triggered, + context); +cpus_read_unlock (); + +return cpu_events; +}EXPORT_SYMBOL_GPL (register_wide_hw_breakpoint);/**
[email protected]
AI reviewRe: [PATCH v20 03/11] perf/hw_breakpoint: Add register_wide_hw_breakpoint_cpuslocked() API
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
From: Masami Hiramatsu (Google) <[email protected]>
Add
register_wide_hw_breakpoint_cpuslocked()which registers a wide hardware breakpoint across all online CPUs while caller holdscpus_read_lock(). This allows callers who need to perform additional setup undercpus_read_lock()without releasing it to avoid races with CPU hotplug and without triggering recursive lockdep warnings.
Quoted 4 lines
Refactor
register_wide_hw_breakpoint()as a wrapper aroundregister_wide_hw_breakpoint_cpuslocked().Signed-off-by Masami Hiramatsu (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=3
Masami Hiramatsu (Google)
maintainerPATCH v20 4/11 tracing/wprobe: Add wprobe (watchpoint probe) trace event support
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Add hardware-breakpoint-based dynamic trace event support (wprobe). Wprobe creates a dynamic event on data read/write accesses using hardware breakpoints and logs the access context and fetchargs.
---
Changes in v20:
- Match and consume the address specification argument in trace_wprobe_match() before matching fetchargs so removing a wprobe with its full specification works properly.
- Call trace_probe_dump_args() in trace_wprobe_show() to support CONFIG_PROBE_EVENTS_DUMP_FETCHARG.
Changes in v16:
- Remove non-existent wprobe_events file description from readme_msg in kernel/trace/trace.c as wprobe events are created via dynamic_events.
Changes in v15:
- Introduce trace_wprobe_is_valid_addr() to validate target address and natural alignment for wprobe length during event creation.
- Move local variable declarations to function entry in trace_wprobe_show() to comply with kernel C coding standards.
- Fix indentation in kernel/trace/trace.c to use tabs instead of spaces.
Changes in v14:
- In parse_address_spec(), reject address 0 and user-space addresses by changing the check to '_addr < TASK_SIZE'.
- In trace_wprobe_show(), format symbol and offset explicitly instead of using '%pS' to ensure dynamic event restoration works properly.
- Add offset field to struct trace_wprobe and pass it to alloc_trace_wprobe().
Changes in v13:
- Fix documentation notation to SYMBOL[+|-OFFS] as same as others.
- Fix documentation indents and add default value.
- Fix README file to add [<args>].
- Add a note about module unloading.
Changes in v12:
- Fix syntax comment typo ('b' to 'w') and remove dead 'ret = 0' initialization in __trace_wprobe_create().
- Fix documentation notation to SYMBOL[[+|-]OFFS].
Changes in v11:
- Add trace_wprobe_is_busy() to prevent releasing busy events.
Changes in v9:
- Use kzalloc_flex for alloc_trace_wprobe.
--- Documentation/trace/index.rst | 1 Documentation/trace/wprobetrace.rst | 78 +++ include/linux/trace_events.h | 2 kernel/trace/Kconfig | 13 + kernel/trace/Makefile | 1 kernel/trace/trace.c | 5 kernel/trace/trace.h | 5 kernel/trace/trace_probe.c | 21 + kernel/trace/trace_probe.h | 10 kernel/trace/trace_wprobe.c | 808 +++++++++++++++++++++++++++++++++++ 10 files changed, 940 insertions(+), 4 deletions(-) create mode 100644 Documentation/trace/wprobetrace.rst create mode 100644 kernel/trace/trace_wprobe.c
Documentation/trace/index.rst +1 -0
@@ -36,6 +36,7 @@ the Linux kernel. kprobes kprobetrace fprobetrace + wprobetrace eprobetrace fprobe ring-buffer-design
Documentation/trace/wprobetrace.rst new file +78 -0
78 lines not on this page · raw message
include/linux/trace_events.h +2 -0
@@ -337,6 +337,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, };
@@ -367,6 +368,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 +13 -0
@@ -870,6 +870,19 @@ 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 + 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 accessed memory address and values. + config BPF_EVENTS depends on BPF_SYSCALL depends on (KPROBE_EVENTS || UPROBE_EVENTS) && PERF_EVENTS
kernel/trace/Makefile +1 -0
@@ -127,6 +127,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 +4 -1
@@ -4307,7 +4307,7 @@ static const char readme_msg[] = "\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"
@@ -4317,6 +4317,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>] [<args>]\n" +#endif #ifdef CONFIG_HIST_TRIGGERS "\t s:[synthetic/]<event> <field> [<field>]\n"#endif
kernel/trace/trace.h +5 -0
@@ -179,6 +179,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 1024struct trace_array ;
kernel/trace/trace_probe.c +19 -2
@@ -1442,6 +1442,23 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t,return 0 ; } +/* 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 ; + } + goto inval; + } +if (strcmp (arg,"comm" ) ==0 ||strcmp (arg,"COMM" ) ==0 ) { code->op =FETCH_OP_COMM ;return 0 ;
@@ -1501,8 +1518,8 @@ static int parse_probe_arg_register(char *arg, struct fetch_insn *code, {int ret; -if (ctx->flags & (TPARG_FL_TEVENT |TPARG_FL_FPROBE )) { -/* eprobe and fprobe do not handle registers */ +if (ctx->flags & (TPARG_FL_TEVENT |TPARG_FL_FPROBE |TPARG_FL_WPROBE )) { +/* eprobe, fprobe and wprobe do not handle registers */ trace_probe_log_err (ctx->offset,BAD_VAR );return -EINVAL ; }
kernel/trace/trace_probe.h +9 -1
@@ -90,6 +90,7 @@ typedef int (*print_type_func_t)(struct trace_seq *, void *, void *);FETCH_OP (STACK , param),/* Stack: .param = index */ \FETCH_OP (STACKP , none),/* Stack pointer */ \FETCH_OP (RETVAL , none),/* Return value */ \ +FETCH_OP (BADDR , none),/* Break address */ \FETCH_OP (IMM , imm),/* Immediate: .immediate */ \FETCH_OP (COMM , none),/* Current comm */ \ FETCH_OP(CURRENT, none), /* Current task_struct address */\
@@ -420,6 +421,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)
@@ -546,6 +548,10 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,C (ARG_TOO_LONG ,"Argument expression is too long" ), \C (ARRAY_NO_CLOSE ,"Array is not closed" ), \C (ARRAY_TOO_BIG ,"Array number is too big" ), \ +C (BAD_ACCESS_ADDR ,"Invalid access memory address" ), \ +C (BAD_ACCESS_FMT ,"Access memory address requires @" ), \ +C (BAD_ACCESS_LEN ,"This memory access length is not supported" ), \ +C (BAD_ACCESS_TYPE ,"Bad memory access type" ), \C (BAD_ADDR_SUFFIX ,"Invalid probed address suffix" ), \C (BAD_ARG_NAME ,"Argument name must follow the same rules as C identifiers" ), \ C(BAD_ARG_NUM, "Invalid argument number"), \
@@ -628,7 +634,9 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,C (TYPECAST_NOT_EVENT ,"Typecasts are only for eprobe fields" ), \C (TYPECAST_REQ_FIELD ,"Typecast requires a field access" ), \C (TYPECAST_SYM_OFFSET ,"@SYM+/-OFFSET with typecast needs parentheses" ), \ -C (USED_ARG_NAME ,"This argument name is already used" ), +C (USED_ARG_NAME ,"This argument name is already used" ), \ +C (WPROBE_NO_MAXACT ,"Watchpoint probe does not support maxactive" ), \ +C (WPROBE_NO_SIBLING ,"Watchpoint probe does not support sibling probes" ), #undef C #define C(a, b) TP_ERR_##a
kernel/trace/trace_wprobe.c new file +808 -0
808 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 04/11] tracing/wprobe: Add wprobe (watchpoint probe) trace event support
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] tracing/wprobe: unheld lock and symbol lookup in trace_wprobe_match() - [Medium] tracing/wprobe…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] tracing/wprobe: unheld lock and symbol lookup in trace_wprobe_match()
- [Medium] tracing/wprobe: TASK_SIZE check in trace_wprobe_is_valid_addr()
- [Medium] tracing/wprobe: trace_ctx underflow in wprobe_trace_handler() --
commit ba36417426baa731cd50929b7289160f5b44d5a3
Author: Masami Hiramatsu (Google) <[email protected]>
tracing/wprobe: Add wprobe (watchpoint probe) trace event support
This commit adds hardware-breakpoint-based dynamic trace event support (wprobe) to trace data read and write accesses and log the access context and fetchargs.
Quoted 5 lines
kernel/trace/trace_wprobe.c new file +0
-0
[ ... ]
Quoted 18 lines
kernel/trace/trace_wprobe.c new file +18
-0+static bool trace_wprobe_match_command_head (struct trace_wprobe *tw, +int argc,const char **argv) +{ + char *symbol __free(kfree) = NULL; +unsigned long addr; +int type, len, offset; + +if (!argc) +return true; + +if (parse_address_spec (argv[0 ], &addr, &type, &len, &symbol, &offset)) +return false; + +if (tw->type != type || tw->len != len) +return false; + +if (tw->symbol) { + if (!symbol || strcmp(tw->symbol, symbol) != 0 ||
kernel/trace/trace_wprobe.c line 108
Quoted 10 lines
kernel/trace/trace_wprobe.c new file +10
-0+ tw->offset != offset) +return false; + }else if (symbol || tw->addr != addr) { +return false; + } + + argc--; + argv++; +return trace_probe_match_command_args (&tw->tp, argc, argv); +}
[Severity: Medium]
Can calling parse_address_spec() from trace_wprobe_match_command_head() trigger a lockdep warning and race on trace_probe_log?
dyn_event_release() invokes pos->ops->match() under event_mutex without holding dyn_event_ops_mutex. When argv[0] does not parse as a valid wprobe specification (for example, while dyn_event_release() walks past a wprobe when removing another probe type with arguments, or when a user passes a non-matching spec), parse_address_spec() calls trace_probe_log_err() -> __trace_probe_log_err():
kernel/trace/trace_probe.c:__trace_probe_log_err() {
lockdep_assert_held(&dyn_event_ops_mutex);
if (!trace_probe_log.argv || !trace_probe_log.argc)
return;
...
}Because dyn_event_ops_mutex is not held, lockdep_assert_held() fires and __trace_probe_log_err() can race with a concurrent dyn_event_create() thread initializing or freeing trace_probe_log.argv.
In addition, parse_address_spec() requires kallsyms_lookup_name() to succeed even when matching a symbol-based wprobe where only tw->symbol and tw->offset are compared. If the watched module has been unloaded, kallsyms_lookup_name() returns 0 and prevents removing the wprobe using its full specification.
[ ... ]
Quoted 15 lines
kernel/trace/trace_wprobe.c new file +15
-0+static void wprobe_trace_handler (struct trace_wprobe *tw, +unsigned long addr, +struct pt_regs *regs, +struct trace_event_file *trace_file) +{ +struct wprobe_trace_entry_head *entry; +struct trace_event_call *call =trace_probe_event_call (&tw->tp); +struct trace_event_buffer fbuffer; +int dsize; + +if (WARN_ON_ONCE (call != trace_file->event_call)) +return ; + +if (trace_trigger_soft_disabled (trace_file)) +return ;
kernel/trace/trace_wprobe.c line 180
Quoted 10 lines
kernel/trace/trace_wprobe.c new file +10
-0+ +if (READ_ONCE (tw->addr) != addr) +return ; + + dsize =__get_data_size (&tw->tp, (void *)addr,NULL ); + + entry =trace_event_buffer_reserve (&fbuffer, trace_file, +sizeof (*entry) + tw->tp.size + dsize); +if (!entry) +return ;
[Severity: Medium]
Does calling trace_event_buffer_reserve() without disabling preemption underflow trace_ctx when CONFIG_PREEMPTION is enabled?
Hardware breakpoint exceptions invoke perf_bp_event() -> ... -> wprobe_perf_handler() with interrupts disabled, without incrementing the low 8-bit preemption count. trace_event_buffer_reserve() calls tracing_gen_ctx_dec(), which decrements trace_ctx assuming the caller disabled preemption. When a watchpoint hits in preemptible kernel context where the preemption and migration-disable counts are 0, subtracting 1 underflows those fields to 0xff and borrows from bit 16 (TRACE_FLAG_IRQS_OFF), corrupting the recorded preempt_count and clearing the irqs-off flag in the trace entry. Acquiring guard(preempt_notrace)() before trace_event_buffer_reserve() (as in trace_fprobe.c) avoids the underflow.
[ ... ]
kernel/trace/trace_wprobe.c line 542
Quoted 10 lines
kernel/trace/trace_wprobe.c new file +10
-0+static bool trace_wprobe_is_valid_addr (unsigned long addr,int len) +{ +if (addr <TASK_SIZE ) +return false; + +if (addr & (len -1 )) +return false; + +return true; +}
[Severity: Medium]
Should trace_wprobe_is_valid_addr() check TASK_SIZE_MAX (or arch_check_bp_in_kernelspace()) instead of TASK_SIZE?
On 64-bit architectures with CONFIG_COMPAT, TASK_SIZE evaluates to the current task's address limit (such as IA32_PAGE_OFFSET when a 32-bit task writes to dynamic_events), which allows addresses in [TASK_SIZE, TASK_SIZE_MAX) to pass validation and register a CPU-wide hardware watchpoint on a 64-bit user-space address.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=4
Masami Hiramatsu (Google)
maintainerPATCH v20 5/11 x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Add CONFIG_HAVE_POST_BREAKPOINT_HOOK which indicates the hw_breakpoint on that architecture fires after the target memory has been modified. This is currently x86 only behavior.
---
Changes in v11:
- Move select to alphabetically sorted place.
--- arch/Kconfig | 10 ++++++++++ arch/x86/Kconfig | 1 + kernel/trace/Kconfig | 1 + 3 files changed, 12 insertions(+)
arch/Kconfig +10 -0
@@ -474,6 +474,16 @@ config HAVE_MIXED_BREAKPOINTS_REGS Select this option if your arch implements breakpoints under the latter fashion. +config HAVE_POST_BREAKPOINT_HOOK + bool + depends on HAVE_HW_BREAKPOINT + help + Depending on the arch implementation of hardware breakpoints, + some of them provide breakpoint hook after the target memory + is modified. + Select this option if your arch implements breakpoints overflow + handler hooks after the target memory is modified. + config HAVE_MODIFY_LOCAL_HW_BREAKPOINT_ADDR bool depends on HAVE_HW_BREAKPOINT
arch/x86/Kconfig +1 -0
@@ -287,6 +287,7 @@ config X86 select ASYNC_KERNEL_PGTABLE_FREE if IOMMU_SVA select MMU_GATHER_MERGE_VMAS select HAVE_POSIX_CPU_TIMERS_TASK_WORK + select HAVE_POST_BREAKPOINT_HOOK select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC || STACK_VALIDATION select HAVE_FUNCTION_ARG_ACCESS_API
kernel/trace/Kconfig +1 -0
@@ -874,6 +874,7 @@ config WPROBE_EVENTS bool "Enable wprobe-based dynamic events" depends on TRACING depends on HAVE_HW_BREAKPOINT + depends on HAVE_POST_BREAKPOINT_HOOK select PROBE_EVENTS select DYNAMIC_EVENTS help
[email protected]
AI reviewRe: [PATCH v20 05/11] x86: hw_breakpoint: Add a kconfig to clarify when a breakpoint fires
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Masami Hiramatsu (Google) <[email protected]>
Add
CONFIG_HAVE_POST_BREAKPOINT_HOOKwhich indicates thehw_breakpointon that architecture fires after the target memory has been modified. This is currently x86 only behavior.Signed-off-by Masami Hiramatsu (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=5
Masami Hiramatsu (Google)
maintainerPATCH v20 6/11 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.
---
Changes in v20:
- Verify $addr and $value fetchargs in trace output.
- Add test checks for access modes (r@, rw@), length specifiers, symbol offset, and spec-based event removal ('!w:...' and '-:...').
Changes in v17:
- Catch failures when enabling wprobe and call exit_unresolved in case hardware watchpoints are exhausted.
Changes in v9:
- Fix command check logic to prevent early exit under 'set -e' (errexit) when grep or test fails.
- Simplify enable/disable status checks by removing cat pipes.
Changes in v8:
- Fixed silently test failure path.
--- tools/testing/selftests/ftrace/config | 1 .../ftrace/test.d/dynevent/add_remove_wprobe.tc | 81 ++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc
tools/testing/selftests/ftrace/config +1 -0
@@ -33,3 +33,4 @@ CONFIG_SYNTH_EVENTS=y CONFIG_TRACER_SNAPSHOT=y CONFIG_UPROBES=y CONFIG_UPROBE_EVENTS=y +CONFIG_WPROBE_EVENTS=y
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_wprobe.tc new file +81 -0
81 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 06/11] selftests: tracing: Add a basic testcase for wprobe
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
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.
Signed-off-by Masami Hiramatsu (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=6
Masami Hiramatsu (Google)
maintainerPATCH v20 7/11 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.
---
Changes in v20:
- Add error_log to requires line in wprobes_syntax_errors.tc.
- Add testcases for unaligned address (BAD_ACCESS_ADDR) and sibling wprobe rejection (WPROBE_NO_SIBLING).
Changes in v14:
- Update comment for invalid offset syntax check to BAD_PROBE_ADDR.
- Add testcase for invalid address 0 error check (BAD_ACCESS_ADDR).
Changes in v12:
- Add NO_ARG_BODY error case.
Changes in v11:
- Add WPROBE_NO_MAXACT syntax error case.
--- .../test.d/dynevent/wprobes_syntax_errors.tc | 28 ++++++++++++++++++++ 1 file changed, 28 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 +28 -0
@@ -0,0 +1,28 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Watch probe event parser error log check +# requires: dynamic_events error_log "w[:[<group>/][<event>]] [r|w|rw]@<addr>[:<len>]":README + +check_error() { # command-with-error-pos-by-^ + ftrace_errlog_check 'wprobe' "$1" 'dynamic_events' +} + +check_error '^w' # NO_ARG_BODY +check_error 'w^10 w@jiffies' # WPROBE_NO_MAXACT +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@^0:4' # BAD_ACCESS_ADDR +check_error 'w w@^jiffies+1:4' # BAD_ACCESS_ADDR (unaligned) +check_error 'w w@jiffies^+offset' # BAD_PROBE_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 + +echo 'w:test_wprobe w@jiffies:4' >> dynamic_events +check_error '^w:test_wprobe r@jiffies:4' # WPROBE_NO_SIBLING +echo '-:test_wprobe' >> dynamic_events + +exit 0
[email protected]
AI reviewRe: [PATCH v20 07/11] selftests: tracing: Add syntax testcase for wprobe
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
From: Masami Hiramatsu (Google) <[email protected]>
Add "wprobe_syntax_errors.tc" testcase for testing syntax errors of the watch probe events.
Signed-off-by Masami Hiramatsu (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=7
Masami Hiramatsu (Google)
maintainerPATCH v20 8/11 tracing/wprobe: Add set_wprobe and clear_wprobe event triggers
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Add set_wprobe and clear_wprobe event triggers to dynamically attach and detach hardware breakpoint address monitoring based on event field contents.
---
Changes in v20:
- Do not set EVENT_FILE_FL_SOFT_DISABLED_BIT in wprobe_trigger_free() so it follows enable_event semantics and does not prematurely silence the wprobe when removing set_wprobe while clear_wprobe is still active.
- Defer trace_event_put_ref() to private_data_free callback after trigger_data_free() synchronization, matching enable_event triggers.
Changes in v18:
- Use register_wide_hw_breakpoint_cpuslocked() under cpus_read_lock() in __register_trace_wprobe() to avoid CPU hotplug race and lockdep recursive locking warnings.
- Return early on in_nmi() in wprobe_trigger() before taking tw->lock to prevent NMI deadlock.
- Always evaluate __wprobe_count_func() under tw->lock in wprobe_trigger() to fix TOCTOU race for counted triggers.
- Drop redundant in_nmi() check from __wprobe_count_func().
- Defer data->count decrement to wprobe_trigger() under tw->lock after successful hardware update to avoid consuming count on missed triggers and prevent counter underflow.
Changes in v17:
- Add dynamic CPU hotplug callbacks to handle CPU offline/online.
- Restore EVENT_FILE_FL_SOFT_DISABLED_BIT in wprobe_trigger_free().
- Check whether trigger event has "unlimited" field before skipping "unlimited" in clear_wprobe trigger parsing.
- Call tracepoint_synchronize_unregister() before freeing trigger data via data->cmd_ops->free() on registration failure.
- Implement __wprobe_count_func()/wprobe_count_func() helpers to consolidate precondition checks and use it for count_func() and inside wprobe_trigger() function.
Changes in v16:
- Immediately update the hardware breakpoint on the local CPU via trace_wprobe_update_local() in wprobe_trigger() to avoid workqueue latency, and only kick irq_work for other CPUs.
- Skip redundant updates in trace_wprobe_update_local() if bp->attr.bp_addr already matches the target address.
- Use strcmp() instead of strncmp() for "unlimited" to avoid misinterpreting field names starting with "unlimited" as count.
- Normalize "unlimited" and "count=" parameters before creating trigger data so trigger parsing handles count keywords correctly.
Changes in v15:
- Use trace_wprobe_is_valid_addr() in wprobe_trigger() to validate address and natural alignment for wprobe length.
- Record SMP local update failures in tw->missed counter.
- Expose missed event count as a trailing comment in trigger file.
- Add set_wprobe and clear_wprobe triggers to readme_msg in trace.c.
- Fix line length exceeding 100 columns in wprobe_trigger_log_err macro.
- Initialize irq_work and work structs immediately after allocation in alloc_trace_wprobe() and check tw->work.func in free_trace_wprobe() to prevent WARN_ON(!work->func) on early allocation failure.
Changes in v14:
- Allow '-1' as a dummy address in parse_address_spec() to set initial address to WPROBE_DEFAULT_CLEAR_ADDRESS for trigger-only wprobes.
- In trace_wprobe_show(), format WPROBE_DEFAULT_CLEAR_ADDRESS as '-1'.
- Update documentation and examples to use '-1' instead of '0'.
- Skip field parsing in clear_wprobe if parameter is a count keyword.
- Set tw->addr to WPROBE_DEFAULT_CLEAR_ADDRESS before soft-enabling event and roll back on failure.
- Fix memory and refcount leak of trigger_data/wprobe_data on error path.
Changes in v13:
- Align WPROBE_DEFAULT_CLEAR_ADDRESS to 8 bytes using dedicated u64.
- Remove manual count decrement to rely on core event_trigger_count().
- Parse optional FIELD argument in clear_wprobe command.
- Fix trigger reference count leak and error cleanup in command parsing.
- Update document to add [:COUNT] to trigger syntax and fix adjust forms.
- Add notes about the exclusive trigger setting behavior.
- Remove unused dyn_event_ops_mutex.
Changes in v12:
- Decrement trigger data->count only when watchpoint state is actually changed.
- Remove dyn_event_ops_mutex to fix lockdep circular dependency deadlock.
- Add event_trigger_init() call to prevent premature freeing of trigger_data.
--- Documentation/trace/wprobetrace.rst | 107 +++++ include/linux/trace_events.h | 1 kernel/trace/Kconfig | 10 kernel/trace/trace.c | 4 kernel/trace/trace.h | 1 kernel/trace/trace_events_trigger.c | 2 kernel/trace/trace_probe.c | 2 kernel/trace/trace_probe.h | 9 kernel/trace/trace_wprobe.c | 791 +++++++++++++++++++++++++++++++++++ 9 files changed, 922 insertions(+), 5 deletions(-)
Documentation/trace/wprobetrace.rst +107 -0
@@ -76,3 +76,110 @@ Wprobe event does not disable itself even if the module is unloaded. For example, if you add a wprobe event on a module variable, and then unload the module, the wprobe event will still be enabled. This is for watching the address is used unexpectedly after the module is unloaded. + +Combination with trigger action +------------------------------- +The event trigger action can extend the utilization of this wprobe. + +- set_wprobe:WPEVENT:FIELD[+|-ADJUST][:COUNT] +- clear_wprobe:WPEVENT[:FIELD[+|-ADJUST][:COUNT]] + +Set these triggers to the target event, then the WPROBE event will be +setup to trace the memory access at FIELD[+|-ADJUST] address. +When clear_wprobe is hit, if FIELD is NOT specified, the WPEVENT is +forcibly cleared. If FIELD[+|-ADJUST] is set, it clears WPEVENT only +if its watching address is the same as the FIELD[+|-ADJUST] value. +If COUNT is specified, it will set/clear WPEVENT only if it hits COUNT +times. + +Notes: +- set_wprobe only works on the wprobe which is NOT set a valid address yet, + and it must be enabled after the trigger is set. +- clear_wprobe only works on the wprobe which is set a valid address, and it + will be soft-disabled after the trigger is cleared. +- Therefore, if a trigger sets/clears a wprobe, other/same trigger events + will not work (on the same event) while the wprobe is set. + +The set_wprobe trigger does not change the type and length, these +must be set when creating a new wprobe. + +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 invalid dummy address (-1) and keep disabled. + +Wprobe triggers only support target addresses in kernel memory. If a +set_wprobe trigger evaluates to a user-space memory address or NULL +pointer, the trigger action ignores the update and skips setting the +watchpoint. + +Wprobe triggers are not supported on kprobe_events, because kprobes +themselves can use software breakpoints which conflicts with wprobe +operation. + + +For example, trace the first 8 bytes 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@-1: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:dentry' >> 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: 32/32 #P:8 + # + # _-----=> irqs-off/BH-disabled + # / _----=> need-resched + # | / _---=> hardirq/softirq + # || / _--=> preempt-depth + # ||| / _-=> migrate-disable + # |||| / delay + # TASK-PID CPU# ||||| TIMESTAMP FUNCTION + # | | | ||||| | | + sh-107 [004] ...1. 9.990418: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004ad6618 + sh-107 [004] ...1. 9.990914: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b3de78 + sh-107 [004] ...1. 9.993175: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049ddd40 + sh-107 [004] ..... 9.995198: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880048083a8 + sh-107 [004] ...1. 9.995389: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db998 + sh-107 [004] ..Zff 9.997503: watch: (lookup_fast+0xaa/0x150) address=0xffff8880048083a8 value=0x8200080 + sh-107 [004] ..Zff 9.997509: watch: (path_openat+0x211/0xda0) address=0xffff8880048083a8 value=0x8200080 + sh-107 [004] ..Zff 9.997514: watch: (path_openat+0xa56/0xda0) address=0xffff8880048083a8 value=0x8200080 + sh-107 [004] ..Zff 9.997518: watch: (path_openat+0xae2/0xda0) address=0xffff8880048083a8 value=0x8200080 + sh-107 [004] ..... 9.997521: truncate: (do_truncate+0x4/0x120) dentry=0xffff8880048083a8 + sh-107 [004] ...1. 9.997582: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004808270 + sh-107 [004] ...1. 9.999365: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db728 + sh-107 [004] ...1. 9.999388: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b1c000 + rm-113 [005] ..Zff 10.000965: watch: (lookup_fast+0xaa/0x150) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.000971: watch: (path_lookupat+0x97/0x1e0) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.000984: watch: (lookup_fast+0xaa/0x150) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.000988: watch: (path_lookupat+0x97/0x1e0) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.001010: watch: (lookup_one_qstr_excl+0x28/0x140) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.001014: watch: (lookup_one_qstr_excl+0xd1/0x140) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.001018: watch: (may_delete_dentry+0x1c/0x200) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.001021: watch: (may_delete_dentry+0x195/0x200) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] ..Zff 10.001031: watch: (vfs_unlink+0x5e/0x260) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] d.Z.. 10.001067: watch: (d_make_discardable+0x1b/0x40) address=0xffff8880048083a8 value=0x8200080 + rm-113 [005] d.Z.. 10.001071: watch: (d_make_discardable+0x29/0x40) address=0xffff8880048083a8 value=0x200080 + rm-113 [005] ...1. 10.001072: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880048083a8 + rm-113 [005] ...1. 10.001218: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880048083a8 + sh-107 [004] ...1. 10.001416: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db110 + sh-107 [004] ...1. 10.001444: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff8880049db248 + sh-107 [004] ...1. 10.001500: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004ad6618 + sh-107 [004] ...1. 10.002067: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b41e78 + sh-107 [004] ...1. 10.904920: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004b41e78 + sh-107 [004] ...1. 10.905129: dentry_kill: (dentry_kill+0x0/0x2c0) dentry=0xffff888004ad6618 + +You can see the watch event is correctly configured on the dentry.
include/linux/trace_events.h +1 -0
@@ -738,6 +738,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
@@ -884,6 +884,16 @@ config WPROBE_EVENTS Those events can be inserted wherever hardware breakpoints can be set, and record accessed memory address and values. +config WPROBE_TRIGGERS + depends on WPROBE_EVENTS + depends on HAVE_MODIFY_LOCAL_HW_BREAKPOINT_ADDR + bool + 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.c +4 -0
@@ -4374,6 +4374,10 @@ static const char readme_msg[] = "\t trigger: traceon, traceoff\n" "\t enable_event:<system>:<event>\n" "\t disable_event:<system>:<event>\n" +#ifdef CONFIG_WPROBE_TRIGGERS + "\t set_wprobe:<wprobe-event>:<field>[+|-<offset>]\n" + "\t clear_wprobe:<wprobe-event>[:<field>[+|-<offset>]]\n" +#endif#ifdef CONFIG_HIST_TRIGGERS "\t enable_hist:<system>:<event>\n" "\t disable_hist:<system>:<event>\n"
kernel/trace/trace.h +1 -0
@@ -1983,6 +1983,7 @@ trigger_data_alloc(struct event_command *cmd_ops, char *cmd, char *param, void *private_data);extern void trigger_data_free (struct event_trigger_data *data);extern int event_trigger_init (struct event_trigger_data *data); +extern void event_trigger_free (struct event_trigger_data *data);extern int trace_event_trigger_enable_disable (struct trace_event_file *file,int trigger_enable);extern void update_cond_flag (struct trace_event_file *file);
kernel/trace/trace_events_trigger.c +1 -1
@@ -589,7 +589,7 @@ int event_trigger_init(struct event_trigger_data *data)* Usually used directly as the @free method in event trigger * implementations. */ -static void +void event_trigger_free (struct event_trigger_data *data) {if (WARN_ON_ONCE (data->ref <=0 ))
kernel/trace/trace_probe.c +1 -1
@@ -20,7 +20,7 @@#undef C#define C (a, b) b -static const char *trace_probe_err_text[] = {ERRORS }; +const char *trace_probe_err_text[] = {ERRORS };static const char *reserved_field_names[] = {"common_type" ,
kernel/trace/trace_probe.h +8 -1
@@ -636,7 +636,12 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,C (TYPECAST_SYM_OFFSET ,"@SYM+/-OFFSET with typecast needs parentheses" ), \C (USED_ARG_NAME ,"This argument name is already used" ), \C (WPROBE_NO_MAXACT ,"Watchpoint probe does not support maxactive" ), \ -C (WPROBE_NO_SIBLING ,"Watchpoint probe does not support sibling probes" ), +C (WPROBE_NO_SIBLING ,"Watchpoint probe does not support sibling probes" ), \ +C (WPROBE_ON_KPROBE ,"Wprobe trigger is not supported on kprobe event" ), \ +C (WPROBE_NOT_FOUND ,"Target wprobe event is not found" ), \ +C (WPROBE_BUSY ,"Target wprobe event is already enabled" ), \ +C (WPROBE_NEED_FIELD ,"Wprobe trigger requires a target field" ), \ +C (WPROBE_BAD_FIELD ,"Target field must be pointer size" ), #undef C #define C(a, b) TP_ERR_##a
@@ -660,6 +665,8 @@ void __trace_probe_log_err(int offset, int err); DEFINE_FREE(trace_probe_log_clear, const char *, if (_T) trace_probe_log_clear()) +extern const char *trace_probe_err_text[]; +#define trace_probe_log_err (offs, err) \ __trace_probe_log_err(offs, TP_ERR_##err)
kernel/trace/trace_wprobe.c +789 -2
887 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 08/11] tracing/wprobe: Add set_wprobe and clear_wprobe event triggers
Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [Medium] tracing/wprobe: stale work_pending after cancel_work_sync() wedges triggers - [Medium]…
Thank you for your contribution! Sashiko AI review found 9 potential issues to consider:
- [Medium] tracing/wprobe: stale work_pending after cancel_work_sync() wedges triggers
- [Medium] tracing/wprobe: race and UAF on bp_event in wprobe_trigger_free() teardown
- [Medium] tracing/wprobe: broken trace_probe_is_enabled() check in trigger parse
- [Medium] tracing/wprobe: TASK_SIZE in trace_wprobe_is_valid_addr() allows user addr
- [Medium] tracing/wprobe: unrestored tw->addr after set_wprobe breaks show and match
- [Medium] tracing/wprobe: stale breakpoint hits fire triggers in wprobe_trace_handler()
- [Medium] tracing/wprobe: self-deadlock on tw->lock in wprobe_trigger()
- [Low] tracing/wprobe: in-place NUL mutation of glob truncates trigger error_log
- [Low] tracing/wprobe: unlocked double read of tw->addr in trace_wprobe_show()
--
commit 86f0de972cafa3458ae22f00d7d3014fc1fc6164
Author: Masami Hiramatsu (Google) <[email protected]>
tracing/wprobe: Add set_wprobe and clear_wprobe event triggers
This commit adds set_wprobe and clear_wprobe event triggers to dynamically configure and clear hardware watchpoint addresses from trace event fields.
Quoted 4 lines
kernel/trace/trace_wprobe.c +0
-0
[ ... ]
Quoted 28 lines
kernel/trace/trace_wprobe.c +10
-1@@ -217,28 +241,143 @@ static int __register_trace_wprobe(struct trace_wprobe *tw) attr.bp_len = tw->len; attr.bp_type = tw->type; - tw->bp_event =register_wide_hw_breakpoint (&attr, wprobe_perf_handler, tw); +cpus_read_lock (); + tw->bp_event =register_wide_hw_breakpoint_cpuslocked (&attr, + wprobe_perf_handler, + tw);if (IS_ERR_PCPU (tw->bp_event)) {int ret =PTR_ERR_PCPU (tw->bp_event); tw->bp_event =NULL ; +cpus_read_unlock ();return ret; } +mutex_lock (&wprobe_mutex); +list_add (&tw->active_list, &active_wprobes); +mutex_unlock (&wprobe_mutex); +cpus_read_unlock (); +return 0 ; }static void __unregister_trace_wprobe (struct trace_wprobe *tw) {if (tw->bp_event) {
kernel/trace/trace_wprobe.c static int __register_trace_wprobe(struct trace_wprobe *tw) · line 276
Quoted 10 lines
kernel/trace/trace_wprobe.c +6
-0+mutex_lock (&wprobe_mutex); +list_del_init (&tw->active_list); +mutex_unlock (&wprobe_mutex); + +irq_work_sync (&tw->irq_work); +cancel_work_sync (&tw->work);unregister_wide_hw_breakpoint (tw->bp_event); tw->bp_event =NULL ; } }
[Severity: Medium]
Does cancelling tw->work in __unregister_trace_wprobe() leave tw->work_pending stuck at 1?
wprobe_trigger() sets tw->work_pending to 1 before queueing tw->irq_work, and only wprobe_work_func() resets it to 0. If __unregister_trace_wprobe() runs after wprobe_irq_work_func() schedules tw->work but before wprobe_work_func() executes, cancel_work_sync(&tw->work) cancels the work item without clearing tw->work_pending. Every later trigger evaluation on that wprobe then sees atomic_read(&tw->work_pending) != 0 in __wprobe_count_func(), increments tw->missed, and drops all future updates.
[ ... ]
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 954
Quoted 11 lines
kernel/trace/trace_wprobe.c +4
-0@@ -788,6 +945,10 @@ static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) tw->offset, len); else seq_printf(m, " %s@%s:%d", type_str, tw->symbol, len); +#ifdef CONFIG_WPROBE_TRIGGERS + }else if (tw->addr ==WPROBE_DEFAULT_CLEAR_ADDRESS ) {\ +seq_printf (m," %s@-1:%d" , type_str, len); +#endif }else {seq_printf (m," %s@0x%lx:%d" , type_str, tw->addr, len); }
[Severity: Low]
Can trace_wprobe_show() print the raw address ofwprobe_trigger_clear_target instead of -1?
wprobe_trigger() updates tw->addr concurrently under tw->lock without holding dyn_event_ops_mutex. Because trace_wprobe_show() reads tw->addr a second time in the else branch instead of reading it once with READ_ONCE() into a local variable, a concurrent clear_wprobe trigger setting tw->addr to WPROBE_DEFAULT_CLEAR_ADDRESS between the comparison and seq_printf() causes dynamic_events to print the address of wprobe_trigger_clear_target.
Quoted 1 line
kernel/trace/trace_wprobe.c +0
-0@@ -800,9 +961,635 @@ static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev)
[ ... ]
Quoted 7 lines
kernel/trace/trace_wprobe.c +7
-0+static bool __wprobe_count_func (struct event_trigger_data *data, +unsigned long addr) +{ +struct wprobe_trigger_data *wprobe_data = data->private_data; +struct trace_wprobe *tw = wprobe_data->tw; +unsigned long cur_addr; +
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 1019
Quoted 10 lines
kernel/trace/trace_wprobe.c +10
-0+if (atomic_read (&tw->work_pending)) +return false; + + cur_addr =READ_ONCE (tw->addr); + +if (!wprobe_data->clear) { +if (cur_addr !=WPROBE_DEFAULT_CLEAR_ADDRESS ) +return false; +if (!trace_wprobe_is_valid_addr (addr, tw->len)) +return false;
[Severity: Medium]
Can trace_wprobe_is_valid_addr() allow a set_wprobe trigger to install a user-space watchpoint address when a 32-bit compat task is running?
kernel/trace/trace_wprobe.c:trace_wprobe_is_valid_addr() {
if (addr < TASK_SIZE)
return false;
...
}On 64-bit architectures with 32-bit compatibility mode (such as x86_64 with CONFIG_IA32_EMULATION), TASK_SIZE depends on the current task's personality and evaluates to IA32_PAGE_OFFSET (~4 GiB) when a 32-bit compat task is running. Because modify_local_hw_breakpoint_addr() bypasses arch_check_bp_in_kernelspace() (which checks TASK_SIZE_MAX), a set_wprobe trigger firing in the context of a 32-bit compat task accepts any aligned 64-bit user-space address in [IA32_PAGE_OFFSET, TASK_SIZE_MAX) and programs it into the CPU-wide hardware debug registers. Using TASK_SIZE_MAX (or arch_check_bp_in_kernelspace()) avoids depending on current.
[ ... ]
Quoted 65 lines
kernel/trace/trace_wprobe.c +65
-0+static void wprobe_trigger (struct event_trigger_data *data, +struct trace_buffer *buffer,void *rec, +struct ring_buffer_event *event) +{ +struct wprobe_trigger_data *wprobe_data = data->private_data; +struct trace_wprobe *tw = wprobe_data->tw; +unsigned long target_addr, addr =0 , flags; + +if (in_nmi ()) +return ; + +if (wprobe_data->field) { +if (!rec) +return ; + addr = *(unsigned long *)((char *)rec + wprobe_data->offset); + addr += wprobe_data->adjust; + } + +raw_spin_lock_irqsave (&tw->lock, flags); + +if (!__wprobe_count_func (data, addr)) { +atomic_inc (&tw->missed); + goto out; + } + +/* +* For counted triggers, verify data->count is still available under +* tw->lock to prevent concurrent executions from exceeding the limit. +*/ +if ((data->flags &EVENT_TRIGGER_FL_COUNT ) && !data->count) + goto out; + + target_addr = wprobe_data->clear ?WPROBE_DEFAULT_CLEAR_ADDRESS : addr; + +/* +* Try updating the hardware breakpoint on the local CPU first. +* If this fails, skip updating tw->addr and do not queue irq_work. +* Note that this wprobe will not be traced until tw_addr is updated. +* (e.g. NMI happens on this CPU.) +*/ +if (trace_wprobe_update_local (tw, target_addr)) { +atomic_inc (&tw->missed); + goto out; + } + +/* +* Decrement data->count here under tw->lock only after the local +* hardware breakpoint has been successfully updated. This avoids: +* 1) Consuming count on trigger attempts that failed/missed. +* 2) Race windows where concurrent CPUs decrement count and underflow +* to -1 (unlimited). +*/ +if (data->flags &EVENT_TRIGGER_FL_COUNT ) { +if (data->count >0 ) + (data->count)--; + } + +WRITE_ONCE (tw->addr, target_addr); +if (!wprobe_data->clear) +clear_bit (EVENT_FILE_FL_SOFT_DISABLED_BIT , &wprobe_data->file->flags); +else +set_bit (EVENT_FILE_FL_SOFT_DISABLED_BIT , &wprobe_data->file->flags); + +/* +* For other CPUs, kick irq_work to asynchronously propagate
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 1140
Quoted 10 lines
kernel/trace/trace_wprobe.c +10
-0+* the new address. +*/ +if (num_online_cpus () >1 ) { +atomic_set (&tw->work_pending,1 ); +irq_work_queue (&tw->irq_work); + } + +out: +raw_spin_unlock_irqrestore (&tw->lock, flags); +}
[Severity: Medium]
Can wprobe_trigger() self-deadlock on tw->lock if a nested event fires while tw->lock is held?
wprobe_trigger()
raw_spin_lock_irqsave(&tw->lock, flags)
irq_work_queue(&tw->irq_work)
...
native_write_msr()
trace_write_msr()
...
wprobe_trigger()
raw_spin_lock_irqsave(&tw->lock, flags) <-- spins foreverWhile wprobe_trigger() holds tw->lock, irq_work_queue() on x86 with x2APIC raises a self-IPI via native_write_msr(), firing the msr:write_msr tracepoint, and functions called by trace_wprobe_update_local() (such as modify_local_hw_breakpoint_addr()) can also be traced by fprobe events. If a wprobe trigger targeting the same trace_wprobe is attached to one of those nested events, the inner wprobe_trigger() runs on the same CPU with in_nmi() == false and spins forever on tw->lock.
[Severity: Medium]
Can a stale breakpoint hit on a remote CPU fire unconditional triggers attached to the wprobe event after clear_wprobe or set_wprobe updates tw->addr?
CPU0 CPU1wprobe_trigger()
WRITE_ONCE(tw->addr,
WPROBE_DEFAULT_CLEAR_ADDRESS)
set_bit(SOFT_DISABLED_BIT, ...)
irq_work_queue(&tw->irq_work)
wprobe_perf_handler()
wprobe_trace_handler(tw, old_addr, ...)
trace_trigger_soft_disabled(trace_file)
event_triggers_call(...)
if (READ_ONCE(tw->addr) != addr)
return;kernel/trace/trace_wprobe.c:wprobe_trace_handler() {
...
if (trace_trigger_soft_disabled(trace_file))
return;
if (READ_ONCE(tw->addr) != addr)
return;
...
}Because remote CPUs update their hardware debug registers asynchronously via tw->work, a remote CPU can still take a breakpoint exception for the old address after tw->addr has changed. In wprobe_trace_handler(), trace_trigger_soft_disabled() runs before the READ_ONCE(tw->addr) != addr check, which invokes __trace_trigger_soft_disabled() -> event_triggers_call() and fires any unconditional triggers (such as traceoff, snapshot, or stacktrace) attached to the wprobe event. Checking READ_ONCE(tw->addr) != addr before trace_trigger_soft_disabled() avoids firing triggers on stale hits.
[ ... ]
Quoted 8 lines
kernel/trace/trace_wprobe.c +8
-0+static void release_private_wprobe_trigger_data (struct event_trigger_data *data) +{ +struct wprobe_trigger_data *wprobe_data = data->private_data; + +/* The file may already be freed here, only the call is kept alive */ +trace_event_put_ref (trace_probe_event_call (&wprobe_data->tw->tp)); +free_wprobe_trigger_data (wprobe_data); +}
[ ... ]
Quoted 5 lines
kernel/trace/trace_wprobe.c +5
-0+static void wprobe_trigger_free (struct event_trigger_data *data) +{ +struct wprobe_trigger_data *wprobe_data = data->private_data; + +if (WARN_ON_ONCE (data->ref <=0 ))
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 1231
Quoted 10 lines
kernel/trace/trace_wprobe.c +10
-0+return ; + + data->ref--; +if (!data->ref) { +/* Remove the SOFT_MODE flag */ +trace_event_enable_disable (wprobe_data->file,0 ,1 ); + data->private_data_free = release_private_wprobe_trigger_data; +trigger_data_free (data); + } +}
[Severity: Medium]
Can wprobe_trigger_free() unregister and free tw->bp_event while an in-flight wprobe_trigger() is still using it?
CPU0 CPU1clear_event_triggers()
list_del_rcu(&data->list)
wprobe_trigger_free(data)
trace_event_enable_disable()
...
__unregister_trace_wprobe(tw)
unregister_wide_hw_breakpoint(
tw->bp_event)
wprobe_trigger()
trace_wprobe_update_local(tw, ...)
bp = *this_cpu_ptr(tw->bp_event)
modify_local_hw_breakpoint_addr(bp, ...)
<-- use-after-free
tw->bp_event = NULL
trigger_data_free(data)
/* tracepoint_synchronize_unregister() happens later in kthread */When a trace instance is removed, clear_event_triggers() calls data->cmd_ops->free(data) immediately after list_del_rcu() without waiting for tracepoint_synchronize_unregister(). Because wprobe_trigger_free() calls trace_event_enable_disable() before trigger_data_free() waits for in-flight tracepoints, __unregister_trace_wprobe() frees the per-CPU perf_event breakpoints and tw->bp_event before clearing tw->bp_event = NULL and without synchronizing with tw->lock, while a concurrent wprobe_trigger() on another CPU dereferences tw->bp_event and queues tw->irq_work after irq_work_sync() has already returned.
Conversely, when a user removes a trigger via wprobe_unregister_trigger(), tracepoint_synchronize_unregister() has already completed, but deferring trace_event_put_ref() to release_private_wprobe_trigger_data() on trigger_kthread means an immediate dynamic_events removal of the wprobe can race with the kthread and fail with -EBUSY.
Quoted 41 lines
kernel/trace/trace_wprobe.c +41
-0+static int wprobe_trigger_cmd_parse (struct event_command *cmd_ops, +struct trace_event_file *file, +char *glob,char *cmd, +char *param_and_filter) +{ +/* +* set_wprobe:EVENT:FIELD[+OFFS] +* clear_wprobe:EVENT[:FIELD[+OFFS]] +*/ +struct wprobe_trigger_data *wprobe_data =NULL ; +struct event_trigger_data *trigger_data =NULL ; +struct trace_event_file *wprobe_file; +struct trace_array *tr = file->tr; +char *event_str, *field_str, *comment; +struct ftrace_event_field *field; +struct trace_event_call *event; +bool remove, clear = false; +unsigned long orig_addr =0 ; +struct trace_wprobe *tw; +char *param, *filter; +int ret; + + remove =event_trigger_check_remove (glob); + +if (!strcmp (cmd,CLEAR_WPROBE_STR )) + clear = true; + +if (param_and_filter) { +/* Recover original trigger string to show the error log correctly. */ +if (*(param_and_filter -1 ) =='\0' ) + *(param_and_filter -1 ) =':' ; + comment =strchr (param_and_filter,'#' ); +if (comment) + *comment ='\0' ; + } + +if (event_trigger_empty_param (param_and_filter)) { +wprobe_trigger_log_err (file, glob,strlen (cmd) +1 ,WPROBE_NOT_FOUND ); +return -EINVAL ; + } +
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 1283
Quoted 10 lines
kernel/trace/trace_wprobe.c +10
-0+ ret =event_trigger_separate_filter (param_and_filter, ¶m, &filter, true); +if (ret) +return ret; + +if (file->event_call->flags &TRACE_EVENT_FL_KPROBE ) { +wprobe_trigger_log_err (file, glob,0 ,WPROBE_ON_KPROBE ); +return -EOPNOTSUPP ; + } + + event_str =strsep (¶m,":" );
[Severity: Low]
Does mutating param_and_filter in place truncate the command string logged by wprobe_trigger_log_err()?
param_and_filter points into the glob buffer. Although the code restores the colon at *(param_and_filter - 1), subsequent calls to event_trigger_separate_filter(), strsep(¶m, ":"), and *offs = '\0' insert NUL terminators directly into glob. Any later wprobe_trigger_log_err(file, glob, ...) call for a bad field, offset, or count logs only the truncated prefix of glob while passing an error caret offset past the end of the logged string. Also, when param_and_filter is NULL (for example, writing "set_wprobe" with no colon), strlen(cmd) + 1 points one byte past the NUL terminator of glob.
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 1295
Quoted 11 lines
kernel/trace/trace_wprobe.c +11
-0+/* Find target wprobe */ + tw =find_trace_wprobe (event_str,WPROBE_EVENT_SYSTEM ); +if (!tw) { +wprobe_trigger_log_err (file, glob, event_str - glob,WPROBE_NOT_FOUND ); +return -ENOENT ; + } +/* The target wprobe must not be used (unless clear) */ +if (!remove && !clear &&trace_probe_is_enabled (&tw->tp)) { +wprobe_trigger_log_err (file, glob, event_str - glob,WPROBE_BUSY ); +return -EBUSY ; + }
[Severity: Medium]
Does checking trace_probe_is_enabled(&tw->tp) here conflate manual enabling with trigger soft-enabling?
Both set_wprobe and clear_wprobe call trace_event_enable_disable(wprobe_file, 1, 1), which sets TP_FLAG_TRACE on tw->tp and makes trace_probe_is_enabled(&tw->tp) return true. As a result, registering clear_wprobe before set_wprobe, re-adding set_wprobe after removing it while clear_wprobe is still attached, or attaching set_wprobe to a second event all fail with -EBUSY. When clear_wprobe is registered first, tw->addr is also not initialized to WPROBE_DEFAULT_CLEAR_ADDRESS because that assignment is gated on !clear.
Conversely, because clear_wprobe skips this busy check, it can be attached to a wprobe that was manually enabled by the user (where sm_ref == 0); when clear_wprobe fires or is later removed, it soft-disables or unregisters the manually enabled wprobe.
[ ... ]
kernel/trace/trace_wprobe.c static int trace_wprobe_show(struct seq_file *m, struct dyn_event *ev) · line 1444
Quoted 6 lines
kernel/trace/trace_wprobe.c +6
-0+if (!clear) { + orig_addr = tw->addr; +WRITE_ONCE (tw->addr,WPROBE_DEFAULT_CLEAR_ADDRESS ); + } + + ret =trace_event_enable_disable (wprobe_file,1 ,1 );
[Severity: Medium]
Does overwriting tw->addr without restoring it on trigger teardown break trace_wprobe_show() and dynamic_events deletion?
When set_wprobe is registered and fires, tw->addr is overwritten first with WPROBE_DEFAULT_CLEAR_ADDRESS and then with the runtime target address, and removing the trigger leaves tw->addr at that runtime value. For a wprobe created with rw@-1:8, removing set_wprobe after it fires causes trace_wprobe_show() to print the runtime address instead of -1, and deleting the wprobe with "!w:watch rw@-1:8 ..." fails in trace_wprobe_match_command_head() because tw->addr no longer equals WPROBE_DEFAULT_CLEAR_ADDRESS. For a symbol-based wprobe, tw->symbol remains set while tw->addr is left clobbered, so trace_wprobe_show() still shows @symbol while re-enabling the wprobe watches the wrong address.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=8
Masami Hiramatsu (Google)
maintainerPATCH v20 9/11 selftests: tracing: Add wprobe trigger testcases
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Add testcases for checking wprobe triggers. This sets set_wprobe and clear_wprobe triggers on fprobe event and static trace event to monitor memory accesses within the trace-events-sample kernel module. Also add a testcase for verifying wprobe triggers across CPU hotplug, and a testcase for verifying wprobe trigger syntax error logging.
---
Changes in v20:
- Verify events/wprobes/watch/enable transitions to '0*' after clear_wprobe fires in trigger-wprobe.tc and trigger-wprobe-hotplug.tc.
- Add test checks for pointer field offset (timer+16), trigger count limit (:1), and conditional clear_wprobe:watch:timer+16 in trigger-wprobe.tc.
- Use $arg1 instead of BTF argument 't' in trigger-wprobe.tc and trigger-wprobe-hotplug.tc, and drop redundant fprobe README check.
- Add WPROBE_BAD_FIELD, BAD_DEREF_OFFS, and BAD_IMM test cases to trigger-wprobe-syntax-errors.tc.
Changes in v18:
- Add "set_wprobe:<wprobe-event>":README to requires line in wprobe trigger tests so they are skipped if CONFIG_WPROBE_TRIGGERS is disabled.
- Clear trace buffer after taking CPU offline in trigger-wprobe-hotplug.tc to avoid matching watchpoint events logged prior to offlining.
Changes in v17:
- Add trigger-wprobe-hotplug.tc to verify wprobe triggers across CPU offline and online transitions.
Changes in v15:
- Add explicit failure checks with fail helper in trigger-wprobe.tc.
- Declare fprobe README requirement in trigger-wprobe.tc.
- Add trigger file check to trigger-wprobe-syntax-errors.tc requires line.
- Fix subject tag to tracing.
Changes in v14:
- Update dummy wprobe event definition to use '-1' instead of '0'.
- Add BTF argument dependency requirement in trigger-wprobe.tc.
- Add delay before clear_trace in trigger-wprobe.tc to avoid race with clear_wprobe trigger execution.
Changes in v13:
- Look up target function dynamically in trigger-wprobe-syntax-errors.tc.
- Disable set_wprobe trigger before verifying clear_wprobe in trigger-wprobe.tc to avoid race condition with sample_timer_cb.
Changes in v12:
- Add trigger-wprobe-syntax-errors.tc for verifying wprobe trigger syntax error logging.
- Fix requires line in trigger-wprobe-syntax-errors.tc so test is not evaluated as unsupported prior to execution.
- Define dfd=$arg1 fetcharg on testevent for trigger syntax checks.
Changes in v11:
- Update testcase to use trace-events-sample kernel module instead of VFS file operations.
--- tools/testing/selftests/ftrace/config | 1 .../test.d/trigger/trigger-wprobe-hotplug.tc | 150 ++++++++++++++++++++ .../test.d/trigger/trigger-wprobe-syntax-errors.tc | 40 +++++ .../ftrace/test.d/trigger/trigger-wprobe.tc | 135 ++++++++++++++++++ 4 files changed, 326 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-hotplug.tc create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-syntax-errors.tc create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc
tools/testing/selftests/ftrace/config +1 -0
@@ -34,3 +34,4 @@ CONFIG_TRACER_SNAPSHOT=y CONFIG_UPROBES=y CONFIG_UPROBE_EVENTS=y CONFIG_WPROBE_EVENTS=y +CONFIG_WPROBE_TRIGGERS=y
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-hotplug.tc new file +150 -0
150 lines not on this page · raw message
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-syntax-errors.tc new file +40 -0
@@ -0,0 +1,40 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: event trigger - test wprobe trigger syntax errors +# requires: dynamic_events error_log "w[:[<group>/][<event>]] [r|w|rw]@<addr>[:<len>]":README "f[:[<group>/][<event>]] <func-name>[%return] [<args>]":README events/sched/sched_process_fork/trigger "set_wprobe:<wprobe-event>":README + +check_error() { # command-with-error-pos-by-^ + ftrace_errlog_check "wprobe_trigger" "$1" "events/fprobes/testevent/trigger" +} + +TARGET_FUNC=$(grep -m 1 -E -w "[tT] (vfs_read|do_sys_openat2|do_sys_open)" /proc/kallsyms | awk '{print $3}') +if [ -z "$TARGET_FUNC" ]; then + echo "UNRESOLVED: target function not found" + exit_unresolved +fi + +# Add a dummy fprobe event to attach triggers to +echo "f:fprobes/testevent $TARGET_FUNC dfd=\$arg1 u32_arg=\$arg2:u32" > dynamic_events + +# Add a target wprobe event +echo 'w:watch rw@-1:8' >> dynamic_events + +# Test errors on trigger syntax +check_error 'set_wprobe:^non_exist_wprobe:dfd' # WPROBE_NOT_FOUND +check_error 'set_wprobe:^' # WPROBE_NOT_FOUND +check_error 'set_wprobe:watch^' # WPROBE_NEED_FIELD +check_error 'set_wprobe:watch:^non_exist_field' # NO_EVENT_FIELD +check_error 'set_wprobe:watch:^u32_arg' # WPROBE_BAD_FIELD +check_error 'set_wprobe:watch:dfd^+bad' # BAD_DEREF_OFFS +check_error 'set_wprobe:watch:dfd:^bad_count' # BAD_IMM + +# Enable target wprobe event and test WPROBE_BUSY error +echo 1 > events/wprobes/watch/enable +check_error 'set_wprobe:^watch:dfd' # WPROBE_BUSY +echo 0 > events/wprobes/watch/enable + +# Cleanup +echo '-:watch' >> dynamic_events +echo '-:testevent' >> dynamic_events + +exit 0
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc new file +135 -0
135 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 09/11] selftests: tracing: Add wprobe trigger testcases
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] selftests: ftrace: race checking count=1 on active timer in trigger-wprobe.tc - [Low] selftests…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] selftests: ftrace: race checking count=1 on active timer in trigger-wprobe.tc
- [Low] selftests: ftrace: race truncating dynamic_events after wprobe trigger removal
--
commit 99426394cee3a23084f980a46322a802a391dabe
Author: Masami Hiramatsu (Google) <[email protected]>
selftests: tracing: Add wprobe trigger testcases
This commit adds ftrace selftests covering set_wprobe and clear_wprobe event triggers, including CPU hotplug and trigger syntax error checks.
Quoted 5 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc new file +0
-0
[ ... ]
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc line 107
Quoted 6 lines
+:;: "Test field offset, count limit, and conditional
clear_wprobe" ;:tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc new file +5
-0+clear_trace +echo 'set_wprobe:watch:timer+16:1' >> events/fprobes/testevent/trigger +if ! grep -q '^set_wprobe:watch:timer+16:count=1' events/fprobes/testevent/trigger; then + fail "Failed to set counted set_wprobe trigger with offset" +fi
[Severity: Low]
Can sample_timer_cb() fire before grep reads events/fprobes/testevent/trigger here?
events/fprobes/testevent/enable is already set to 1 while sample_timer_cb() runs every second on a timer. If the timer expires between registering the trigger and spawning grep, wprobe_trigger() decrements data->count from 1 to 0:
shell <softirq>write()
wprobe_register_trigger()
sample_timer_cb()
wprobe_trigger()
data->count-- (1 -> 0)grep
wprobe_trigger_print()
prints count=0 <-- grep for count=1 fails
Disabling testevent while registering and checking count=1, or matching count=[01] before the post-sleep count=0 check, would avoid a spurious test failure.
Quoted 15 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc new file +15
-0+ +sleep 2 +if ! grep -q watch trace; then + fail "Failed to trigger watchpoint with field offset and count" +fi +if ! grep -q '^set_wprobe:watch:timer+16:count=0' events/fprobes/testevent/trigger; then + fail "Counted set_wprobe trigger did not decrement count to 0" +fi + +echo 'clear_wprobe:watch:timer+16' >> events/fprobes/testevent/trigger +echo '!set_wprobe:watch:timer+16' >> events/fprobes/testevent/trigger +sleep 2 +clear_trace +sleep 1 +if ! grep -q '^0\*' events/wprobes/watch/enable; then
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc line 132
Quoted 10 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe.tc new file +10
-0+ fail "Conditional clear_wprobe did not soft-disable watchpoint" +fi +if grep -q watch trace; then + fail "Failed to clear watchpoint with conditional clear_wprobe" +fi +echo '!clear_wprobe:watch:timer+16' >> events/fprobes/testevent/trigger + +:;: "Disable events and remove dynamic events" ;: +echo 0 > events/enable +echo > dynamic_events
[Severity: Low]
Can truncating dynamic_events immediately after removing clear_wprobe fail with -EBUSY?
When a wprobe trigger is registered, wprobe_trigger_cmd_parse() takes a reference on the target wprobe event via trace_event_try_get_ref(). Unregistering the trigger calls wprobe_trigger_free() -> trigger_data_free(), which defers release_private_wprobe_trigger_data() -> trace_event_put_ref() to trigger_kthread after tracepoint_synchronize_unregister() finishes:
shell trigger_kthreadwrite("!clear_wprobe:...")
wprobe_unregister_trigger()
trigger_data_free()write("" > dynamic_events)
dyn_events_release_all()
unregister_trace_wprobe()
trace_event_dyn_busy() <-- returns -EBUSY
tracepoint_synchronize_unregister() release_private_wprobe_trigger_data()
trace_event_put_ref()
The same race applies to cleanup_wprobe_triggers() and to trigger-wprobe-hotplug.tc where echo > dynamic_events runs immediately after removing the triggers; calling clear_dynamic_events (which retries in a loop) or sleeping before truncating dynamic_events would avoid this.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=9
Masami Hiramatsu (Google)
maintainerPATCH v20 10/11 tracing/wprobe: Support BTF typecast in fetchargs
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Allow BTF typecast syntax (STRUCT)FETCHARG->MEMBER in wprobe event fetchargs. Previously, handle_typecast() rejected any probe context that was not a function entry/return or tracepoint event probe.
Wprobe events use $addr (the accessed address) and $value (the value at that address). By enabling BTF typecast, users can now cast these to a concrete struct type and access its fields directly. For example:
echo 'w:watch rw@-1:8 dflag=(dentry)$addr->d_flags' >> dynamic_events
With a set_wprobe trigger pointing the watchpoint at a dentry address, the resulting trace shows d_flags being accessed at that location.
Note that $addr and $value are restricted to kernel-space memory, which is consistent with the existing TPARG_FL_KERNEL flag used when parsing wprobe fetchargs.
---
Changes in v20:
- Verify BTF typecast fields (counter= and expires=) in trace output in trigger-wprobe-btf-typecast.tc, and test direct (STRUCT)$addr->MEMBER and (STRUCT)$value->MEMBER typecasts.
- Drop redundant fprobe README check in trigger-wprobe-btf-typecast.tc.
Changes in v18:
- Add "set_wprobe:<wprobe-event>":README to requires line in trigger-wprobe-btf-typecast.tc so the test is skipped if CONFIG_WPROBE_TRIGGERS is disabled.
Changes in v15:
- Document BTF typecast syntax for wprobe fetchargs in wprobetrace.rst.
- Add explicit failure checks with fail helper in trigger-wprobe-btf-typecast.tc.
- Declare fprobe README requirement in trigger-wprobe-btf-typecast.tc.
Changes in v14:
- Update dummy wprobe event definition to use '-1' instead of '0'.
Changes in v11:
- Update trigger-wprobe-btf-typecast.tc to use trace-events-sample kernel module.
- Fix commit comment.
Changes in v9:
- Newly added.
--- Documentation/trace/wprobetrace.rst | 8 ++ kernel/trace/trace_probe.c | 13 +++ kernel/trace/trace_probe.h | 5 + tools/testing/selftests/ftrace/config | 1 .../test.d/trigger/trigger-wprobe-btf-typecast.tc | 85 ++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-btf-typecast.tc
Documentation/trace/wprobetrace.rst +8 -0
@@ -47,6 +47,14 @@ Synopsis of wprobe-events (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types (x8/x16/x32/x64), "char", "string", "ustring", "symbol", "symstr" and bitfield are supported. + (STRUCT[,ASGN])FETCHARG->MEMBER[->MEMBER] : If BTF is supported, typecast + FETCHARG to a pointer to STRUCT and then dereference the + pointer defined by ->MEMBER. ASGN can be specified optionally. + If ASGN is specified, FETCHARG will be cast to the same offset + position as the ASGN member, rather than to the beginning of + the STRUCT. + (STRUCT[,ASGN])(FETCHARG)->MEMBER[->MEMBER] : typecast can nest, so the above + can also be used with another FETCHARG. (\*1) This is useful for fetching a field of data structures. (\*2) "u" means user-space dereference.
kernel/trace/trace_probe.c +12 -1
@@ -928,6 +928,16 @@ static int query_btf_struct(const char *sname, struct traceprobe_parse_context * ctx->struct_btf =NULL ; } +if (ctx->btf) { + id =btf_find_by_name_kind (ctx->btf, sname,BTF_KIND_STRUCT ); +if (id >0 ) { +btf_get (ctx->btf); + ctx->struct_btf = ctx->btf; + ctx->last_struct =btf_type_by_id (ctx->struct_btf, id); +return 0 ; + } + } + id =bpf_find_btf_id (sname,BTF_KIND_STRUCT , &btf);if (id <0 )return id;
@@ -1003,7 +1013,8 @@ static int handle_typecast(char *arg, struct traceprobe_parse_context *ctx)if (!(tparg_is_event_probe (ctx->flags) ||tparg_is_function_entry (ctx->flags) || -tparg_is_function_return (ctx->flags))) { +tparg_is_function_return (ctx->flags) || +tparg_is_wprobe (ctx->flags))) {trace_probe_log_err (ctx->offset,NOSUP_BTFARG );return -EOPNOTSUPP ; }
kernel/trace/trace_probe.h +5 -0
@@ -439,6 +439,11 @@ static inline bool tparg_is_event_probe(unsigned int flags)return !!(flags &TPARG_FL_TEVENT ); } +static inline bool tparg_is_wprobe (unsigned int flags) +{ +return !!(flags &TPARG_FL_WPROBE ); +} +/* Each typecast consumes nested level. So the max number of typecast is 8. */ #define TRACEPROBE_MAX_NESTED_LEVEL 8
tools/testing/selftests/ftrace/config +1 -0
@@ -2,6 +2,7 @@ CONFIG_BOOT_CONFIG=y CONFIG_BOOTTIME_TRACING=y CONFIG_BPF_SYSCALL=y CONFIG_DEBUG_INFO_BTF=y +CONFIG_DEBUG_INFO_BTF_MODULES=y CONFIG_DEBUG_INFO_DWARF4=y CONFIG_EPROBE_EVENTS=y CONFIG_FPROBE=y
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-btf-typecast.tc new file +85 -0
85 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 10/11] tracing/wprobe: Support BTF typecast in fetchargs
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
From: Masami Hiramatsu (Google) <[email protected]>
Allow BTF typecast syntax (STRUCT)FETCHARG->MEMBER in wprobe event fetchargs. Previously,
handle_typecast()rejected any probe context that was not a function entry/return or tracepoint event probe.Wprobe events use $addr (the accessed address) and $value (the value at that address). By enabling BTF typecast, users can now cast these to a concrete struct type and access its fields directly. For example:
echo 'w:watch rw@-1:8 dflag=(dentry)$addr->d_flags' >>
dynamic_events
Quoted 8 lines
With a
set_wprobetrigger pointing the watchpoint at a dentry address, the resulting trace showsd_flagsbeing accessed at that location.Note that $addr and $value are restricted to kernel-space memory, which is consistent with the existing
TPARG_FL_KERNELflag used when parsing wprobe fetchargs.Signed-off-by Masami Hiramatsu (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=10
Masami Hiramatsu (Google)
maintainerPATCH v20 11/11 tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Allow set_wprobe trigger to use BTF struct offset resolution to specify the target address field.
---
Changes in v20:
- Verify resolved non-zero BTF offset in trigger file and test clear_wprobe with BTF struct offset resolution in trigger-wprobe-btf-offset.tc.
- Drop redundant fprobe README check in trigger-wprobe-btf-offset.tc.
Changes in v18:
- In get_offset_of_field(), rename mtype to container and document that it represents the containing structure/union type (handling anonymous structures/unions) rather than member's own type.
- In get_offset_of_field(), verify bit offset is byte-aligned before returning byte offset.
- Add "set_wprobe:<wprobe-event>":README to requires line in trigger-wprobe-btf-offset.tc so the test is skipped if CONFIG_WPROBE_TRIGGERS is disabled.
Changes in v15:
- Duplicate field string to avoid modifying glob in place in wprobe_trigger_typecast_parse() so tracing_log_err() prints pristine command string.
- Remove leftover offset and adjust debug print in wprobe_trigger_print().
- Document BTF struct offset resolution syntax in wprobetrace.rst.
- Add explicit failure checks with fail helper in trigger-wprobe-btf-offset.tc.
- Declare fprobe README requirement in trigger-wprobe-btf-offset.tc.
Changes in v14:
- Update dummy wprobe event definition to use '-1' instead of '0'.
- Pass member_type to btf_find_struct_member() and check its kflag in get_offset_of_field().
Changes in v13:
- Check for field token before calling wprobe_trigger_field_parse() in clear_wprobe to avoid spurious error log entries on numeric counts.
Changes in v12:
- Refactor field parsing logic into wprobe_trigger_field_parse().
- Remove unused variable count_str in wprobe_trigger_cmd_parse().
--- Documentation/trace/wprobetrace.rst | 7 kernel/trace/trace_wprobe.c | 304 +++++++++++++++----- .../test.d/trigger/trigger-wprobe-btf-offset.tc | 94 ++++++ 3 files changed, 327 insertions(+), 78 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-btf-offset.tc
Documentation/trace/wprobetrace.rst +7 -0
@@ -90,10 +90,17 @@ Combination with trigger action The event trigger action can extend the utilization of this wprobe. - set_wprobe:WPEVENT:FIELD[+|-ADJUST][:COUNT] +- set_wprobe:WPEVENT:(STRUCT[,ASGN])EVENT_FIELD->MEMBER[+|-ADJUST][:COUNT] - clear_wprobe:WPEVENT[:FIELD[+|-ADJUST][:COUNT]] +- clear_wprobe:WPEVENT[:(STRUCT[,ASGN])EVENT_FIELD->MEMBER[+|-ADJUST][:COUNT]] Set these triggers to the target event, then the WPROBE event will be setup to trace the memory access at FIELD[+|-ADJUST] address. +If BTF is supported, the target address can also be resolved using BTF +struct offset resolution: `(STRUCT[,ASGN])EVENT_FIELD->MEMBER[+|-ADJUST]`. +Here, EVENT_FIELD is an event field containing a pointer to STRUCT (or to +the ASGN member if ASGN is specified), and MEMBER is the struct member whose +offset is resolved automatically via BTF. When clear_wprobe is hit, if FIELD is NOT specified, the WPEVENT is forcibly cleared. If FIELD[+|-ADJUST] is set, it clears WPEVENT only if its watching address is the same as the FIELD[+|-ADJUST] value.
kernel/trace/trace_wprobe.c +226 -78
341 lines not on this page · raw message
tools/testing/selftests/ftrace/test.d/trigger/trigger-wprobe-btf-offset.tc new file +94 -0
94 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH v20 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] tracing/wprobe: truncated command logged by wprobe_trigger_field_parse() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] tracing/wprobe: truncated command logged by wprobe_trigger_field_parse()
--
commit 2effd66bbdbad9649e094446a260cd6b20b2df1c
Author: Masami Hiramatsu (Google) <[email protected]>
tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger
This commit adds BTF struct offset resolution support for the target address field in set_wprobe and clear_wprobe event triggers, along with documentation and a selftest.
Quoted 4 lines
kernel/trace/trace_wprobe.c +0
-0
[ ... ]
Quoted 5 lines
kernel/trace/trace_wprobe.c +1
-0@@ -1230,6 +1231,223 @@ static void wprobe_trigger_free(struct event_trigger_data *data) } } +#ifdef CONFIG_PROBE_EVENTS_BTF_ARGS
[ ... ]
Quoted 23 lines
kernel/trace/trace_wprobe.c +23
-0+/* parse typecast: (TYPE[,ASGN])EVENT_FIELD->FIELD[.SUBFIELD...][+-OFFS] and set adjust. */ +static int wprobe_trigger_typecast_parse (char *field_str, +struct trace_event_file *file, +struct wprobe_trigger_data *wprobe_data, +const char *glob) +{ + struct btf *btf __free(btf_put) = NULL; + char *buf __free(kfree) = NULL; +struct ftrace_event_field *field; +const struct btf_type *type; +char *assign_field; +char *event_field; +char *type_field; +char *type_name; +char *offs; +long val =0 ; +int base_offset = field_str - glob; +int event_field_offset; +int id, adjust; + + buf =kstrdup (field_str,GFP_KERNEL ); +if (!buf) +return -ENOMEM ;
[ ... ]
Quoted 38 lines
kernel/trace/trace_wprobe.c +38
-0+static int wprobe_trigger_field_parse (char *field_str,struct trace_event_file *file, +struct wprobe_trigger_data *wprobe_data, +const char *glob) +{ +struct ftrace_event_field *field; +char *offs; + +if (field_str[0 ] =='(' ) +return wprobe_trigger_typecast_parse (field_str, file, wprobe_data, glob); + + offs =strpbrk (field_str,"+-" ); +if (offs) { +long val; + +if (kstrtol (offs,0 , &val) <0 ) { +wprobe_trigger_log_err (file, glob, offs - glob,BAD_DEREF_OFFS ); +return -EINVAL ; + } + wprobe_data->adjust = val; + *offs ='\0' ; + } + + field =trace_find_event_field (file->event_call, field_str); +if (!field) { +wprobe_trigger_log_err (file, glob, field_str - glob,NO_EVENT_FIELD ); +return -ENOENT ; + } +if (field->size !=sizeof (void *)) { +wprobe_trigger_log_err (file, glob, field_str - glob,WPROBE_BAD_FIELD ); +return -ENOEXEC ; + } + wprobe_data->offset = field->offset; + wprobe_data->field =kstrdup (field_str,GFP_KERNEL ); +if (!wprobe_data->field) +return -ENOMEM ; + +return 0 ; +}
[ ... ]
Quoted 38 lines
kernel/trace/trace_wprobe.c +1
-27@@ -1306,93 +1522,25 @@ static int wprobe_trigger_cmd_parse(struct event_command *cmd_ops,/* clear_wprobe does not need field, but can have optional field. */ if (!clear) { -char *offs; +char *field_str =strsep (¶m,":" ); -/* Find target field, which must be equivalent to "void *" */ - field_str =strsep (¶m,":" );if (!field_str) {wprobe_trigger_log_err (file, glob,strlen (glob),WPROBE_NEED_FIELD ); ret = -EINVAL ; goto out_free; } - - offs =strpbrk (field_str,"+-" ); -if (offs) { -long val; - -if (kstrtol (offs,0 , &val) <0 ) { -wprobe_trigger_log_err (file, glob, offs - glob,BAD_DEREF_OFFS ); - ret = -EINVAL ; - goto out_free; - } - wprobe_data->adjust = val; - *offs ='\0' ; - } - - event = file->event_call; - field =trace_find_event_field (event, field_str); -if (!field) { -wprobe_trigger_log_err (file, glob, field_str - glob,NO_EVENT_FIELD ); - ret = -ENOENT ; - goto out_free; - } - -if (field->size !=sizeof (void *)) { -wprobe_trigger_log_err (file, glob, field_str - glob,WPROBE_BAD_FIELD );
kernel/trace/trace_wprobe.c static int wprobe_trigger_cmd_parse(struct event_command *cmd_ops, · line 1534
Quoted 10 lines
kernel/trace/trace_wprobe.c +2
-7- ret = -ENOEXEC ; - goto out_free; - } - wprobe_data->offset = field->offset; - wprobe_data->field =kstrdup (field_str,GFP_KERNEL ); -if (!wprobe_data->field) { - ret = -ENOMEM ; + ret =wprobe_trigger_field_parse (field_str, file, wprobe_data, glob); +if (ret <0 ) goto out_free;
[Severity: Low]
Does wprobe_trigger_log_err() still print a truncated command string when wprobe_trigger_field_parse() or wprobe_trigger_typecast_parse() fails?
wprobe_trigger_typecast_parse() duplicates field_str to avoid mutating glob in place, but wprobe_trigger_cmd_parse() has already split event_str and field_str out of param using strsep(¶m, ":"), which overwrites the colon after event_str inside glob with a NUL byte:
kernel/trace/trace_wprobe.c:wprobe_trigger_cmd_parse() {
...
if (param_and_filter) {
/* Recover original trigger string to show the error log correctly. */
if (*(param_and_filter - 1) == '\0')
*(param_and_filter - 1) = ':';
...
ret = event_trigger_separate_filter(param_and_filter, ¶m, &filter, true);
...
event_str = strsep(¶m, ":");
...
}Because that colon at *(field_str - 1) (and any colon after field_str when a count follows) is never restored, tracing_log_err() stops printing glob right after event_str, while the error caret position is still calculated relative to field_str inside glob and lands past the end of the printed command. In the non-typecast path of wprobe_trigger_field_parse(), *offs = '\0' also truncates glob before logging NO_EVENT_FIELD or WPROBE_BAD_FIELD.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=11