Blame SOURCES/github_1e488cfe_to_1160ba19.patch

ec6d61
commit 1e488cfefa1d9ca4ca626bc2a308b39f7404f5db
ec6d61
Author: Dave Anderson <anderson@redhat.com>
ec6d61
Date:   Tue Jan 23 16:35:41 2018 -0500
ec6d61
ec6d61
    Fix for the "bt" command and the "ps -s" option for zombie tasks
ec6d61
    whose kernel stacks have been freed/detached.  Without the patch,
ec6d61
    the "bt" command indicates "bt: invalid kernel virtual address: 0
ec6d61
    type: stack contents" and "bt: read of stack at 0 failed"; it will
ec6d61
    be changed to display "(no stack)".  The "ps -s" option would fail
ec6d61
    prematurely upon reaching such a task, indicating "ps: invalid kernel
ec6d61
    virtual address: 0  type: stack contents" and "ps: read of stack at 0
ec6d61
    failed".
ec6d61
    (anderson@redhat.com)
ec6d61
ec6d61
diff --git a/kernel.c b/kernel.c
ec6d61
index 4638495..1bf6251 100644
ec6d61
--- a/kernel.c
ec6d61
+++ b/kernel.c
ec6d61
@@ -1,8 +1,8 @@
ec6d61
 /* kernel.c - core analysis suite
ec6d61
  *
ec6d61
  * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
ec6d61
- * Copyright (C) 2002-2017 David Anderson
ec6d61
- * Copyright (C) 2002-2017 Red Hat, Inc. All rights reserved.
ec6d61
+ * Copyright (C) 2002-2018 David Anderson
ec6d61
+ * Copyright (C) 2002-2018 Red Hat, Inc. All rights reserved.
ec6d61
  *
ec6d61
  * This program is free software; you can redistribute it and/or modify
ec6d61
  * it under the terms of the GNU General Public License as published by
ec6d61
@@ -2890,6 +2890,11 @@ back_trace(struct bt_info *bt)
ec6d61
 			return;
ec6d61
  	}
ec6d61
 
ec6d61
+	if (bt->stackbase == 0) {
ec6d61
+		fprintf(fp, "(no stack)\n");
ec6d61
+		return;
ec6d61
+	}
ec6d61
+
ec6d61
 	fill_stackbuf(bt);
ec6d61
 
ec6d61
 	if (CRASHDEBUG(4)) {
ec6d61
diff --git a/task.c b/task.c
ec6d61
index b303ef7..db05ab4 100644
ec6d61
--- a/task.c
ec6d61
+++ b/task.c
ec6d61
@@ -1,8 +1,8 @@
ec6d61
 /* task.c - core analysis suite
ec6d61
  *
ec6d61
  * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
ec6d61
- * Copyright (C) 2002-2017 David Anderson
ec6d61
- * Copyright (C) 2002-2017 Red Hat, Inc. All rights reserved.
ec6d61
+ * Copyright (C) 2002-2018 David Anderson
ec6d61
+ * Copyright (C) 2002-2018 Red Hat, Inc. All rights reserved.
ec6d61
  *
ec6d61
  * This program is free software; you can redistribute it and/or modify
ec6d61
  * it under the terms of the GNU General Public License as published by
ec6d61
@@ -4182,12 +4182,14 @@ task_pointer_string(struct task_context *tc, ulong do_kstackp, char *buf)
ec6d61
 				KVADDR, &bt->stkptr, sizeof(void *),
ec6d61
                 		"thread_struct ksp", FAULT_ON_ERROR);
ec6d61
 		} else {
ec6d61
-               		bt->task = tc->task;
ec6d61
-               		bt->tc = tc;
ec6d61
-               		bt->stackbase = GET_STACKBASE(tc->task);
ec6d61
-               		bt->stacktop = GET_STACKTOP(tc->task);
ec6d61
-			bt->flags |= BT_KSTACKP;
ec6d61
-			back_trace(bt);
ec6d61
+			if ((bt->stackbase = GET_STACKBASE(tc->task))) {
ec6d61
+				bt->stacktop = GET_STACKTOP(tc->task);
ec6d61
+				bt->task = tc->task;
ec6d61
+				bt->tc = tc;
ec6d61
+				bt->flags |= BT_KSTACKP;
ec6d61
+				back_trace(bt);
ec6d61
+			} else
ec6d61
+				bt->stkptr = 0;
ec6d61
 		}
ec6d61
 
ec6d61
 		if (bt->stkptr)
ec6d61
ec6d61
commit 693e0fa8ea8b2791329a4197fafd8700afa14c3b
ec6d61
Author: Dave Anderson <anderson@redhat.com>
ec6d61
Date:   Thu Jan 25 14:52:54 2018 -0500
ec6d61
ec6d61
    Fix for running on live systems on 4.15-rc2 and later kernels that
ec6d61
    are configured with CONFIG_RANDOMIZE_BASE and contain kernel commit
ec6d61
    668533dc0764b30c9dd2baf3ca800156f688326b, titled "kallsyms: take
ec6d61
    advantage of the new '%px' format".  Without the patch, a live crash
ec6d61
    session does not show the "WARNING: kernel relocated ..." message
ec6d61
    expected with KASLR, and then displays the message "crash: cannot set
ec6d61
    context for pid: <pid>" prior to generating a SIGSEGV.
ec6d61
    (anderson@redhat.com)
ec6d61
ec6d61
diff --git a/symbols.c b/symbols.c
ec6d61
index 2372887..9a3763c 100644
ec6d61
--- a/symbols.c
ec6d61
+++ b/symbols.c
ec6d61
@@ -1,8 +1,8 @@
ec6d61
 /* symbols.c - core analysis suite
ec6d61
  *
ec6d61
  * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
ec6d61
- * Copyright (C) 2002-2017 David Anderson
ec6d61
- * Copyright (C) 2002-2017 Red Hat, Inc. All rights reserved.
ec6d61
+ * Copyright (C) 2002-2018 David Anderson
ec6d61
+ * Copyright (C) 2002-2018 Red Hat, Inc. All rights reserved.
ec6d61
  *
ec6d61
  * This program is free software; you can redistribute it and/or modify
ec6d61
  * it under the terms of the GNU General Public License as published by
ec6d61
@@ -1004,10 +1004,9 @@ symbol_value_from_proc_kallsyms(char *symname)
ec6d61
 
ec6d61
 	found = FALSE;
ec6d61
 	while (!found && fgets(buf, BUFSIZE, kp) &&
ec6d61
-	    (parse_line(buf, kallsyms) == 3) && 
ec6d61
-	    hexadecimal(kallsyms[0], 0)) {
ec6d61
-
ec6d61
-		if (STREQ(kallsyms[2], symname)) {
ec6d61
+	    (parse_line(buf, kallsyms) == 3)) {
ec6d61
+		if (hexadecimal(kallsyms[0], 0) && 
ec6d61
+		    STREQ(kallsyms[2], symname)) {
ec6d61
 			kallsym = htol(kallsyms[0], RETURN_ON_ERROR, NULL);
ec6d61
 			found = TRUE;
ec6d61
 			break;
ec6d61
ec6d61
commit 1af7813e0552ac93b39a44abffffc04600d3ed4c
ec6d61
Author: Dave Anderson <anderson@redhat.com>
ec6d61
Date:   Thu Jan 25 15:17:26 2018 -0500
ec6d61
ec6d61
    Fix for 4.15-rc5 and later x86_64 kernels that contain kernel commit
ec6d61
    c482feefe1aeb150156248ba0fd3e029bc886605, titled "x86/entry/64: Make
ec6d61
    cpu_entry_area.tss read-only".  Without the patch, the addresses and
ec6d61
    sizes of the x86_64 exception stacks cannot be determined; therefore
ec6d61
    if a backtrace starts on one of the exception stacks, then the "bt"
ec6d61
    command will fail.
ec6d61
    (anderson@redhat.com)
ec6d61
ec6d61
diff --git a/x86_64.c b/x86_64.c
ec6d61
index e924ca9..467b5d7 100644
ec6d61
--- a/x86_64.c
ec6d61
+++ b/x86_64.c
ec6d61
@@ -1245,8 +1245,10 @@ x86_64_ist_init(void)
ec6d61
 	struct syment *boot_sp, *tss_sp, *ist_sp;
ec6d61
 
ec6d61
         ms = machdep->machspec;
ec6d61
-	if (!(tss_sp = per_cpu_symbol_search("per_cpu__init_tss")))
ec6d61
-		tss_sp = per_cpu_symbol_search("per_cpu__cpu_tss");
ec6d61
+	if (!(tss_sp = per_cpu_symbol_search("per_cpu__init_tss"))) {
ec6d61
+		if (!(tss_sp = per_cpu_symbol_search("per_cpu__cpu_tss")))
ec6d61
+			tss_sp = per_cpu_symbol_search("per_cpu__cpu_tss_rw");
ec6d61
+	}
ec6d61
 	ist_sp = per_cpu_symbol_search("per_cpu__orig_ist");
ec6d61
 
ec6d61
 	x86_64_exception_stacks_init();
ec6d61
ec6d61
commit 1160ba19884fed4420c334394cde7a40b113e09c
ec6d61
Author: Dave Anderson <anderson@redhat.com>
ec6d61
Date:   Fri Jan 26 11:06:48 2018 -0500
ec6d61
ec6d61
    Additional fix for support of KASLR enabled kernels captured by the
ec6d61
    SADUMP dumpfile facility, where this patch fixes a problem when Page
ec6d61
    Table Isolation(PTI) is enabled.  When PTI is enabled, bit 12 of CR3
ec6d61
    register is used to split user space and kernel space.  Also bit 11:0
ec6d61
    is used for Process Context IDentifiers(PCID).  To open an SADUMP
ec6d61
    dumpfile, the value of CR3 is used to calculate KASLR offset and
ec6d61
    phys_base; this patch masks the CR3 register value correctly for
ec6d61
    a PTI enabled kernel.
ec6d61
    (indou.takao@jp.fujitsu.com)
ec6d61
ec6d61
diff --git a/defs.h b/defs.h
ec6d61
index 4d2fb2f..92341d2 100644
ec6d61
--- a/defs.h
ec6d61
+++ b/defs.h
ec6d61
@@ -2605,6 +2605,8 @@ struct symbol_table_data {
ec6d61
 	ulong divide_error_vmlinux;
ec6d61
 	ulong idt_table_vmlinux;
ec6d61
 	ulong saved_command_line_vmlinux;
ec6d61
+	ulong pti_init_vmlinux;
ec6d61
+	ulong kaiser_init_vmlinux;
ec6d61
 };
ec6d61
 
ec6d61
 /* flags for st */
ec6d61
diff --git a/sadump.c b/sadump.c
ec6d61
index 6b912d4..25cefe9 100644
ec6d61
--- a/sadump.c
ec6d61
+++ b/sadump.c
ec6d61
@@ -1749,7 +1749,7 @@ static ulong memparse(char *ptr, char **retptr)
ec6d61
  * of elfcorehdr.
ec6d61
  */
ec6d61
 static ulong
ec6d61
-get_elfcorehdr(ulong cr3, ulong kaslr_offset)
ec6d61
+get_elfcorehdr(ulong kaslr_offset)
ec6d61
 {
ec6d61
 	char cmdline[BUFSIZE], *ptr;
ec6d61
 	ulong cmdline_vaddr;
ec6d61
@@ -1906,7 +1906,7 @@ get_vmcoreinfo(ulong elfcorehdr, ulong *addr, int *len)
ec6d61
  *    using "elfcorehdr=" and retrieve kaslr_offset/phys_base from vmcoreinfo.
ec6d61
  */
ec6d61
 static int
ec6d61
-get_kaslr_offset_from_vmcoreinfo(ulong cr3, ulong orig_kaslr_offset,
ec6d61
+get_kaslr_offset_from_vmcoreinfo(ulong orig_kaslr_offset,
ec6d61
 		                 ulong *kaslr_offset, ulong *phys_base)
ec6d61
 {
ec6d61
 	ulong elfcorehdr_addr = 0;
ec6d61
@@ -1916,7 +1916,7 @@ get_kaslr_offset_from_vmcoreinfo(ulong cr3, ulong orig_kaslr_offset,
ec6d61
 	int ret = FALSE;
ec6d61
 
ec6d61
 	/* Find "elfcorehdr=" in the kernel boot parameter */
ec6d61
-	elfcorehdr_addr = get_elfcorehdr(cr3, orig_kaslr_offset);
ec6d61
+	elfcorehdr_addr = get_elfcorehdr(orig_kaslr_offset);
ec6d61
 	if (!elfcorehdr_addr)
ec6d61
 		return FALSE;
ec6d61
 
ec6d61
@@ -1973,8 +1973,8 @@ quit:
ec6d61
  * 1) Get IDTR and CR3 value from the dump header.
ec6d61
  * 2) Get a virtual address of IDT from IDTR value
ec6d61
  *    --- (A)
ec6d61
- * 3) Translate (A) to physical address using CR3, which points a top of
ec6d61
- *    page table.
ec6d61
+ * 3) Translate (A) to physical address using CR3, the upper 52 bits
ec6d61
+ *    of which points a top of page table.
ec6d61
  *    --- (B)
ec6d61
  * 4) Get an address of vector0 (Devide Error) interrupt handler from
ec6d61
  *    IDT, which are pointed by (B).
ec6d61
@@ -2023,12 +2023,15 @@ quit:
ec6d61
  *    kernel. Retrieve vmcoreinfo from address of "elfcorehdr=" and
ec6d61
  *    get kaslr_offset and phys_base from vmcoreinfo.
ec6d61
  */
ec6d61
+#define PTI_USER_PGTABLE_BIT	PAGE_SHIFT
ec6d61
+#define PTI_USER_PGTABLE_MASK	(1 << PTI_USER_PGTABLE_BIT)
ec6d61
+#define CR3_PCID_MASK		0xFFFull
ec6d61
 int
ec6d61
 sadump_calc_kaslr_offset(ulong *kaslr_offset)
ec6d61
 {
ec6d61
 	ulong phys_base = 0;
ec6d61
 	struct sadump_smram_cpu_state scs;
ec6d61
-	uint64_t idtr = 0, cr3 = 0, idtr_paddr;
ec6d61
+	uint64_t idtr = 0, pgd = 0, idtr_paddr;
ec6d61
 	ulong divide_error_vmcore;
ec6d61
 	ulong kaslr_offset_kdump, phys_base_kdump;
ec6d61
 	int ret = FALSE;
ec6d61
@@ -2039,7 +2042,10 @@ sadump_calc_kaslr_offset(ulong *kaslr_offset)
ec6d61
 
ec6d61
 	memset(&scs, 0, sizeof(scs));
ec6d61
 	get_sadump_smram_cpu_state_any(&scs);
ec6d61
-	cr3 = scs.Cr3;
ec6d61
+	if (st->pti_init_vmlinux || st->kaiser_init_vmlinux)
ec6d61
+		pgd = scs.Cr3 & ~(CR3_PCID_MASK|PTI_USER_PGTABLE_MASK);
ec6d61
+	else
ec6d61
+		pgd = scs.Cr3 & ~CR3_PCID_MASK;
ec6d61
 	idtr = ((uint64_t)scs.IdtUpper)<<32 | (uint64_t)scs.IdtLower;
ec6d61
 
ec6d61
 	/*
ec6d61
@@ -2050,12 +2056,12 @@ sadump_calc_kaslr_offset(ulong *kaslr_offset)
ec6d61
 	 *
ec6d61
 	 * TODO: XEN and 5-level is not supported
ec6d61
 	 */
ec6d61
-	vt->kernel_pgd[0] = cr3;
ec6d61
+	vt->kernel_pgd[0] = pgd;
ec6d61
 	machdep->machspec->last_pml4_read = vt->kernel_pgd[0];
ec6d61
 	machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_2_6;
ec6d61
 	machdep->machspec->pgdir_shift = PGDIR_SHIFT;
ec6d61
-	if (!readmem(cr3, PHYSADDR, machdep->machspec->pml4, PAGESIZE(),
ec6d61
-			"cr3", RETURN_ON_ERROR))
ec6d61
+	if (!readmem(pgd, PHYSADDR, machdep->machspec->pml4, PAGESIZE(),
ec6d61
+			"pgd", RETURN_ON_ERROR))
ec6d61
 		goto quit;
ec6d61
 
ec6d61
 	/* Convert virtual address of IDT table to physical address */
ec6d61
@@ -2070,7 +2076,7 @@ sadump_calc_kaslr_offset(ulong *kaslr_offset)
ec6d61
 
ec6d61
 	if (CRASHDEBUG(1)) {
ec6d61
 		fprintf(fp, "calc_kaslr_offset: idtr=%lx\n", idtr);
ec6d61
-		fprintf(fp, "calc_kaslr_offset: cr3=%lx\n", cr3);
ec6d61
+		fprintf(fp, "calc_kaslr_offset: pgd=%lx\n", pgd);
ec6d61
 		fprintf(fp, "calc_kaslr_offset: idtr(phys)=%lx\n", idtr_paddr);
ec6d61
 		fprintf(fp, "calc_kaslr_offset: divide_error(vmlinux): %lx\n",
ec6d61
 			st->divide_error_vmlinux);
ec6d61
@@ -2084,9 +2090,12 @@ sadump_calc_kaslr_offset(ulong *kaslr_offset)
ec6d61
 	 * from vmcoreinfo
ec6d61
 	 */
ec6d61
 	if (get_kaslr_offset_from_vmcoreinfo(
ec6d61
-		cr3, *kaslr_offset, &kaslr_offset_kdump, &phys_base_kdump)) {
ec6d61
+		*kaslr_offset, &kaslr_offset_kdump, &phys_base_kdump)) {
ec6d61
 		*kaslr_offset =  kaslr_offset_kdump;
ec6d61
 		phys_base =  phys_base_kdump;
ec6d61
+	} else if (CRASHDEBUG(1)) {
ec6d61
+		fprintf(fp, "sadump: failed to determine which kernel was running at crash,\n");
ec6d61
+		fprintf(fp, "sadump: asssuming the kdump 1st kernel.\n");
ec6d61
 	}
ec6d61
 
ec6d61
 	if (CRASHDEBUG(1)) {
ec6d61
diff --git a/symbols.c b/symbols.c
ec6d61
index 9a3763c..4db9af7 100644
ec6d61
--- a/symbols.c
ec6d61
+++ b/symbols.c
ec6d61
@@ -3071,10 +3071,14 @@ dump_symbol_table(void)
ec6d61
 		fprintf(fp, "divide_error_vmlinux: %lx\n", st->divide_error_vmlinux);
ec6d61
 		fprintf(fp, "   idt_table_vmlinux: %lx\n", st->idt_table_vmlinux);
ec6d61
 		fprintf(fp, "saved_command_line_vmlinux: %lx\n", st->saved_command_line_vmlinux);
ec6d61
+		fprintf(fp, "    pti_init_vmlinux: %lx\n", st->pti_init_vmlinux);
ec6d61
+		fprintf(fp, " kaiser_init_vmlinux: %lx\n", st->kaiser_init_vmlinux);
ec6d61
 	} else {
ec6d61
 		fprintf(fp, "divide_error_vmlinux: (unused)\n");
ec6d61
 		fprintf(fp, "   idt_table_vmlinux: (unused)\n");
ec6d61
 		fprintf(fp, "saved_command_line_vmlinux: (unused)\n");
ec6d61
+		fprintf(fp, "    pti_init_vmlinux: (unused)\n");
ec6d61
+		fprintf(fp, " kaiser_init_vmlinux: (unused)\n");
ec6d61
 	}
ec6d61
 
ec6d61
         fprintf(fp, "    symval_hash[%d]: %lx\n", SYMVAL_HASH,
ec6d61
@@ -12305,6 +12309,11 @@ numeric_forward(const void *P_x, const void *P_y)
ec6d61
 			st->saved_command_line_vmlinux = valueof(x);
ec6d61
 		else if (STREQ(y->name, "saved_command_line"))
ec6d61
 			st->saved_command_line_vmlinux = valueof(y);
ec6d61
+
ec6d61
+		if (STREQ(x->name, "pti_init"))
ec6d61
+			st->pti_init_vmlinux = valueof(x);
ec6d61
+		else if (STREQ(y->name, "kaiser_init"))
ec6d61
+			st->kaiser_init_vmlinux = valueof(y);
ec6d61
 	}
ec6d61
 
ec6d61
   	xs = bfd_get_section(x);