linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64
@ 2025-10-30  3:26 Masami Hiramatsu (Google)
  2025-10-30  3:27 ` [PATCH 1/2] perf: Introduce default_overflow_compatible flag Masami Hiramatsu (Google)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-10-30  3:26 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Steven Rostedt
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Masami Hiramatsu, Mathieu Desnoyers,
	linux-perf-users, linux-kernel, linux-trace-kernel, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Hi,

Here are patches which fixes a wprobe bug reported by Mark Brown on
arm64[1]. The root cause was that the infinite watchpoint exception on
the same instruction, because arm64 watchpoint exception happens before
the memory access has done, it needs to configure a single-step after
calling overflow handler. It does that only for the default overflow
handlers, and not for custom overflow handler registered via
hw_breakpoint interface.

[1] https://lore.kernel.org/all/aPvwGhMBJqMKcC9D@finisterre.sirena.org.uk/

To fix this issue, this series introduces default_overflow_compatible
flag in the perf_event and use it for identifying default overflow
handlers instead of checking handler functions everytime[1/2], and
set it in wprobe[2/2].

Thank you,

---

Masami Hiramatsu (Google) (2):
      perf: Introduce default_overflow_compatible flag
      tracing: wprobe: Make wprobe_handler default overflow_handler compatible


 include/linux/perf_event.h  |    9 ++-------
 kernel/events/core.c        |    2 ++
 kernel/trace/trace_wprobe.c |    7 +++++++
 3 files changed, 11 insertions(+), 7 deletions(-)

--
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] perf: Introduce default_overflow_compatible flag
  2025-10-30  3:26 [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu (Google)
@ 2025-10-30  3:27 ` Masami Hiramatsu (Google)
  2025-10-30  3:27 ` [PATCH 2/2] tracing: wprobe: Make wprobe_handler default overflow_handler compatible Masami Hiramatsu (Google)
  2025-11-04 13:37 ` [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu
  2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-10-30  3:27 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Steven Rostedt
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Masami Hiramatsu, Mathieu Desnoyers,
	linux-perf-users, linux-kernel, linux-trace-kernel, Will Deacon,
	Catalin Marinas, linux-arm-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Instead of checking whether event->overflow_handler everytime in
is_default_overflow_handler(), just use a flag to check it once when
registering the handler.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 include/linux/perf_event.h |    9 ++-------
 kernel/events/core.c       |    2 ++
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index fd1d91017b99..40dd897e26b0 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -902,6 +902,7 @@ struct perf_event {
 	u64				(*clock)(void);
 	perf_overflow_handler_t		overflow_handler;
 	void				*overflow_handler_context;
+	bool				default_overflow_compatible;
 	struct bpf_prog			*prog;
 	u64				bpf_cookie;
 
@@ -1505,13 +1506,7 @@ extern int perf_event_output(struct perf_event *event,
 static inline bool
 is_default_overflow_handler(struct perf_event *event)
 {
-	perf_overflow_handler_t overflow_handler = event->overflow_handler;
-
-	if (likely(overflow_handler == perf_event_output_forward))
-		return true;
-	if (unlikely(overflow_handler == perf_event_output_backward))
-		return true;
-	return false;
+	return event->default_overflow_compatible;
 }
 
 extern void
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 177e57c1a362..6bbbde82cb21 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -12946,9 +12946,11 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 	} else if (is_write_backward(event)){
 		event->overflow_handler = perf_event_output_backward;
 		event->overflow_handler_context = NULL;
+		event->default_overflow_compatible = true;
 	} else {
 		event->overflow_handler = perf_event_output_forward;
 		event->overflow_handler_context = NULL;
+		event->default_overflow_compatible = true;
 	}
 
 	perf_event__state_init(event);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] tracing: wprobe: Make wprobe_handler default overflow_handler compatible
  2025-10-30  3:26 [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu (Google)
  2025-10-30  3:27 ` [PATCH 1/2] perf: Introduce default_overflow_compatible flag Masami Hiramatsu (Google)
@ 2025-10-30  3:27 ` Masami Hiramatsu (Google)
  2025-11-04 13:37 ` [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu
  2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-10-30  3:27 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Steven Rostedt
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Masami Hiramatsu, Mathieu Desnoyers,
	linux-perf-users, linux-kernel, linux-trace-kernel, Will Deacon,
	Catalin Marinas, linux-arm-kernel

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

To fix arm64 repeating watchpoint exception on the same instruction
bug, markthe wprobe handler as compatible with the default overflow
handler.

Since do_watchpoint() on arm64 does not configure the single step
execution correctly if the overflow_handler is not compatible with
default perf overflow handlers, custom handler will loop on the
same instruction by repeating watchpoint exception. But if the
overflow handler is compatible with the default handlers, it
configures the single step. So set the compatible flag since
wprobe_handler will not care arch-dependent case.

Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/all/aPvwGhMBJqMKcC9D@finisterre.sirena.org.uk/
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace_wprobe.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/trace/trace_wprobe.c b/kernel/trace/trace_wprobe.c
index 98605b207f43..f2c2f26fd668 100644
--- a/kernel/trace/trace_wprobe.c
+++ b/kernel/trace/trace_wprobe.c
@@ -163,6 +163,8 @@ static void wprobe_perf_handler(struct perf_event *bp,
 static int __register_trace_wprobe(struct trace_wprobe *tw)
 {
 	struct perf_event_attr attr;
+	struct perf_event *bp;
+	int cpu;
 
 	if (tw->bp_event)
 		return -EINVAL;
@@ -179,6 +181,11 @@ static int __register_trace_wprobe(struct trace_wprobe *tw)
 		tw->bp_event = NULL;
 		return ret;
 	}
+	/* Mark wprobe_perf_handler is compatible with default one. */
+	for_each_online_cpu(cpu) {
+		bp = per_cpu(*tw->bp_event, cpu);
+		bp->default_overflow_compatible = true;
+	}
 
 	return 0;
 }


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64
  2025-10-30  3:26 [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu (Google)
  2025-10-30  3:27 ` [PATCH 1/2] perf: Introduce default_overflow_compatible flag Masami Hiramatsu (Google)
  2025-10-30  3:27 ` [PATCH 2/2] tracing: wprobe: Make wprobe_handler default overflow_handler compatible Masami Hiramatsu (Google)
@ 2025-11-04 13:37 ` Masami Hiramatsu
  2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2025-11-04 13:37 UTC (permalink / raw)
  To: Masami Hiramatsu (Google)
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Steven Rostedt, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Ian Rogers, Adrian Hunter, Mathieu Desnoyers,
	linux-perf-users, linux-kernel, linux-trace-kernel, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Gently ping.

There is a bugfix (or strange behavior) on arm64 hw breakpoint but
to fix it cleanly, it should change the perf itself (but I'm not
sure why arm64 changes the behavior only for the default overflow
handlers.) Anyone knows it?

Thank you,

On Thu, 30 Oct 2025 12:26:55 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> Hi,
> 
> Here are patches which fixes a wprobe bug reported by Mark Brown on
> arm64[1]. The root cause was that the infinite watchpoint exception on
> the same instruction, because arm64 watchpoint exception happens before
> the memory access has done, it needs to configure a single-step after
> calling overflow handler. It does that only for the default overflow
> handlers, and not for custom overflow handler registered via
> hw_breakpoint interface.
> 
> [1] https://lore.kernel.org/all/aPvwGhMBJqMKcC9D@finisterre.sirena.org.uk/
> 
> To fix this issue, this series introduces default_overflow_compatible
> flag in the perf_event and use it for identifying default overflow
> handlers instead of checking handler functions everytime[1/2], and
> set it in wprobe[2/2].
> 
> Thank you,
> 
> ---
> 
> Masami Hiramatsu (Google) (2):
>       perf: Introduce default_overflow_compatible flag
>       tracing: wprobe: Make wprobe_handler default overflow_handler compatible
> 
> 
>  include/linux/perf_event.h  |    9 ++-------
>  kernel/events/core.c        |    2 ++
>  kernel/trace/trace_wprobe.c |    7 +++++++
>  3 files changed, 11 insertions(+), 7 deletions(-)
> 
> --
> Masami Hiramatsu (Google) <mhiramat@kernel.org>


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-04 13:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30  3:26 [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu (Google)
2025-10-30  3:27 ` [PATCH 1/2] perf: Introduce default_overflow_compatible flag Masami Hiramatsu (Google)
2025-10-30  3:27 ` [PATCH 2/2] tracing: wprobe: Make wprobe_handler default overflow_handler compatible Masami Hiramatsu (Google)
2025-11-04 13:37 ` [PATCH 0/2] tracing/wprobe: Fix to avoid inifinite watchpoint exception on arm64 Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).