Blame SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-kernel_version-variable-being-uninitia.patch

06c2a2
From 08e08d1330f5d4dd0989bfb1558d85c82254654e Mon Sep 17 00:00:00 2001
06c2a2
From: Bhupesh Sharma <bhsharma@redhat.com>
06c2a2
Date: Fri, 17 Nov 2017 06:30:41 +0900
06c2a2
Subject: [PATCH 2/2] [PATCH 2/2] Fix 'kernel_version' variable being
06c2a2
 uninitialized & introduce minor reorganization
06c2a2
06c2a2
On executing `makedumpfile --mem-usage /proc/kcore`, it
06c2a2
fails currently with the following error message on newer Linux kernels
06c2a2
like 4.13.0 or 4.14.0:
06c2a2
06c2a2
mem-usage not supported for this kernel.
06c2a2
You can try with -f if your kernel's kcore has valid p_paddr
06c2a2
makedumpfile Failed.
06c2a2
06c2a2
This happens because 'info->kernel_version' is uninitialized in function
06c2a2
main(). So when we perform the following check, it fails even though the
06c2a2
kernel version is greater than 4.11.0:
06c2a2
06c2a2
if (info->kernel_version < KERNEL_VERSION(4, 11, 0) &&
06c2a2
				!info->flag_force) {
06c2a2
06c2a2
Fix this by reorganizing the code to:
06c2a2
- Add an API to populate the kernel version.
06c2a2
- Call this API rather than replicating the open code across other APIs
06c2a2
  across 'makedumpfile.c'
06c2a2
06c2a2
After this patch, '--mem-usage' can be used properly with makedumpfile.
06c2a2
Here are the logs I observe on a Fedora 26 ppc64le system:
06c2a2
06c2a2
The kernel version is not supported.
06c2a2
The makedumpfile operation may be incomplete.
06c2a2
06c2a2
TYPE		PAGES			EXCLUDABLE	DESCRIPTION
06c2a2
----------------------------------------------------------------------
06c2a2
ZERO		99              	yes		Pages filled with zero
06c2a2
NON_PRI_CACHE	7817            	yes		Cache pages without private flag
06c2a2
PRI_CACHE		63603           	yes		Cache pages with private flag
06c2a2
USER		4105            	yes		User process pages
06c2a2
FREE		165446          	yes		Free pages
06c2a2
KERN_DATA		6738            	no		Dumpable kernel data
06c2a2
06c2a2
page size:		65536
06c2a2
Total pages on system:	247808
06c2a2
Total size on system:	16240345088      Byte
06c2a2
06c2a2
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
06c2a2
---
06c2a2
 makedumpfile.c | 31 ++++++++++++++++++++-----------
06c2a2
 1 file changed, 20 insertions(+), 11 deletions(-)
06c2a2
06c2a2
diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c
06c2a2
index 7ce0c6d648aa..4bde542b4f0c 100644
06c2a2
--- a/makedumpfile-1.6.2/makedumpfile.c
06c2a2
+++ b/makedumpfile-1.6.2/makedumpfile.c
06c2a2
@@ -1089,6 +1089,21 @@ fallback_to_current_page_size(void)
06c2a2
 	return TRUE;
06c2a2
 }
06c2a2
 
06c2a2
+static int populate_kernel_version(void)
06c2a2
+{
06c2a2
+	struct utsname utsname;
06c2a2
+
06c2a2
+	if (uname(&utsname)) {
06c2a2
+		ERRMSG("Cannot get name and information about current kernel : %s\n",
06c2a2
+		       strerror(errno));
06c2a2
+		return FALSE;
06c2a2
+	}
06c2a2
+
06c2a2
+	info->kernel_version = get_kernel_version(utsname.release);
06c2a2
+
06c2a2
+	return TRUE;
06c2a2
+}
06c2a2
+
06c2a2
 int
06c2a2
 check_release(void)
06c2a2
 {
06c2a2
@@ -1120,11 +1135,8 @@ check_release(void)
06c2a2
 		}
06c2a2
 	}
06c2a2
 
06c2a2
-	info->kernel_version = get_kernel_version(info->system_utsname.release);
06c2a2
-	if (info->kernel_version == FALSE) {
06c2a2
-		ERRMSG("Can't get the kernel version.\n");
06c2a2
+	if (!populate_kernel_version())
06c2a2
 		return FALSE;
06c2a2
-	}
06c2a2
 
06c2a2
 	return TRUE;
06c2a2
 }
06c2a2
@@ -10973,20 +10985,14 @@ int is_crashkernel_mem_reserved(void)
06c2a2
 
06c2a2
 static int get_page_offset(void)
06c2a2
 {
06c2a2
-	struct utsname utsname;
06c2a2
-	if (uname(&utsname)) {
06c2a2
-		ERRMSG("Cannot get name and information about current kernel : %s",
06c2a2
-		       strerror(errno));
06c2a2
+	if (!populate_kernel_version())
06c2a2
 		return FALSE;
06c2a2
-	}
06c2a2
 
06c2a2
-	info->kernel_version = get_kernel_version(utsname.release);
06c2a2
 	get_versiondep_info();
06c2a2
 
06c2a2
 	return TRUE;
06c2a2
 }
06c2a2
 
06c2a2
-
06c2a2
 /* Returns the physical address of start of crash notes buffer for a kernel. */
06c2a2
 static int get_sys_kernel_vmcoreinfo(uint64_t *addr, uint64_t *len)
06c2a2
 {
06c2a2
@@ -11363,6 +11369,9 @@ main(int argc, char *argv[])
06c2a2
 			MSG("Try `makedumpfile --help' for more information.\n");
06c2a2
 			goto out;
06c2a2
 		}
06c2a2
+		if (!populate_kernel_version())
06c2a2
+			goto out;
06c2a2
+
06c2a2
 		if (info->kernel_version < KERNEL_VERSION(4, 11, 0) &&
06c2a2
 				!info->flag_force) {
06c2a2
 			MSG("mem-usage not supported for this kernel.\n");
06c2a2
-- 
06c2a2
2.7.4
06c2a2