Skip to content

Commit 6cce07f

Browse files
author
Mamatha Inamdar
committed
powerpc/kexec: move *_memory_ranges functions to ranges.c
JIRA: https://issues.redhat.com/browse/RHEL-101851 commit f5f0da5 Author: Sourabh Jain <sourabhjain@linux.ibm.com> Date: Tue Mar 26 11:24:10 2024 +0530 powerpc/kexec: move *_memory_ranges functions to ranges.c Move the following functions form kexec/{file_load_64.c => ranges.c} and make them public so that components other than KEXEC_FILE can also use these functions. 1. get_exclude_memory_ranges 2. get_reserved_memory_ranges 3. get_crash_memory_ranges 4. get_usable_memory_ranges Later in the series get_crash_memory_ranges function is utilized for in-kernel updates to kdump image during CPU/Memory hotplug or online/offline events for both kexec_load and kexec_file_load syscalls. Since the above functions are moved to ranges.c, some of the helper functions in ranges.c are no longer required to be public. Mark them as static and removed them from kexec_ranges.h header file. Finally, remove the CONFIG_KEXEC_FILE build dependency for range.c because it is required for other config, such as CONFIG_CRASH_DUMP. No functional changes are intended. Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240326055413.186534-4-sourabhjain@linux.ibm.com Signed-off-by: Mamatha Inamdar <minamdar@redhat.com>
1 parent df37740 commit 6cce07f

File tree

4 files changed

+224
-216
lines changed

4 files changed

+224
-216
lines changed

arch/powerpc/include/asm/kexec_ranges.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,8 @@
77
void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
88
struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
99
int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
10-
int add_tce_mem_ranges(struct crash_mem **mem_ranges);
11-
int add_initrd_mem_range(struct crash_mem **mem_ranges);
12-
#ifdef CONFIG_PPC_64S_HASH_MMU
13-
int add_htab_mem_range(struct crash_mem **mem_ranges);
14-
#else
15-
static inline int add_htab_mem_range(struct crash_mem **mem_ranges)
16-
{
17-
return 0;
18-
}
19-
#endif
20-
int add_kernel_mem_range(struct crash_mem **mem_ranges);
21-
int add_rtas_mem_range(struct crash_mem **mem_ranges);
22-
int add_opal_mem_range(struct crash_mem **mem_ranges);
23-
int add_reserved_mem_ranges(struct crash_mem **mem_ranges);
24-
10+
int get_exclude_memory_ranges(struct crash_mem **mem_ranges);
11+
int get_reserved_memory_ranges(struct crash_mem **mem_ranges);
12+
int get_crash_memory_ranges(struct crash_mem **mem_ranges);
13+
int get_usable_memory_ranges(struct crash_mem **mem_ranges);
2514
#endif /* _ASM_POWERPC_KEXEC_RANGES_H */

arch/powerpc/kexec/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Makefile for the linux kernel.
44
#
55

6-
obj-y += core.o core_$(BITS).o
6+
obj-y += core.o core_$(BITS).o ranges.o
77

88
obj-$(CONFIG_PPC32) += relocate_32.o
99

10-
obj-$(CONFIG_KEXEC_FILE) += file_load.o ranges.o file_load_$(BITS).o elf_$(BITS).o
10+
obj-$(CONFIG_KEXEC_FILE) += file_load.o file_load_$(BITS).o elf_$(BITS).o
1111
obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o
1212
obj-$(CONFIG_CRASH_DUMP) += crash.o
1313

arch/powerpc/kexec/file_load_64.c

Lines changed: 0 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -46,83 +46,6 @@ const struct kexec_file_ops * const kexec_file_loaders[] = {
4646
NULL
4747
};
4848

49-
/**
50-
* get_exclude_memory_ranges - Get exclude memory ranges. This list includes
51-
* regions like opal/rtas, tce-table, initrd,
52-
* kernel, htab which should be avoided while
53-
* setting up kexec load segments.
54-
* @mem_ranges: Range list to add the memory ranges to.
55-
*
56-
* Returns 0 on success, negative errno on error.
57-
*/
58-
static int get_exclude_memory_ranges(struct crash_mem **mem_ranges)
59-
{
60-
int ret;
61-
62-
ret = add_tce_mem_ranges(mem_ranges);
63-
if (ret)
64-
goto out;
65-
66-
ret = add_initrd_mem_range(mem_ranges);
67-
if (ret)
68-
goto out;
69-
70-
ret = add_htab_mem_range(mem_ranges);
71-
if (ret)
72-
goto out;
73-
74-
ret = add_kernel_mem_range(mem_ranges);
75-
if (ret)
76-
goto out;
77-
78-
ret = add_rtas_mem_range(mem_ranges);
79-
if (ret)
80-
goto out;
81-
82-
ret = add_opal_mem_range(mem_ranges);
83-
if (ret)
84-
goto out;
85-
86-
ret = add_reserved_mem_ranges(mem_ranges);
87-
if (ret)
88-
goto out;
89-
90-
/* exclude memory ranges should be sorted for easy lookup */
91-
sort_memory_ranges(*mem_ranges, true);
92-
out:
93-
if (ret)
94-
pr_err("Failed to setup exclude memory ranges\n");
95-
return ret;
96-
}
97-
98-
/**
99-
* get_reserved_memory_ranges - Get reserve memory ranges. This list includes
100-
* memory regions that should be added to the
101-
* memory reserve map to ensure the region is
102-
* protected from any mischief.
103-
* @mem_ranges: Range list to add the memory ranges to.
104-
*
105-
* Returns 0 on success, negative errno on error.
106-
*/
107-
static int get_reserved_memory_ranges(struct crash_mem **mem_ranges)
108-
{
109-
int ret;
110-
111-
ret = add_rtas_mem_range(mem_ranges);
112-
if (ret)
113-
goto out;
114-
115-
ret = add_tce_mem_ranges(mem_ranges);
116-
if (ret)
117-
goto out;
118-
119-
ret = add_reserved_mem_ranges(mem_ranges);
120-
out:
121-
if (ret)
122-
pr_err("Failed to setup reserved memory ranges\n");
123-
return ret;
124-
}
125-
12649
/**
12750
* __locate_mem_hole_top_down - Looks top down for a large enough memory hole
12851
* in the memory regions between buf_min & buf_max
@@ -321,119 +244,6 @@ static int locate_mem_hole_bottom_up_ppc64(struct kexec_buf *kbuf,
321244
}
322245

323246
#ifdef CONFIG_CRASH_DUMP
324-
/**
325-
* get_usable_memory_ranges - Get usable memory ranges. This list includes
326-
* regions like crashkernel, opal/rtas & tce-table,
327-
* that kdump kernel could use.
328-
* @mem_ranges: Range list to add the memory ranges to.
329-
*
330-
* Returns 0 on success, negative errno on error.
331-
*/
332-
static int get_usable_memory_ranges(struct crash_mem **mem_ranges)
333-
{
334-
int ret;
335-
336-
/*
337-
* Early boot failure observed on guests when low memory (first memory
338-
* block?) is not added to usable memory. So, add [0, crashk_res.end]
339-
* instead of [crashk_res.start, crashk_res.end] to workaround it.
340-
* Also, crashed kernel's memory must be added to reserve map to
341-
* avoid kdump kernel from using it.
342-
*/
343-
ret = add_mem_range(mem_ranges, 0, crashk_res.end + 1);
344-
if (ret)
345-
goto out;
346-
347-
ret = add_rtas_mem_range(mem_ranges);
348-
if (ret)
349-
goto out;
350-
351-
ret = add_opal_mem_range(mem_ranges);
352-
if (ret)
353-
goto out;
354-
355-
ret = add_tce_mem_ranges(mem_ranges);
356-
out:
357-
if (ret)
358-
pr_err("Failed to setup usable memory ranges\n");
359-
return ret;
360-
}
361-
362-
/**
363-
* get_crash_memory_ranges - Get crash memory ranges. This list includes
364-
* first/crashing kernel's memory regions that
365-
* would be exported via an elfcore.
366-
* @mem_ranges: Range list to add the memory ranges to.
367-
*
368-
* Returns 0 on success, negative errno on error.
369-
*/
370-
static int get_crash_memory_ranges(struct crash_mem **mem_ranges)
371-
{
372-
phys_addr_t base, end;
373-
struct crash_mem *tmem;
374-
u64 i;
375-
int ret;
376-
377-
for_each_mem_range(i, &base, &end) {
378-
u64 size = end - base;
379-
380-
/* Skip backup memory region, which needs a separate entry */
381-
if (base == BACKUP_SRC_START) {
382-
if (size > BACKUP_SRC_SIZE) {
383-
base = BACKUP_SRC_END + 1;
384-
size -= BACKUP_SRC_SIZE;
385-
} else
386-
continue;
387-
}
388-
389-
ret = add_mem_range(mem_ranges, base, size);
390-
if (ret)
391-
goto out;
392-
393-
/* Try merging adjacent ranges before reallocation attempt */
394-
if ((*mem_ranges)->nr_ranges == (*mem_ranges)->max_nr_ranges)
395-
sort_memory_ranges(*mem_ranges, true);
396-
}
397-
398-
/* Reallocate memory ranges if there is no space to split ranges */
399-
tmem = *mem_ranges;
400-
if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) {
401-
tmem = realloc_mem_ranges(mem_ranges);
402-
if (!tmem)
403-
goto out;
404-
}
405-
406-
/* Exclude crashkernel region */
407-
ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end);
408-
if (ret)
409-
goto out;
410-
411-
/*
412-
* FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL
413-
* regions are exported to save their context at the time of
414-
* crash, they should actually be backed up just like the
415-
* first 64K bytes of memory.
416-
*/
417-
ret = add_rtas_mem_range(mem_ranges);
418-
if (ret)
419-
goto out;
420-
421-
ret = add_opal_mem_range(mem_ranges);
422-
if (ret)
423-
goto out;
424-
425-
/* create a separate program header for the backup region */
426-
ret = add_mem_range(mem_ranges, BACKUP_SRC_START, BACKUP_SRC_SIZE);
427-
if (ret)
428-
goto out;
429-
430-
sort_memory_ranges(*mem_ranges, false);
431-
out:
432-
if (ret)
433-
pr_err("Failed to setup crash memory ranges\n");
434-
return ret;
435-
}
436-
437247
/**
438248
* check_realloc_usable_mem - Reallocate buffer if it can't accommodate entries
439249
* @um_info: Usable memory buffer and ranges info.

0 commit comments

Comments
 (0)