Skip to content

Commit 735c2f9

Browse files
AKASHI Takahirowildea01
authored andcommitted
powerpc, kexec_file: factor out memblock-based arch_kexec_walk_mem()
Memblock list is another source for usable system memory layout. So move powerpc's arch_kexec_walk_mem() to common code so that other memblock-based architectures, particularly arm64, can also utilise it. A moved function is now renamed to kexec_walk_memblock() and integrated into kexec_locate_mem_hole(), which will now be usable for all architectures with no need for overriding arch_kexec_walk_mem(). With this change, arch_kexec_walk_mem() need no longer be a weak function, and was now renamed to kexec_walk_resources(). Since powerpc doesn't support kdump in its kexec_file_load(), the current kexec_walk_memblock() won't work for kdump either in this form, this will be fixed in the next patch. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Dave Young <dyoung@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Baoquan He <bhe@redhat.com> Acked-by: James Morse <james.morse@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent b6664ba commit 735c2f9

File tree

3 files changed

+57
-60
lines changed

3 files changed

+57
-60
lines changed

arch/powerpc/kernel/machine_kexec_file_64.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include <linux/slab.h>
2626
#include <linux/kexec.h>
27-
#include <linux/memblock.h>
2827
#include <linux/of_fdt.h>
2928
#include <linux/libfdt.h>
3029
#include <asm/ima.h>
@@ -46,59 +45,6 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
4645
return kexec_image_probe_default(image, buf, buf_len);
4746
}
4847

49-
/**
50-
* arch_kexec_walk_mem - call func(data) for each unreserved memory block
51-
* @kbuf: Context info for the search. Also passed to @func.
52-
* @func: Function to call for each memory block.
53-
*
54-
* This function is used by kexec_add_buffer and kexec_locate_mem_hole
55-
* to find unreserved memory to load kexec segments into.
56-
*
57-
* Return: The memory walk will stop when func returns a non-zero value
58-
* and that value will be returned. If all free regions are visited without
59-
* func returning non-zero, then zero will be returned.
60-
*/
61-
int arch_kexec_walk_mem(struct kexec_buf *kbuf,
62-
int (*func)(struct resource *, void *))
63-
{
64-
int ret = 0;
65-
u64 i;
66-
phys_addr_t mstart, mend;
67-
struct resource res = { };
68-
69-
if (kbuf->top_down) {
70-
for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0,
71-
&mstart, &mend, NULL) {
72-
/*
73-
* In memblock, end points to the first byte after the
74-
* range while in kexec, end points to the last byte
75-
* in the range.
76-
*/
77-
res.start = mstart;
78-
res.end = mend - 1;
79-
ret = func(&res, kbuf);
80-
if (ret)
81-
break;
82-
}
83-
} else {
84-
for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend,
85-
NULL) {
86-
/*
87-
* In memblock, end points to the first byte after the
88-
* range while in kexec, end points to the last byte
89-
* in the range.
90-
*/
91-
res.start = mstart;
92-
res.end = mend - 1;
93-
ret = func(&res, kbuf);
94-
if (ret)
95-
break;
96-
}
97-
}
98-
99-
return ret;
100-
}
101-
10248
/**
10349
* setup_purgatory - initialize the purgatory's global variables
10450
* @image: kexec image.

include/linux/kexec.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ int __weak arch_kexec_apply_relocations(struct purgatory_info *pi,
192192
const Elf_Shdr *relsec,
193193
const Elf_Shdr *symtab);
194194

195-
int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
196-
int (*func)(struct resource *, void *));
197195
extern int kexec_add_buffer(struct kexec_buf *kbuf);
198196
int kexec_locate_mem_hole(struct kexec_buf *kbuf);
199197

kernel/kexec_file.c

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/file.h>
1717
#include <linux/slab.h>
1818
#include <linux/kexec.h>
19+
#include <linux/memblock.h>
1920
#include <linux/mutex.h>
2021
#include <linux/list.h>
2122
#include <linux/fs.h>
@@ -499,17 +500,66 @@ static int locate_mem_hole_callback(struct resource *res, void *arg)
499500
return locate_mem_hole_bottom_up(start, end, kbuf);
500501
}
501502

503+
#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK
504+
static int kexec_walk_memblock(struct kexec_buf *kbuf,
505+
int (*func)(struct resource *, void *))
506+
{
507+
return 0;
508+
}
509+
#else
510+
static int kexec_walk_memblock(struct kexec_buf *kbuf,
511+
int (*func)(struct resource *, void *))
512+
{
513+
int ret = 0;
514+
u64 i;
515+
phys_addr_t mstart, mend;
516+
struct resource res = { };
517+
518+
if (kbuf->top_down) {
519+
for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0,
520+
&mstart, &mend, NULL) {
521+
/*
522+
* In memblock, end points to the first byte after the
523+
* range while in kexec, end points to the last byte
524+
* in the range.
525+
*/
526+
res.start = mstart;
527+
res.end = mend - 1;
528+
ret = func(&res, kbuf);
529+
if (ret)
530+
break;
531+
}
532+
} else {
533+
for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend,
534+
NULL) {
535+
/*
536+
* In memblock, end points to the first byte after the
537+
* range while in kexec, end points to the last byte
538+
* in the range.
539+
*/
540+
res.start = mstart;
541+
res.end = mend - 1;
542+
ret = func(&res, kbuf);
543+
if (ret)
544+
break;
545+
}
546+
}
547+
548+
return ret;
549+
}
550+
#endif
551+
502552
/**
503-
* arch_kexec_walk_mem - call func(data) on free memory regions
553+
* kexec_walk_resources - call func(data) on free memory regions
504554
* @kbuf: Context info for the search. Also passed to @func.
505555
* @func: Function to call for each memory region.
506556
*
507557
* Return: The memory walk will stop when func returns a non-zero value
508558
* and that value will be returned. If all free regions are visited without
509559
* func returning non-zero, then zero will be returned.
510560
*/
511-
int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
512-
int (*func)(struct resource *, void *))
561+
static int kexec_walk_resources(struct kexec_buf *kbuf,
562+
int (*func)(struct resource *, void *))
513563
{
514564
if (kbuf->image->type == KEXEC_TYPE_CRASH)
515565
return walk_iomem_res_desc(crashk_res.desc,
@@ -536,7 +586,10 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)
536586
if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN)
537587
return 0;
538588

539-
ret = arch_kexec_walk_mem(kbuf, locate_mem_hole_callback);
589+
if (IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK))
590+
ret = kexec_walk_resources(kbuf, locate_mem_hole_callback);
591+
else
592+
ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback);
540593

541594
return ret == 1 ? 0 : -EADDRNOTAVAIL;
542595
}

0 commit comments

Comments
 (0)