Blame SOURCES/kexec-tools-2.0.18-makedumpfiles-exclude-pages-that-are-logically-offline.patch

603de6
From 0f9ee000904ffd1e171ba1f000a83e5ce3717e45 Mon Sep 17 00:00:00 2001
603de6
From: David Hildenbrand <david@redhat.com>
603de6
Date: Thu, 22 Nov 2018 11:09:38 +0100
603de6
Subject: [PATCH] [PATCH] exclude pages that are logically offline
603de6
603de6
Linux marks pages that are logically offline via a page flag (map count).
603de6
Such pages e.g. include pages infated as part of a balloon driver or
603de6
pages that were not actually onlined when onlining the whole section.
603de6
603de6
While the hypervisor usually allows to read such inflated memory, we
603de6
basically read and dump data that is completely irrelevant. Also, this
603de6
might result in quite some overhead in the hypervisor. In addition,
603de6
we saw some problems under Hyper-V, whereby we can crash the kernel by
603de6
dumping, when reading memory of a partially onlined memory segment
603de6
(for memory added by the Hyper-V balloon driver).
603de6
603de6
Therefore, don't read and dump pages that are marked as being logically
603de6
offline.
603de6
603de6
Signed-off-by: David Hildenbrand <david@redhat.com>
603de6
Signed-off-by: Pingfan Liu <piliu@redhat.com>
603de6
---
603de6
 makedumpfile.c | 34 ++++++++++++++++++++++++++++++----
603de6
 makedumpfile.h |  1 +
603de6
 2 files changed, 31 insertions(+), 4 deletions(-)
603de6
603de6
diff --git a/makedumpfile.c b/makedumpfile.c
603de6
index 8923538..a5f2ea9 100644
603de6
--- a/makedumpfile-1.6.5/makedumpfile.c
603de6
+++ b/makedumpfile-1.6.5/makedumpfile.c
603de6
@@ -88,6 +88,7 @@ mdf_pfn_t pfn_cache_private;
603de6
 mdf_pfn_t pfn_user;
603de6
 mdf_pfn_t pfn_free;
603de6
 mdf_pfn_t pfn_hwpoison;
603de6
+mdf_pfn_t pfn_offline;
603de6
 
603de6
 mdf_pfn_t num_dumped;
603de6
 
603de6
@@ -250,6 +251,21 @@ isHugetlb(unsigned long dtor)
603de6
 }
603de6
 
603de6
 static int
603de6
+isOffline(unsigned long flags, unsigned int _mapcount)
603de6
+{
603de6
+	if (NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE) == NOT_FOUND_NUMBER)
603de6
+		return FALSE;
603de6
+
603de6
+	if (flags & (1UL << NUMBER(PG_slab)))
603de6
+		return FALSE;
603de6
+
603de6
+	if (_mapcount == (int)NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE))
603de6
+		return TRUE;
603de6
+
603de6
+	return FALSE;
603de6
+}
603de6
+
603de6
+static int
603de6
 is_cache_page(unsigned long flags)
603de6
 {
603de6
 	if (isLRU(flags))
603de6
@@ -2287,6 +2303,8 @@ write_vmcoreinfo_data(void)
603de6
 	WRITE_NUMBER("PG_hwpoison", PG_hwpoison);
603de6
 
603de6
 	WRITE_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
603de6
+	WRITE_NUMBER("PAGE_OFFLINE_MAPCOUNT_VALUE",
603de6
+		     PAGE_OFFLINE_MAPCOUNT_VALUE);
603de6
 	WRITE_NUMBER("phys_base", phys_base);
603de6
 
603de6
 	WRITE_NUMBER("HUGETLB_PAGE_DTOR", HUGETLB_PAGE_DTOR);
603de6
@@ -2687,6 +2705,7 @@ read_vmcoreinfo(void)
603de6
 	READ_SRCFILE("pud_t", pud_t);
603de6
 
603de6
 	READ_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
603de6
+	READ_NUMBER("PAGE_OFFLINE_MAPCOUNT_VALUE", PAGE_OFFLINE_MAPCOUNT_VALUE);
603de6
 	READ_NUMBER("phys_base", phys_base);
603de6
 #ifdef __aarch64__
603de6
 	READ_NUMBER("VA_BITS", VA_BITS);
603de6
@@ -6042,6 +6061,12 @@ __exclude_unnecessary_pages(unsigned long mem_map,
603de6
 			pfn_counter = &pfn_hwpoison;
603de6
 		}
603de6
 		/*
603de6
+		 * Exclude pages that are logically offline.
603de6
+		 */
603de6
+		else if (isOffline(flags, _mapcount)) {
603de6
+			pfn_counter = &pfn_offline;
603de6
+		}
603de6
+		/*
603de6
 		 * Unexcludable page
603de6
 		 */
603de6
 		else
603de6
@@ -7522,7 +7547,7 @@ write_elf_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_page)
603de6
 	 */
603de6
 	if (info->flag_cyclic) {
603de6
 		pfn_zero = pfn_cache = pfn_cache_private = 0;
603de6
-		pfn_user = pfn_free = pfn_hwpoison = 0;
603de6
+		pfn_user = pfn_free = pfn_hwpoison = pfn_offline = 0;
603de6
 		pfn_memhole = info->max_mapnr;
603de6
 	}
603de6
 
603de6
@@ -8804,7 +8829,7 @@ write_kdump_pages_and_bitmap_cyclic(struct cache_data *cd_header, struct cache_d
603de6
 		 * Reset counter for debug message.
603de6
 		 */
603de6
 		pfn_zero = pfn_cache = pfn_cache_private = 0;
603de6
-		pfn_user = pfn_free = pfn_hwpoison = 0;
603de6
+		pfn_user = pfn_free = pfn_hwpoison = pfn_offline = 0;
603de6
 		pfn_memhole = info->max_mapnr;
603de6
 
603de6
 		/*
603de6
@@ -9749,7 +9774,7 @@ print_report(void)
603de6
 	pfn_original = info->max_mapnr - pfn_memhole;
603de6
 
603de6
 	pfn_excluded = pfn_zero + pfn_cache + pfn_cache_private
603de6
-	    + pfn_user + pfn_free + pfn_hwpoison;
603de6
+	    + pfn_user + pfn_free + pfn_hwpoison + pfn_offline;
603de6
 	shrinking = (pfn_original - pfn_excluded) * 100;
603de6
 	shrinking = shrinking / pfn_original;
603de6
 
603de6
@@ -9763,6 +9788,7 @@ print_report(void)
603de6
 	REPORT_MSG("    User process data pages : 0x%016llx\n", pfn_user);
603de6
 	REPORT_MSG("    Free pages              : 0x%016llx\n", pfn_free);
603de6
 	REPORT_MSG("    Hwpoison pages          : 0x%016llx\n", pfn_hwpoison);
603de6
+	REPORT_MSG("    Offline pages           : 0x%016llx\n", pfn_offline);
603de6
 	REPORT_MSG("  Remaining pages  : 0x%016llx\n",
603de6
 	    pfn_original - pfn_excluded);
603de6
 	REPORT_MSG("  (The number of pages is reduced to %lld%%.)\n",
603de6
@@ -9790,7 +9816,7 @@ print_mem_usage(void)
603de6
 	pfn_original = info->max_mapnr - pfn_memhole;
603de6
 
603de6
 	pfn_excluded = pfn_zero + pfn_cache + pfn_cache_private
603de6
-	    + pfn_user + pfn_free + pfn_hwpoison;
603de6
+	    + pfn_user + pfn_free + pfn_hwpoison + pfn_offline;
603de6
 	shrinking = (pfn_original - pfn_excluded) * 100;
603de6
 	shrinking = shrinking / pfn_original;
603de6
 	total_size = info->page_size * pfn_original;
603de6
diff --git a/makedumpfile.h b/makedumpfile.h
603de6
index 73813ed..04c903f 100644
603de6
--- a/makedumpfile-1.6.5/makedumpfile.h
603de6
+++ b/makedumpfile-1.6.5/makedumpfile.h
603de6
@@ -1927,6 +1927,7 @@ struct number_table {
603de6
 	long    PG_hwpoison;
603de6
 
603de6
 	long	PAGE_BUDDY_MAPCOUNT_VALUE;
603de6
+	long	PAGE_OFFLINE_MAPCOUNT_VALUE;
603de6
 	long	SECTION_SIZE_BITS;
603de6
 	long	MAX_PHYSMEM_BITS;
603de6
 	long    HUGETLB_PAGE_DTOR;
603de6
-- 
603de6
2.7.4
603de6