Blame SOURCES/github_5fe78861_ppc64_invalid_NIP.patch

474a44
commit 5fe78861ea1589084f6a2956a6ff63677c9269e1
474a44
Author: Dave Anderson <anderson@redhat.com>
474a44
Date:   Fri Sep 7 16:05:52 2018 -0400
474a44
474a44
    Commit 3db3d3992d781c1e42587d2d2bf81e785408e0c2 in crash-7.1.8 was
474a44
    aimed at making the PPC64 "bt" command work for dumpfiles saved
474a44
    with the FADUMP facility, but it introduced a bit of unwarranted
474a44
    complexity in "bt" command processing.  Reworked the "bt" command
474a44
    processing for PPC64 arch to make it a little less compilated and
474a44
    also to print symbols for NIP and LR registers in exception frames.
474a44
    Without the patch, "bt" on non-panic active tasks may fail with
474a44
    the message "bt: invalid kernel virtual address: <address>
474a44
    type: Regs NIP value".
474a44
    (hbathini@linux.ibm.com)
474a44
474a44
diff --git a/ppc64.c b/ppc64.c
474a44
index f5d0dac..03fecd3 100644
474a44
--- a/ppc64.c
474a44
+++ b/ppc64.c
474a44
@@ -2093,15 +2093,10 @@ ppc64_print_stack_entry(int frame,
474a44
 					lr);
474a44
 				return;
474a44
 			}
474a44
-			if (req->pc != lr) {
474a44
-				fprintf(fp, "\n%s[Link Register] ", 
474a44
-					frame < 10 ? " " : "");
474a44
-				fprintf(fp, "[%lx] %s at %lx",
474a44
-					req->sp, lrname, lr);
474a44
-			}
474a44
 			req->ra = lr;
474a44
 		}
474a44
-		if (!req->name || STREQ(req->name,lrname)) 
474a44
+		if (!req->name || STREQ(req->name, lrname) ||
474a44
+		    !is_kernel_text(req->pc))
474a44
 			fprintf(fp, "  (unreliable)");
474a44
 		
474a44
 		fprintf(fp, "\n"); 
474a44
@@ -2219,6 +2214,22 @@ ppc64_print_regs(struct ppc64_pt_regs *regs)
474a44
         fprintf(fp, "    Syscall Result: %016lx\n", regs->result);
474a44
 }
474a44
 
474a44
+static void ppc64_print_nip_lr(struct ppc64_pt_regs *regs, int print_lr)
474a44
+{
474a44
+	char buf[BUFSIZE];
474a44
+	char *sym_buf;
474a44
+
474a44
+	sym_buf = value_to_symstr(regs->nip, buf, 0);
474a44
+	if (sym_buf[0] != NULLCHAR)
474a44
+		fprintf(fp, " [NIP  : %s]\n", sym_buf);
474a44
+
474a44
+	if (print_lr) {
474a44
+		sym_buf = value_to_symstr(regs->link, buf, 0);
474a44
+		if (sym_buf[0] != NULLCHAR)
474a44
+			fprintf(fp, " [LR   : %s]\n", sym_buf);
474a44
+	}
474a44
+}
474a44
+
474a44
 /*
474a44
  * Print the exception frame information
474a44
  */
474a44
@@ -2231,6 +2242,59 @@ ppc64_print_eframe(char *efrm_str, struct ppc64_pt_regs *regs,
474a44
 
474a44
 	fprintf(fp, " %s [%lx] exception frame:\n", efrm_str, regs->trap);
474a44
 	ppc64_print_regs(regs);
474a44
+	ppc64_print_nip_lr(regs, 1);
474a44
+}
474a44
+
474a44
+/*
474a44
+ * For vmcore typically saved with KDump or FADump, get SP and IP values
474a44
+ * from the saved ptregs.
474a44
+ */
474a44
+static int
474a44
+ppc64_vmcore_stack_frame(struct bt_info *bt_in, ulong *nip, ulong *ksp)
474a44
+{
474a44
+	struct ppc64_pt_regs *pt_regs;
474a44
+	unsigned long unip;
474a44
+
474a44
+	pt_regs = (struct ppc64_pt_regs *)bt_in->machdep;
474a44
+	if (!pt_regs || !pt_regs->gpr[1]) {
474a44
+		/*
474a44
+		 * Not collected regs. May be the corresponding CPU not
474a44
+		 * responded to an IPI in case of KDump OR f/w has not
474a44
+		 * not provided the register info in case of FADump.
474a44
+		 */
474a44
+		fprintf(fp, "%0lx: GPR1 register value (SP) was not saved\n",
474a44
+			bt_in->task);
474a44
+		return FALSE;
474a44
+	}
474a44
+	*ksp = pt_regs->gpr[1];
474a44
+	if (IS_KVADDR(*ksp)) {
474a44
+		readmem(*ksp+16, KVADDR, &unip, sizeof(ulong), "Regs NIP value",
474a44
+			FAULT_ON_ERROR);
474a44
+		*nip = unip;
474a44
+	} else {
474a44
+		if (IN_TASK_VMA(bt_in->task, *ksp))
474a44
+			fprintf(fp, "%0lx: Task is running in user space\n",
474a44
+				bt_in->task);
474a44
+		else
474a44
+			fprintf(fp, "%0lx: Invalid Stack Pointer %0lx\n",
474a44
+				bt_in->task, *ksp);
474a44
+		*nip = pt_regs->nip;
474a44
+	}
474a44
+
474a44
+	if (bt_in->flags &&
474a44
+	((BT_TEXT_SYMBOLS|BT_TEXT_SYMBOLS_PRINT|BT_TEXT_SYMBOLS_NOPRINT)))
474a44
+		return TRUE;
474a44
+
474a44
+	/*
474a44
+	 * Print the collected regs for the active task
474a44
+	 */
474a44
+	ppc64_print_regs(pt_regs);
474a44
+	if (!IS_KVADDR(*ksp))
474a44
+		return FALSE;
474a44
+
474a44
+	ppc64_print_nip_lr(pt_regs, (unip != pt_regs->link) ? 1 : 0);
474a44
+
474a44
+	return TRUE;
474a44
 }
474a44
 
474a44
 /*
474a44
@@ -2239,7 +2303,7 @@ ppc64_print_eframe(char *efrm_str, struct ppc64_pt_regs *regs,
474a44
 static int
474a44
 ppc64_get_dumpfile_stack_frame(struct bt_info *bt_in, ulong *nip, ulong *ksp)
474a44
 {
474a44
-	int i;
474a44
+	int i, ret, panic_task;
474a44
 	char *sym;
474a44
 	ulong *up;
474a44
 	struct bt_info bt_local, *bt;
474a44
@@ -2251,11 +2315,29 @@ ppc64_get_dumpfile_stack_frame(struct bt_info *bt_in, ulong *nip, ulong *ksp)
474a44
 	struct ppc64_pt_regs *pt_regs;
474a44
 	struct syment *sp;
474a44
 
474a44
-        bt = &bt_local;
474a44
-        BCOPY(bt_in, bt, sizeof(struct bt_info));
474a44
-        ms = machdep->machspec;
474a44
+	bt = &bt_local;
474a44
+	BCOPY(bt_in, bt, sizeof(struct bt_info));
474a44
+	ms = machdep->machspec;
474a44
+	ur_nip = ur_ksp = 0;
474a44
+
474a44
+	panic_task = tt->panic_task == bt->task ? TRUE : FALSE;
474a44
 
474a44
 	check_hardirq = check_softirq = tt->flags & IRQSTACKS ? TRUE : FALSE;
474a44
+	if (panic_task && bt->machdep) {
474a44
+		pt_regs = (struct ppc64_pt_regs *)bt->machdep;
474a44
+		ur_nip = pt_regs->nip;
474a44
+		ur_ksp = pt_regs->gpr[1];
474a44
+	} else if ((pc->flags & KDUMP) ||
474a44
+		   ((pc->flags & DISKDUMP) &&
474a44
+		    (*diskdump_flags & KDUMP_CMPRS_LOCAL))) {
474a44
+		/*
474a44
+		 * For the KDump or FADump vmcore, use SP and IP values
474a44
+		 * that are saved in ptregs.
474a44
+		 */
474a44
+		ret = ppc64_vmcore_stack_frame(bt_in, nip, ksp);
474a44
+		if (ret)
474a44
+			return TRUE;
474a44
+	}
474a44
 
474a44
 	if (bt->task != tt->panic_task) {
474a44
 		char cpu_frozen = FALSE;
474a44
@@ -2385,38 +2467,14 @@ retry:
474a44
 		check_intrstack = FALSE;
474a44
 		goto retry;
474a44
 	}
474a44
-
474a44
 	/*
474a44
-	 * We didn't find what we were looking for, so try to use
474a44
-	 * the SP and IP values saved in ptregs.
474a44
+	 *  We didn't find what we were looking for, so just use what was
474a44
+	 *  passed in the ELF header.
474a44
 	 */
474a44
-	pt_regs = (struct ppc64_pt_regs *)bt_in->machdep;
474a44
-	if (!pt_regs || !pt_regs->gpr[1]) {
474a44
-		/*
474a44
-		 * Not collected regs. May be the corresponding CPU did not
474a44
-		 * respond to an IPI.
474a44
-		 */
474a44
-		if (CRASHDEBUG(1))
474a44
-			fprintf(fp, "%0lx: GPR1(SP) register value not saved\n",
474a44
-				bt_in->task);
474a44
-	} else {
474a44
-		*ksp = pt_regs->gpr[1];
474a44
-		if (IS_KVADDR(*ksp)) {
474a44
-			readmem(*ksp+16, KVADDR, nip, sizeof(ulong),
474a44
-				"Regs NIP value", FAULT_ON_ERROR);
474a44
-			ppc64_print_regs(pt_regs);
474a44
-			return TRUE;
474a44
-		} else {
474a44
-			if (IN_TASK_VMA(bt_in->task, *ksp))
474a44
-				fprintf(fp, "%0lx: Task is running in user space\n",
474a44
-					bt_in->task);
474a44
-			else
474a44
-				fprintf(fp, "%0lx: Invalid Stack Pointer %0lx\n",
474a44
-					bt_in->task, *ksp);
474a44
-			*nip = pt_regs->nip;
474a44
-			ppc64_print_regs(pt_regs);
474a44
-			return FALSE;
474a44
-		}
474a44
+	if (ur_nip && ur_ksp) {
474a44
+		*nip = ur_nip;
474a44
+		*ksp = ur_ksp;
474a44
+		return TRUE;
474a44
 	}
474a44
 
474a44
         console("ppc64_get_dumpfile_stack_frame: cannot find SP for panic task\n");