Blame SOURCES/kexec-tools-2.0.15-makedumpfile-fix-for-hugepages-filtering.patch

fb94db
From 5b6fe3ecda7c000360065834e7eb14d1add8017d Mon Sep 17 00:00:00 2001
fb94db
From: Hari Bathini <hbathini@linux.vnet.ibm.com>
fb94db
Date: Thu, 8 Mar 2018 23:39:55 +0530
fb94db
Subject: [PATCH] makedumpfile: fix for hugepages filtering
fb94db
fb94db
Kernel commit 036e7aa49fb2 changed 'compound_dtor' & 'compound_order'
fb94db
types from 'unsigned short' to 'unsigned char'. Fix it here to ensure
fb94db
hugepages are filtered properly.
fb94db
fb94db
Also, makedumpfile tool commit 484c6b18624 used 'int' type for 'dtor'
fb94db
argument in 'isHugetlb' function. While this works in recent kernels
fb94db
that use 'unsigned short/char' type for 'compound_dtor', it breaks
fb94db
older kernels that used address of 'free_huge_page' as dtor. Fix it
fb94db
by changing 'dtor' type.
fb94db
fb94db
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
fb94db
Signed-off-by: Pingfan Liu <piliu@redhat.com>
fb94db
---
fb94db
 makedumpfile.c | 30 ++++++++++++++++++++++++------
fb94db
 makedumpfile.h |  1 +
fb94db
 2 files changed, 25 insertions(+), 6 deletions(-)
fb94db
fb94db
diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c
fb94db
index ed138d3..ac8483d 100644
fb94db
--- a/makedumpfile-1.6.2/makedumpfile.c
fb94db
+++ b/makedumpfile-1.6.2/makedumpfile.c
fb94db
@@ -241,7 +241,7 @@ is_in_same_page(unsigned long vaddr1, unsigned long vaddr2)
fb94db
 }
fb94db
 
fb94db
 static inline int
fb94db
-isHugetlb(int dtor)
fb94db
+isHugetlb(unsigned long dtor)
fb94db
 {
fb94db
         return ((NUMBER(HUGETLB_PAGE_DTOR) != NOT_FOUND_NUMBER)
fb94db
 		&& (NUMBER(HUGETLB_PAGE_DTOR) == dtor))
fb94db
@@ -5798,18 +5798,36 @@ __exclude_unnecessary_pages(unsigned long mem_map,
fb94db
 		 * and PGMM_CACHED is a power of 2.
fb94db
 		 */
fb94db
 		if ((index_pg < PGMM_CACHED - 1) && isCompoundHead(flags)) {
fb94db
-			if (order_offset)
fb94db
-				compound_order = USHORT(pcache + SIZE(page) + order_offset);
fb94db
+			unsigned long long addr =
fb94db
+				(unsigned long long)(pcache + SIZE(page));
fb94db
+
fb94db
+			if (order_offset) {
fb94db
+				if (info->kernel_version >=
fb94db
+				    KERNEL_VERSION(4, 16, 0)) {
fb94db
+					compound_order =
fb94db
+						UCHAR(addr + order_offset);
fb94db
+				} else {
fb94db
+					compound_order =
fb94db
+						USHORT(addr + order_offset);
fb94db
+				}
fb94db
+			}
fb94db
 
fb94db
 			if (dtor_offset) {
fb94db
 				/*
fb94db
 				 * compound_dtor has been changed from the address of descriptor
fb94db
 				 * to the ID of it since linux-4.4.
fb94db
 				 */
fb94db
-				if (info->kernel_version >= KERNEL_VERSION(4, 4, 0)) {
fb94db
-					compound_dtor = USHORT(pcache + SIZE(page) + dtor_offset);
fb94db
+				if (info->kernel_version >=
fb94db
+				    KERNEL_VERSION(4, 16, 0)) {
fb94db
+					compound_dtor =
fb94db
+						UCHAR(addr + dtor_offset);
fb94db
+				} else if (info->kernel_version >=
fb94db
+					   KERNEL_VERSION(4, 4, 0)) {
fb94db
+					compound_dtor =
fb94db
+						USHORT(addr + dtor_offset);
fb94db
 				} else {
fb94db
-					compound_dtor = ULONG(pcache + SIZE(page) + dtor_offset);
fb94db
+					compound_dtor =
fb94db
+						ULONG(addr + dtor_offset);
fb94db
 				}
fb94db
 			}
fb94db
 
fb94db
diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h
fb94db
index 01eece2..4cfad98 100644
fb94db
--- a/makedumpfile-1.6.2/makedumpfile.h
fb94db
+++ b/makedumpfile-1.6.2/makedumpfile.h
fb94db
@@ -241,6 +241,7 @@ static inline int string_exists(char *s) { return (s ? TRUE : FALSE); }
fb94db
 		     string_exists((char *)(B)) &&	\
fb94db
 	(strncmp((char *)(A), (char *)(B), strlen((char *)(B))) == 0))
fb94db
 
fb94db
+#define UCHAR(ADDR)	*((unsigned char *)(ADDR))
fb94db
 #define USHORT(ADDR)	*((unsigned short *)(ADDR))
fb94db
 #define UINT(ADDR)	*((unsigned int *)(ADDR))
fb94db
 #define ULONG(ADDR)	*((unsigned long *)(ADDR))
fb94db
-- 
fb94db
2.7.4
fb94db