Skip to content

Commit 54622f1

Browse files
Mohan Kumar Mozbenh
authored andcommitted
powerpc: Support for relocatable kdump kernel
This adds relocatable kernel support for kdump. With this one can use the same regular kernel to capture the kdump. A signature (0xfeed1234) is passed in r6 from panic code to the next kernel through kexec_sequence and purgatory code. The signature is used to differentiate between kdump kernel and non-kdump kernels. The purgatory code compares the signature and sets the __kdump_flag in head_64.S. During the boot up, kernel code checks __kdump_flag and if it is set, the kernel will behave as relocatable kdump kernel. This kernel will boot at the address where it was loaded by kexec-tools ie. at the address reserved through crashkernel boot parameter. CONFIG_CRASH_DUMP depends on CONFIG_RELOCATABLE option to build kdump kernel as relocatable. So the same kernel can be used as production and kdump kernel. This patch incorporates the changes suggested by Paul Mackerras to avoid GOT use and to avoid two copies of the code. Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Mohan Kumar M <mohan@in.ibm.com> Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 4792adb commit 54622f1

11 files changed

Lines changed: 121 additions & 66 deletions

File tree

‎Documentation/kdump/kdump.txt‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ There are two possible methods of using Kdump.
109109
2) Or use the system kernel binary itself as dump-capture kernel and there is
110110
no need to build a separate dump-capture kernel. This is possible
111111
only with the architecutres which support a relocatable kernel. As
112-
of today, i386, x86_64 and ia64 architectures support relocatable kernel.
112+
of today, i386, x86_64, ppc64 and ia64 architectures support relocatable
113+
kernel.
113114

114115
Building a relocatable kernel is advantageous from the point of view that
115116
one does not have to build a second kernel for capturing the dump. But
@@ -207,8 +208,15 @@ Dump-capture kernel config options (Arch Dependent, i386 and x86_64)
207208
Dump-capture kernel config options (Arch Dependent, ppc64)
208209
----------------------------------------------------------
209210

210-
* Make and install the kernel and its modules. DO NOT add this kernel
211-
to the boot loader configuration files.
211+
1) Enable "Build a kdump crash kernel" support under "Kernel" options:
212+
213+
CONFIG_CRASH_DUMP=y
214+
215+
2) Enable "Build a relocatable kernel" support
216+
217+
CONFIG_RELOCATABLE=y
218+
219+
Make and install the kernel and its modules.
212220

213221
Dump-capture kernel config options (Arch Dependent, ia64)
214222
----------------------------------------------------------

‎arch/powerpc/Kconfig‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,11 @@ config KEXEC
323323

324324
config CRASH_DUMP
325325
bool "Build a kdump crash kernel"
326-
depends on PPC_MULTIPLATFORM && PPC64
326+
depends on PPC_MULTIPLATFORM && PPC64 && RELOCATABLE
327327
help
328328
Build a kernel suitable for use as a kdump capture kernel.
329-
The kernel will be linked at a different address than normal, and
330-
so can only be used for Kdump.
331-
332-
Don't change this unless you know what you are doing.
329+
The same kernel binary can be used as production kernel and dump
330+
capture kernel.
333331

334332
config PHYP_DUMP
335333
bool "Hypervisor-assisted dump (EXPERIMENTAL)"
@@ -829,11 +827,9 @@ config PAGE_OFFSET
829827
default "0xc000000000000000"
830828
config KERNEL_START
831829
hex
832-
default "0xc000000002000000" if CRASH_DUMP
833830
default "0xc000000000000000"
834831
config PHYSICAL_START
835832
hex
836-
default "0x02000000" if CRASH_DUMP
837833
default "0x00000000"
838834
endif
839835

‎arch/powerpc/include/asm/kdump.h‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
* Reserve to the end of the FWNMI area, see head_64.S */
1010
#define KDUMP_RESERVE_LIMIT 0x10000 /* 64K */
1111

12+
/*
13+
* Used to differentiate between relocatable kdump kernel and other
14+
* kernels
15+
*/
16+
#define KDUMP_SIGNATURE 0xfeed1234
17+
1218
#ifdef CONFIG_CRASH_DUMP
1319

1420
#define KDUMP_TRAMPOLINE_START 0x0100
@@ -19,17 +25,18 @@
1925
#endif /* CONFIG_CRASH_DUMP */
2026

2127
#ifndef __ASSEMBLY__
22-
#ifdef CONFIG_CRASH_DUMP
2328

29+
extern unsigned long __kdump_flag;
30+
31+
#if defined(CONFIG_CRASH_DUMP) && !defined(CONFIG_RELOCATABLE)
2432
extern void reserve_kdump_trampoline(void);
2533
extern void setup_kdump_trampoline(void);
26-
27-
#else /* !CONFIG_CRASH_DUMP */
28-
34+
#else
35+
/* !CRASH_DUMP || RELOCATABLE */
2936
static inline void reserve_kdump_trampoline(void) { ; }
3037
static inline void setup_kdump_trampoline(void) { ; }
38+
#endif
3139

32-
#endif /* CONFIG_CRASH_DUMP */
3340
#endif /* __ASSEMBLY__ */
3441

3542
#endif /* __PPC64_KDUMP_H */

‎arch/powerpc/kernel/crash_dump.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
/* Stores the physical address of elf header of crash image. */
3131
unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
3232

33+
#ifndef CONFIG_RELOCATABLE
3334
void __init reserve_kdump_trampoline(void)
3435
{
3536
lmb_reserve(0, KDUMP_RESERVE_LIMIT);
@@ -68,6 +69,7 @@ void __init setup_kdump_trampoline(void)
6869

6970
DBG(" <- setup_kdump_trampoline()\n");
7071
}
72+
#endif /* CONFIG_RELOCATABLE */
7173

7274
/*
7375
* Note: elfcorehdr_addr is not just limited to vmcore. It is also used by

‎arch/powerpc/kernel/head_64.S‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ __secondary_hold_spinloop:
9797
__secondary_hold_acknowledge:
9898
.llong 0x0
9999

100+
/* This flag is set by purgatory if we should be a kdump kernel. */
101+
/* Do not move this variable as purgatory knows about it. */
102+
.globl __kdump_flag
103+
__kdump_flag:
104+
.llong 0x0
105+
100106
#ifdef CONFIG_PPC_ISERIES
101107
/*
102108
* At offset 0x20, there is a pointer to iSeries LPAR data.
@@ -1384,7 +1390,13 @@ _STATIC(__after_prom_start)
13841390
/* process relocations for the final address of the kernel */
13851391
lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */
13861392
sldi r25,r25,32
1387-
mr r3,r25
1393+
#ifdef CONFIG_CRASH_DUMP
1394+
ld r7,__kdump_flag-_stext(r26)
1395+
cmpldi cr0,r7,1 /* kdump kernel ? - stay where we are */
1396+
bne 1f
1397+
add r25,r25,r26
1398+
#endif
1399+
1: mr r3,r25
13881400
bl .relocate
13891401
#endif
13901402

@@ -1398,11 +1410,26 @@ _STATIC(__after_prom_start)
13981410
li r3,0 /* target addr */
13991411
mr. r4,r26 /* In some cases the loader may */
14001412
beq 9f /* have already put us at zero */
1401-
lis r5,(copy_to_here - _stext)@ha
1402-
addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */
14031413
li r6,0x100 /* Start offset, the first 0x100 */
14041414
/* bytes were copied earlier. */
14051415

1416+
#ifdef CONFIG_CRASH_DUMP
1417+
/*
1418+
* Check if the kernel has to be running as relocatable kernel based on the
1419+
* variable __kdump_flag, if it is set the kernel is treated as relocatable
1420+
* kernel, otherwise it will be moved to PHYSICAL_START
1421+
*/
1422+
ld r7,__kdump_flag-_stext(r26)
1423+
cmpldi cr0,r7,1
1424+
bne 3f
1425+
1426+
li r5,__end_interrupts - _stext /* just copy interrupts */
1427+
b 5f
1428+
3:
1429+
#endif
1430+
lis r5,(copy_to_here - _stext)@ha
1431+
addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */
1432+
14061433
bl .copy_and_flush /* copy the first n bytes */
14071434
/* this includes the code being */
14081435
/* executed here. */
@@ -1411,15 +1438,15 @@ _STATIC(__after_prom_start)
14111438
mtctr r8
14121439
bctr
14131440

1441+
p_end: .llong _end - _stext
1442+
14141443
4: /* Now copy the rest of the kernel up to _end */
14151444
addis r5,r26,(p_end - _stext)@ha
14161445
ld r5,(p_end - _stext)@l(r5) /* get _end */
1417-
bl .copy_and_flush /* copy the rest */
1446+
5: bl .copy_and_flush /* copy the rest */
14181447

14191448
9: b .start_here_multiplatform
14201449

1421-
p_end: .llong _end - _stext
1422-
14231450
/*
14241451
* Copy routine used to copy the kernel to start at physical address 0
14251452
* and flush and invalidate the caches as needed.

‎arch/powerpc/kernel/iommu.c‎

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,42 @@ void iommu_unmap_sg(struct iommu_table *tbl, struct scatterlist *sglist,
458458
spin_unlock_irqrestore(&(tbl->it_lock), flags);
459459
}
460460

461+
static void iommu_table_clear(struct iommu_table *tbl)
462+
{
463+
if (!__kdump_flag) {
464+
/* Clear the table in case firmware left allocations in it */
465+
ppc_md.tce_free(tbl, tbl->it_offset, tbl->it_size);
466+
return;
467+
}
468+
469+
#ifdef CONFIG_CRASH_DUMP
470+
if (ppc_md.tce_get) {
471+
unsigned long index, tceval, tcecount = 0;
472+
473+
/* Reserve the existing mappings left by the first kernel. */
474+
for (index = 0; index < tbl->it_size; index++) {
475+
tceval = ppc_md.tce_get(tbl, index + tbl->it_offset);
476+
/*
477+
* Freed TCE entry contains 0x7fffffffffffffff on JS20
478+
*/
479+
if (tceval && (tceval != 0x7fffffffffffffffUL)) {
480+
__set_bit(index, tbl->it_map);
481+
tcecount++;
482+
}
483+
}
484+
485+
if ((tbl->it_size - tcecount) < KDUMP_MIN_TCE_ENTRIES) {
486+
printk(KERN_WARNING "TCE table is full; freeing ");
487+
printk(KERN_WARNING "%d entries for the kdump boot\n",
488+
KDUMP_MIN_TCE_ENTRIES);
489+
for (index = tbl->it_size - KDUMP_MIN_TCE_ENTRIES;
490+
index < tbl->it_size; index++)
491+
__clear_bit(index, tbl->it_map);
492+
}
493+
}
494+
#endif
495+
}
496+
461497
/*
462498
* Build a iommu_table structure. This contains a bit map which
463499
* is used to manage allocation of the tce space.
@@ -484,38 +520,7 @@ struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid)
484520
tbl->it_largehint = tbl->it_halfpoint;
485521
spin_lock_init(&tbl->it_lock);
486522

487-
#ifdef CONFIG_CRASH_DUMP
488-
if (ppc_md.tce_get) {
489-
unsigned long index;
490-
unsigned long tceval;
491-
unsigned long tcecount = 0;
492-
493-
/*
494-
* Reserve the existing mappings left by the first kernel.
495-
*/
496-
for (index = 0; index < tbl->it_size; index++) {
497-
tceval = ppc_md.tce_get(tbl, index + tbl->it_offset);
498-
/*
499-
* Freed TCE entry contains 0x7fffffffffffffff on JS20
500-
*/
501-
if (tceval && (tceval != 0x7fffffffffffffffUL)) {
502-
__set_bit(index, tbl->it_map);
503-
tcecount++;
504-
}
505-
}
506-
if ((tbl->it_size - tcecount) < KDUMP_MIN_TCE_ENTRIES) {
507-
printk(KERN_WARNING "TCE table is full; ");
508-
printk(KERN_WARNING "freeing %d entries for the kdump boot\n",
509-
KDUMP_MIN_TCE_ENTRIES);
510-
for (index = tbl->it_size - KDUMP_MIN_TCE_ENTRIES;
511-
index < tbl->it_size; index++)
512-
__clear_bit(index, tbl->it_map);
513-
}
514-
}
515-
#else
516-
/* Clear the hardware table in case firmware left allocations in it */
517-
ppc_md.tce_free(tbl, tbl->it_offset, tbl->it_size);
518-
#endif
523+
iommu_table_clear(tbl);
519524

520525
if (!welcomed) {
521526
printk(KERN_INFO "IOMMU table initialized, virtual merging %s\n",

‎arch/powerpc/kernel/machine_kexec.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ void __init reserve_crashkernel(void)
8888

8989
crash_size = crashk_res.end - crashk_res.start + 1;
9090

91+
#ifndef CONFIG_RELOCATABLE
9192
if (crashk_res.start != KDUMP_KERNELBASE)
9293
printk("Crash kernel location must be 0x%x\n",
9394
KDUMP_KERNELBASE);
9495

9596
crashk_res.start = KDUMP_KERNELBASE;
97+
#endif
9698
crash_size = PAGE_ALIGN(crash_size);
9799
crashk_res.end = crashk_res.start + crash_size - 1;
98100

‎arch/powerpc/kernel/machine_kexec_64.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,14 @@ static union thread_union kexec_stack
255255
/* Our assembly helper, in kexec_stub.S */
256256
extern NORET_TYPE void kexec_sequence(void *newstack, unsigned long start,
257257
void *image, void *control,
258-
void (*clear_all)(void)) ATTRIB_NORET;
258+
void (*clear_all)(void),
259+
unsigned long kdump_flag) ATTRIB_NORET;
259260

260261
/* too late to fail here */
261262
void default_machine_kexec(struct kimage *image)
262263
{
264+
unsigned long kdump_flag = 0;
265+
263266
/* prepare control code if any */
264267

265268
/*
@@ -270,8 +273,10 @@ void default_machine_kexec(struct kimage *image)
270273
* using debugger IPI.
271274
*/
272275

273-
if (crashing_cpu == -1)
274-
kexec_prepare_cpus();
276+
if (crashing_cpu == -1)
277+
kexec_prepare_cpus();
278+
else
279+
kdump_flag = KDUMP_SIGNATURE;
275280

276281
/* switch to a staticly allocated stack. Based on irq stack code.
277282
* XXX: the task struct will likely be invalid once we do the copy!
@@ -284,7 +289,7 @@ void default_machine_kexec(struct kimage *image)
284289
*/
285290
kexec_sequence(&kexec_stack, image->start, image,
286291
page_address(image->control_code_page),
287-
ppc_md.hpte_clear_all);
292+
ppc_md.hpte_clear_all, kdump_flag);
288293
/* NOTREACHED */
289294
}
290295

‎arch/powerpc/kernel/misc_64.S‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,12 @@ real_mode: /* assume normal blr return */
611611

612612

613613
/*
614-
* kexec_sequence(newstack, start, image, control, clear_all())
614+
* kexec_sequence(newstack, start, image, control, clear_all(), kdump_flag)
615615
*
616616
* does the grungy work with stack switching and real mode switches
617617
* also does simple calls to other code
618+
*
619+
* kdump_flag says whether the next kernel should be a kdump kernel.
618620
*/
619621

620622
_GLOBAL(kexec_sequence)
@@ -647,7 +649,7 @@ _GLOBAL(kexec_sequence)
647649
mr r29,r5 /* image (virt) */
648650
mr r28,r6 /* control, unused */
649651
mr r27,r7 /* clear_all() fn desc */
650-
mr r26,r8 /* spare */
652+
mr r26,r8 /* kdump flag */
651653
lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
652654

653655
/* disable interrupts, we are overwriting kernel data next */
@@ -709,5 +711,6 @@ _GLOBAL(kexec_sequence)
709711
mr r4,r30 # start, aka phys mem offset
710712
mtlr 4
711713
li r5,0
712-
blr /* image->start(physid, image->start, 0); */
714+
mr r6,r26 /* kdump_flag */
715+
blr /* image->start(physid, image->start, 0, kdump_flag); */
713716
#endif /* CONFIG_KEXEC */

‎arch/powerpc/platforms/cell/ras.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <asm/machdep.h>
2222
#include <asm/rtas.h>
2323
#include <asm/cell-regs.h>
24+
#include <asm/kdump.h>
2425

2526
#include "ras.h"
2627

@@ -111,9 +112,8 @@ static int __init cbe_ptcal_enable_on_node(int nid, int order)
111112
int ret = -ENOMEM;
112113
unsigned long addr;
113114

114-
#ifdef CONFIG_CRASH_DUMP
115-
rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
116-
#endif
115+
if (__kdump_flag)
116+
rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
117117

118118
area = kmalloc(sizeof(*area), GFP_KERNEL);
119119
if (!area)

0 commit comments

Comments
 (0)