All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] ARC __builtin_trap handling
@ 2017-12-20 22:49 ` Vineet Gupta
  0 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2017-12-20 22:49 UTC (permalink / raw)
  To: linux-snps-arc; +Cc: linux-kernel, Arnd Bergmann, Vineet Gupta

Vineet Gupta (2):
  ARC: handle gcc generated __builtin_trap()
  ARC: handle gcc generated __builtin_trap for older compiler

 arch/arc/kernel/traps.c        | 14 ++++++++++++++
 arch/arc/kernel/troubleshoot.c |  3 +++
 2 files changed, 17 insertions(+)

-- 
2.7.4

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

* [PATCH 0/2] ARC __builtin_trap handling
@ 2017-12-20 22:49 ` Vineet Gupta
  0 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2017-12-20 22:49 UTC (permalink / raw)
  To: linux-snps-arc

Vineet Gupta (2):
  ARC: handle gcc generated __builtin_trap()
  ARC: handle gcc generated __builtin_trap for older compiler

 arch/arc/kernel/traps.c        | 14 ++++++++++++++
 arch/arc/kernel/troubleshoot.c |  3 +++
 2 files changed, 17 insertions(+)

-- 
2.7.4

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

* [PATCH 1/2] ARC: handle gcc generated __builtin_trap()
  2017-12-20 22:49 ` Vineet Gupta
@ 2017-12-20 22:49   ` Vineet Gupta
  -1 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2017-12-20 22:49 UTC (permalink / raw)
  To: linux-snps-arc; +Cc: linux-kernel, Arnd Bergmann, Vineet Gupta

gcc toggle -fisolate-erroneous-paths-dereference (default at -O2
onwards) isolates faulty code paths such as null pointer access, divide
by zero etc by emitting __builtin_trap()

Newer ARC gcc generates TRAP_S 5 instruction correspondingly which this
patch handles. If user mode, the task is terminated with a SEGV, for
kernel mode die() called after register and stack dump.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
---
 arch/arc/kernel/traps.c        | 6 ++++++
 arch/arc/kernel/troubleshoot.c | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/arch/arc/kernel/traps.c b/arch/arc/kernel/traps.c
index bcd7c9fc5d0f..004f4e4a4c10 100644
--- a/arch/arc/kernel/traps.c
+++ b/arch/arc/kernel/traps.c
@@ -83,6 +83,7 @@ DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
 DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", __weak do_memory_error, BUS_ADRERR)
 DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
 DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
+DO_ERROR_INFO(SIGSEGV, "gcc generated __builtin_trap", do_trap5_error, 0)
 
 /*
  * Entry Point for Misaligned Data access Exception, for emulating in software
@@ -115,6 +116,8 @@ void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
  * Thus TRAP_S <n> can be used for specific purpose
  *  -1 used for software breakpointing (gdb)
  *  -2 used by kprobes
+ *  -5 __builtin_trap() generated by gcc (2018.03 onwards) for toggle such as
+ *     -fno-isolate-erroneous-paths-dereference
  */
 void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
 {
@@ -134,6 +137,9 @@ void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
 		kgdb_trap(regs);
 		break;
 
+	case 5:
+		do_trap5_error(address, regs);
+		break;
 	default:
 		break;
 	}
diff --git a/arch/arc/kernel/troubleshoot.c b/arch/arc/kernel/troubleshoot.c
index 7d8c1d6c2f60..6e9a0a9a6a04 100644
--- a/arch/arc/kernel/troubleshoot.c
+++ b/arch/arc/kernel/troubleshoot.c
@@ -163,6 +163,9 @@ static void show_ecr_verbose(struct pt_regs *regs)
 		else
 			pr_cont("Bus Error, check PRM\n");
 #endif
+	} else if (vec == ECR_V_TRAP) {
+		if (regs->ecr_param == 5)
+			pr_cont("gcc generated __builtin_trap\n");
 	} else {
 		pr_cont("Check Programmer's Manual\n");
 	}
-- 
2.7.4

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

* [PATCH 1/2] ARC: handle gcc generated __builtin_trap()
@ 2017-12-20 22:49   ` Vineet Gupta
  0 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2017-12-20 22:49 UTC (permalink / raw)
  To: linux-snps-arc

gcc toggle -fisolate-erroneous-paths-dereference (default at -O2
onwards) isolates faulty code paths such as null pointer access, divide
by zero etc by emitting __builtin_trap()

Newer ARC gcc generates TRAP_S 5 instruction correspondingly which this
patch handles. If user mode, the task is terminated with a SEGV, for
kernel mode die() called after register and stack dump.

Signed-off-by: Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/traps.c        | 6 ++++++
 arch/arc/kernel/troubleshoot.c | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/arch/arc/kernel/traps.c b/arch/arc/kernel/traps.c
index bcd7c9fc5d0f..004f4e4a4c10 100644
--- a/arch/arc/kernel/traps.c
+++ b/arch/arc/kernel/traps.c
@@ -83,6 +83,7 @@ DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
 DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", __weak do_memory_error, BUS_ADRERR)
 DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
 DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
+DO_ERROR_INFO(SIGSEGV, "gcc generated __builtin_trap", do_trap5_error, 0)
 
 /*
  * Entry Point for Misaligned Data access Exception, for emulating in software
@@ -115,6 +116,8 @@ void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
  * Thus TRAP_S <n> can be used for specific purpose
  *  -1 used for software breakpointing (gdb)
  *  -2 used by kprobes
+ *  -5 __builtin_trap() generated by gcc (2018.03 onwards) for toggle such as
+ *     -fno-isolate-erroneous-paths-dereference
  */
 void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
 {
@@ -134,6 +137,9 @@ void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
 		kgdb_trap(regs);
 		break;
 
+	case 5:
+		do_trap5_error(address, regs);
+		break;
 	default:
 		break;
 	}
diff --git a/arch/arc/kernel/troubleshoot.c b/arch/arc/kernel/troubleshoot.c
index 7d8c1d6c2f60..6e9a0a9a6a04 100644
--- a/arch/arc/kernel/troubleshoot.c
+++ b/arch/arc/kernel/troubleshoot.c
@@ -163,6 +163,9 @@ static void show_ecr_verbose(struct pt_regs *regs)
 		else
 			pr_cont("Bus Error, check PRM\n");
 #endif
+	} else if (vec == ECR_V_TRAP) {
+		if (regs->ecr_param == 5)
+			pr_cont("gcc generated __builtin_trap\n");
 	} else {
 		pr_cont("Check Programmer's Manual\n");
 	}
-- 
2.7.4

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

* [PATCH 2/2] ARC: handle gcc generated __builtin_trap for older compiler
  2017-12-20 22:49 ` Vineet Gupta
@ 2017-12-20 22:49   ` Vineet Gupta
  -1 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2017-12-20 22:49 UTC (permalink / raw)
  To: linux-snps-arc; +Cc: linux-kernel, Arnd Bergmann, Vineet Gupta

ARC gcc prior to GNU 2018.03 release didn't have a target specific
__builtin_trap() implementation, generating default abort() call.

Implement the abort() call - emulating what newer gcc does for the same,
as suggested by Arnd.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
---
 arch/arc/kernel/traps.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arc/kernel/traps.c b/arch/arc/kernel/traps.c
index 004f4e4a4c10..51a55b06cb2a 100644
--- a/arch/arc/kernel/traps.c
+++ b/arch/arc/kernel/traps.c
@@ -161,3 +161,12 @@ void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
 
 	insterror_is_error(address, regs);
 }
+
+/*
+ * abort() call generated by older gcc for __builtin_trap()
+ */
+void abort(void)
+{
+	__asm__ __volatile__("trap_s  5\n");
+}
+EXPORT_SYMBOL(abort);
-- 
2.7.4

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

* [PATCH 2/2] ARC: handle gcc generated __builtin_trap for older compiler
@ 2017-12-20 22:49   ` Vineet Gupta
  0 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2017-12-20 22:49 UTC (permalink / raw)
  To: linux-snps-arc

ARC gcc prior to GNU 2018.03 release didn't have a target specific
__builtin_trap() implementation, generating default abort() call.

Implement the abort() call - emulating what newer gcc does for the same,
as suggested by Arnd.

Signed-off-by: Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/traps.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arc/kernel/traps.c b/arch/arc/kernel/traps.c
index 004f4e4a4c10..51a55b06cb2a 100644
--- a/arch/arc/kernel/traps.c
+++ b/arch/arc/kernel/traps.c
@@ -161,3 +161,12 @@ void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
 
 	insterror_is_error(address, regs);
 }
+
+/*
+ * abort() call generated by older gcc for __builtin_trap()
+ */
+void abort(void)
+{
+	__asm__ __volatile__("trap_s  5\n");
+}
+EXPORT_SYMBOL(abort);
-- 
2.7.4

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

* Re: [PATCH 2/2] ARC: handle gcc generated __builtin_trap for older compiler
  2017-12-20 22:49   ` Vineet Gupta
@ 2017-12-21  8:09     ` Arnd Bergmann
  -1 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2017-12-21  8:09 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: open list:SYNOPSYS ARC ARCHITECTURE, Linux Kernel Mailing List

On Wed, Dec 20, 2017 at 11:49 PM, Vineet Gupta
<Vineet.Gupta1@synopsys.com> wrote:
> ARC gcc prior to GNU 2018.03 release didn't have a target specific
> __builtin_trap() implementation, generating default abort() call.
>
> Implement the abort() call - emulating what newer gcc does for the same,
> as suggested by Arnd.
>
> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

Acked-by: Arnd Bergmann <arnd@arndb.de>

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

* [PATCH 2/2] ARC: handle gcc generated __builtin_trap for older compiler
@ 2017-12-21  8:09     ` Arnd Bergmann
  0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2017-12-21  8:09 UTC (permalink / raw)
  To: linux-snps-arc

On Wed, Dec 20, 2017 at 11:49 PM, Vineet Gupta
<Vineet.Gupta1@synopsys.com> wrote:
> ARC gcc prior to GNU 2018.03 release didn't have a target specific
> __builtin_trap() implementation, generating default abort() call.
>
> Implement the abort() call - emulating what newer gcc does for the same,
> as suggested by Arnd.
>
> Signed-off-by: Vineet Gupta <vgupta at synopsys.com>

Acked-by: Arnd Bergmann <arnd at arndb.de>

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

end of thread, other threads:[~2017-12-21  8:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-20 22:49 [PATCH 0/2] ARC __builtin_trap handling Vineet Gupta
2017-12-20 22:49 ` Vineet Gupta
2017-12-20 22:49 ` [PATCH 1/2] ARC: handle gcc generated __builtin_trap() Vineet Gupta
2017-12-20 22:49   ` Vineet Gupta
2017-12-20 22:49 ` [PATCH 2/2] ARC: handle gcc generated __builtin_trap for older compiler Vineet Gupta
2017-12-20 22:49   ` Vineet Gupta
2017-12-21  8:09   ` Arnd Bergmann
2017-12-21  8:09     ` Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.