[PATCH] scripts/gdb: support lx-slabinfo on x86

Seongjun Hong posted 1 patch 5 days, 19 hours ago
scripts/gdb/linux/constants.py.in |  2 +-
scripts/gdb/linux/mm.py           | 25 ++++++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
[PATCH] scripts/gdb: support lx-slabinfo on x86
Posted by Seongjun Hong 5 days, 19 hours ago
The lx-slabinfo command failed on x86 because x86_page_ops was not
implemented. This patch implements x86_page_ops in mm.py.

Additionally, CONFIG_PAGE_SHIFT is required for the calculation but
was only available for ARM64 in constants.py.in. This patch moves
it to be available for all architectures.

Signed-off-by: Seongjun Hong <hsj0512@snu.ac.kr>
---
 scripts/gdb/linux/constants.py.in |  2 +-
 scripts/gdb/linux/mm.py           | 25 ++++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
index c3886739a028..11fd4ba6ba85 100644
--- a/scripts/gdb/linux/constants.py.in
+++ b/scripts/gdb/linux/constants.py.in
@@ -150,8 +150,8 @@ LX_CONFIG(CONFIG_ARM64_64K_PAGES)
 if IS_BUILTIN(CONFIG_ARM64):
     LX_VALUE(CONFIG_ARM64_PA_BITS)
     LX_VALUE(CONFIG_ARM64_VA_BITS)
-    LX_VALUE(CONFIG_PAGE_SHIFT)
     LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER)
+LX_VALUE(CONFIG_PAGE_SHIFT)
 LX_CONFIG(CONFIG_SPARSEMEM)
 LX_CONFIG(CONFIG_SPARSEMEM_EXTREME)
 LX_CONFIG(CONFIG_SPARSEMEM_VMEMMAP)
diff --git a/scripts/gdb/linux/mm.py b/scripts/gdb/linux/mm.py
index 7571aebbe650..d6e84e4bf102 100644
--- a/scripts/gdb/linux/mm.py
+++ b/scripts/gdb/linux/mm.py
@@ -26,8 +26,31 @@ class page_ops():
             raise gdb.GdbError('Only support CONFIG_SPARSEMEM_VMEMMAP now')
         if constants.LX_CONFIG_ARM64 and utils.is_target_arch('aarch64'):
             self.ops = aarch64_page_ops()
+        elif utils.is_target_arch('x86_64') or utils.is_target_arch('x86-64'):
+            self.ops = x86_page_ops()
         else:
-            raise gdb.GdbError('Only support aarch64 now')
+            raise gdb.GdbError('Only support aarch64 and x86_64 now')
+
+class x86_page_ops():
+    def __init__(self):
+        self.MAX_NUMNODES = 1 << constants.LX_CONFIG_NODES_SHIFT
+        self.struct_page_size = utils.get_page_type().sizeof
+        self.PAGE_SHIFT = constants.LX_CONFIG_PAGE_SHIFT
+        self.PAGE_SIZE = 1 << self.PAGE_SHIFT
+        self.PAGE_OFFSET = int(gdb.parse_and_eval("page_offset_base"))
+        self.VMEMMAP_START = int(gdb.parse_and_eval("vmemmap_base"))
+
+    def page_to_virt(self, page):
+        page_ptr = page.cast(utils.get_page_type().pointer())
+        vmemmap_ptr = gdb.Value(self.VMEMMAP_START).cast(utils.get_page_type().pointer())
+        idx = int(page_ptr - vmemmap_ptr)
+        return self.PAGE_OFFSET + (idx * self.PAGE_SIZE)
+
+    def page_address(self, page):
+        return self.page_to_virt(page)
+
+    def folio_address(self, folio):
+        return self.page_address(folio['page'].address)
 
 class aarch64_page_ops():
     def __init__(self):
-- 
2.34.1
Re: [PATCH] scripts/gdb: support lx-slabinfo on x86
Posted by Jan Kiszka 5 days, 18 hours ago
On 01.02.26 13:06, Seongjun Hong wrote:
> The lx-slabinfo command failed on x86 because x86_page_ops was not
> implemented. This patch implements x86_page_ops in mm.py.
> 
> Additionally, CONFIG_PAGE_SHIFT is required for the calculation but
> was only available for ARM64 in constants.py.in. This patch moves
> it to be available for all architectures.
> 
> Signed-off-by: Seongjun Hong <hsj0512@snu.ac.kr>
> ---
>  scripts/gdb/linux/constants.py.in |  2 +-
>  scripts/gdb/linux/mm.py           | 25 ++++++++++++++++++++++++-
>  2 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in
> index c3886739a028..11fd4ba6ba85 100644
> --- a/scripts/gdb/linux/constants.py.in
> +++ b/scripts/gdb/linux/constants.py.in
> @@ -150,8 +150,8 @@ LX_CONFIG(CONFIG_ARM64_64K_PAGES)
>  if IS_BUILTIN(CONFIG_ARM64):
>      LX_VALUE(CONFIG_ARM64_PA_BITS)
>      LX_VALUE(CONFIG_ARM64_VA_BITS)
> -    LX_VALUE(CONFIG_PAGE_SHIFT)
>      LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER)
> +LX_VALUE(CONFIG_PAGE_SHIFT)
>  LX_CONFIG(CONFIG_SPARSEMEM)
>  LX_CONFIG(CONFIG_SPARSEMEM_EXTREME)
>  LX_CONFIG(CONFIG_SPARSEMEM_VMEMMAP)
> diff --git a/scripts/gdb/linux/mm.py b/scripts/gdb/linux/mm.py
> index 7571aebbe650..d6e84e4bf102 100644
> --- a/scripts/gdb/linux/mm.py
> +++ b/scripts/gdb/linux/mm.py
> @@ -26,8 +26,31 @@ class page_ops():
>              raise gdb.GdbError('Only support CONFIG_SPARSEMEM_VMEMMAP now')
>          if constants.LX_CONFIG_ARM64 and utils.is_target_arch('aarch64'):
>              self.ops = aarch64_page_ops()
> +        elif utils.is_target_arch('x86_64') or utils.is_target_arch('x86-64'):
> +            self.ops = x86_page_ops()
>          else:
> -            raise gdb.GdbError('Only support aarch64 now')
> +            raise gdb.GdbError('Only support aarch64 and x86_64 now')
> +
> +class x86_page_ops():
> +    def __init__(self):
> +        self.MAX_NUMNODES = 1 << constants.LX_CONFIG_NODES_SHIFT
> +        self.struct_page_size = utils.get_page_type().sizeof
> +        self.PAGE_SHIFT = constants.LX_CONFIG_PAGE_SHIFT
> +        self.PAGE_SIZE = 1 << self.PAGE_SHIFT
> +        self.PAGE_OFFSET = int(gdb.parse_and_eval("page_offset_base"))
> +        self.VMEMMAP_START = int(gdb.parse_and_eval("vmemmap_base"))
> +
> +    def page_to_virt(self, page):
> +        page_ptr = page.cast(utils.get_page_type().pointer())
> +        vmemmap_ptr = gdb.Value(self.VMEMMAP_START).cast(utils.get_page_type().pointer())
> +        idx = int(page_ptr - vmemmap_ptr)
> +        return self.PAGE_OFFSET + (idx * self.PAGE_SIZE)
> +
> +    def page_address(self, page):
> +        return self.page_to_virt(page)
> +
> +    def folio_address(self, folio):
> +        return self.page_address(folio['page'].address)
>  
>  class aarch64_page_ops():
>      def __init__(self):

Thanks for the contribution! From my quick (re-)reading, there are more
page_ops than what you implement above. I think command like
lx-pfn_to_page will now cause splats rather than a nicer "not
implemented yet". Could you add the missing ops or handle those cases
more gracefully for now?

Jan

-- 
Siemens AG, Foundational Technologies
Linux Expert Center