Skip to contentSkip to conversation

makedumpfile/arm64: get SECTIONS_SIZE_BITS from sysfs

PATCH In review Pingfan Liu 2 participants 5 messages Jun 8, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 makedumpfile/arm64: get SECTIONS_SIZE_BITS from sysfs

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"

Cc Kazuhito Hagio <[email protected]>

To: [email protected]

---
 arch/arm64.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
arch/arm64.c +20 -1
index 1072178..2f6f5cf 100644
@@ -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);
Signature · 7 lines
2.29.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

-----Original Message-----

Quoted 5 lines

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"

Thanks for the patch, but the place where we should put/get such necessary information first is vmcoreinfo, which exists for that. Can we add an entry for the SECTIONS_SIZE_BITS there?

If we use information from a runtime environment, makedumpfile cannot process vmcores/dumpfiles generated from other kernels than one that makedumpfile is running.

Thanks,
Kazu

Quoted 48 lines
Cc Kazuhito Hagio <[email protected]>

To: [email protected]

---
 arch/arm64.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
arch/arm64.c +20 -2
index 1072178..2f6f5cf 100644
@@ -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);
--
Quoted 1 line

2.29.2

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 5 lines · HAGIO KAZUHITO(萩尾 一仁)

-----Original Message-----

Quoted 3 lines

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

Quoted 7 lines
Quoted 2 lines

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

Thanks for the patch, but the place where we should put/get such necessary information first is vmcoreinfo, which exists for that. Can we add an entry for the SECTIONS_SIZE_BITS there?

OK, I will send a patch to kernel for it.

Thanks,
Pingfan

Quoted 52 lines

If we use information from a runtime environment, makedumpfile cannot process vmcores/dumpfiles generated from other kernels than one that makedumpfile is running.

Thanks,
Kazu

Quoted 45 lines
Cc Kazuhito Hagio <[email protected]>

To: [email protected]

---
 arch/arm64.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
arch/arm64.c +20 -1
index 1072178..2f6f5cf 100644
@@ -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;
+     }
 
Quoted 5 lines
Quoted 4 lines
arch/arm64.c +0 -1
      DEBUG_MSG("kimage_voffset   : %lx\n", kimage_voffset);
      DEBUG_MSG("section_size_bits: %ld\n", info->section_size_bits);
--

2.29.2

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

-----Original Message-----

Quoted 6 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 5 lines

-----Original Message-----

Quoted 3 lines

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

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

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

Thanks for the patch, but the place where we should put/get such necessary information first is vmcoreinfo, which exists for that. Can we add an entry for the SECTIONS_SIZE_BITS there?

OK, I will send a patch to kernel for it.

FWIW, my expectation is that it will be added to kernel/crash_core.c, i.e. not only for arm64, because some architectures like arm and mips also have multiple values like arm64 and that will help use makedumpfile, and also will make it adaptable to future changes on all architectures.

$ git grep SECTION_SIZE_BITS arch/

arch/arm/include/asm/sparsemem.h:#define SECTION_SIZE_BITS 28
arch/arm/mach-rpc/include/mach/memory.h:#define SECTION_SIZE_BITS 26
arch/arm/mach-sa1100/include/mach/memory.h:#define SECTION_SIZE_BITS 27

arch/mips/include/asm/sparsemem.h:# define SECTION_SIZE_BITS 29
arch/mips/include/asm/sparsemem.h:# define SECTION_SIZE_BITS 28

Thanks,
Kazu

Quoted 61 lines

Thanks,
Pingfan

Quoted 57 lines

If we use information from a runtime environment, makedumpfile cannot process vmcores/dumpfiles generated from other kernels than one that makedumpfile is running.

Thanks,
Kazu

Quoted 49 lines
Cc Kazuhito Hagio <[email protected]>

To: [email protected]

---
 arch/arm64.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
arch/arm64.c +20 -2
index 1072178..2f6f5cf 100644
@@ -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

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw
Quoted 15 lines · HAGIO KAZUHITO(萩尾 一仁)

-----Original Message-----

Quoted 13 lines · HAGIO KAZUHITO(萩尾 一仁)
Quoted 12 lines

-----Original Message-----

Quoted 5 lines

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"

Thanks for the patch, but the place where we should put/get such necessary information first is vmcoreinfo, which exists for that. Can we add an entry for the SECTIONS_SIZE_BITS there?

Quoted 7 lines
Quoted 1 line

OK, I will send a patch to kernel for it.

FWIW, my expectation is that it will be added to kernel/crash_core.c, i.e. not only for arm64, because some architectures like arm and mips also have multiple values like arm64 and that will help use makedumpfile, and also will make it adaptable to future changes on all architectures.

Thanks for your suggestion. I have composed one and run some test now.

Will cc you when sending it.

Thanks,
Pingfan

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec