Skip to content

Commit 33f2cc0

Browse files
hbathinimpe
authored andcommitted
powerpc/kexec: split CONFIG_KEXEC_FILE and CONFIG_CRASH_DUMP
CONFIG_KEXEC_FILE does not have to select CONFIG_CRASH_DUMP. Move some code under CONFIG_CRASH_DUMP to support CONFIG_KEXEC_FILE and !CONFIG_CRASH_DUMP case. Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240226103010.589537-3-hbathini@linux.ibm.com
1 parent 56a34d7 commit 33f2cc0

File tree

2 files changed

+142
-131
lines changed

2 files changed

+142
-131
lines changed

arch/powerpc/kexec/elf_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
4747
if (ret)
4848
return ERR_PTR(ret);
4949

50-
if (image->type == KEXEC_TYPE_CRASH) {
50+
if (IS_ENABLED(CONFIG_CRASH_DUMP) && image->type == KEXEC_TYPE_CRASH) {
5151
/* min & max buffer values for kdump case */
5252
kbuf.buf_min = pbuf.buf_min = crashk_res.start;
5353
kbuf.buf_max = pbuf.buf_max =
@@ -70,7 +70,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
7070
kexec_dprintk("Loaded purgatory at 0x%lx\n", pbuf.mem);
7171

7272
/* Load additional segments needed for panic kernel */
73-
if (image->type == KEXEC_TYPE_CRASH) {
73+
if (IS_ENABLED(CONFIG_CRASH_DUMP) && image->type == KEXEC_TYPE_CRASH) {
7474
ret = load_crashdump_segments_ppc64(image, &kbuf);
7575
if (ret) {
7676
pr_err("Failed to load kdump kernel segments\n");

arch/powerpc/kexec/file_load_64.c

Lines changed: 140 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -96,119 +96,6 @@ static int get_exclude_memory_ranges(struct crash_mem **mem_ranges)
9696
return ret;
9797
}
9898

99-
/**
100-
* get_usable_memory_ranges - Get usable memory ranges. This list includes
101-
* regions like crashkernel, opal/rtas & tce-table,
102-
* that kdump kernel could use.
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_usable_memory_ranges(struct crash_mem **mem_ranges)
108-
{
109-
int ret;
110-
111-
/*
112-
* Early boot failure observed on guests when low memory (first memory
113-
* block?) is not added to usable memory. So, add [0, crashk_res.end]
114-
* instead of [crashk_res.start, crashk_res.end] to workaround it.
115-
* Also, crashed kernel's memory must be added to reserve map to
116-
* avoid kdump kernel from using it.
117-
*/
118-
ret = add_mem_range(mem_ranges, 0, crashk_res.end + 1);
119-
if (ret)
120-
goto out;
121-
122-
ret = add_rtas_mem_range(mem_ranges);
123-
if (ret)
124-
goto out;
125-
126-
ret = add_opal_mem_range(mem_ranges);
127-
if (ret)
128-
goto out;
129-
130-
ret = add_tce_mem_ranges(mem_ranges);
131-
out:
132-
if (ret)
133-
pr_err("Failed to setup usable memory ranges\n");
134-
return ret;
135-
}
136-
137-
/**
138-
* get_crash_memory_ranges - Get crash memory ranges. This list includes
139-
* first/crashing kernel's memory regions that
140-
* would be exported via an elfcore.
141-
* @mem_ranges: Range list to add the memory ranges to.
142-
*
143-
* Returns 0 on success, negative errno on error.
144-
*/
145-
static int get_crash_memory_ranges(struct crash_mem **mem_ranges)
146-
{
147-
phys_addr_t base, end;
148-
struct crash_mem *tmem;
149-
u64 i;
150-
int ret;
151-
152-
for_each_mem_range(i, &base, &end) {
153-
u64 size = end - base;
154-
155-
/* Skip backup memory region, which needs a separate entry */
156-
if (base == BACKUP_SRC_START) {
157-
if (size > BACKUP_SRC_SIZE) {
158-
base = BACKUP_SRC_END + 1;
159-
size -= BACKUP_SRC_SIZE;
160-
} else
161-
continue;
162-
}
163-
164-
ret = add_mem_range(mem_ranges, base, size);
165-
if (ret)
166-
goto out;
167-
168-
/* Try merging adjacent ranges before reallocation attempt */
169-
if ((*mem_ranges)->nr_ranges == (*mem_ranges)->max_nr_ranges)
170-
sort_memory_ranges(*mem_ranges, true);
171-
}
172-
173-
/* Reallocate memory ranges if there is no space to split ranges */
174-
tmem = *mem_ranges;
175-
if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) {
176-
tmem = realloc_mem_ranges(mem_ranges);
177-
if (!tmem)
178-
goto out;
179-
}
180-
181-
/* Exclude crashkernel region */
182-
ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end);
183-
if (ret)
184-
goto out;
185-
186-
/*
187-
* FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL
188-
* regions are exported to save their context at the time of
189-
* crash, they should actually be backed up just like the
190-
* first 64K bytes of memory.
191-
*/
192-
ret = add_rtas_mem_range(mem_ranges);
193-
if (ret)
194-
goto out;
195-
196-
ret = add_opal_mem_range(mem_ranges);
197-
if (ret)
198-
goto out;
199-
200-
/* create a separate program header for the backup region */
201-
ret = add_mem_range(mem_ranges, BACKUP_SRC_START, BACKUP_SRC_SIZE);
202-
if (ret)
203-
goto out;
204-
205-
sort_memory_ranges(*mem_ranges, false);
206-
out:
207-
if (ret)
208-
pr_err("Failed to setup crash memory ranges\n");
209-
return ret;
210-
}
211-
21299
/**
213100
* get_reserved_memory_ranges - Get reserve memory ranges. This list includes
214101
* memory regions that should be added to the
@@ -434,6 +321,120 @@ static int locate_mem_hole_bottom_up_ppc64(struct kexec_buf *kbuf,
434321
return ret;
435322
}
436323

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

864865
return 0;
865866
}
867+
#endif
866868

867869
/**
868870
* setup_purgatory_ppc64 - initialize PPC64 specific purgatory's global
@@ -972,26 +974,14 @@ static unsigned int cpu_node_size(void)
972974
return size;
973975
}
974976

975-
/**
976-
* kexec_extra_fdt_size_ppc64 - Return the estimated additional size needed to
977-
* setup FDT for kexec/kdump kernel.
978-
* @image: kexec image being loaded.
979-
*
980-
* Returns the estimated extra size needed for kexec/kdump kernel FDT.
981-
*/
982-
unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
977+
static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image)
983978
{
984979
unsigned int cpu_nodes, extra_size = 0;
985980
struct device_node *dn;
986981
u64 usm_entries;
987982

988-
// Budget some space for the password blob. There's already extra space
989-
// for the key name
990-
if (plpks_is_available())
991-
extra_size += (unsigned int)plpks_get_passwordlen();
992-
993-
if (image->type != KEXEC_TYPE_CRASH)
994-
return extra_size;
983+
if (!IS_ENABLED(CONFIG_CRASH_DUMP) || image->type != KEXEC_TYPE_CRASH)
984+
return 0;
995985

996986
/*
997987
* For kdump kernel, account for linux,usable-memory and
@@ -1019,6 +1009,25 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
10191009
return extra_size;
10201010
}
10211011

1012+
/**
1013+
* kexec_extra_fdt_size_ppc64 - Return the estimated additional size needed to
1014+
* setup FDT for kexec/kdump kernel.
1015+
* @image: kexec image being loaded.
1016+
*
1017+
* Returns the estimated extra size needed for kexec/kdump kernel FDT.
1018+
*/
1019+
unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
1020+
{
1021+
unsigned int extra_size = 0;
1022+
1023+
// Budget some space for the password blob. There's already extra space
1024+
// for the key name
1025+
if (plpks_is_available())
1026+
extra_size += (unsigned int)plpks_get_passwordlen();
1027+
1028+
return extra_size + kdump_extra_fdt_size_ppc64(image);
1029+
}
1030+
10221031
/**
10231032
* add_node_props - Reads node properties from device node structure and add
10241033
* them to fdt.
@@ -1171,6 +1180,7 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
11711180
struct crash_mem *umem = NULL, *rmem = NULL;
11721181
int i, nr_ranges, ret;
11731182

1183+
#ifdef CONFIG_CRASH_DUMP
11741184
/*
11751185
* Restrict memory usage for kdump kernel by setting up
11761186
* usable memory ranges and memory reserve map.
@@ -1207,6 +1217,7 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
12071217
goto out;
12081218
}
12091219
}
1220+
#endif
12101221

12111222
/* Update cpus nodes information to account hotplug CPUs. */
12121223
ret = update_cpus_node(fdt);
@@ -1278,7 +1289,7 @@ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf)
12781289
buf_min = kbuf->buf_min;
12791290
buf_max = kbuf->buf_max;
12801291
/* Segments for kdump kernel should be within crashkernel region */
1281-
if (kbuf->image->type == KEXEC_TYPE_CRASH) {
1292+
if (IS_ENABLED(CONFIG_CRASH_DUMP) && kbuf->image->type == KEXEC_TYPE_CRASH) {
12821293
buf_min = (buf_min < crashk_res.start ?
12831294
crashk_res.start : buf_min);
12841295
buf_max = (buf_max > crashk_res.end ?

0 commit comments

Comments
 (0)