Skip to content

Commit ced1bf5

Browse files
hbathinimpe
authored andcommitted
powerpc/fadump: merge adjacent memory ranges to reduce PT_LOAD segements
With dynamic memory allocation support for crash memory ranges array, there is no hard limit on the no. of crash memory ranges kernel could export, but program headers count could overflow in the /proc/vmcore ELF file while exporting each memory range as PT_LOAD segment. Reduce the likelihood of a such scenario, by folding adjacent crash memory ranges which minimizes the total number of PT_LOAD segments. Signed-off-by: Hari Bathini <[email protected]> Reviewed-by: Mahesh Salgaonkar <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 1bd6a1c commit ced1bf5

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

arch/powerpc/kernel/fadump.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -908,22 +908,41 @@ static int allocate_crash_memory_ranges(void)
908908
static inline int fadump_add_crash_memory(unsigned long long base,
909909
unsigned long long end)
910910
{
911+
u64 start, size;
912+
bool is_adjacent = false;
913+
911914
if (base == end)
912915
return 0;
913916

914-
if (crash_mem_ranges == max_crash_mem_ranges) {
915-
int ret;
917+
/*
918+
* Fold adjacent memory ranges to bring down the memory ranges/
919+
* PT_LOAD segments count.
920+
*/
921+
if (crash_mem_ranges) {
922+
start = crash_memory_ranges[crash_mem_ranges - 1].base;
923+
size = crash_memory_ranges[crash_mem_ranges - 1].size;
916924

917-
ret = allocate_crash_memory_ranges();
918-
if (ret)
919-
return ret;
925+
if ((start + size) == base)
926+
is_adjacent = true;
927+
}
928+
if (!is_adjacent) {
929+
/* resize the array on reaching the limit */
930+
if (crash_mem_ranges == max_crash_mem_ranges) {
931+
int ret;
932+
933+
ret = allocate_crash_memory_ranges();
934+
if (ret)
935+
return ret;
936+
}
937+
938+
start = base;
939+
crash_memory_ranges[crash_mem_ranges].base = start;
940+
crash_mem_ranges++;
920941
}
921942

943+
crash_memory_ranges[crash_mem_ranges - 1].size = (end - start);
922944
pr_debug("crash_memory_range[%d] [%#016llx-%#016llx], %#llx bytes\n",
923-
crash_mem_ranges, base, end - 1, (end - base));
924-
crash_memory_ranges[crash_mem_ranges].base = base;
925-
crash_memory_ranges[crash_mem_ranges].size = end - base;
926-
crash_mem_ranges++;
945+
(crash_mem_ranges - 1), start, end - 1, (end - start));
927946
return 0;
928947
}
929948

@@ -999,6 +1018,14 @@ static int fadump_setup_crash_memory_ranges(void)
9991018

10001019
pr_debug("Setup crash memory ranges.\n");
10011020
crash_mem_ranges = 0;
1021+
1022+
/* allocate memory for crash memory ranges for the first time */
1023+
if (!max_crash_mem_ranges) {
1024+
ret = allocate_crash_memory_ranges();
1025+
if (ret)
1026+
return ret;
1027+
}
1028+
10021029
/*
10031030
* add the first memory chunk (RMA_START through boot_memory_size) as
10041031
* a separate memory chunk. The reason is, at the time crash firmware

0 commit comments

Comments
 (0)