<div dir="ltr"><div dir="ltr">On Sat, Oct 14, 2023 at 9:39 PM <<a href="mailto:crash-utility-request@redhat.com">crash-utility-request@redhat.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Date: Sat, 14 Oct 2023 19:09:30 +0530<br>
From: Aditya Gupta <<a href="mailto:adityag@linux.ibm.com" target="_blank">adityag@linux.ibm.com</a>><br>
To: <a href="mailto:crash-utility@redhat.com" target="_blank">crash-utility@redhat.com</a>, <<a href="mailto:lijiang@redhat.com" target="_blank">lijiang@redhat.com</a>><br>
Cc: Hari Bathini <<a href="mailto:hbathini@linux.ibm.com" target="_blank">hbathini@linux.ibm.com</a>>, Mahesh J Salgaonkar<br>
        <<a href="mailto:mahesh@linux.ibm.com" target="_blank">mahesh@linux.ibm.com</a>>, Sourabh Jain <<a href="mailto:sourabhjain@linux.ibm.com" target="_blank">sourabhjain@linux.ibm.com</a>>,<br>
        <a href="mailto:d.hatayama@fujitsu.com" target="_blank">d.hatayama@fujitsu.com</a><br>
Subject: [Crash-utility] [PATCH RESEND v2] diskdump: add hook for<br>
        additional checks on prstatus notes validity<br>
Message-ID: <<a href="mailto:20231014133930.147343-1-adityag@linux.ibm.com" target="_blank">20231014133930.147343-1-adityag@linux.ibm.com</a>><br>
Content-Type: text/plain; charset="US-ASCII"; x-default=true<br>
<br>
Upstream crash reports these warnings on PowerPC64:<br>
<br>
    WARNING: cpu 0 invalid NT_PRSTATUS note (n_type != NT_PRSTATUS)<br>
    ...<br>
<br>
Apart from these warnings, register values are also invalid.<br>
<br>
This warning was found in the commit:<br>
<br>
    commit db8c030857b4 ("diskdump/netdump: fix segmentation fault<br>
    caused by failure of stopping CPUs")<br>
<br>
With above commit, crash checks whether 'crash_notes' is initialised,<br>
before mapping PRSTATUS notes.<br>
<br>
But some architectures such as PowerPC64, in fadump case<br>
(firmware-assisted dump), don't populate 'crash_notes' since the<br>
registers are already stored in the cpu notes in the vmcore.<br>
<br>
Instead of checking 'crash_notes' for all architectures, introduce<br>
a machdep hook ('is_cpu_prstatus_valid'), for architectures to<br>
decide validity checks for PRSTATUS notes<br>
<br>
A default hook ('diskdump_is_cpu_prstatus_valid') has also been provided<br>
for all architectures other than PowerPC64, which checks if 'crash_notes'<br>
for a given cpu is valid, maintaining the current behaviour<br>
<br>
PowerPC64 doesn't utilise 'crash_notes' to get register values, so no<br>
additional checks are required<br>
<br>
Fixes: db8c030857b4 ("diskdump/netdump: fix segmentation fault caused by failure of stopping CPUs")<br>
Signed-off-by: Aditya Gupta <<a href="mailto:adityag@linux.ibm.com" target="_blank">adityag@linux.ibm.com</a>><br>
<br>
---<br>
Testing<br>
=======<br>
<br>
NOTE: To test this on PowerPC64 with upstream kernel dump, AND on system<br>
with Radix MMU, following patch will also be needed to be applied:<br>
<br>
Link: <a href="https://listman.redhat.com/archives/crash-utility/2023-September/010961.html" rel="noreferrer" target="_blank">https://listman.redhat.com/archives/crash-utility/2023-September/010961.html</a><br>
<br>
This is due to change in vmemmap address mapping for Radix MMU, since<br>
following patch in the kernel:<br>
<br>
    368a0590d954: (powerpc/book3s64/vmemmap: switch radix to use a<br>
    different vmemmap handling function)<br>
<br>
More details about the change are in the linked patch. Basically what<br>
changed is, the address mapping for vmemmap address is now in kernel<br>
page table, in case of Radix MMU, instead of 'vmemmap_list' which is currently<br>
used in crash.<br>
<br>
Git Tree for Testing<br>
====================<br>
<br>
1. With this patch (diskdump: add hook for additional ...) applied:<br>
<br>
<a href="https://github.com/adi-g15-ibm/crash/tree/bugzilla-203256-list-v2" rel="noreferrer" target="_blank">https://github.com/adi-g15-ibm/crash/tree/bugzilla-203256-list-v2</a><br>
<br>
2. With both this and the linked patch (ppc64: do page traversal ...) applied:<br>
<br>
<a href="https://github.com/adi-g15-ibm/crash/tree/bugzilla-203256-withupstreamradix" rel="noreferrer" target="_blank">https://github.com/adi-g15-ibm/crash/tree/bugzilla-203256-withupstreamradix</a><br>
<br>
Changelog<br>
=========<br>
<br>
V2<br>
+ added fix for netdump also, same as diskdump, as that was also modified by<br>
db8c030857b4<br>
+ fixed compile warnings<br>
<br></blockquote><div><br></div><div>Thank  you for the update,  Aditya.</div><div><br></div><div>For the v2: Ack.</div><div><br></div><div>Thanks</div><div>Lianbo</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
<br>
---<br>
 defs.h     |  2 ++<br>
 diskdump.c | 15 ++++++++++++---<br>
 netdump.c  |  5 ++---<br>
 ppc64.c    | 10 ++++++++++<br>
 4 files changed, 26 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/defs.h b/defs.h<br>
index 96a7a2a31471..23dee48759fb 100644<br>
--- a/defs.h<br>
+++ b/defs.h<br>
@@ -1075,6 +1075,7 @@ struct machdep_table {<br>
         void (*show_interrupts)(int, ulong *);<br>
        int (*is_page_ptr)(ulong, physaddr_t *);<br>
        int (*get_cpu_reg)(int, int, const char *, int, void *);<br>
+       int (*is_cpu_prstatus_valid)(int cpu);<br>
 };<br>
<br>
 /*<br>
@@ -7181,6 +7182,7 @@ int dumpfile_is_split(void);<br>
 void show_split_dumpfiles(void);<br>
 void x86_process_elf_notes(void *, unsigned long);<br>
 void *diskdump_get_prstatus_percpu(int);<br>
+int diskdump_is_cpu_prstatus_valid(int cpu);<br>
 int have_crash_notes(int cpu);<br>
 void map_cpus_to_prstatus_kdump_cmprs(void);<br>
 void diskdump_display_regs(int, FILE *);<br>
diff --git a/diskdump.c b/diskdump.c<br>
index 2c284ff3f97f..ad9a00b08ce1 100644<br>
--- a/diskdump.c<br>
+++ b/diskdump.c<br>
@@ -142,13 +142,22 @@ int have_crash_notes(int cpu)<br>
        return TRUE;<br>
 }<br>
<br>
+int diskdump_is_cpu_prstatus_valid(int cpu)<br>
+{<br>
+       static int crash_notes_exists = -1;<br>
+<br>
+       if (crash_notes_exists == -1)<br>
+               crash_notes_exists = kernel_symbol_exists("crash_notes");<br>
+<br>
+       return (!crash_notes_exists || have_crash_notes(cpu));<br>
+}<br>
+<br>
 void<br>
 map_cpus_to_prstatus_kdump_cmprs(void)<br>
 {<br>
        void **nt_ptr;<br>
        int online, i, j, nrcpus;<br>
        size_t size;<br>
-       int crash_notes_exists;<br>
<br>
        if (pc->flags2 & QEMU_MEM_DUMP_COMPRESSED)  /* notes exist for all cpus */<br>
                goto resize_note_pointers;<br>
@@ -171,10 +180,9 @@ map_cpus_to_prstatus_kdump_cmprs(void)<br>
         *  Re-populate the array with the notes mapping to online cpus<br>
         */<br>
        nrcpus = (kt->kernel_NR_CPUS ? kt->kernel_NR_CPUS : NR_CPUS);<br>
-       crash_notes_exists = kernel_symbol_exists("crash_notes");<br>
<br>
        for (i = 0, j = 0; i < nrcpus; i++) {<br>
-               if (in_cpu_map(ONLINE_MAP, i) && (!crash_notes_exists || have_crash_notes(i))) {<br>
+               if (in_cpu_map(ONLINE_MAP, i) && machdep->is_cpu_prstatus_valid(i)) {<br>
                        dd->nt_prstatus_percpu[i] = nt_ptr[j++];<br>
                        dd->num_prstatus_notes = <br>
                                MAX(dd->num_prstatus_notes, i+1);<br>
@@ -1076,6 +1084,7 @@ diskdump_init(char *unused, FILE *fptr)<br>
        if (!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID())<br>
                return FALSE;<br>
<br>
+       machdep->is_cpu_prstatus_valid = diskdump_is_cpu_prstatus_valid;<br>
        dd->ofp = fptr;<br>
        return TRUE;<br>
 }<br>
diff --git a/netdump.c b/netdump.c<br>
index 61ddeaa08831..390786364959 100644<br>
--- a/netdump.c<br>
+++ b/netdump.c<br>
@@ -75,7 +75,6 @@ map_cpus_to_prstatus(void)<br>
        void **nt_ptr;<br>
        int online, i, j, nrcpus;<br>
        size_t size;<br>
-       int crash_notes_exists;<br>
<br>
        if (pc->flags2 & QEMU_MEM_DUMP_ELF)  /* notes exist for all cpus */<br>
                return;<br>
@@ -98,10 +97,9 @@ map_cpus_to_prstatus(void)<br>
         *  Re-populate the array with the notes mapping to online cpus<br>
         */<br>
        nrcpus = (kt->kernel_NR_CPUS ? kt->kernel_NR_CPUS : NR_CPUS);<br>
-       crash_notes_exists = kernel_symbol_exists("crash_notes");<br>
<br>
        for (i = 0, j = 0; i < nrcpus; i++) {<br>
-               if (in_cpu_map(ONLINE_MAP, i) && (!crash_notes_exists || have_crash_notes(i))) {<br>
+               if (in_cpu_map(ONLINE_MAP, i) && machdep->is_cpu_prstatus_valid(i)) {<br>
                        nd->nt_prstatus_percpu[i] = nt_ptr[j++];<br>
                        nd->num_prstatus_notes =<br>
                                MAX(nd->num_prstatus_notes, i+1);<br>
@@ -735,6 +733,7 @@ netdump_init(char *unused, FILE *fptr)<br>
        if (!VMCORE_VALID())<br>
                return FALSE;<br>
<br>
+       machdep->is_cpu_prstatus_valid = diskdump_is_cpu_prstatus_valid;<br>
        nd->ofp = fptr;<br>
<br>
        check_dumpfile_size(pc->dumpfile);<br>
diff --git a/ppc64.c b/ppc64.c<br>
index fc34006f4863..5a8ef9e58173 100644<br>
--- a/ppc64.c<br>
+++ b/ppc64.c<br>
@@ -298,6 +298,15 @@ struct machine_specific book3e_machine_specific = {<br>
        .is_vmaddr = book3e_is_vmaddr,<br>
 };<br>
<br>
+/**<br>
+ * No additional checks are required on PPC64, for checking if PRSTATUS notes<br>
+ * is valid<br>
+ */<br>
+static int ppc64_is_cpu_prstatus_valid(int cpu)<br>
+{<br>
+       return TRUE;<br>
+}<br>
+<br>
 #define SKIBOOT_BASE                   0x30000000<br>
<br>
 /*<br>
@@ -400,6 +409,7 @@ ppc64_init(int when)<br>
                machdep->value_to_symbol = generic_machdep_value_to_symbol;<br>
                machdep->get_kvaddr_ranges = ppc64_get_kvaddr_ranges;<br>
                machdep->init_kernel_pgd = NULL;<br>
+               machdep->is_cpu_prstatus_valid = ppc64_is_cpu_prstatus_valid;<br>
<br>
                if (symbol_exists("vmemmap_populate")) {<br>
                        if (symbol_exists("vmemmap")) {<br>
-- <br>
2.41.0<br>
</blockquote></div></div>