From ccbee1fd3e18a0d2507ceb8c73be6e621a944659 Mon Sep 17 00:00:00 2001 From: Lianbo Jiang Date: Mon, 5 Jul 2021 14:34:27 +0800 Subject: [PATCH] Fix "kmem -n|-p" options display wrong values Release crash-7.3.0-3 Resolves: rhbz#1975621 Signed-off-by: Lianbo Jiang --- ...rt-for-SECTION_TAINT_ZONE_DEVICE-fla.patch | 101 ++++++++++++++++++ ...mem-n-option-to-display-NID-correctl.patch | 48 +++++++++ crash.spec | 9 +- 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 0001-memory-Add-support-for-SECTION_TAINT_ZONE_DEVICE-fla.patch create mode 100644 0002-memory-Fix-for-kmem-n-option-to-display-NID-correctl.patch diff --git a/0001-memory-Add-support-for-SECTION_TAINT_ZONE_DEVICE-fla.patch b/0001-memory-Add-support-for-SECTION_TAINT_ZONE_DEVICE-fla.patch new file mode 100644 index 0000000..fe76553 --- /dev/null +++ b/0001-memory-Add-support-for-SECTION_TAINT_ZONE_DEVICE-fla.patch @@ -0,0 +1,101 @@ +From 0b5435e10161345cf713ed447a155a611a1b408b Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Wed, 26 May 2021 17:33:13 +0900 +Subject: [PATCH 1/2] memory: Add support for SECTION_TAINT_ZONE_DEVICE flag + +Fix for "kmem -n|-p" options on Linux 5.12-rc1 and later kernels +that contain commit 1f90a3477df3f ("mm: teach pfn_to_online_page() +about ZONE_DEVICE section collisions"). Without the patch, the +"kmem -n" option incorrectly shows mem_map addresses containing the +flag in bit 5 as part of the virtual address, and also the "kmem -p" +option shows page structures at wrong position. With the patch, +the "kmem -n" option displays the new "D" state flag. + +Without the patch: + crash> kmem -n + ... + NR SECTION CODED_MEM_MAP MEM_MAP STATE PFN + 1040 ffff9edf3ffd4100 ffffe2bcc0000010 ffffe2bd42000010 PMOE 34078720 + ^ ^ + crash> kmem -p + PAGE PHYSICAL MAPPING INDEX CNT FLAGS + ffffe2bd42000010 2080000000 400040 1ffffffff 9961471 dead000000000122 referenced,active,error + ffffe2bd42000050 2080001000 800080 1ffffffff 9961471 dead000000000122 referenced,active,error + ffffe2bd42000090 2080002000 0 1ffffffff 9961471 dead000000000122 referenced,active,error + ^^ +With the patch: + crash> kmem -n + ... + NR SECTION CODED_MEM_MAP MEM_MAP STATE PFN + 1040 ffff9edf3ffd4100 ffffe2bcc0000000 ffffe2bd42000000 PMOED 34078720 + + crash> kmem -p + PAGE PHYSICAL MAPPING INDEX CNT FLAGS + ffffe2bd42000000 2080000000 ffff9ebfc0044100 0 1 97ffffc0000200 slab + ffffe2bd42000040 2080001000 ffff9ebfc0044400 0 1 97ffffc0000200 slab + ffffe2bd42000080 2080002000 0 0 1 97ffffc0000000 + +Signed-off-by: Kazuhito Hagio +--- + help.c | 11 +++++++---- + memory.c | 15 +++++++++------ + 2 files changed, 16 insertions(+), 10 deletions(-) + +diff --git a/help.c b/help.c +index e0c84087add3..9649cc81fa36 100644 +--- a/help.c ++++ b/help.c +@@ -6584,10 +6584,13 @@ char *help_kmem[] = { + " kernels, the vm_zone_stat, vm_node_stat and vm_numa_stat tables,", + " the cumulative page_states counter values if they exist, and/or ", + " the cumulative, vm_event_states counter values if they exist.", +-" -n display memory node, memory section, and memory block data", +-" and state; the state of each memory section state is encoded", +-" as \"P\", \"M\", \"O\" and/or \"E\", meaning SECTION_MARKED_PRESENT,", +-" SECTION_HAS_MEM_MAP, SECTION_IS_ONLINE and SECTION_IS_EARLY.", ++" -n display memory node, memory section, memory block data and state;", ++" the state of each memory section is shown as the following flags:", ++" \"P\": SECTION_MARKED_PRESENT", ++" \"M\": SECTION_HAS_MEM_MAP", ++" \"O\": SECTION_IS_ONLINE", ++" \"E\": SECTION_IS_EARLY", ++" \"D\": SECTION_TAINT_ZONE_DEVICE", + " -z displays per-zone memory statistics.", + " -o displays each cpu's offset value that is added to per-cpu symbol", + " values to translate them into kernel virtual addresses.", +diff --git a/memory.c b/memory.c +index a3cf8a86728d..2c4f9790f498 100644 +--- a/memory.c ++++ b/memory.c +@@ -17270,12 +17270,13 @@ nr_to_section(ulong nr) + * which results in PFN_SECTION_SHIFT equal 6. + * To sum it up, at least 6 bits are available. + */ +-#define SECTION_MARKED_PRESENT (1UL<<0) +-#define SECTION_HAS_MEM_MAP (1UL<<1) +-#define SECTION_IS_ONLINE (1UL<<2) +-#define SECTION_IS_EARLY (1UL<<3) +-#define SECTION_MAP_LAST_BIT (1UL<<4) +-#define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) ++#define SECTION_MARKED_PRESENT (1UL<<0) ++#define SECTION_HAS_MEM_MAP (1UL<<1) ++#define SECTION_IS_ONLINE (1UL<<2) ++#define SECTION_IS_EARLY (1UL<<3) ++#define SECTION_TAINT_ZONE_DEVICE (1UL<<4) ++#define SECTION_MAP_LAST_BIT (1UL<<5) ++#define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) + + + int +@@ -17373,6 +17374,8 @@ fill_mem_section_state(ulong state, char *buf) + bufidx += sprintf(buf + bufidx, "%s", "O"); + if (state & SECTION_IS_EARLY) + bufidx += sprintf(buf + bufidx, "%s", "E"); ++ if (state & SECTION_TAINT_ZONE_DEVICE) ++ bufidx += sprintf(buf + bufidx, "%s", "D"); + } + + void +-- +2.30.2 + diff --git a/0002-memory-Fix-for-kmem-n-option-to-display-NID-correctl.patch b/0002-memory-Fix-for-kmem-n-option-to-display-NID-correctl.patch new file mode 100644 index 0000000..6ac3c71 --- /dev/null +++ b/0002-memory-Fix-for-kmem-n-option-to-display-NID-correctl.patch @@ -0,0 +1,48 @@ +From ec44b902d3467e7b86ee39e2d7d472b9cb202148 Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Mon, 31 May 2021 14:08:28 +0900 +Subject: [PATCH 2/2] memory: Fix for "kmem -n" option to display NID correctly + +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 +--- + memory.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/memory.c b/memory.c +index 2c4f9790f498..cbe90eebe748 100644 +--- a/memory.c ++++ b/memory.c +@@ -17568,13 +17568,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.30.2 + diff --git a/crash.spec b/crash.spec index 1686fc6..e5c8589 100644 --- a/crash.spec +++ b/crash.spec @@ -4,7 +4,7 @@ Summary: Kernel analysis utility for live systems, netdump, diskdump, kdump, LKCD or mcore dumpfiles Name: crash Version: 7.3.0 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv3 Source0: https://github.com/crash-utility/crash/archive/crash-%{version}.tar.gz Source1: http://ftp.gnu.org/gnu/gdb/gdb-7.6.tar.gz @@ -19,6 +19,8 @@ Provides: bundled(libiberty) Provides: bundled(gdb) = 7.6 Patch0: lzo_snappy.patch Patch1: 0001-Fix-for-kmem-s-S-option-on-Linux-5.7-and-later-kerne.patch +Patch2: 0001-memory-Add-support-for-SECTION_TAINT_ZONE_DEVICE-fla.patch +Patch3: 0002-memory-Fix-for-kmem-n-option-to-display-NID-correctl.patch %description The core analysis suite is a self-contained tool that can be used to @@ -40,6 +42,8 @@ offered by Mission Critical Linux, or the LKCD kernel patch. %setup -n %{name}-%{version} -q %patch0 -p1 -b lzo_snappy.patch %patch1 -p1 +%patch2 -p1 +%patch3 -p1 %build # This package has an internal copy of GDB which has broken configure code for @@ -71,6 +75,9 @@ cp -p defs.h %{buildroot}%{_includedir}/crash %{_includedir}/* %changelog +* Mon Jul 05 2021 Lianbo Jiang - 7.3.0-3 +- Fix "kmem -n|-p" options display wrong values. + * Fri Jun 11 2021 Lianbo Jiang - 7.3.0-2 - Fix for "kmem -s|-S" option on Linux 5.7 and later kernels