Skip to contentSkip to conversation

arch/arm64/mm/fault: Implement exceptions tracepoints

PATCH In review Balbir Singh 3 participants 5 messages Oct 13, 2025 – Nov 11, 2025 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch/arm64/mm/fault: Implement exceptions tracepoints

x86 and riscv provide trace points for page-faults (user and kernel tracepoints). Some scripts [1],[2] rely on these trace points. The tracepoint is useful for tracking faults and their reasons.

Adding the tracepoints is simple and straight-forward. For arm64 use esr as error code and untagged memory address as addr.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>

[1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
[2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/

---

Tested at my end with a kernel-compile and running a user space program to check that the trace points are indeed reported.

 arch/arm64/mm/fault.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm64/mm/fault.c +8 -1
index d816ff44faff..9d7b86e92434 100644
@@ -44,6 +44,9 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/exceptions.h>
+
 struct fault_info {
 	int	(*fn)(unsigned long far, unsigned long esr,
 		      struct pt_regs *regs);
@@ -572,8 +575,12 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	if (faulthandler_disabled() || !mm)
 		goto no_context;
 
-	if (user_mode(regs))
+	if (user_mode(regs)) {
 		mm_flags |= FAULT_FLAG_USER;
+		trace_page_fault_user(addr, regs, esr);
+	} else {
+		trace_page_fault_kernel(addr, regs, esr);
+	}
 
 	/*
 	 * vm_flags tells us what bits we must have in vma->vm_flags
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Balbir Singh

x86 and riscv provide trace points for page-faults (user and kernel tracepoints). Some scripts [1],[2] rely on these trace points. The tracepoint is useful for tracking faults and their reasons.

Agreed.

Quoted 3 lines

Adding the tracepoints is simple and straight-forward. For arm64 use esr as error code and untagged memory address as addr.

Providing the entire esr register value makes sense.

Quoted 37 lines
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>

[1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
[2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/

---

Tested at my end with a kernel-compile and running a user space program to check that the trace points are indeed reported.

 arch/arm64/mm/fault.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm64/mm/fault.c +3 -0
index d816ff44faff..9d7b86e92434 100644
@@ -44,6 +44,9 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/exceptions.h>
+
 struct fault_info {
 	int	(*fn)(unsigned long far, unsigned long esr,
 		      struct pt_regs *regs);
@@ -572,8 +575,12 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	if (faulthandler_disabled() || !mm)
 		goto no_context;
 

arch/arm64/mm/fault.c static int __kprobes do_page_fault(unsigned long far, unsigned long esr, · line 586

Quoted 10 lines
arch/arm64/mm/fault.c +5 -1
-	if (user_mode(regs))
+	if (user_mode(regs)) {
 		mm_flags |= FAULT_FLAG_USER;
+		trace_page_fault_user(addr, regs, esr);
+	} else {
+		trace_page_fault_kernel(addr, regs, esr);
+	}
 
 	/*
 	 * vm_flags tells us what bits we must have in vma->vm_flags

LGTM

maintainer
#2 lore raw
In reply to Balbir Singh
Quoted 40 lines · Balbir Singh

x86 and riscv provide trace points for page-faults (user and kernel tracepoints). Some scripts [1],[2] rely on these trace points. The tracepoint is useful for tracking faults and their reasons.

Adding the tracepoints is simple and straight-forward. For arm64 use esr as error code and untagged memory address as addr.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>

[1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
[2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/

---

Tested at my end with a kernel-compile and running a user space program to check that the trace points are indeed reported.

 arch/arm64/mm/fault.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm64/mm/fault.c +3 -0
index d816ff44faff..9d7b86e92434 100644
@@ -44,6 +44,9 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/exceptions.h>
+
 struct fault_info {
 	int	(*fn)(unsigned long far, unsigned long esr,
 		      struct pt_regs *regs);

arch/arm64/mm/fault.c static int __kprobes do_page_fault(unsigned long far, unsigned long esr, · line 583

Quoted 10 lines
arch/arm64/mm/fault.c +5 -1
@@ -572,8 +575,12 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	if (faulthandler_disabled() || !mm)
 		goto no_context;
 
-	if (user_mode(regs))
+	if (user_mode(regs)) {
 		mm_flags |= FAULT_FLAG_USER;
+		trace_page_fault_user(addr, regs, esr);
+	} else {
+		trace_page_fault_kernel(addr, regs, esr);
+	}

This has come up before and rejected:

https://lore.kernel.org/all/aG0aIKzxApp9j7X0@willie-the-truck/

Signature · 1 line
Catalin
#3 lore raw
Quoted 54 lines · Catalin Marinas
Quoted 40 lines · Balbir Singh

x86 and riscv provide trace points for page-faults (user and kernel tracepoints). Some scripts [1],[2] rely on these trace points. The tracepoint is useful for tracking faults and their reasons.

Adding the tracepoints is simple and straight-forward. For arm64 use esr as error code and untagged memory address as addr.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>

[1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
[2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/

---

Tested at my end with a kernel-compile and running a user space program to check that the trace points are indeed reported.

 arch/arm64/mm/fault.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm64/mm/fault.c +3 -0
index d816ff44faff..9d7b86e92434 100644
@@ -44,6 +44,9 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/exceptions.h>
+
 struct fault_info {
 	int	(*fn)(unsigned long far, unsigned long esr,
 		      struct pt_regs *regs);

arch/arm64/mm/fault.c static int __kprobes do_page_fault(unsigned long far, unsigned long esr, · line 583

Quoted 10 lines
arch/arm64/mm/fault.c +5 -1
@@ -572,8 +575,12 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	if (faulthandler_disabled() || !mm)
 		goto no_context;
 
-	if (user_mode(regs))
+	if (user_mode(regs)) {
 		mm_flags |= FAULT_FLAG_USER;
+		trace_page_fault_user(addr, regs, esr);
+	} else {
+		trace_page_fault_kernel(addr, regs, esr);
+	}

This has come up before and rejected:

Quoted 2 lines

https://lore.kernel.org/all/aG0aIKzxApp9j7X0@willie-the-truck/

Thanks for the pointer, since it's been five to six months since the discussion, I don't see the kprobe handler being merged with the trace point. The real issue is that while we fix the issue some scripts are broken by default on arm64, see [1] and [2] above and a simple search for exceptions:page_fault will show up many more. It's just hard to be have all of those break and fix them as and when needed.

Can we please have this fixed, so that trace-points scripts can work on arm64

Balbir

maintainer
#4 lore raw
Quoted 55 lines · Balbir Singh
Quoted 54 lines · Catalin Marinas
Quoted 40 lines · Balbir Singh

x86 and riscv provide trace points for page-faults (user and kernel tracepoints). Some scripts [1],[2] rely on these trace points. The tracepoint is useful for tracking faults and their reasons.

Adding the tracepoints is simple and straight-forward. For arm64 use esr as error code and untagged memory address as addr.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Alexandre Ghiti <[email protected]>

[1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
[2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/

---

Tested at my end with a kernel-compile and running a user space program to check that the trace points are indeed reported.

 arch/arm64/mm/fault.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
arch/arm64/mm/fault.c +3 -0
index d816ff44faff..9d7b86e92434 100644
@@ -44,6 +44,9 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/exceptions.h>
+
 struct fault_info {
 	int	(*fn)(unsigned long far, unsigned long esr,
 		      struct pt_regs *regs);

arch/arm64/mm/fault.c static int __kprobes do_page_fault(unsigned long far, unsigned long esr, · line 583

Quoted 10 lines
arch/arm64/mm/fault.c +5 -1
@@ -572,8 +575,12 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	if (faulthandler_disabled() || !mm)
 		goto no_context;
 
-	if (user_mode(regs))
+	if (user_mode(regs)) {
 		mm_flags |= FAULT_FLAG_USER;
+		trace_page_fault_user(addr, regs, esr);
+	} else {
+		trace_page_fault_kernel(addr, regs, esr);
+	}

This has come up before and rejected:

Quoted 5 lines
Quoted 1 line

https://lore.kernel.org/all/aG0aIKzxApp9j7X0@willie-the-truck/

Thanks for the pointer, since it's been five to six months since the discussion, I don't see the kprobe handler being merged with the trace point.

I was hinting that whoever needs these tracepoints can do the work ;).

Quoted 4 lines

The real issue is that while we fix the issue some scripts are broken by default on arm64, see [1] and [2] above and a simple search for exceptions:page_fault will show up many more. It's just hard to be have all of those break and fix them as and when needed.

Does Steve's proposal in the earlier discussion help with fixing these scripts:

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

Signature · 1 line
Catalin