linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix GDB commands error
@ 2023-11-27  7:04 Kuan-Ying Lee
  2023-11-27  7:04 ` [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error Kuan-Ying Lee
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2023-11-27  7:04 UTC (permalink / raw)
  To: Matthias Brugger, AngeloGioacchino Del Regno
  Cc: casper.li, chinwen.chang, qun-wei.lin, linux-mm, akpm,
	Kuan-Ying Lee, linux-kernel, linux-arm-kernel, linux-mediatek

This patchset fix some issues of gdb command.

Patch 1:
 - Fix lx-ps command error
Patch 2:
 - Fix stackdepot usage error
Patch 3:
 - Remove exception handling
 - Refine the printing format

---
This patchset is based on linux-next-20231127.

Kuan-Ying Lee (3):
  scripts/gdb/tasks: Fix lx-ps command error
  scripts/gdb/stackdepot: Rename pool_index_cached to pools_num
  scripts/gdb: Remove exception handling and refine print format

 scripts/gdb/linux/page_owner.py | 58 ++++++++++++++-------------------
 scripts/gdb/linux/slab.py       |  3 +-
 scripts/gdb/linux/stackdepot.py |  6 ++--
 scripts/gdb/linux/tasks.py      | 12 +++----
 4 files changed, 33 insertions(+), 46 deletions(-)

-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error
  2023-11-27  7:04 [PATCH 0/3] Fix GDB commands error Kuan-Ying Lee
@ 2023-11-27  7:04 ` Kuan-Ying Lee
  2023-11-27 12:03   ` Oleg Nesterov
  2023-11-27  7:04 ` [PATCH 2/3] scripts/gdb/stackdepot: Rename pool_index_cached to pools_num Kuan-Ying Lee
  2023-11-27  7:04 ` [PATCH 3/3] scripts/gdb: Remove exception handling and refine print format Kuan-Ying Lee
  2 siblings, 1 reply; 6+ messages in thread
From: Kuan-Ying Lee @ 2023-11-27  7:04 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham, Matthias Brugger,
	AngeloGioacchino Del Regno, Andrew Morton, Oleg Nesterov
  Cc: casper.li, chinwen.chang, qun-wei.lin, linux-mm, Kuan-Ying Lee,
	stable, linux-kernel, linux-arm-kernel, linux-mediatek

Since commit 8e1f385104ac ("kill task_struct->thread_group") remove
the thread_group, we will encounter below issue.

(gdb) lx-ps
      TASK          PID    COMM
0xffff800086503340   0   swapper/0
Python Exception <class 'gdb.error'>: There is no member named thread_group.
Error occurred in Python: There is no member named thread_group.

We use signal->thread_head to iterate all threads instead.

Fixes: 8e1f385104ac ("kill task_struct->thread_group")
Cc: stable@vger.kernel.org
Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
---
 scripts/gdb/linux/tasks.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/scripts/gdb/linux/tasks.py b/scripts/gdb/linux/tasks.py
index 17ec19e9b5bf..7c32f4c8284b 100644
--- a/scripts/gdb/linux/tasks.py
+++ b/scripts/gdb/linux/tasks.py
@@ -13,7 +13,7 @@
 
 import gdb
 
-from linux import utils
+from linux import utils, lists
 
 
 task_type = utils.CachedType("struct task_struct")
@@ -25,13 +25,9 @@ def task_lists():
     t = g = init_task
 
     while True:
-        while True:
-            yield t
-
-            t = utils.container_of(t['thread_group']['next'],
-                                   task_ptr_type, "thread_group")
-            if t == g:
-                break
+        thread_head = t['signal']['thread_head']
+        for thread in lists.list_for_each_entry(thread_head, task_ptr_type, 'thread_node'):
+            yield thread
 
         t = g = utils.container_of(g['tasks']['next'],
                                    task_ptr_type, "tasks")
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] scripts/gdb/stackdepot: Rename pool_index_cached to pools_num
  2023-11-27  7:04 [PATCH 0/3] Fix GDB commands error Kuan-Ying Lee
  2023-11-27  7:04 ` [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error Kuan-Ying Lee
@ 2023-11-27  7:04 ` Kuan-Ying Lee
  2023-11-27  7:04 ` [PATCH 3/3] scripts/gdb: Remove exception handling and refine print format Kuan-Ying Lee
  2 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2023-11-27  7:04 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: casper.li, chinwen.chang, qun-wei.lin, linux-mm, akpm,
	Kuan-Ying Lee, Andrey Konovalov, linux-kernel, linux-arm-kernel,
	linux-mediatek

After stackdepot evicting support patchset[1], we rename
pool_index_cached to pools_num.

[1] https://lore.kernel.org/linux-mm/cover.1700502145.git.andreyknvl@google.com/
Cc: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
---
 scripts/gdb/linux/stackdepot.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/gdb/linux/stackdepot.py b/scripts/gdb/linux/stackdepot.py
index 047d329a6a12..0281d9de4b7c 100644
--- a/scripts/gdb/linux/stackdepot.py
+++ b/scripts/gdb/linux/stackdepot.py
@@ -25,10 +25,10 @@ def stack_depot_fetch(handle):
     handle_parts_t = gdb.lookup_type("union handle_parts")
     parts = handle.cast(handle_parts_t)
     offset = parts['offset'] << DEPOT_STACK_ALIGN
-    pool_index_cached = gdb.parse_and_eval('pool_index')
+    pools_num = gdb.parse_and_eval('pools_num')
 
-    if parts['pool_index'] > pool_index_cached:
-        gdb.write("pool index %d out of bounds (%d) for stack id 0x%08x\n" % (parts['pool_index'], pool_index_cached, handle))
+    if parts['pool_index'] > pools_num:
+        gdb.write("pool index %d out of bounds (%d) for stack id 0x%08x\n" % (parts['pool_index'], pools_num, handle))
         return gdb.Value(0), 0
 
     stack_pools = gdb.parse_and_eval('stack_pools')
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] scripts/gdb: Remove exception handling and refine print format
  2023-11-27  7:04 [PATCH 0/3] Fix GDB commands error Kuan-Ying Lee
  2023-11-27  7:04 ` [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error Kuan-Ying Lee
  2023-11-27  7:04 ` [PATCH 2/3] scripts/gdb/stackdepot: Rename pool_index_cached to pools_num Kuan-Ying Lee
@ 2023-11-27  7:04 ` Kuan-Ying Lee
  2 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee @ 2023-11-27  7:04 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: casper.li, chinwen.chang, qun-wei.lin, linux-mm, akpm,
	Kuan-Ying Lee, linux-kernel, linux-arm-kernel, linux-mediatek

1. When we crash on a page, we want to check what
happened on this page instead of skipping this page by
try-except block. Thus, removing the try-except block.

2. Remove redundant comma and print the task name properly.

Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
---
 scripts/gdb/linux/page_owner.py | 58 ++++++++++++++-------------------
 scripts/gdb/linux/slab.py       |  3 +-
 2 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/scripts/gdb/linux/page_owner.py b/scripts/gdb/linux/page_owner.py
index 844fd5d0c912..8e713a09cfe7 100644
--- a/scripts/gdb/linux/page_owner.py
+++ b/scripts/gdb/linux/page_owner.py
@@ -122,27 +122,24 @@ class DumpPageOwner(gdb.Command):
         if not (page_ext['flags'] & (1 << PAGE_EXT_OWNER_ALLOCATED)):
             gdb.write("page_owner is not allocated\n")
 
-        try:
-            page_owner = self.get_page_owner(page_ext)
-            gdb.write("Page last allocated via order %d, gfp_mask: 0x%x, pid: %d, tgid: %d (%s), ts %u ns, free_ts %u ns\n" %\
-                    (page_owner["order"], page_owner["gfp_mask"],\
-                    page_owner["pid"], page_owner["tgid"], page_owner["comm"],\
-                    page_owner["ts_nsec"], page_owner["free_ts_nsec"]))
-            gdb.write("PFN: %d, Flags: 0x%x\n" % (pfn, page['flags']))
-            if page_owner["handle"] == 0:
-                gdb.write('page_owner allocation stack trace missing\n')
-            else:
-                stackdepot.stack_depot_print(page_owner["handle"])
+        page_owner = self.get_page_owner(page_ext)
+        gdb.write("Page last allocated via order %d, gfp_mask: 0x%x, pid: %d, tgid: %d (%s), ts %u ns, free_ts %u ns\n" %\
+                (page_owner["order"], page_owner["gfp_mask"],\
+                page_owner["pid"], page_owner["tgid"], page_owner["comm"].string(),\
+                page_owner["ts_nsec"], page_owner["free_ts_nsec"]))
+        gdb.write("PFN: %d, Flags: 0x%x\n" % (pfn, page['flags']))
+        if page_owner["handle"] == 0:
+            gdb.write('page_owner allocation stack trace missing\n')
+        else:
+            stackdepot.stack_depot_print(page_owner["handle"])
 
-            if page_owner["free_handle"] == 0:
-                gdb.write('page_owner free stack trace missing\n')
-            else:
-                gdb.write('page last free stack trace:\n')
-                stackdepot.stack_depot_print(page_owner["free_handle"])
-            if page_owner['last_migrate_reason'] != -1:
-                gdb.write('page has been migrated, last migrate reason: %s\n' % self.migrate_reason_names[page_owner['last_migrate_reason']])
-        except:
-            gdb.write("\n")
+        if page_owner["free_handle"] == 0:
+            gdb.write('page_owner free stack trace missing\n')
+        else:
+            gdb.write('page last free stack trace:\n')
+            stackdepot.stack_depot_print(page_owner["free_handle"])
+        if page_owner['last_migrate_reason'] != -1:
+            gdb.write('page has been migrated, last migrate reason: %s\n' % self.migrate_reason_names[page_owner['last_migrate_reason']])
 
     def read_page_owner(self):
         pfn = self.min_pfn
@@ -173,18 +170,13 @@ class DumpPageOwner(gdb.Command):
                 pfn += 1
                 continue
 
-            try:
-                page_owner = self.get_page_owner(page_ext)
-                gdb.write("Page allocated via order %d, gfp_mask: 0x%x, pid: %d, tgid: %d (%s), ts %u ns, free_ts %u ns\n" %\
-                        (page_owner["order"], page_owner["gfp_mask"],\
-                        page_owner["pid"], page_owner["tgid"], page_owner["comm"],\
-                        page_owner["ts_nsec"], page_owner["free_ts_nsec"]))
-                gdb.write("PFN: %d, Flags: 0x%x\n" % (pfn, page['flags']))
-                stackdepot.stack_depot_print(page_owner["handle"])
-                pfn += (1 << page_owner["order"])
-                continue
-            except:
-                gdb.write("\n")
-            pfn += 1
+            page_owner = self.get_page_owner(page_ext)
+            gdb.write("Page allocated via order %d, gfp_mask: 0x%x, pid: %d, tgid: %d (%s), ts %u ns, free_ts %u ns\n" %\
+                    (page_owner["order"], page_owner["gfp_mask"],\
+                    page_owner["pid"], page_owner["tgid"], page_owner["comm"].string(),\
+                    page_owner["ts_nsec"], page_owner["free_ts_nsec"]))
+            gdb.write("PFN: %d, Flags: 0x%x\n" % (pfn, page['flags']))
+            stackdepot.stack_depot_print(page_owner["handle"])
+            pfn += (1 << page_owner["order"])
 
 DumpPageOwner()
diff --git a/scripts/gdb/linux/slab.py b/scripts/gdb/linux/slab.py
index f012ba38c7d9..0e2d93867fe2 100644
--- a/scripts/gdb/linux/slab.py
+++ b/scripts/gdb/linux/slab.py
@@ -228,8 +228,7 @@ def slabtrace(alloc, cache_name):
             nr_cpu = gdb.parse_and_eval('__num_online_cpus')['counter']
             if nr_cpu > 1:
                 gdb.write(" cpus=")
-                for i in loc['cpus']:
-                    gdb.write("%d," % i)
+                gdb.write(','.join(str(cpu) for cpu in loc['cpus']))
         gdb.write("\n")
         if constants.LX_CONFIG_STACKDEPOT:
             if loc['handle']:
-- 
2.18.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error
  2023-11-27  7:04 ` [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error Kuan-Ying Lee
@ 2023-11-27 12:03   ` Oleg Nesterov
  2023-11-28 11:45     ` Kuan-Ying Lee (李冠穎)
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2023-11-27 12:03 UTC (permalink / raw)
  To: Kuan-Ying Lee
  Cc: Jan Kiszka, Kieran Bingham, Matthias Brugger,
	AngeloGioacchino Del Regno, Andrew Morton, casper.li,
	chinwen.chang, qun-wei.lin, linux-mm, stable, linux-kernel,
	linux-arm-kernel, linux-mediatek

On 11/27, Kuan-Ying Lee wrote:
>
> @@ -25,13 +25,9 @@ def task_lists():
>      t = g = init_task
>  
>      while True:
> -        while True:
> -            yield t
> -
> -            t = utils.container_of(t['thread_group']['next'],
> -                                   task_ptr_type, "thread_group")
> -            if t == g:
> -                break
> +        thread_head = t['signal']['thread_head']
> +        for thread in lists.list_for_each_entry(thread_head, task_ptr_type, 'thread_node'):
> +            yield thread
>  
>          t = g = utils.container_of(g['tasks']['next'],
>                                     task_ptr_type, "tasks")

Thanks!

I do not know python, but it seems that with this patch we can kill g or t?
Can't

	def task_lists():
	    task_ptr_type = task_type.get_type().pointer()
	    init_task = gdb.parse_and_eval("init_task").address
	    t = init_task

	    while True:
		thread_head = t['signal']['thread_head']
		for thread in lists.list_for_each_entry(thread_head, task_ptr_type, 'thread_node'):
		    yield thread

		t = utils.container_of(t['tasks']['next'],
				       task_ptr_type, "tasks")
		if t == init_task:
		    return

work?

Oleg.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error
  2023-11-27 12:03   ` Oleg Nesterov
@ 2023-11-28 11:45     ` Kuan-Ying Lee (李冠穎)
  0 siblings, 0 replies; 6+ messages in thread
From: Kuan-Ying Lee (李冠穎) @ 2023-11-28 11:45 UTC (permalink / raw)
  To: oleg@redhat.com
  Cc: linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	Qun-wei Lin (林群崴), linux-mm@kvack.org,
	Chinwen Chang (張錦文), stable@vger.kernel.org,
	Casper Li (李中榮), akpm@linux-foundation.org,
	kbingham@kernel.org, linux-arm-kernel@lists.infradead.org,
	matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
	jan.kiszka@siemens.com

On Mon, 2023-11-27 at 13:03 +0100, Oleg Nesterov wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  On 11/27, Kuan-Ying Lee wrote:
> >
> > @@ -25,13 +25,9 @@ def task_lists():
> >      t = g = init_task
> >  
> >      while True:
> > -        while True:
> > -            yield t
> > -
> > -            t = utils.container_of(t['thread_group']['next'],
> > -                                   task_ptr_type, "thread_group")
> > -            if t == g:
> > -                break
> > +        thread_head = t['signal']['thread_head']
> > +        for thread in lists.list_for_each_entry(thread_head,
> task_ptr_type, 'thread_node'):
> > +            yield thread
> >  
> >          t = g = utils.container_of(g['tasks']['next'],
> >                                     task_ptr_type, "tasks")
> 
> Thanks!
> 
> I do not know python, but it seems that with this patch we can kill g
> or t?
> Can't
> 
> def task_lists():
>     task_ptr_type = task_type.get_type().pointer()
>     init_task = gdb.parse_and_eval("init_task").address
>     t = init_task
> 
>     while True:
> thread_head = t['signal']['thread_head']
> for thread in lists.list_for_each_entry(thread_head, task_ptr_type,
> 'thread_node'):
>     yield thread
> 
> t = utils.container_of(t['tasks']['next'],
>        task_ptr_type, "tasks")
> if t == init_task:
>     return
> 
> work?

Yes, you are right.
I will fix it in v2.

Thanks,
Kuan-Ying Lee
> 
> Oleg.
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-28 11:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-27  7:04 [PATCH 0/3] Fix GDB commands error Kuan-Ying Lee
2023-11-27  7:04 ` [PATCH 1/3] scripts/gdb/tasks: Fix lx-ps command error Kuan-Ying Lee
2023-11-27 12:03   ` Oleg Nesterov
2023-11-28 11:45     ` Kuan-Ying Lee (李冠穎)
2023-11-27  7:04 ` [PATCH 2/3] scripts/gdb/stackdepot: Rename pool_index_cached to pools_num Kuan-Ying Lee
2023-11-27  7:04 ` [PATCH 3/3] scripts/gdb: Remove exception handling and refine print format Kuan-Ying Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).