linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64/traps: show fault address in exception trace
@ 2025-04-29  7:15 Baruch Siach
  2025-04-29 15:33 ` Will Deacon
  0 siblings, 1 reply; 3+ messages in thread
From: Baruch Siach @ 2025-04-29  7:15 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, Baruch Siach

The FAR (fault address) register provides useful information when
debugging an unhandled exception.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 arch/arm64/kernel/traps.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 4e26bd356a48..14eb598e33a7 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -239,7 +239,7 @@ void die(const char *str, struct pt_regs *regs, long err)
 		make_task_dead(SIGSEGV);
 }
 
-static void arm64_show_signal(int signo, const char *str)
+static void arm64_show_signal(int signo, const char *str, unsigned long far)
 {
 	static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
 				      DEFAULT_RATELIMIT_BURST);
@@ -256,6 +256,7 @@ static void arm64_show_signal(int signo, const char *str)
 	pr_info("%s[%d]: unhandled exception: ", tsk->comm, task_pid_nr(tsk));
 	if (esr)
 		pr_cont("%s, ESR 0x%016lx, ", esr_get_class_string(esr), esr);
+	pr_cont("FAR 0x%016lx, ", far);
 
 	pr_cont("%s", str);
 	print_vma_addr(KERN_CONT " in ", regs->pc);
@@ -266,7 +267,7 @@ static void arm64_show_signal(int signo, const char *str)
 void arm64_force_sig_fault(int signo, int code, unsigned long far,
 			   const char *str)
 {
-	arm64_show_signal(signo, str);
+	arm64_show_signal(signo, str, far);
 	if (signo == SIGKILL)
 		force_sig(SIGKILL);
 	else
@@ -275,21 +276,21 @@ void arm64_force_sig_fault(int signo, int code, unsigned long far,
 
 void arm64_force_sig_fault_pkey(unsigned long far, const char *str, int pkey)
 {
-	arm64_show_signal(SIGSEGV, str);
+	arm64_show_signal(SIGSEGV, str, far);
 	force_sig_pkuerr((void __user *)far, pkey);
 }
 
 void arm64_force_sig_mceerr(int code, unsigned long far, short lsb,
 			    const char *str)
 {
-	arm64_show_signal(SIGBUS, str);
+	arm64_show_signal(SIGBUS, str, far);
 	force_sig_mceerr(code, (void __user *)far, lsb);
 }
 
 void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far,
 				       const char *str)
 {
-	arm64_show_signal(SIGTRAP, str);
+	arm64_show_signal(SIGTRAP, str, far);
 	force_sig_ptrace_errno_trap(errno, (void __user *)far);
 }
 
-- 
2.47.2



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

* Re: [PATCH] arm64/traps: show fault address in exception trace
  2025-04-29  7:15 [PATCH] arm64/traps: show fault address in exception trace Baruch Siach
@ 2025-04-29 15:33 ` Will Deacon
  2025-04-30  4:46   ` Baruch Siach
  0 siblings, 1 reply; 3+ messages in thread
From: Will Deacon @ 2025-04-29 15:33 UTC (permalink / raw)
  To: Baruch Siach; +Cc: Catalin Marinas, linux-arm-kernel

On Tue, Apr 29, 2025 at 10:15:24AM +0300, Baruch Siach wrote:
> The FAR (fault address) register provides useful information when
> debugging an unhandled exception.
> 
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
>  arch/arm64/kernel/traps.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index 4e26bd356a48..14eb598e33a7 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -239,7 +239,7 @@ void die(const char *str, struct pt_regs *regs, long err)
>  		make_task_dead(SIGSEGV);
>  }
>  
> -static void arm64_show_signal(int signo, const char *str)
> +static void arm64_show_signal(int signo, const char *str, unsigned long far)
>  {
>  	static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
>  				      DEFAULT_RATELIMIT_BURST);
> @@ -256,6 +256,7 @@ static void arm64_show_signal(int signo, const char *str)
>  	pr_info("%s[%d]: unhandled exception: ", tsk->comm, task_pid_nr(tsk));
>  	if (esr)
>  		pr_cont("%s, ESR 0x%016lx, ", esr_get_class_string(esr), esr);
> +	pr_cont("FAR 0x%016lx, ", far);

Are you sure the FAR is always valid here? For example, if we're delivering
a SIGILL due to an undefined instruction.

Also, once you have the PC and the registers (both of which we print),
it's not too hard to dig the instruction out of the binary and figure out
the faulting address that way.

Will


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

* Re: [PATCH] arm64/traps: show fault address in exception trace
  2025-04-29 15:33 ` Will Deacon
@ 2025-04-30  4:46   ` Baruch Siach
  0 siblings, 0 replies; 3+ messages in thread
From: Baruch Siach @ 2025-04-30  4:46 UTC (permalink / raw)
  To: Will Deacon; +Cc: Catalin Marinas, linux-arm-kernel

Hi Will,

On Tue, Apr 29 2025, Will Deacon wrote:
> On Tue, Apr 29, 2025 at 10:15:24AM +0300, Baruch Siach wrote:
>> The FAR (fault address) register provides useful information when
>> debugging an unhandled exception.
>> 
>> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
>> ---
>>  arch/arm64/kernel/traps.c | 11 ++++++-----
>>  1 file changed, 6 insertions(+), 5 deletions(-)
>> 
>> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
>> index 4e26bd356a48..14eb598e33a7 100644
>> --- a/arch/arm64/kernel/traps.c
>> +++ b/arch/arm64/kernel/traps.c
>> @@ -239,7 +239,7 @@ void die(const char *str, struct pt_regs *regs, long err)
>>  		make_task_dead(SIGSEGV);
>>  }
>>  
>> -static void arm64_show_signal(int signo, const char *str)
>> +static void arm64_show_signal(int signo, const char *str, unsigned long far)
>>  {
>>  	static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
>>  				      DEFAULT_RATELIMIT_BURST);
>> @@ -256,6 +256,7 @@ static void arm64_show_signal(int signo, const char *str)
>>  	pr_info("%s[%d]: unhandled exception: ", tsk->comm, task_pid_nr(tsk));
>>  	if (esr)
>>  		pr_cont("%s, ESR 0x%016lx, ", esr_get_class_string(esr), esr);
>> +	pr_cont("FAR 0x%016lx, ", far);
>
> Are you sure the FAR is always valid here? For example, if we're delivering
> a SIGILL due to an undefined instruction.

A user interested in hardware exception information should be in a
position to know whether this information is valid. But I guess that FAR
can't be valid when ESR isn't valid either.

> Also, once you have the PC and the registers (both of which we print),
> it's not too hard to dig the instruction out of the binary and figure out
> the faulting address that way.

I find FAR helpful to confirm the analysis of the instruction being
executed and its operands. The cost for adding this bit of information
isn't huge, I think.

Thanks for your review,
baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -


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

end of thread, other threads:[~2025-04-30  4:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29  7:15 [PATCH] arm64/traps: show fault address in exception trace Baruch Siach
2025-04-29 15:33 ` Will Deacon
2025-04-30  4:46   ` Baruch Siach

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).