Blame SOURCES/github_5fe78861_ppc64_invalid_NIP.patch

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