On Wed, Mar 23, 2022 at 8:00 PM <crash-utility-request@redhat.com> wrote:
Date: Wed, 23 Mar 2022 18:25:48 +0000
From: Huang Shijie <shijie@os.amperecomputing.com>
To: k-hagio-ab@nec.com
Cc: patches@amperecomputing.com, zwang@amperecomputing.com,
        darren@os.amperecomputing.com, crash-utility@redhat.com,
        lijiang@redhat.com, Huang Shijie <shijie@os.amperecomputing.com>
Subject: [Crash-utility] [PATCH v2] arm64: fix the "pud page" crash
        for live system
Message-ID: <20220323182548.301261-1-shijie@os.amperecomputing.com>
Content-Type: text/plain

1.) When I tested live system with "crash vmlinux /proc/kcore" in kernel v5.7,
    I met the following crash issue:
       ........................................
       crash: seek error: kernel virtual address: ffff75e9fffff000  type: "pud page"
       ........................................

2.) The root cause is the PTOV does not work correctly for some kernel,
    and then arm64_vtop_4level_4k() does not work correctly too.

    Why PTOV does not work?

    Because the physvirt_offset does not get the correct value.

3.) This patch uses symbol_value_from_proc_kallsyms() to get the
    virtual address of "physvirt_offset", and then uses
    READMEM(,..,KCORE_USE_VADDR) to get the correct value of
    "physvirt_offset".

    And also updates the ms->phys_offset which is initialized with
    a wrong value in kernel version [5.4, 5.10).

    Also add more comments for arm64_calc_physvirt_offset().

Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
---
v1 --> v2:
        v1 tried to get the correct value for phys_offset,
        and then get the physvirt_offset correctly.

        v2 tried to get the physvirt_offset correctly,
        and them update phys_offset correctly.

        Tested this patch with kernel 5.7.

Thank you for the update, Shijie.

Applied(with Kazu's fix) and I also modified the patch log:
https://github.com/crash-utility/crash/commit/8827424f2b05587b8aaaeb7aae0ce8bcc017999f

Thanks.
Lianbo

---
 arm64.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/arm64.c b/arm64.c
index b843032..60ae644 100644
--- a/arm64.c
+++ b/arm64.c
@@ -1399,15 +1399,43 @@ arm64_calc_kimage_voffset(void)
                ms->kimage_voffset += (kt->relocate * -1);
 }

+/*
+ * The physvirt_offset only exits in kernel [5.4, 5.10)
+ *
+ *   1) In kernel v5.4, the patch:
+ *        "5383cc6efed137 arm64: mm: Introduce vabits_actual"
+ *
+ *      introduced the physvirt_offset.
+ *
+ *   2) In kernel v5.10, the patch:
+ *          "7bc1a0f9e17658 arm64: mm: use single quantity
+ *                           to represent the PA to VA translation"
+ *      removed the physvirt_offset.
+ */
 static void
 arm64_calc_physvirt_offset(void)
 {
        struct machine_specific *ms = machdep->machspec;
        ulong physvirt_offset;
        struct syment *sp;
+       ulong value;

        if ((sp = kernel_symbol_search("physvirt_offset")) &&
                        machdep->machspec->kimage_voffset) {
+               if (pc->flags & PROC_KCORE) {
+                       value = symbol_value_from_proc_kallsyms("physvirt_offset");
+                       if ((value != BADVAL) &&
+                               (READMEM(pc->mfd, &physvirt_offset, sizeof(ulong),
+                                          value, KCORE_USE_VADDR) > 0)) {
+                               machdep->flags |= HAS_PHYSVIRT_OFFSET;
+                               ms->physvirt_offset = physvirt_offset;
+
+                               /* Update the ms->phys_offset which is wrong */
+                               ms->phys_offset = ms->physvirt_offset + ms->page_offset;
+                               return;
+                       }
+               }
+
                if (READMEM(pc->mfd, &physvirt_offset, sizeof(physvirt_offset),
                        sp->value, sp->value -
                        machdep->machspec->kimage_voffset) > 0) {
--
2.30.2



------------------------------

Subject: Digest Footer

--
Crash-utility mailing list
Crash-utility@redhat.com
https://listman.redhat.com/mailman/listinfo/crash-utility


------------------------------

End of Crash-utility Digest, Vol 198, Issue 27
**********************************************