[PATCH] makedumpfile/arm64: get SECTIONS_SIZE_BITS from sysfs

Pingfan Liu piliu at redhat.com
Mon Jun 7 20:15:08 PDT 2021


On arm64, memory section size changes due to the kernel commit
f0b13ee23241 ("arm64/sparsemem: reduce SECTION_SIZE_BITS")

To tackle the compatibility, it is safe to read this info from sysfs
"/sys/devices/system/memory/block_size_bytes"

Signed-off-by: Pingfan Liu <piliu at redhat.com>
Cc: Kazuhito Hagio <k-hagio-ab at nec.com>
To: kexec at lists.infradead.org
---
 arch/arm64.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/arm64.c b/arch/arm64.c
index 1072178..2f6f5cf 100644
--- a/arch/arm64.c
+++ b/arch/arm64.c
@@ -424,6 +424,11 @@ get_page_offset_arm64(void)
 int
 get_machdep_info_arm64(void)
 {
+	const char sys_path_section_sz[] = "/sys/devices/system/memory/block_size_bytes";
+	char memsection_sz_str[64] = { 0 };
+	unsigned long memsection_sz = 0;
+	FILE *fp;
+
 	/* Check if va_bits is still not initialized. If still 0, call
 	 * get_versiondep_info() to initialize the same.
 	 */
@@ -451,7 +456,21 @@ get_machdep_info_arm64(void)
 	}
 
 	kimage_voffset = NUMBER(kimage_voffset);
-	info->section_size_bits = SECTIONS_SIZE_BITS;
+
+	fp = fopen(sys_path_section_sz, "r");
+	if (fp) {
+		int i;
+
+		fread(&memsection_sz_str, 64, 1, fp);
+		fclose(fp);
+		memsection_sz = strtol(memsection_sz_str, NULL, 16);
+		for (i = -1; memsection_sz != 0; i++)
+			memsection_sz >>= 1;
+		info->section_size_bits = i;
+	}
+	else {
+		info->section_size_bits = SECTIONS_SIZE_BITS;
+	}
 
 	DEBUG_MSG("kimage_voffset   : %lx\n", kimage_voffset);
 	DEBUG_MSG("section_size_bits: %ld\n", info->section_size_bits);
-- 
2.29.2




More information about the kexec mailing list