Re: [Crash-utility] Problem in bt for ARM64

2017-10-18 Thread AKASHI Takahiro
On Tue, Oct 17, 2017 at 03:44:36PM -0400, Dave Anderson wrote:
> 
> Thanks Takahiro, much appreciated.  Queued for crash-7.2.1:
>  
>   
> https://github.com/crash-utility/crash/commit/2b93c036edf2a5cc21a06a14f377cd9b365f858a

Oops, I've made small changes, nothing essential but some sort of
clean-ups/readability improvements with deleting incomplete fixes
against "bt -o."

Thanks,
-Takahiro AKASHI
===8<===
>From 826147807e2f2e00155b41b8ab97d3083bb0e607 Mon Sep 17 00:00:00 2001
From: AKASHI Takahiro 
Date: Thu, 12 Oct 2017 10:46:34 +0900
Subject: [PATCH v2] arm64: backtrace for v4.14

---
 arm64.c | 212 +++-
 defs.h  |   3 +
 task.c  |   2 +
 3 files changed, 161 insertions(+), 56 deletions(-)

diff --git a/arm64.c b/arm64.c
index 20c5d34..80cb476 100644
--- a/arm64.c
+++ b/arm64.c
@@ -72,6 +72,7 @@ static void arm64_cmd_mach(void);
 static void arm64_display_machine_stats(void);
 static int arm64_get_smp_cpus(void);
 static void arm64_clear_machdep_cache(void);
+static int arm64_on_process_stack(struct bt_info *, ulong);
 static int arm64_in_alternate_stack(int, ulong);
 static int arm64_on_irq_stack(int, ulong);
 static void arm64_set_irq_stack(struct bt_info *);
@@ -611,6 +612,7 @@ arm64_dump_machdep_table(ulong arg)
fprintf(fp, "exp_entry2_end: %lx\n", ms->exp_entry2_end);
fprintf(fp, "   panic_task_regs: %lx\n", 
(ulong)ms->panic_task_regs);
fprintf(fp, "user_eframe_offset: %ld\n", ms->user_eframe_offset);
+   fprintf(fp, "kern_eframe_offset: %ld\n", ms->kern_eframe_offset);
fprintf(fp, " PTE_PROT_NONE: %lx\n", ms->PTE_PROT_NONE);
fprintf(fp, "  PTE_FILE: ");
if (ms->PTE_FILE)
@@ -1336,31 +1338,64 @@ arm64_irq_stack_init(void)
req = &request;
struct machine_specific *ms = machdep->machspec;
 
-   if (!symbol_exists("irq_stack") ||
-   !(sp = per_cpu_symbol_search("irq_stack")) ||
-   !get_symbol_type("irq_stack", NULL, req) ||
-   (req->typecode != TYPE_CODE_ARRAY) ||
-   (req->target_typecode != TYPE_CODE_INT))
-   return;
+   if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus
+   * sizeof(ulong)
+   error(FATAL, "cannot malloc irq_stack addresses\n");
 
-   if (CRASHDEBUG(1)) {
-   fprintf(fp, "irq_stack: \n");
-   fprintf(fp, "  type: %s\n", 
-   (req->typecode == TYPE_CODE_ARRAY) ? "TYPE_CODE_ARRAY" 
: "other");
-   fprintf(fp, "  target_typecode: %s\n", 
-   req->target_typecode == TYPE_CODE_INT ? "TYPE_CODE_INT" 
: "other");
-   fprintf(fp, "  target_length: %ld\n", req->target_length);
-   fprintf(fp, "  length: %ld\n", req->length);
-   }
+   if (symbol_exists("irq_stack") &&
+   (sp = per_cpu_symbol_search("irq_stack")) &&
+   get_symbol_type("irq_stack", NULL, req)) {
+   /* before v4.14 or CONFIG_VMAP_STACK disabled */
+   if (CRASHDEBUG(1)) {
+   fprintf(fp, "irq_stack: \n");
+   fprintf(fp, "  type: %s\n",
+   (req->typecode == TYPE_CODE_ARRAY) ?
+   "TYPE_CODE_ARRAY" : "other");
+   fprintf(fp, "  target_typecode: %s\n",
+   req->target_typecode == TYPE_CODE_INT ?
+   "TYPE_CODE_INT" : "other");
+   fprintf(fp, "  target_length: %ld\n",
+   req->target_length);
+   fprintf(fp, "  length: %ld\n", req->length);
+   }
 
-   ms->irq_stack_size = req->length;
-   if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus * 
sizeof(ulong)
-   error(FATAL, "cannot malloc irq_stack addresses\n");
+   ms->irq_stack_size = req->length;
+
+   for (i = 0; i < kt->cpus; i++)
+   ms->irq_stacks[i] = kt->__per_cpu_offset[i] + sp->value;
+
+   machdep->flags |= IRQ_STACKS;
+   } else if (symbol_exists("irq_stack_ptr") &&
+  (sp = per_cpu_symbol_search("irq_stack_ptr")) &&
+  get_symbol_type("irq_stack_ptr", NULL, req)) {
+   /* v4.14 and later with CONFIG_VMAP_STACK enabled */
+   if (CRASHDEBUG(1)) {
+   fprintf(fp, "irq_stack_ptr: \n");
+   fprintf(fp, "  type: %x, %s\n",
+   (int)req->typecode,
+   (req->typecode == TYPE_CODE_PTR) ?
+   "TYPE_CODE_PTR" : "other");
+   fprintf(fp, "  target_typecode: %x, %s\n",
+   (int)req->target_typecode,
+   

Re: [Crash-utility] Problem in bt for ARM64

2017-10-18 Thread Dave Anderson


- Original Message -
> On Tue, Oct 17, 2017 at 03:44:36PM -0400, Dave Anderson wrote:
> > 
> > Thanks Takahiro, much appreciated.  Queued for crash-7.2.1:
> >  
> >   
> > https://github.com/crash-utility/crash/commit/2b93c036edf2a5cc21a06a14f377cd9b365f858a
> 
> Oops, I've made small changes, nothing essential but some sort of
> clean-ups/readability improvements with deleting incomplete fixes
> against "bt -o."

Hmmm, except it's kind of difficult to pick through the patch below
for the changes, given that it's a combination of your original patch
plus the new changes.  So I can't apply it to get a clean view of
the new changes.  I do see that it's mostly the stacksize and stackframe
related updates, but would it be possible for you to make a patch
that can be applied to the github sources?

Thanks,
  Dave


> 
> Thanks,
> -Takahiro AKASHI
> ===8<===
> >From 826147807e2f2e00155b41b8ab97d3083bb0e607 Mon Sep 17 00:00:00 2001
> From: AKASHI Takahiro 
> Date: Thu, 12 Oct 2017 10:46:34 +0900
> Subject: [PATCH v2] arm64: backtrace for v4.14
> 
> ---
>  arm64.c | 212
>  +++-
>  defs.h  |   3 +
>  task.c  |   2 +
>  3 files changed, 161 insertions(+), 56 deletions(-)
> 
> diff --git a/arm64.c b/arm64.c
> index 20c5d34..80cb476 100644
> --- a/arm64.c
> +++ b/arm64.c
> @@ -72,6 +72,7 @@ static void arm64_cmd_mach(void);
>  static void arm64_display_machine_stats(void);
>  static int arm64_get_smp_cpus(void);
>  static void arm64_clear_machdep_cache(void);
> +static int arm64_on_process_stack(struct bt_info *, ulong);
>  static int arm64_in_alternate_stack(int, ulong);
>  static int arm64_on_irq_stack(int, ulong);
>  static void arm64_set_irq_stack(struct bt_info *);
> @@ -611,6 +612,7 @@ arm64_dump_machdep_table(ulong arg)
>   fprintf(fp, "exp_entry2_end: %lx\n", ms->exp_entry2_end);
>   fprintf(fp, "   panic_task_regs: %lx\n", 
> (ulong)ms->panic_task_regs);
>   fprintf(fp, "user_eframe_offset: %ld\n", ms->user_eframe_offset);
> + fprintf(fp, "kern_eframe_offset: %ld\n", ms->kern_eframe_offset);
>   fprintf(fp, " PTE_PROT_NONE: %lx\n", ms->PTE_PROT_NONE);
>   fprintf(fp, "  PTE_FILE: ");
>   if (ms->PTE_FILE)
> @@ -1336,31 +1338,64 @@ arm64_irq_stack_init(void)
>   req = &request;
>   struct machine_specific *ms = machdep->machspec;
>  
> - if (!symbol_exists("irq_stack") ||
> - !(sp = per_cpu_symbol_search("irq_stack")) ||
> - !get_symbol_type("irq_stack", NULL, req) ||
> - (req->typecode != TYPE_CODE_ARRAY) ||
> - (req->target_typecode != TYPE_CODE_INT))
> - return;
> + if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus
> + * sizeof(ulong)
> + error(FATAL, "cannot malloc irq_stack addresses\n");
>  
> - if (CRASHDEBUG(1)) {
> - fprintf(fp, "irq_stack: \n");
> - fprintf(fp, "  type: %s\n",
> - (req->typecode == TYPE_CODE_ARRAY) ? "TYPE_CODE_ARRAY" 
> : "other");
> - fprintf(fp, "  target_typecode: %s\n",
> - req->target_typecode == TYPE_CODE_INT ? "TYPE_CODE_INT" 
> : "other");
> - fprintf(fp, "  target_length: %ld\n", req->target_length);
> - fprintf(fp, "  length: %ld\n", req->length);
> - }
> + if (symbol_exists("irq_stack") &&
> + (sp = per_cpu_symbol_search("irq_stack")) &&
> + get_symbol_type("irq_stack", NULL, req)) {
> + /* before v4.14 or CONFIG_VMAP_STACK disabled */
> + if (CRASHDEBUG(1)) {
> + fprintf(fp, "irq_stack: \n");
> + fprintf(fp, "  type: %s\n",
> + (req->typecode == TYPE_CODE_ARRAY) ?
> + "TYPE_CODE_ARRAY" : "other");
> + fprintf(fp, "  target_typecode: %s\n",
> + req->target_typecode == TYPE_CODE_INT ?
> + "TYPE_CODE_INT" : "other");
> + fprintf(fp, "  target_length: %ld\n",
> + req->target_length);
> + fprintf(fp, "  length: %ld\n", req->length);
> + }
>  
> - ms->irq_stack_size = req->length;
> - if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus *
> sizeof(ulong)
> - error(FATAL, "cannot malloc irq_stack addresses\n");
> + ms->irq_stack_size = req->length;
> +
> + for (i = 0; i < kt->cpus; i++)
> + ms->irq_stacks[i] = kt->__per_cpu_offset[i] + sp->value;
> +
> + machdep->flags |= IRQ_STACKS;
> + } else if (symbol_exists("irq_stack_ptr") &&
> +(sp = per_cpu_symbol_search("irq_stack_ptr")) &&
> +get_symbol_type("irq_stack_ptr", NULL, req)) {
> + /* v4.14 

Re: [Crash-utility] Problem in bt for ARM64

2017-10-18 Thread AKASHI Takahiro
Dave,

On Wed, Oct 18, 2017 at 02:12:17PM -0400, Dave Anderson wrote:
> 
> 
> - Original Message -
> > On Tue, Oct 17, 2017 at 03:44:36PM -0400, Dave Anderson wrote:
> > > 
> > > Thanks Takahiro, much appreciated.  Queued for crash-7.2.1:
> > >  
> > >   
> > > https://github.com/crash-utility/crash/commit/2b93c036edf2a5cc21a06a14f377cd9b365f858a
> > 
> > Oops, I've made small changes, nothing essential but some sort of
> > clean-ups/readability improvements with deleting incomplete fixes
> > against "bt -o."
> 
> Hmmm, except it's kind of difficult to pick through the patch below
> for the changes, given that it's a combination of your original patch
> plus the new changes.  So I can't apply it to get a clean view of
> the new changes.  I do see that it's mostly the stacksize and stackframe
> related updates, but would it be possible for you to make a patch
> that can be applied to the github sources?

Here is what you requested. Pls check.

Thanks,
-Takahiro AKASHI

===8<===
>From 7b99a1c2e688ba81e18541c21a7d0fa70504e5bc Mon Sep 17 00:00:00 2001
From: AKASHI Takahiro 
Date: Thu, 19 Oct 2017 10:18:22 +0900
Subject: [PATCH] arm64: bt: cleanup stuff

---
 arm64.c | 159 +---
 defs.h  |   3 ++
 task.c  |   2 +
 3 files changed, 86 insertions(+), 78 deletions(-)

diff --git a/arm64.c b/arm64.c
index c75669b..1f742d4 100644
--- a/arm64.c
+++ b/arm64.c
@@ -612,6 +612,7 @@ arm64_dump_machdep_table(ulong arg)
fprintf(fp, "exp_entry2_end: %lx\n", ms->exp_entry2_end);
fprintf(fp, "   panic_task_regs: %lx\n", 
(ulong)ms->panic_task_regs);
fprintf(fp, "user_eframe_offset: %ld\n", ms->user_eframe_offset);
+   fprintf(fp, "kern_eframe_offset: %ld\n", ms->kern_eframe_offset);
fprintf(fp, " PTE_PROT_NONE: %lx\n", ms->PTE_PROT_NONE);
fprintf(fp, "  PTE_FILE: ");
if (ms->PTE_FILE)
@@ -1383,7 +1384,7 @@ arm64_irq_stack_init(void)
 
if (!(ms->irq_stacks = (ulong *)malloc((size_t)(kt->cpus * 
sizeof(ulong)
error(FATAL, "cannot malloc irq_stack addresses\n");
-   ms->irq_stack_size = 16384;
+   ms->irq_stack_size = ARM64_IRQ_STACK_SIZE;
machdep->flags |= IRQ_STACKS;
 
for (i = 0; i < kt->cpus; i++) {
@@ -1410,10 +1411,13 @@ arm64_stackframe_init(void)
MEMBER_OFFSET_INIT(elf_prstatus_pr_pid, "elf_prstatus", "pr_pid");
MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus", "pr_reg");
 
-   if (MEMBER_EXISTS("pt_regs", "stackframe")) 
+   if (MEMBER_EXISTS("pt_regs", "stackframe")) {
machdep->machspec->user_eframe_offset = SIZE(pt_regs);
-   else
+   machdep->machspec->kern_eframe_offset = SIZE(pt_regs) - 16;
+   } else {
machdep->machspec->user_eframe_offset = SIZE(pt_regs) + 16;
+   machdep->machspec->kern_eframe_offset = SIZE(pt_regs);
+   }
 
machdep->machspec->__exception_text_start = 
symbol_value("__exception_text_start");
@@ -1503,6 +1507,7 @@ arm64_stackframe_init(void)
 #define USER_MODE   (2)
 
 #define USER_EFRAME_OFFSET (machdep->machspec->user_eframe_offset)
+#define KERN_EFRAME_OFFSET (machdep->machspec->kern_eframe_offset)
 
 /*
  * PSR bits
@@ -1778,7 +1783,7 @@ arm64_display_full_frame(struct bt_info *bt, ulong sp)
ulong words, addr;
char buf[BUFSIZE];
 
-   if (bt->frameptr == sp)
+   if (bt->frameptr >= sp)
return;
 
if (INSTACK(bt->frameptr, bt)) {
@@ -1793,7 +1798,7 @@ arm64_display_full_frame(struct bt_info *bt, ulong sp)
sp = bt->stacktop;
}
} else { 
-   /* IRQ exception frame */
+   /* This is a transition case from irq to process stack. */
return;
}
 
@@ -1903,61 +1908,73 @@ arm64_unwind_frame(struct bt_info *bt, struct 
arm64_stackframe *frame)
if (!(machdep->flags & IRQ_STACKS))
return TRUE;
 
-   /*
-* The kernel's manner of determining the end of the IRQ stack:
-*
-*  #define THREAD_SIZE16384
-*  #define THREAD_START_SP(THREAD_SIZE - 16)
-*  #define IRQ_STACK_START_SP THREAD_START_SP
-*  #define IRQ_STACK_PTR(cpu) ((unsigned long)per_cpu(irq_stack, cpu) 
+ IRQ_STACK_START_SP)
-*  #define IRQ_STACK_TO_TASK_STACK(ptr) (*((unsigned long *)((ptr) - 
0x08)))
-*
-*  irq_stack_ptr = IRQ_STACK_PTR(raw_smp_processor_id());
-*  orig_sp = IRQ_STACK_TO_TASK_STACK(irq_stack_ptr);   (pt_regs 
pointer on process stack)
-*/
+   if (!(machdep->flags & IRQ_STACKS))
+   return TRUE;
+
if (machdep->flags & UNW_4_14) {
if ((bt->flags & BT_IRQSTACK) &&
!arm64_on_irq_stack(bt->tc->processor, frame->fp)) {