Hi, Tao
Thank you for the fix.
On Thu, Aug 25, 2022 at 8:00 PM <crash-utility-request@redhat.com> wrote:
Date: Thu, 25 Aug 2022 14:42:45 +0800
From: Tao Liu <ltao@redhat.com>
To: crash-utility@redhat.com
Subject: [Crash-utility] [PATCH v2] Fix kmem failing to print task
        context when address is vmalloced stack
Message-ID: <20220825064243.71447-1-ltao@redhat.com>
Content-Type: text/plain; charset="US-ASCII"; x-default=true

When kernel enabled CONFIG_VMAP_STACK, stack can be allocated to
vmalloced area. Currently crash didn't handle the case, as a result,
kmem will not print the task context as expected. This patch fix the
bug by checking if the address is a vmalloced stack first.

Before:
    crash> kmem ffffb7efce9bbe28
       VMAP_AREA         VM_STRUCT                 ADDRESS RANGE                SIZE
    ffff94eb9102c640  ffff94eb9102b140  ffffb7efce9b8000 - ffffb7efce9bd000    20480

          PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
    ffffdd28220dc000 1883700000                0        0  1 50000000000000

After:
    crash> kmem ffffb7efce9bbe28
        PID: 847
    COMMAND: "khungtaskd"
       TASK: ffff94f8038f4000  [THREAD_INFO: ffff94f8038f4000]
        CPU: 72
      STATE: TASK_RUNNING (PANIC)

       VMAP_AREA         VM_STRUCT                 ADDRESS RANGE                SIZE
    ffff94eb9102c640  ffff94eb9102b140  ffffb7efce9b8000 - ffffb7efce9bd000    20480


I have one question: If the given physical address falls in the vmalloc area, it won't print the task context, is that expected? For example:

[1] Before this patch: the "kmem + physical/virtual address" has the same output asbelow.

crash> kmem ffffb7efce9bbe28
   VMAP_AREA         VM_STRUCT                 ADDRESS RANGE                SIZE
ffff94eb9102c640  ffff94eb9102b140  ffffb7efce9b8000 - ffffb7efce9bd000    20480

      PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
ffffdd28220dc000 1883700000                0        0  1 50000000000000

crash> kmem 1883700e28   <----- vtop ffffb7efce9bbe28
   VMAP_AREA         VM_STRUCT                 ADDRESS RANGE                SIZE
ffff94eb9102c640  ffff94eb9102b140  ffffb7efce9b8000 - ffffb7efce9bd000    20480

      PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
ffffdd28220dc000 1883700000                0        0  1 50000000000000

[2] After this patch: the "kmem + physical/virtual address" has different output asbelow.
crash>  kmem ffffb7efce9bbe28
    PID: 847
COMMAND: "khungtaskd"
   TASK: ffff94f8038f4000  [THREAD_INFO: ffff94f8038f4000]
    CPU: 72
  STATE: TASK_RUNNING (PANIC)

   VMAP_AREA         VM_STRUCT                 ADDRESS RANGE                SIZE
ffff94eb9102c640  ffff94eb9102b140  ffffb7efce9b8000 - ffffb7efce9bd000    20480

      PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
ffffdd28220dc000 1883700000                0        0  1 50000000000000

crash> kmem 1883700e28  <----- vtop ffffb7efce9bbe28
   VMAP_AREA         VM_STRUCT                 ADDRESS RANGE                SIZE
ffff94eb9102c640  ffff94eb9102b140  ffffb7efce9b8000 - ffffb7efce9bd000    20480

      PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
ffffdd28220dc000 1883700000                0        0  1 50000000000000


Thanks.
Lianbo

          PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
    ffffdd28220dc000 1883700000                0        0  1 50000000000000

Signed-off-by: Tao Liu <ltao@redhat.com>
---

v1 -> v2: 1) Remove goto to print task context and vmlist.
          2) Update commit log to show the change.

---
 memory.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/memory.c b/memory.c
index 7339f0c..9ab5781 100644
--- a/memory.c
+++ b/memory.c
@@ -13477,6 +13477,10 @@ kmem_search(struct meminfo *mi)
         *  Check for a valid mapped address.
         */
        if ((mi->memtype == KVADDR) && IS_VMALLOC_ADDR(mi->spec_addr)) {
+               if ((task = stkptr_to_task(vaddr)) && (tc = task_to_context(task))) {
+                       show_context(tc);
+                       fprintf(fp, "\n");
+               }
                if (kvtop(NULL, mi->spec_addr, &paddr, 0)) {
                        mi->flags = orig_flags | VMLIST_VERIFY;
                        dump_vmlist(mi);
--
2.33.1



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

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 203, Issue 41
**********************************************