Skip to contentSkip to conversation

MIPS kexec,kdump support

PATCH In review Maxim Uvarov 3 participants 6 messages Mar 3, 2010 – Mar 4, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 MIPS kexec,kdump support

Hello folks,

Please find here MIPS crash and kdump patches. This is patch set of 3 patches:
1. generic MIPS changes (kernel);
2. MIPS Cavium Octeon board kexec/kdump code (kernel);
3. Kexec user space MIPS changes.

Patches were tested on the latest linux-mips@ git kernel and the latest kexec-tools git on Cavium Octeon 50xx board.

I also made the same code working on RMI XLR/XLS boards for both mips32 and mips64 kernels.

Best regards,
Maxim Uvarov.

---

 arch/mips/Kconfig                  |   24 ++++++++++
 arch/mips/Makefile                 |    4 ++
 arch/mips/include/asm/kexec.h      |   31 +++++++++++--
 arch/mips/include/asm/smp.h        |    7 +++
 arch/mips/kernel/Makefile          |    3 +
 arch/mips/kernel/crash.c           |   75 +++++++++++++++++++++++++++++++
 arch/mips/kernel/crash_dump.c      |   86 +++++++++++++++++++++++++++++++++++
 arch/mips/kernel/machine_kexec.c   |   30 +++++++++++-
 arch/mips/kernel/relocate_kernel.S |   88 ++++++++++++++++++++++++++++++++++++
 arch/mips/kernel/setup.c           |   55 +++++++++++++++++++++++
 arch/mips/kernel/smp.c             |   18 +++++++
 11 files changed, 413 insertions(+), 8 deletions(-)
 create mode 100644 arch/mips/kernel/crash.c
 create mode 100644 arch/mips/kernel/crash_dump.c
arch/mips/Kconfig +24 -0
index 591ca0c..8079260 100644
@@ -2035,6 +2035,30 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config CRASH_DUMP
+	  bool "kernel crash dumps (EXPERIMENTAL)"
+	  depends on EXPERIMENTAL
+	  help
+	  Generate crash dump after being started by kexec.
+	  This should be normally only set in special crash dump kernels
+	  which are loaded in the main kernel with kexec-tools into
+	  a specially reserved region and then later executed after
+	  a crash by kdump/kexec. The crash dump kernel must be compiled
+	  to a memory address not used by the main kernel or BIOS using
+	  PHYSICAL_START.
+
+config PHYSICAL_START
+	  hex "Physical address where the kernel is loaded"
+	  default "0xffffffff84000000" if 64BIT
+	  default "0x84000000" if 32BIT
+	  depends on CRASH_DUMP
+	  help
+	  This gives the CKSEG0 or KSEG0 address where the kernel is loaded.
+	  If you plan to use kernel for capturing the crash dump change
+	  this value to start of the reserved region (the "X" value as
+			  specified in the "crashkernel=YM@XM" command line boot parameter
+			  passed to the panic-ed kernel).
+
 config SECCOMP
 	bool "Enable seccomp to safely compute untrusted bytecode"
 	depends on PROC_FS
arch/mips/Makefile +4 -0
index 2f2eac2..431283d 100644
@@ -646,6 +646,10 @@ else
 load-$(CONFIG_CPU_CAVIUM_OCTEON) 	+= 0xffffffff81100000
 endif
 
+ifdef CONFIG_PHYSICAL_START
+load-y                                  = $(CONFIG_PHYSICAL_START)
+endif
+
 cflags-y			+= -I$(srctree)/arch/mips/include/asm/mach-generic
 drivers-$(CONFIG_PCI)		+= arch/mips/pci/
 
arch/mips/include/asm/kexec.h +27 -4
index 4314892..e9eba1a 100644
@@ -9,22 +9,45 @@
 #ifndef _MIPS_KEXEC
 # define _MIPS_KEXEC
 
+#include <asm/stacktrace.h>
+
+extern unsigned long long elfcorehdr_addr;
+
 /* Maximum physical address we can use pages from */
 #define KEXEC_SOURCE_MEMORY_LIMIT (0x20000000)
 /* Maximum address we can reach in physical address mode */
 #define KEXEC_DESTINATION_MEMORY_LIMIT (0x20000000)
  /* Maximum address we can use for the control code buffer */
 #define KEXEC_CONTROL_MEMORY_LIMIT (0x20000000)
-
-#define KEXEC_CONTROL_PAGE_SIZE 4096
+/* Reserve 3*4096 bytes for board-specific info */
+#define KEXEC_CONTROL_PAGE_SIZE (4096 + 3*4096)
 
 /* The native architecture */
 #define KEXEC_ARCH KEXEC_ARCH_MIPS
+#define MAX_NOTE_BYTES 1024
 
 static inline void crash_setup_regs(struct pt_regs *newregs,
-				    struct pt_regs *oldregs)
+					struct pt_regs *oldregs)
 {
-	/* Dummy implementation for now */
+	if (oldregs)
+		memcpy(newregs, oldregs, sizeof(*newregs));
+	else
+		prepare_frametrace(newregs);
 }
 
+#ifdef CONFIG_KEXEC
+struct kimage;
+extern unsigned long kexec_args[4];
+extern int (*_machine_kexec_prepare)(struct kimage *);
+extern void (*_machine_kexec_shutdown)(void);
+extern void (*_machine_crash_shutdown)(struct pt_regs *regs);
+extern void default_machine_crash_shutdown(struct pt_regs *regs);
+#ifdef CONFIG_SMP
+extern const unsigned char kexec_smp_wait[];
+extern unsigned long secondary_kexec_args[4];
+extern void (*relocated_kexec_smp_wait) (void *);
+extern atomic_t kexec_ready_to_reboot;
+#endif
+#endif
+
 #endif /* !_MIPS_KEXEC */
arch/mips/include/asm/smp.h +7 -0
index af42385..9b50048 100644
@@ -40,6 +40,8 @@ extern int __cpu_logical_map[NR_CPUS];
 #define SMP_CALL_FUNCTION	0x2
 /* Octeon - Tell another core to flush its icache */
 #define SMP_ICACHE_FLUSH	0x4
+/* Used by kexec crashdump to save all cpu's state */
+#define SMP_DUMP		0x8
 
 extern volatile cpumask_t cpu_callin_map;
 
@@ -91,4 +93,9 @@ static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
 	mp_ops->send_ipi_mask(mask, SMP_CALL_FUNCTION);
 }
 
+extern void core_send_ipi(int cpu, unsigned int action);
+#if defined(CONFIG_KEXEC)
+extern void (*dump_ipi_function_ptr)(void *);
+void dump_send_ipi(void (*dump_ipi_callback)(void *));
+#endif
 #endif /* __ASM_SMP_H */
arch/mips/kernel/Makefile +2 -1
index ef20957..7ae634d 100644
@@ -91,7 +91,8 @@ obj-$(CONFIG_I8253)		+= i8253.o
 
 obj-$(CONFIG_GPIO_TXX9)		+= gpio_txx9.o
 
-obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o crash.o
+obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 obj-$(CONFIG_SPINLOCK_TEST)	+= spinlock_test.o
 
arch/mips/kernel/crash.c new file +75 -0

75 lines not on this page · raw message

arch/mips/kernel/crash_dump.c new file +86 -0

86 lines not on this page · raw message

arch/mips/kernel/machine_kexec.c +28 -2
index 85beb9b..4d25843 100644
@@ -19,9 +19,19 @@ extern const size_t relocate_new_kernel_size;
 extern unsigned long kexec_start_address;
 extern unsigned long kexec_indirection_page;
 
+int (*_machine_kexec_prepare)(struct kimage *) = NULL;
+void (*_machine_kexec_shutdown)(void) = NULL;
+void (*_machine_crash_shutdown)(struct pt_regs *regs) = NULL;
+#ifdef CONFIG_SMP
+void (*relocated_kexec_smp_wait) (void *);
+atomic_t kexec_ready_to_reboot = ATOMIC_INIT(0);
+#endif
+
 int
 machine_kexec_prepare(struct kimage *kimage)
 {
+	if (_machine_kexec_prepare)
+		return _machine_kexec_prepare(kimage);
 	return 0;
 }
 
@@ -33,11 +43,17 @@ machine_kexec_cleanup(struct kimage *kimage)
 void
 machine_shutdown(void)
 {
+	if (_machine_kexec_shutdown)
+		_machine_kexec_shutdown();
 }
 
 void
 machine_crash_shutdown(struct pt_regs *regs)
 {
+	if (_machine_crash_shutdown)
+		_machine_crash_shutdown(regs);
+	else
+		default_machine_crash_shutdown(regs);
 }
 
 typedef void (*noretfun_t)(void) __attribute__((noreturn));
@@ -52,7 +68,9 @@ machine_kexec(struct kimage *image)
 	reboot_code_buffer =
 	  (unsigned long)page_address(image->control_code_page);
 
-	kexec_start_address = image->start;
+	kexec_start_address =
+		(unsigned long) phys_to_virt(image->start);
+
 	kexec_indirection_page =
 		(unsigned long) phys_to_virt(image->head & PAGE_MASK);
 
@@ -63,7 +81,7 @@ machine_kexec(struct kimage *image)
 	 * The generic kexec code builds a page list with physical
 	 * addresses. they are directly accessible through KSEG0 (or
 	 * CKSEG0 or XPHYS if on 64bit system), hence the
-	 * pys_to_virt() call.
+	 * phys_to_virt() call.
 	 */
 	for (ptr = &image->head; (entry = *ptr) && !(entry &IND_DONE);
 	     ptr = (entry & IND_INDIRECTION) ?
@@ -81,5 +99,13 @@ machine_kexec(struct kimage *image)
 	printk("Will call new kernel at %08lx\n", image->start);
 	printk("Bye ...\n");
 	__flush_cache_all();
+#ifdef CONFIG_SMP
+	/* All secondary cpus now may jump to kexec_wait cycle */
+	relocated_kexec_smp_wait = reboot_code_buffer +
+		(void *)(kexec_smp_wait - relocate_new_kernel);
+	smp_wmb();
+	atomic_set(&kexec_ready_to_reboot, 1);
+#endif
 	((noretfun_t) reboot_code_buffer)();
 }
+
arch/mips/kernel/relocate_kernel.S +87 -1

110 lines not on this page · raw message

arch/mips/kernel/setup.c +55 -0

83 lines not on this page · raw message

arch/mips/kernel/smp.c +18 -0
index 6cdca19..e2f4d53 100644
@@ -402,3 +402,21 @@ void flush_tlb_one(unsigned long vaddr)
 
 EXPORT_SYMBOL(flush_tlb_page);
 EXPORT_SYMBOL(flush_tlb_one);
+
+#if defined(CONFIG_KEXEC)
+void (*dump_ipi_function_ptr)(void *) = NULL;
+void dump_send_ipi(void (*dump_ipi_callback)(void *))
+{
+	int i;
+	int cpu = smp_processor_id();
+
+	dump_ipi_function_ptr = dump_ipi_callback;
+	smp_mb();
+	for_each_online_cpu(i)
+		if (i != cpu)
+			core_send_ipi(i, SMP_DUMP);
+
+}
+EXPORT_SYMBOL(dump_send_ipi);
+#endif
+

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw

PATCH 2/2 MIPS Cavium Octeon board kexec,kdump support

Hello folks,

Please find here MIPS crash and kdump patches. This is patch set of 3 patches:
1. generic MIPS changes (kernel);
2. MIPS Cavium Octeon board kexec/kdump code (kernel);
3. Kexec user space MIPS changes.

Patches were tested on the latest linux-mips@ git kernel and the latest kexec-tools git on Cavium Octeon 50xx board.

I also made the same code working on RMI XLR/XLS boards for both mips32 and mips64 kernels.

Best regards,
Maxim Uvarov.

---

 arch/mips/cavium-octeon/dma-octeon.c             |    6 
 arch/mips/cavium-octeon/executive/cvmx-bootmem.c |    5 
 arch/mips/cavium-octeon/setup.c                  |  309 +++++++++++++++++++++-
 arch/mips/cavium-octeon/smp.c                    |    5 
 arch/mips/include/asm/octeon/cvmx-bootmem.h      |    2 
 arch/mips/kernel/relocate_kernel.S               |   19 +
 6 files changed, 326 insertions(+), 20 deletions(-)
arch/mips/cavium-octeon/dma-octeon.c +4 -2
index be531ec..679d7b5 100644
@@ -105,7 +105,8 @@ dma_addr_t octeon_map_dma_mem(struct device *dev, void *ptr, size_t size)
 			pr_warning("dma_map_single: Warning: "
 				   "Mapping memory address that might "
 				   "conflict with devices 0x%llx-0x%llx\n",
-				   physical, physical+size-1);
+				   (unsigned long long) physical,
+				   (unsigned long long) (physical + size - 1));
 		/* The 2nd 256MB is mapped at 256<<20 instead of 0x410000000 */
 		if ((physical >= 0x410000000ull) && physical < 0x420000000ull)
 			result = physical - 0x400000000ull;
@@ -115,7 +116,8 @@ dma_addr_t octeon_map_dma_mem(struct device *dev, void *ptr, size_t size)
 			panic("dma_map_single: Attempt to map address "
 			      "0x%llx-0x%llx, which can't be accessed "
 			      "according to the dma mask 0x%llx\n",
-			      physical, physical+size-1, dma_mask);
+			      physical, (unsigned long long)(physical+size-1),
+			      dma_mask);
 		goto done;
 
 	case OCTEON_DMA_BAR_TYPE_BIG:
arch/mips/cavium-octeon/executive/cvmx-bootmem.c +5 -0
index fdf5f19..1ae35ec 100644
@@ -688,3 +688,8 @@ int64_t cvmx_bootmem_phy_named_block_alloc(uint64_t size, uint64_t min_addr,
 		cvmx_spinlock_unlock((cvmx_spinlock_t *)&(cvmx_bootmem_desc->lock));
 	return addr_allocated;
 }
+
+void *cvmx_bootmem_get_desc(void)
+{
+    return cvmx_bootmem_desc;
+}
arch/mips/cavium-octeon/setup.c +291 -18

393 lines not on this page · raw message

arch/mips/cavium-octeon/smp.c +5 -0
index 51e9802..06fe291 100644
@@ -65,6 +65,11 @@ void octeon_send_ipi_single(int cpu, unsigned int action)
 	cvmx_write_csr(CVMX_CIU_MBOX_SETX(coreid), action);
 }
 
+void core_send_ipi(int cpu, unsigned int action)
+{
+	octeon_send_ipi_single(cpu, action);
+}
+
 static inline void octeon_send_ipi_mask(const struct cpumask *mask,
 					unsigned int action)
 {
arch/mips/include/asm/octeon/cvmx-bootmem.h +2 -0
index 8e708bd..2f3cb9f 100644
@@ -370,4 +370,6 @@ void cvmx_bootmem_lock(void);
  */
 void cvmx_bootmem_unlock(void);
 
+void  *cvmx_bootmem_get_desc(void);
+
 #endif /*   __CVMX_BOOTMEM_H__ */
arch/mips/kernel/relocate_kernel.S +19 -0
index 0abaf7a..961c10b 100644
@@ -78,7 +78,19 @@ done:
  	LONG_S		zero,(t0)
 #endif
 
+#ifdef CONFIG_CPU_CAVIUM_OCTEON
+ 	/* We need to flush I-cache before jumping to new kernel.
+ 	 * Unfortunatelly, this code is cpu-specific.
+ 	 */
+ 	.set push
+ 	.set noreorder
+ 	syncw
+ 	syncw
+ 	synci		0($0)
+ 	.set pop
+#else
 	sync
+#endif
 	/* jump to kexec_start_address */
 	j		s1
 	END(relocate_new_kernel)
@@ -110,7 +122,14 @@ LEAF(kexec_smp_wait)
 1:	LONG_L		s0, (t0)
 	bne		s0, zero,1b
 
+#ifdef CONFIG_CPU_CAVIUM_OCTEON
+	.set push
+	.set noreorder
+	synci		0($0)
+	.set pop
+#else
 	sync
+#endif
 	j		s1
 	END(kexec_smp_wait)
 #endif

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
In reply to Maxim Uvarov

2010/3/3 Maxim Uvarov <[email protected]>:

Quoted 11 lines

Hello folks,

Please find here MIPS crash and kdump patches. This is patch set of 3 patches:
1. generic MIPS changes (kernel);
2. MIPS Cavium Octeon board kexec/kdump code (kernel);
3. Kexec user space MIPS changes.

Patches were tested on the latest linux-mips@ git kernel and the latest kexec-tools git on Cavium Octeon 50xx board.

Quoted 11 lines

I also made the same code working on RMI XLR/XLS boards for both mips32 and mips64 kernels.

Best regards,
Maxim Uvarov.

Hi, Maxim

In XLR series ,

1)How to protect boardinfo and pass it to second kernel ?

2)If all cpus jumped to same entry point , did you change head.s ,if so , how ?

Thank you!

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

2010/3/3 wilbur.chan <[email protected]>:

Quoted 24 lines

2010/3/3 Maxim Uvarov <[email protected]>:

Quoted 11 lines

Hello folks,

Please find here MIPS crash and kdump patches. This is patch set of 3 patches:
1. generic MIPS changes (kernel);
2. MIPS Cavium Octeon board kexec/kdump code (kernel);
3. Kexec user space MIPS changes.

Patches were tested on the latest linux-mips@ git kernel and the latest kexec-tools git on Cavium Octeon 50xx board.

Quoted 11 lines

I also made the same code working on RMI XLR/XLS boards for both mips32 and mips64 kernels.

Best regards,
Maxim Uvarov.

Quoted 6 lines

Hi, Maxim

In XLR series ,

1)How to protect  boardinfo and pass it to second kernel ?

It is very simple. I just looked at physical addresses where boardinfo is and protect this
region. For xls simple add additional exclude region to setup.c static struct boot_mem_map_exclude_region static_exclude_regions[] = {
+ [1] = {0xc000000, 0xd000000 }, /*Bootloader stuctures*/

To pass it to second kernel copy pointer to original psb_info to static variable in beginning of prom_init() and provide this pointer as kexec_args[3].

kexec_args[0] is argc on XLS
kexec_args[1] is argv on XLS

Quoted 2 lines

2)If all cpus jumped to same entry point , did you change head.s, if so , how ?

Please take a look how other platforms do this. You need write .macro kernel_entry_setup which should be located in somewhere is include/asm-mips/mach-rmi. Then you write this macro it will be executed before kernel_entry. So after kexec all cpus jump to this entry point and after they you can do all things what you want:
- make cpu0 boot new kernel and other cpus go to boot slaves procedure;
- take first cpu and make it boot, and all others go to boot slaves procedure;
- boot only cpu0 and infinite loop others cpus (you might want to do this for kdump)

Quoted 4 lines

Thank you!

Signature · 7 lines
Best regards,
Maxim Uvarov

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#4 lore raw
In reply to Maxim Uvarov
Quoted 21 lines · Maxim Uvarov

Hello folks,

Please find here MIPS crash and kdump patches. This is patch set of 3 patches:
1. generic MIPS changes (kernel);
2. MIPS Cavium Octeon board kexec/kdump code (kernel);
3. Kexec user space MIPS changes.

Patches were tested on the latest linux-mips@ git kernel and the latest kexec-tools git on Cavium Octeon 50xx board.

I also made the same code working on RMI XLR/XLS boards for both mips32 and mips64 kernels.

Best regards,
Maxim Uvarov.

---

  arch/mips/Kconfig                  |   24 ++++++++++

[...]

Quoted 4 lines

That Signed-off-by: needs to be just above the '---' not at the end.

David Daney

#5 lore raw

2010/3/3 David Daney <[email protected]>:

Quoted 27 lines · Maxim Uvarov
Quoted 22 lines

Hello folks,

Please find here MIPS crash and kdump patches. This is patch set of 3 patches:
1. generic MIPS changes (kernel);
2. MIPS Cavium Octeon board kexec/kdump code (kernel);
3. Kexec user space MIPS changes.

Patches were tested on the latest linux-mips@ git kernel and the latest kexec-tools git on Cavium Octeon 50xx board.

I also made the same code working on RMI XLR/XLS boards for both mips32 and mips64 kernels.

Best regards,
Maxim Uvarov.

---

 arch/mips/Kconfig                  |   24 ++++++++++

[...]

Quoted 2 lines
Quoted 7 lines
Quoted 2 lines

That Signed-off-by: needs to be just above the '---' not at the end.

David Daney

Thanks David, I corrected stgit email template. I think I don't need resend patches with only this change.

Signature · 7 lines
Best regards,
Maxim Uvarov

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec