[Crash-utility] [PATCH] Fix for "kmem -n" option to display NID correctly

HAGIO KAZUHITO(萩尾 一仁) k-hagio-ab at nec.com
Mon May 31 05:08:28 UTC 2021


The nid member of struct memory_block is a 4-byte integer, but read
and printed as a 8-byte integer on 64-bit machines.  Without the patch,
the option displays wrong NIDs.

  crash> kmem -n
  ...
     MEM_BLOCK        NAME          PHYSICAL RANGE       NODE  STATE   START_SECTION_NO
   ffff9edeff2b9400   memory0             0 -   7fffffff 14195095130662240256  ONLINE  0
   ffff9edeff2bb400   memory2     100000000 -  17fffffff 14195094718345379840  ONLINE  32

The issue seems to appear on Linux 5.12 and later kernels that contain
commit e9a2e48e8704c ("drivers/base/memory: don't store phys_device in
memory blocks"), which changed the arrangement of the members of struct
memory_block.

Signed-off-by: Kazuhito Hagio <k-hagio-ab at nec.com>
---
 memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index 8c6bbe409922..600f2de336d9 100644
--- a/memory.c
+++ b/memory.c
@@ -17564,13 +17564,13 @@ print_memory_block(ulong memory_block)
 
 	if (MEMBER_EXISTS("memory_block", "nid")) {
 		readmem(memory_block + OFFSET(memory_block_nid), KVADDR, &nid,
-			sizeof(void *), "memory_block nid", FAULT_ON_ERROR);
+			sizeof(int), "memory_block nid", FAULT_ON_ERROR);
 		fprintf(fp, " %s %s %s %s  %s %s\n",
 			mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX,
 			MKSTR(memory_block)),
 			mkstring(buf2, 12, CENTER, name),
 			parangebuf,
-			mkstring(buf5, strlen("NODE"), CENTER|LONG_DEC,
+			mkstring(buf5, strlen("NODE"), CENTER|INT_DEC,
 			MKSTR(nid)),
 			mkstring(buf6, strlen("OFFLINE"), LJUST,
 			statebuf),
-- 
2.27.0





More information about the Crash-utility mailing list