Blame SOURCES/0001-memory-Add-support-for-SECTION_TAINT_ZONE_DEVICE-fla.patch

3e5f3d
From 0b5435e10161345cf713ed447a155a611a1b408b Mon Sep 17 00:00:00 2001
3e5f3d
From: Kazuhito Hagio <k-hagio-ab@nec.com>
3e5f3d
Date: Wed, 26 May 2021 17:33:13 +0900
3e5f3d
Subject: [PATCH 1/2] memory: Add support for SECTION_TAINT_ZONE_DEVICE flag
3e5f3d
3e5f3d
Fix for "kmem -n|-p" options on Linux 5.12-rc1 and later kernels
3e5f3d
that contain commit 1f90a3477df3f ("mm: teach pfn_to_online_page()
3e5f3d
about ZONE_DEVICE section collisions").  Without the patch, the
3e5f3d
"kmem -n" option incorrectly shows mem_map addresses containing the
3e5f3d
flag in bit 5 as part of the virtual address, and also the "kmem -p"
3e5f3d
option shows page structures at wrong position.  With the patch,
3e5f3d
the "kmem -n" option displays the new "D" state flag.
3e5f3d
3e5f3d
Without the patch:
3e5f3d
  crash> kmem -n
3e5f3d
  ...
3e5f3d
  NR      SECTION        CODED_MEM_MAP        MEM_MAP       STATE PFN
3e5f3d
  1040  ffff9edf3ffd4100  ffffe2bcc0000010  ffffe2bd42000010  PMOE  34078720
3e5f3d
                                        ^                 ^
3e5f3d
  crash> kmem -p
3e5f3d
      PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
3e5f3d
  ffffe2bd42000010 2080000000           400040 1ffffffff 9961471 dead000000000122 referenced,active,error
3e5f3d
  ffffe2bd42000050 2080001000           800080 1ffffffff 9961471 dead000000000122 referenced,active,error
3e5f3d
  ffffe2bd42000090 2080002000                0 1ffffffff 9961471 dead000000000122 referenced,active,error
3e5f3d
                ^^
3e5f3d
With the patch:
3e5f3d
  crash> kmem -n
3e5f3d
  ...
3e5f3d
  NR      SECTION        CODED_MEM_MAP        MEM_MAP       STATE PFN
3e5f3d
  1040  ffff9edf3ffd4100  ffffe2bcc0000000  ffffe2bd42000000  PMOED 34078720
3e5f3d
3e5f3d
  crash> kmem -p
3e5f3d
      PAGE         PHYSICAL      MAPPING       INDEX CNT FLAGS
3e5f3d
  ffffe2bd42000000 2080000000 ffff9ebfc0044100        0  1 97ffffc0000200 slab
3e5f3d
  ffffe2bd42000040 2080001000 ffff9ebfc0044400        0  1 97ffffc0000200 slab
3e5f3d
  ffffe2bd42000080 2080002000                0        0  1 97ffffc0000000
3e5f3d
3e5f3d
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
3e5f3d
---
3e5f3d
 help.c   | 11 +++++++----
3e5f3d
 memory.c | 15 +++++++++------
3e5f3d
 2 files changed, 16 insertions(+), 10 deletions(-)
3e5f3d
3e5f3d
diff --git a/help.c b/help.c
3e5f3d
index e0c84087add3..9649cc81fa36 100644
3e5f3d
--- a/help.c
3e5f3d
+++ b/help.c
3e5f3d
@@ -6584,10 +6584,13 @@ char *help_kmem[] = {
3e5f3d
 "            kernels, the vm_zone_stat, vm_node_stat and vm_numa_stat tables,",
3e5f3d
 "            the cumulative page_states counter values if they exist, and/or ",
3e5f3d
 "            the cumulative, vm_event_states counter values if they exist.",
3e5f3d
-"        -n  display memory node, memory section, and memory block data",
3e5f3d
-"            and state; the state of each memory section state is encoded",
3e5f3d
-"            as \"P\", \"M\", \"O\" and/or \"E\", meaning SECTION_MARKED_PRESENT,",
3e5f3d
-"            SECTION_HAS_MEM_MAP, SECTION_IS_ONLINE and SECTION_IS_EARLY.",
3e5f3d
+"        -n  display memory node, memory section, memory block data and state;",
3e5f3d
+"            the state of each memory section is shown as the following flags:",
3e5f3d
+"              \"P\": SECTION_MARKED_PRESENT",
3e5f3d
+"              \"M\": SECTION_HAS_MEM_MAP",
3e5f3d
+"              \"O\": SECTION_IS_ONLINE",
3e5f3d
+"              \"E\": SECTION_IS_EARLY",
3e5f3d
+"              \"D\": SECTION_TAINT_ZONE_DEVICE",
3e5f3d
 "        -z  displays per-zone memory statistics.",
3e5f3d
 "        -o  displays each cpu's offset value that is added to per-cpu symbol",
3e5f3d
 "            values to translate them into kernel virtual addresses.",
3e5f3d
diff --git a/memory.c b/memory.c
3e5f3d
index a3cf8a86728d..2c4f9790f498 100644
3e5f3d
--- a/memory.c
3e5f3d
+++ b/memory.c
3e5f3d
@@ -17270,12 +17270,13 @@ nr_to_section(ulong nr)
3e5f3d
  *      which results in PFN_SECTION_SHIFT equal 6.
3e5f3d
  * To sum it up, at least 6 bits are available.
3e5f3d
  */
3e5f3d
-#define SECTION_MARKED_PRESENT	(1UL<<0)
3e5f3d
-#define SECTION_HAS_MEM_MAP	(1UL<<1)
3e5f3d
-#define SECTION_IS_ONLINE	(1UL<<2)
3e5f3d
-#define SECTION_IS_EARLY	(1UL<<3)
3e5f3d
-#define SECTION_MAP_LAST_BIT	(1UL<<4)
3e5f3d
-#define SECTION_MAP_MASK	(~(SECTION_MAP_LAST_BIT-1))
3e5f3d
+#define SECTION_MARKED_PRESENT		(1UL<<0)
3e5f3d
+#define SECTION_HAS_MEM_MAP		(1UL<<1)
3e5f3d
+#define SECTION_IS_ONLINE		(1UL<<2)
3e5f3d
+#define SECTION_IS_EARLY		(1UL<<3)
3e5f3d
+#define SECTION_TAINT_ZONE_DEVICE	(1UL<<4)
3e5f3d
+#define SECTION_MAP_LAST_BIT		(1UL<<5)
3e5f3d
+#define SECTION_MAP_MASK		(~(SECTION_MAP_LAST_BIT-1))
3e5f3d
 
3e5f3d
 
3e5f3d
 int 
3e5f3d
@@ -17373,6 +17374,8 @@ fill_mem_section_state(ulong state, char *buf)
3e5f3d
 		bufidx += sprintf(buf + bufidx, "%s", "O");
3e5f3d
 	if (state & SECTION_IS_EARLY)
3e5f3d
 		bufidx += sprintf(buf + bufidx, "%s", "E");
3e5f3d
+	if (state & SECTION_TAINT_ZONE_DEVICE)
3e5f3d
+		bufidx += sprintf(buf + bufidx, "%s", "D");
3e5f3d
 }
3e5f3d
 
3e5f3d
 void 
3e5f3d
-- 
3e5f3d
2.30.2
3e5f3d