* [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints
@ 2025-10-13 3:55 Balbir Singh
2025-10-13 4:45 ` Anshuman Khandual
2025-11-03 17:26 ` Catalin Marinas
0 siblings, 2 replies; 5+ messages in thread
From: Balbir Singh @ 2025-10-13 3:55 UTC (permalink / raw)
To: linux-arm-kernel
Cc: linux-kernel, Balbir Singh, Catalin Marinas, Will Deacon,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
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 <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
[1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
[2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/
Signed-off-by: Balbir Singh <balbirs@nvidia.com>
---
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(-)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index d816ff44faff..9d7b86e92434 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -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
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints
2025-10-13 3:55 [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints Balbir Singh
@ 2025-10-13 4:45 ` Anshuman Khandual
2025-11-03 17:26 ` Catalin Marinas
1 sibling, 0 replies; 5+ messages in thread
From: Anshuman Khandual @ 2025-10-13 4:45 UTC (permalink / raw)
To: Balbir Singh, linux-arm-kernel
Cc: linux-kernel, Catalin Marinas, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti
On 13/10/25 9:25 AM, Balbir Singh wrote:
> 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.
>
> 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.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Paul Walmsley <pjw@kernel.org>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Alexandre Ghiti <alex@ghiti.fr>
>
> [1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
> [2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/
> Signed-off-by: Balbir Singh <balbirs@nvidia.com>
> ---
>
> 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(-)
>
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index d816ff44faff..9d7b86e92434 100644
> --- a/arch/arm64/mm/fault.c
> +++ b/arch/arm64/mm/fault.c
> @@ -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
LGTM
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints
2025-10-13 3:55 [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints Balbir Singh
2025-10-13 4:45 ` Anshuman Khandual
@ 2025-11-03 17:26 ` Catalin Marinas
2025-11-05 0:27 ` Balbir Singh
1 sibling, 1 reply; 5+ messages in thread
From: Catalin Marinas @ 2025-11-03 17:26 UTC (permalink / raw)
To: Balbir Singh
Cc: linux-arm-kernel, linux-kernel, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti
On Mon, Oct 13, 2025 at 02:55:32PM +1100, Balbir Singh wrote:
> 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 <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Paul Walmsley <pjw@kernel.org>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Alexandre Ghiti <alex@ghiti.fr>
>
> [1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
> [2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/
> Signed-off-by: Balbir Singh <balbirs@nvidia.com>
> ---
>
> 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(-)
>
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index d816ff44faff..9d7b86e92434 100644
> --- a/arch/arm64/mm/fault.c
> +++ b/arch/arm64/mm/fault.c
> @@ -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);
> + }
This has come up before and rejected:
https://lore.kernel.org/all/aG0aIKzxApp9j7X0@willie-the-truck/
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints
2025-11-03 17:26 ` Catalin Marinas
@ 2025-11-05 0:27 ` Balbir Singh
2025-11-11 20:13 ` Catalin Marinas
0 siblings, 1 reply; 5+ messages in thread
From: Balbir Singh @ 2025-11-05 0:27 UTC (permalink / raw)
To: Catalin Marinas
Cc: linux-arm-kernel, linux-kernel, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti
On 11/4/25 04:26, Catalin Marinas wrote:
> On Mon, Oct 13, 2025 at 02:55:32PM +1100, Balbir Singh wrote:
>> 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 <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Paul Walmsley <pjw@kernel.org>
>> Cc: Palmer Dabbelt <palmer@dabbelt.com>
>> Cc: Albert Ou <aou@eecs.berkeley.edu>
>> Cc: Alexandre Ghiti <alex@ghiti.fr>
>>
>> [1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
>> [2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/
>> Signed-off-by: Balbir Singh <balbirs@nvidia.com>
>> ---
>>
>> 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(-)
>>
>> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
>> index d816ff44faff..9d7b86e92434 100644
>> --- a/arch/arm64/mm/fault.c
>> +++ b/arch/arm64/mm/fault.c
>> @@ -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);
>> + }
>
> This has come up before and rejected:
>
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints
2025-11-05 0:27 ` Balbir Singh
@ 2025-11-11 20:13 ` Catalin Marinas
0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2025-11-11 20:13 UTC (permalink / raw)
To: Balbir Singh
Cc: linux-arm-kernel, linux-kernel, Will Deacon, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti
On Wed, Nov 05, 2025 at 11:27:18AM +1100, Balbir Singh wrote:
> On 11/4/25 04:26, Catalin Marinas wrote:
> > On Mon, Oct 13, 2025 at 02:55:32PM +1100, Balbir Singh wrote:
> >> 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 <catalin.marinas@arm.com>
> >> Cc: Will Deacon <will@kernel.org>
> >> Cc: Paul Walmsley <pjw@kernel.org>
> >> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> >> Cc: Albert Ou <aou@eecs.berkeley.edu>
> >> Cc: Alexandre Ghiti <alex@ghiti.fr>
> >>
> >> [1] https://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
> >> [2] https://taras.glek.net/posts/ebpf-mmap-page-fault-tracing/
> >> Signed-off-by: Balbir Singh <balbirs@nvidia.com>
> >> ---
> >>
> >> 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(-)
> >>
> >> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> >> index d816ff44faff..9d7b86e92434 100644
> >> --- a/arch/arm64/mm/fault.c
> >> +++ b/arch/arm64/mm/fault.c
> >> @@ -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);
> >> + }
> >
> > This has come up before and rejected:
> >
> > 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 ;).
> 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/20250519120837.794f6738@batman.local.home/
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-11 20:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-13 3:55 [PATCH] arch/arm64/mm/fault: Implement exceptions tracepoints Balbir Singh
2025-10-13 4:45 ` Anshuman Khandual
2025-11-03 17:26 ` Catalin Marinas
2025-11-05 0:27 ` Balbir Singh
2025-11-11 20:13 ` Catalin Marinas
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).