[PATCH v9 17/22] arm64: mm: Add page fault trace points

Nam Cao posted 22 patches 7 months ago
There is a newer version of this series
[PATCH v9 17/22] arm64: mm: Add page fault trace points
Posted by Nam Cao 7 months ago
Add page fault trace points, which are useful to implement RV monitor which
watches page faults.

Signed-off-by: Nam Cao <namcao@linutronix.de>
---
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
---
 arch/arm64/mm/fault.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index ec0a337891dd..d917556869f9 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);
@@ -556,6 +559,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	int si_code;
 	int pkey = -1;
 
+	if (user_mode(regs))
+		trace_page_fault_user(addr, regs, esr);
+	else
+		trace_page_fault_kernel(addr, regs, esr);
+
 	if (kprobe_page_fault(regs, esr))
 		return 0;
 
-- 
2.39.5
Re: [PATCH v9 17/22] arm64: mm: Add page fault trace points
Posted by Will Deacon 5 months, 2 weeks ago
On Mon, May 19, 2025 at 12:27:35PM +0200, Nam Cao wrote:
> Add page fault trace points, which are useful to implement RV monitor which
> watches page faults.
> 
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> ---
>  arch/arm64/mm/fault.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index ec0a337891dd..d917556869f9 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);
> @@ -556,6 +559,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
>  	int si_code;
>  	int pkey = -1;
>  
> +	if (user_mode(regs))
> +		trace_page_fault_user(addr, regs, esr);
> +	else
> +		trace_page_fault_kernel(addr, regs, esr);
> +
>  	if (kprobe_page_fault(regs, esr))
>  		return 0;

As per the discussion with Steve on v6, I still object to relying on the
arch code to call all these different trace helpers (rv, kprobes, perf)
in the right place and consistently with each other.

In:

https://lore.kernel.org/r/20250519120837.794f6738@batman.local.home

Steve suggested wrapping some of this up in a core function to help with
that.

Will
Re: [PATCH v9 17/22] arm64: mm: Add page fault trace points
Posted by Nam Cao 5 months, 2 weeks ago
On Tue, Jul 08, 2025 at 02:16:16PM +0100, Will Deacon wrote:
> As per the discussion with Steve on v6, I still object to relying on the
> arch code to call all these different trace helpers (rv, kprobes, perf)
> in the right place and consistently with each other.
> 
> In:
> 
> https://lore.kernel.org/r/20250519120837.794f6738@batman.local.home
> 
> Steve suggested wrapping some of this up in a core function to help with
> that.

I have dropped this one from my latest version, so that the series can move
forward while we figure this part out.

Best regards,
Nam