Skip to contentSkip to conversation

arm: fix building by adding a feature

PATCH Superseded Andrew Jones 2 participants 20 messages Apr 19, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover arm: fix building by adding a feature

The main motivator of this series is to get the arm build fixed. 522667917 "lib: backtrace printing" added a common backtrace() function, but we missed that arm's __builtin_return_address only accepts the input 0, and thus the function, which calls it with all values 0 to 20, can't compile on arm. To fix backtrace() for arm, the easiest thing to do is to override it with a backtrace that works. So this series makes some cleanups to stack tracing support and adds the support for ARM.

Andrew Jones (8):
x86: change exit to abort again
x86: trivial: there's no dump_stack.o
pretty_print_stacks: keep the 'STACK:' line
pretty_print_stacks: use elf file for the kernel
pretty_print_stacks: addr2line may need a cross prefix
stack: share api prototypes
stack: copy common asm/stack.h bits to all arches
arm: stack: add dump_stack support

 arm/Makefile.arm               |  4 ++++
 configure                      |  2 ++
 lib/arm/asm/stack.h            | 11 +++++++++++
 lib/arm/processor.c            |  1 +
 lib/arm/stack.c                | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/arm64/asm/stack.h          |  8 ++++++++
 lib/powerpc/asm/stack.h        |  8 ++++++++
 lib/ppc64/asm/stack.h          |  8 ++++++++
 lib/stack.h                    |  9 +++++----
 lib/x86/asm/stack.h            |  3 ---
 lib/x86/desc.c                 |  2 +-
 scripts/pretty_print_stacks.py | 14 +++++++++++---
 x86/Makefile.common            |  2 +-
 13 files changed, 101 insertions(+), 12 deletions(-)
 create mode 100644 lib/arm/stack.c
Signature · 1 line
2.4.11
#1 lore raw

PATCH 1/8 x86: change exit to abort again

This is needed again because ed0a50e5 "x86: lib: debug dump on unhandled exceptions" must have missed it in a rebase.

---
 lib/x86/desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
index 75765ef5d7804..402204ddcac44 100644
@@ -96,7 +96,7 @@ static void unhandled_exception(struct ex_regs *regs, bool cpu)
 #endif
 	);
 	dump_frame_stack((void*) regs->rip, (void*) regs->rbp);
-	exit(7);
+	abort();
 }
 
 static void check_exception_table(struct ex_regs *regs)
Signature · 1 line
2.4.11
#3 lore raw

PATCH 2/8 x86: trivial: there's no dump_stack.o

In reply to Andrew Jones
---
 x86/Makefile.common | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/Makefile.common +1 -1
index ca8036722a535..298e5f721ff15 100644
@@ -20,7 +20,7 @@ $(libcflat): CFLAGS += -ffreestanding -I lib
 CFLAGS += -m$(bits)
 CFLAGS += -O1
 
-# dump_stack.o relies on frame pointers.
+# stack.o relies on frame pointers.
 KEEP_FRAME_POINTER := y
 
 libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
Signature · 1 line
2.4.11
#5 lore raw

PATCH 3/8 pretty_print_stacks: keep the 'STACK:' line

In reply to Andrew Jones

It's sometimes useful to have the addresses for searching in a disassembly. Anyway, there's no reason to drop it.

---
 scripts/pretty_print_stacks.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/pretty_print_stacks.py +2 -1
index ee5a52edf07cd..11090deb122b1 100755
@@ -67,8 +67,9 @@ def main():
             if line == '':
                 break
 
+            puts(line)
+
             if not line.strip().startswith('STACK:'):
-                puts(line)
                 continue
 
             try:
Signature · 1 line
2.4.11
#7 lore raw

PATCH 4/8 pretty_print_stacks: use elf file for the kernel

In reply to Andrew Jones

x86 doesn't seem to care, but other architectures do.

---
 scripts/pretty_print_stacks.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/pretty_print_stacks.py +1 -1
index 11090deb122b1..db2f145323c45 100755
@@ -58,7 +58,7 @@ def main():
         sys.stderr.write('usage: %s <kernel>\n' % sys.argv[0])
         sys.exit(1)
 
-    binary = sys.argv[1]
+    binary = sys.argv[1].replace("flat", "elf")
 
     try:
         while True:
Signature · 1 line
2.4.11
#8 lore raw

Re: [kvm-unit-tests PATCH 4/8] pretty_print_stacks: use elf file for the kernel

Quoted 12 lines · Andrew Jones

x86 doesn't seem to care, but other architectures do.

---
 scripts/pretty_print_stacks.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/pretty_print_stacks.py +0 -0
index 11090deb122b1..db2f145323c45 100755

scripts/pretty_print_stacks.py def main(): · line 61

Quoted 5 lines
scripts/pretty_print_stacks.py +1 -1
@@ -58,7 +58,7 @@ def main():
         sys.stderr.write('usage: %s <kernel>\n' % sys.argv[0])
         sys.exit(1)
 
-    binary = sys.argv[1]
+    binary = sys.argv[1].replace("flat", "elf")

grr... I should have used (".flat", ".elf") since the string 'flat' could easily show up in other parts of a test name.

Quoted 6 lines
scripts/pretty_print_stacks.py +0 -0
     try:
         while True:
Signature · 1 line
2.4.11
#10 lore raw

PATCH 5/8 pretty_print_stacks: addr2line may need a cross prefix

In reply to Andrew Jones
---
 configure                      | 2 ++
 scripts/pretty_print_stacks.py | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
configure +2 -0
index ba6c55b3bc5b3..ca0ef83b942e5 100755
@@ -7,6 +7,7 @@ ld=ld
 objcopy=objcopy
 objdump=objdump
 ar=ar
+addr2line=addr2line
 arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
 host=$arch
 cross_prefix=
@@ -154,6 +155,7 @@ LD=$cross_prefix$ld
 OBJCOPY=$cross_prefix$objcopy
 OBJDUMP=$cross_prefix$objdump
 AR=$cross_prefix$ar
+ADDR2LINE=$cross_prefix$addr2line
 API=$api
 TEST_DIR=$testdir
 FIRMWARE=$firmware
scripts/pretty_print_stacks.py +8 -1
index db2f145323c45..336fc681e45b2 100755
@@ -5,6 +5,8 @@ import subprocess
 import sys
 import traceback
 
+config = {}
+
 # Subvert output buffering.
 def puts(string):
     sys.stdout.write(string)
@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line):
     # Output like this:
     #        0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208
     #         (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1)
-    cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address']
+    cmd = [config["ADDR2LINE"], '-e', binary, '-i', '-f', '--pretty', '--address']
     cmd.extend(addrs)
 
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -60,6 +62,11 @@ def main():
 
     binary = sys.argv[1].replace("flat", "elf")
 
+    with open("config.mak") as config_file:
+        for line in config_file:
+            name, val = line.partition("=")[::2]
+            config[name.strip()] = val.strip()
+
     try:
         while True:
             # Subvert input buffering.
Signature · 1 line
2.4.11
#11 lore raw

Re: [kvm-unit-tests PATCH 5/8] pretty_print_stacks: addr2line may need a cross prefix

Quoted 40 lines · Andrew Jones
---
 configure                      | 2 ++
 scripts/pretty_print_stacks.py | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
configure +2 -0
index ba6c55b3bc5b3..ca0ef83b942e5 100755
@@ -7,6 +7,7 @@ ld=ld
 objcopy=objcopy
 objdump=objdump
 ar=ar
+addr2line=addr2line
 arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
 host=$arch
 cross_prefix=
@@ -154,6 +155,7 @@ LD=$cross_prefix$ld
 OBJCOPY=$cross_prefix$objcopy
 OBJDUMP=$cross_prefix$objdump
 AR=$cross_prefix$ar
+ADDR2LINE=$cross_prefix$addr2line
 API=$api
 TEST_DIR=$testdir
 FIRMWARE=$firmware
scripts/pretty_print_stacks.py +2 -0
index db2f145323c45..336fc681e45b2 100755
@@ -5,6 +5,8 @@ import subprocess
 import sys
 import traceback
 
+config = {}
+
 # Subvert output buffering.
 def puts(string):
     sys.stdout.write(string)

scripts/pretty_print_stacks.py def pretty_print_stack(binary, line): · line 30

Quoted 5 lines
scripts/pretty_print_stacks.py +1 -1
@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line):
     # Output like this:
     #        0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208
     #         (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1)
-    cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address']
+    cmd = [config["ADDR2LINE"], '-e', binary, '-i', '-f', '--pretty', '--address']

Perhaps config.get('ADDR2LINE', 'addr2line') so my old config still works?

scripts/pretty_print_stacks.py def main(): · line 67

Quoted 10 lines
scripts/pretty_print_stacks.py +3 -0
     cmd.extend(addrs)
 
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -60,6 +62,11 @@ def main():
 
     binary = sys.argv[1].replace("flat", "elf")
 
+    with open("config.mak") as config_file:
+        for line in config_file:
+            name, val = line.partition("=")[::2]

Very elegant trick here! I always do name, _, val = line.partition("=")!

Quoted 8 lines
scripts/pretty_print_stacks.py +2 -1
+            config[name.strip()] = val.strip()
+
     try:
         while True:
             # Subvert input buffering.
--

2.4.11

Otherwise, reviewed-by: Peter Feiner <[email protected]>

#12 lore raw

Re: [kvm-unit-tests PATCH 5/8] pretty_print_stacks: addr2line may need a cross prefix

Quoted 35 lines · Peter Feiner
Quoted 34 lines · Andrew Jones
---
 configure                      | 2 ++
 scripts/pretty_print_stacks.py | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
configure +2 -0
index ba6c55b3bc5b3..ca0ef83b942e5 100755
@@ -7,6 +7,7 @@ ld=ld
 objcopy=objcopy
 objdump=objdump
 ar=ar
+addr2line=addr2line
 arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
 host=$arch
 cross_prefix=
@@ -154,6 +155,7 @@ LD=$cross_prefix$ld
 OBJCOPY=$cross_prefix$objcopy
 OBJDUMP=$cross_prefix$objdump
 AR=$cross_prefix$ar
+ADDR2LINE=$cross_prefix$addr2line
 API=$api
 TEST_DIR=$testdir
 FIRMWARE=$firmware
scripts/pretty_print_stacks.py +0 -0
index db2f145323c45..336fc681e45b2 100755
@@ -5,6 +5,8 @@ import subprocess
 import sys
 import traceback
 
Quoted 13 lines

scripts/pretty_print_stacks.py def pretty_print_stack(binary, line): · line 30

Quoted 11 lines
scripts/pretty_print_stacks.py +3 -1
+config = {}
+
 # Subvert output buffering.
 def puts(string):
     sys.stdout.write(string)
@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line):
     # Output like this:
     #        0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208
     #         (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1)
-    cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address']
+    cmd = [config["ADDR2LINE"], '-e', binary, '-i', '-f', '--pretty', '--address']

Perhaps config.get('ADDR2LINE', 'addr2line') so my old config still works?

OK, will do in v2.

Quoted 28 lines

scripts/pretty_print_stacks.py def main(): · line 67

Quoted 11 lines
scripts/pretty_print_stacks.py +3 -0
     cmd.extend(addrs)
 
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -60,6 +62,11 @@ def main():
 
     binary = sys.argv[1].replace("flat", "elf")
 
+    with open("config.mak") as config_file:
+        for line in config_file:
+            name, val = line.partition("=")[::2]

Very elegant trick here! I always do name, _, val = line.partition("=")!

Quoted 8 lines
scripts/pretty_print_stacks.py +2 -1
+            config[name.strip()] = val.strip()
+
     try:
         while True:
             # Subvert input buffering.
--

2.4.11

Otherwise, reviewed-by: Peter Feiner <[email protected]> --
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

PATCH 6/8 stack: share api prototypes

In reply to Andrew Jones
---
 lib/stack.h         | 9 +++++----
 lib/x86/asm/stack.h | 3 ---
 2 files changed, 5 insertions(+), 7 deletions(-)
lib/stack.h +5 -4
index bb6b9aa70876d..cfc66f442f997 100644
@@ -4,7 +4,10 @@
 #include <libcflat.h>
 #include <asm/stack.h>
 
-#ifndef HAVE_ARCH_BACKTRACE_FRAME
+#ifdef HAVE_ARCH_BACKTRACE_FRAME
+extern int backtrace_frame(const void *frame, const void **return_addrs,
+			   int max_depth);
+#else
 static inline int
 backtrace_frame(const void *frame __unused, const void **return_addrs __unused,
 		int max_depth __unused)
@@ -13,8 +16,6 @@ backtrace_frame(const void *frame __unused, const void **return_addrs __unused,
 }
 #endif
 
-#ifndef HAVE_ARCH_BACKTRACE
-int backtrace(const void **return_addrs, int max_depth);
-#endif
+extern int backtrace(const void **return_addrs, int max_depth);
 
 #endif
lib/x86/asm/stack.h +0 -3
index fc4766d37b172..b14e2c0fa012e 100644
@@ -6,9 +6,6 @@
 #endif
 
 #define HAVE_ARCH_BACKTRACE_FRAME
-int backtrace_frame(const void *frame, const void **return_addrs, int max_depth);
-
 #define HAVE_ARCH_BACKTRACE
-int backtrace(const void **return_addrs, int max_depth);
 
 #endif
Signature · 1 line
2.4.11
#15 lore raw

PATCH 7/8 stack: copy common asm/stack.h bits to all arches

In reply to Andrew Jones
---
 lib/arm/asm/stack.h     | 8 ++++++++
 lib/arm64/asm/stack.h   | 8 ++++++++
 lib/powerpc/asm/stack.h | 8 ++++++++
 lib/ppc64/asm/stack.h   | 8 ++++++++
 4 files changed, 32 insertions(+)
lib/arm/asm/stack.h +8 -0
index e69de29bb2d1d..fe97ac5d4b7d9 100644
@@ -0,0 +1,8 @@
+#ifndef _ASMARM_STACK_H_
+#define _ASMARM_STACK_H_
+
+#ifndef _STACK_H_
+#error Do not directly include <asm/stack.h>. Just use <stack.h>.
+#endif
+
+#endif
lib/arm64/asm/stack.h +8 -0
index e69de29bb2d1d..d0006242fdaaf 100644
@@ -0,0 +1,8 @@
+#ifndef _ASMARM64_STACK_H_
+#define _ASMARM64_STACK_H_
+
+#ifndef _STACK_H_
+#error Do not directly include <asm/stack.h>. Just use <stack.h>.
+#endif
+
+#endif
lib/powerpc/asm/stack.h +8 -0
index e69de29bb2d1d..e1c46ee092a10 100644
@@ -0,0 +1,8 @@
+#ifndef _ASMPOWERPC_STACK_H_
+#define _ASMPOWERPC_STACK_H_
+
+#ifndef _STACK_H_
+#error Do not directly include <asm/stack.h>. Just use <stack.h>.
+#endif
+
+#endif
lib/ppc64/asm/stack.h +8 -0
index e69de29bb2d1d..9734bbb8f7bd9 100644
@@ -0,0 +1,8 @@
+#ifndef _ASMPPC64_STACK_H_
+#define _ASMPPC64_STACK_H_
+
+#ifndef _STACK_H_
+#error Do not directly include <asm/stack.h>. Just use <stack.h>.
+#endif
+
+#endif
Signature · 1 line
2.4.11
#17 lore raw

PATCH 8/8 arm: stack: add dump_stack support

In reply to Andrew Jones

This actually fixes the arm build too, as arm's __builtin_return_address doesn't allow any input other than zero, and thus the common backtrace() wasn't compiling.

---
 arm/Makefile.arm    |  4 ++++
 lib/arm/asm/stack.h |  3 +++
 lib/arm/processor.c |  1 +
 lib/arm/stack.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 lib/arm/stack.c
arm/Makefile.arm +4 -0
index 946422872532d..92f375700c45e 100644
@@ -8,12 +8,16 @@ ldarch = elf32-littlearm
 kernel_offset = 0x10000
 machine = -marm
 
+# stack.o relies on frame pointers.
+KEEP_FRAME_POINTER := y
+
 CFLAGS += $(machine)
 CFLAGS += -mcpu=$(PROCESSOR)
 
 cstart.o = $(TEST_DIR)/cstart.o
 cflatobjs += lib/arm/spinlock.o
 cflatobjs += lib/arm/processor.o
+cflatobjs += lib/arm/stack.o
 
 # arm specific tests
 tests =
lib/arm/asm/stack.h +3 -0
index fe97ac5d4b7d9..ebcedc2ef938c 100644
@@ -5,4 +5,7 @@
 #error Do not directly include <asm/stack.h>. Just use <stack.h>.
 #endif
 
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
 #endif
lib/arm/processor.c +1 -0
index 1cef46ab28647..54fdb87ef0196 100644
@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs)
 		asm volatile("mrc p15, 0, %0, c5, c0, 1": "=r" (fsr));
 		printf("IFAR: %08lx    IFSR: %08lx\n", far, fsr);
 	}
+	dump_frame_stack((void *)regs->ARM_pc, (void *)regs->ARM_fp);
 	abort();
 }
 
lib/arm/stack.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.4.11
#18 lore raw

Re: [kvm-unit-tests PATCH 8/8] arm: stack: add dump_stack support

Quoted 69 lines · Andrew Jones

This actually fixes the arm build too, as arm's __builtin_return_address doesn't allow any input other than zero, and thus the common backtrace() wasn't compiling.

---
 arm/Makefile.arm    |  4 ++++
 lib/arm/asm/stack.h |  3 +++
 lib/arm/processor.c |  1 +
 lib/arm/stack.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 lib/arm/stack.c
arm/Makefile.arm +4 -0
index 946422872532d..92f375700c45e 100644
@@ -8,12 +8,16 @@ ldarch = elf32-littlearm
 kernel_offset = 0x10000
 machine = -marm
 
+# stack.o relies on frame pointers.
+KEEP_FRAME_POINTER := y
+
 CFLAGS += $(machine)
 CFLAGS += -mcpu=$(PROCESSOR)
 
 cstart.o = $(TEST_DIR)/cstart.o
 cflatobjs += lib/arm/spinlock.o
 cflatobjs += lib/arm/processor.o
+cflatobjs += lib/arm/stack.o
 
 # arm specific tests
 tests =
lib/arm/asm/stack.h +3 -0
index fe97ac5d4b7d9..ebcedc2ef938c 100644
@@ -5,4 +5,7 @@
 #error Do not directly include <asm/stack.h>. Just use <stack.h>.
 #endif
 
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
 #endif
lib/arm/processor.c +1 -0
index 1cef46ab28647..54fdb87ef0196 100644
@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs)
                asm volatile("mrc p15, 0, %0, c5, c0, 1": "=r" (fsr));
                printf("IFAR: %08lx    IFSR: %08lx\n", far, fsr);
        }
+       dump_frame_stack((void *)regs->ARM_pc, (void *)regs->ARM_fp);
        abort();
 }
 
lib/arm/stack.c new file +5 -0
new file mode 100644
index 0000000000000..f58b731f277bf
@@ -0,0 +1,41 @@
+/*
+ * backtrace support (this is a modified lib/x86/stack.c)
+ *
+ * Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]>
+ *

lib/arm/stack.c line 15

Quoted 10 lines
lib/arm/stack.c new file +10 -0
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <libcflat.h>
+#include <stack.h>
+
+int backtrace_frame(const void *frame, const void **return_addrs,
+                   int max_depth)
+{
+       static int walking;
+       int depth = 0;

Nit: unnecessary initialization.

lib/arm/stack.c line 25

Quoted 10 lines
lib/arm/stack.c new file +10 -0
+       const unsigned long *fp = (unsigned long *)frame;
+
+       if (walking) {
+               printf("RECURSIVE STACK WALK!!!\n");
+               return 0;
+       }
+       walking = 1;
+
+       for (depth = 0; depth < max_depth; depth++) {
+               if (!fp)

Interesting difference in termination case here from x86. Instead of checking for a null return address, you check for a null frame address. Any particular reason why?

Quoted 17 lines
lib/arm/stack.c new file +16 -1
+                       break;
+               return_addrs[depth] = (void *)fp[0];
+               if (return_addrs[depth] == 0)
+                       break;
+               fp = (unsigned long *)fp[-1];
+       }
+
+       walking = 0;
+       return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+       return backtrace_frame(__builtin_frame_address(0),
+                              return_addrs, max_depth);
+}
--
Quoted 2 lines

2.4.11

Nice fix!

#19 lore raw

Re: [kvm-unit-tests PATCH 8/8] arm: stack: add dump_stack support

Quoted 74 lines · Peter Feiner
Quoted 73 lines · Andrew Jones

This actually fixes the arm build too, as arm's __builtin_return_address doesn't allow any input other than zero, and thus the common backtrace() wasn't compiling.

---
 arm/Makefile.arm    |  4 ++++
 lib/arm/asm/stack.h |  3 +++
 lib/arm/processor.c |  1 +
 lib/arm/stack.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 lib/arm/stack.c
arm/Makefile.arm +4 -0
index 946422872532d..92f375700c45e 100644
@@ -8,12 +8,16 @@ ldarch = elf32-littlearm
 kernel_offset = 0x10000
 machine = -marm
 
+# stack.o relies on frame pointers.
+KEEP_FRAME_POINTER := y
+
 CFLAGS += $(machine)
 CFLAGS += -mcpu=$(PROCESSOR)
 
 cstart.o = $(TEST_DIR)/cstart.o
 cflatobjs += lib/arm/spinlock.o
 cflatobjs += lib/arm/processor.o
+cflatobjs += lib/arm/stack.o
 
 # arm specific tests
 tests =
lib/arm/asm/stack.h +3 -0
index fe97ac5d4b7d9..ebcedc2ef938c 100644
@@ -5,4 +5,7 @@
 #error Do not directly include <asm/stack.h>. Just use <stack.h>.
 #endif
 
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
 #endif
lib/arm/processor.c +1 -0
index 1cef46ab28647..54fdb87ef0196 100644
@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs)
                asm volatile("mrc p15, 0, %0, c5, c0, 1": "=r" (fsr));
                printf("IFAR: %08lx    IFSR: %08lx\n", far, fsr);
        }
+       dump_frame_stack((void *)regs->ARM_pc, (void *)regs->ARM_fp);
        abort();
 }
 
lib/arm/stack.c new file +9 -0
new file mode 100644
index 0000000000000..f58b731f277bf
@@ -0,0 +1,41 @@
+/*
+ * backtrace support (this is a modified lib/x86/stack.c)
+ *
+ * Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <libcflat.h>
+#include <stack.h>
Quoted 8 lines

lib/arm/stack.c line 15

Quoted 6 lines
lib/arm/stack.c new file +6 -0
+
+int backtrace_frame(const void *frame, const void **return_addrs,
+                   int max_depth)
+{
+       static int walking;
+       int depth = 0;

Nit: unnecessary initialization.

/me catches the nit and flings it over to lib/x86/stack.c :-)

I'll fix for v2.

Quoted 15 lines

lib/arm/stack.c line 25

Quoted 11 lines
lib/arm/stack.c new file +10 -0
+       const unsigned long *fp = (unsigned long *)frame;
+
+       if (walking) {
+               printf("RECURSIVE STACK WALK!!!\n");
+               return 0;
+       }
+       walking = 1;
+
+       for (depth = 0; depth < max_depth; depth++) {
+               if (!fp)

Interesting difference in termination case here from x86. Instead of checking for a null return address, you check for a null frame address. Any particular reason why?

When I configured a unit test that had more than one vcpu, then if I dereferenced a null frame, address zero, I actually got non-zero junk. Then fp was getting updated to fffffffc, and when I dereferenced that (an unmapped address) it led to an exception. So I just threw this test in to make sure that can't happen. It'll also keep me safe in case regs->ARM_fp is ever null in do_handle_exception.

Quoted 26 lines
Quoted 18 lines
lib/arm/stack.c new file +16 -1
+                       break;
+               return_addrs[depth] = (void *)fp[0];
+               if (return_addrs[depth] == 0)
+                       break;
+               fp = (unsigned long *)fp[-1];
+       }
+
+       walking = 0;
+       return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+       return backtrace_frame(__builtin_frame_address(0),
+                              return_addrs, max_depth);
+}
--
Quoted 2 lines

2.4.11

Nice fix!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html