
Date: Tue, 19 Jun 2012 11:50:10 +0900
Subject: [PATCH] update NT_PRSTATUS issue fixed up code

- Keep crash session even if readmem() is failed.
- Rename cpu_was_lost_crash_note() to cpu_saved_crash_note() with
  inverting return value.
- Move warning message to map_cpus_to_prstatus_kdump_cmprs() with
  re-word into new one and CRASHDEBUG(1) condition.
- Add CRASHDEBUG(1) message to map_cpus_to_prstatus_kdump_cmprs()
  if NT_PRSTATUS is remapped from different cpu.
- __diskdump_memory_dump() show "not saved" message for all valid
  cpus which don't own NT_PRSTATUS.

Signed-off-by: Toshikazu Nakayama <nakayama.ts@ncos.nec.co.jp>
---
 diskdump.c |   50 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/diskdump.c b/diskdump.c
index 4bf8560..909ce47 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -91,13 +91,13 @@ int dumpfile_is_split(void)
 }
 
 static int
-cpu_was_lost_crash_note(int cpu)
+cpu_saved_crash_note(int cpu)
 {
 	int ret;
 	ulong crash_notes_ptr;
 	char *buf, *name;
 
-	ret = FALSE;
+	ret = TRUE;
 
 	if (cpu < 0 || cpu > NR_CPUS)
 		error(FATAL, "cpu#%d is out of range\n", cpu);
@@ -106,16 +106,21 @@ cpu_was_lost_crash_note(int cpu)
 	    !VALID_STRUCT(note_buf) || !VALID_STRUCT(elf_prstatus))
 		goto out;
 
-	readmem(symbol_value("crash_notes"), KVADDR, &crash_notes_ptr,
-		sizeof(ulong), "crash_notes", FAULT_ON_ERROR);
+	if (!readmem(symbol_value("crash_notes"), KVADDR, &crash_notes_ptr,
+		     sizeof(ulong), "crash_notes", QUIET|RETURN_ON_ERROR))
+		goto out;
 	if (!crash_notes_ptr)
 		goto out;
 
 	buf = GETBUF(SIZE(note_buf));
 	if ((kt->flags & SMP) && (kt->flags &PER_CPU_OFF))
 		crash_notes_ptr += kt->__per_cpu_offset[cpu];
-	readmem(crash_notes_ptr, KVADDR, buf, SIZE(note_buf),
-		"cpu crash_notes", FAULT_ON_ERROR);
+	if (!readmem(crash_notes_ptr, KVADDR, buf, SIZE(note_buf),
+		     "cpu crash_notes", QUIET|RETURN_ON_ERROR)) {
+		FREEBUF(buf);
+		goto out;
+	}
+
 	if (BITS64()) {
 		Elf64_Nhdr *note64;
 
@@ -125,7 +130,7 @@ cpu_was_lost_crash_note(int cpu)
 		    note64->n_namesz != strlen("CORE") + 1 ||
 		    strncmp(name, "CORE", note64->n_namesz) ||
 		    note64->n_descsz != SIZE(elf_prstatus))
-			ret = TRUE;
+			ret = FALSE;
 	} else {
 		Elf32_Nhdr *note32;
 
@@ -135,12 +140,10 @@ cpu_was_lost_crash_note(int cpu)
 		    note32->n_namesz != strlen("CORE") + 1 ||
 		    strncmp(name, "CORE", note32->n_namesz) ||
 		    note32->n_descsz != SIZE(elf_prstatus))
-			ret = TRUE;
+			ret = FALSE;
 	}
 	FREEBUF(buf);
 out:
-	if (ret)
-		error(WARNING, "catch lost crash_notes at cpu#%d\n", cpu);
 	return ret;
 }
 
@@ -172,8 +175,20 @@ map_cpus_to_prstatus_kdump_cmprs(void)
 	nrcpus = (kt->kernel_NR_CPUS ? kt->kernel_NR_CPUS : NR_CPUS);
 
 	for (i = 0, j = 0; i < nrcpus; i++) {
-		if (in_cpu_map(ONLINE, i) && !cpu_was_lost_crash_note(i))
+		if (in_cpu_map(ONLINE, i)) {
+			if (!cpu_saved_crash_note(i)) {
+				if (CRASHDEBUG(1))
+					error(WARNING,
+					      "cpu#%d: not saved crash_notes\n",
+					      i);
+				continue;
+			}
+			if (CRASHDEBUG(1) && (i != j))
+				error(INFO,
+			  "NT_PRSTATUS: cpu#%d = %lx (remapped from cpu#%d)\n",
+				      i, (ulong)nt_ptr[j], j);
 			dd->nt_prstatus_percpu[i] = nt_ptr[j++];
+		}
 	}
 
 	FREEBUF(nt_ptr);
@@ -1325,7 +1340,7 @@ dump_nt_prstatus_offset(FILE *fp)
 int
 __diskdump_memory_dump(FILE *fp)
 {
-	int i, j, others, dump_level;
+	int i, nrcpus, others, dump_level;
 	struct disk_dump_header *dh;
 	struct disk_dump_sub_header *dsh;
 	struct kdump_sub_header *kdsh;
@@ -1515,12 +1530,17 @@ __diskdump_memory_dump(FILE *fp)
 				dd->num_prstatus_notes);
 			fprintf(fp, "           notes_buf: %lx\n",
 				(ulong)dd->notes_buf);
-			for (i = 0, j = 0; j < dd->num_prstatus_notes; i++) {
-				if (dd->nt_prstatus_percpu[i] == NULL)
+			nrcpus = kt->kernel_NR_CPUS ? kt->kernel_NR_CPUS :
+						      NR_CPUS;
+			for (i = 0; i < nrcpus; i++) {
+				if (dd->nt_prstatus_percpu[i] == NULL) {
+					fprintf(fp,
+					"            notes[%d]: (not saved)\n",
+						i);
 					continue;
+				}
 				fprintf(fp, "            notes[%d]: %lx\n",
 					i, (ulong)dd->nt_prstatus_percpu[i]);
-				j++;
 			}
 			dump_nt_prstatus_offset(fp);
 		}
-- 
1.7.0.4

