Skip to contentSkip to conversation

kexec-tools: ARM kernel crashdump support

PATCH In review Mika Westerberg 2 participants 4 messages May 5, 2010 – May 19, 2010

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

v2 cover kexec-tools: ARM kernel crashdump support

Hello,

These patches bring ARM kernel crashdump support for kexec-tools. Only zImage format is currently supported.

Changes to v1:
- removed virtual address calculation based on phys_offset and moved this to a separate function (phys_to_virt()) which can then be redefined by archs if needed.
- ARM version redefines this function and uses phys_offset for calculating virtual addresses for kernel direct mapped region.

In addition, I have modified sample gdb macros from kernel/Documentation/kdump/gdbmacrox.txt to work with ARM crashdumps. They are included in the end of this email in case someone finds them useful.

Thanks,
MW

Mika Westerberg (2):
kexec: introduce phys_to_virt() function
kexec: implement ARM crashdump support

 kexec/Makefile                    |    2 +
 kexec/arch/arm/Makefile           |    3 +
 kexec/arch/arm/crashdump-arm.c    |  320 +++++++++++++++++++++++++++++++++++++
 kexec/arch/arm/crashdump-arm.h    |   21 +++
 kexec/arch/arm/kexec-arm.c        |    5 -
 kexec/arch/arm/kexec-zImage-arm.c |   47 +++++-
 kexec/arch/arm/phys_to_virt.c     |   20 +++
 kexec/crashdump-elf.c             |    2 +-
 kexec/crashdump.h                 |    3 +
 kexec/phys_to_virt.c              |   16 ++
 10 files changed, 431 insertions(+), 8 deletions(-)
 create mode 100644 kexec/arch/arm/crashdump-arm.c
 create mode 100644 kexec/arch/arm/crashdump-arm.h
 create mode 100644 kexec/arch/arm/phys_to_virt.c
 create mode 100644 kexec/phys_to_virt.c

------------------------- ~/.gdbinit ------------------------- #
# Useful gdb macros for ARM kdumps. Derived from macros

# in Documentation/kdump/gdbmacros.txt.
#
# Credits:
# Alexander Nyberg <[email protected]>
# V Srivatsa <[email protected]>
# Maneesh Soni <[email protected]>
# Mika Westerberg <[email protected]>
#

define arch_current_thread_info

	set $current_thread_info = \
		(struct thread_info *)((unsigned long)$sp & ~(8192-1))

end

define current

	arch_current_thread_info

	set $current = $current_thread_info->task

end

define ps

	set $tasks_off=((size_t)&((struct task_struct *)0)->tasks)
	set $init_t=&init_task
	set $next_t=(((char *)($init_t->tasks).next) - $tasks_off)

	# get current task
	current

	printf "PID        COMMAND              TASK\n"

	while ($next_t != $init_t)
		set $next_t=(struct task_struct *)$next_t

		printf "%-10d %-20s 0x%x", $next_t->pid, $next_t->comm, $next_t
		if ($next_t == $current)
			printf "*\n"
		else
			printf "\n"
		end

		set $next_t=(char *)($next_t->tasks.next) - $tasks_off
	end

end

define dmesg

	set $i = 0
	set $end_idx = (log_end - 1) & (log_buf_len - 1)

	while ($i < logged_chars)
		set $idx = (log_end - 1 - logged_chars + $i) & (log_buf_len - 1)

		if ($idx + 100 <= $end_idx) || \
		   ($end_idx <= $idx && $idx + 100 < log_buf_len)
			printf "%.100s", &log_buf[$idx]
			set $i = $i + 100
		else
			printf "%c", log_buf[$idx]
			set $i = $i + 1
		end
	end

end
document dmesg
print the kernel ring buffer
end

define lsfs

	set $fs = file_systems

	while ($fs != 0)
		printf "%-20s %p\n", $fs->name, $fs
		set $fs = $fs->next
	end

end
document lsfs
prints registered filesystems
end

define print_mount_path

	if ($arg0 != $arg1->d_parent)
		print_mount_path $arg0->d_parent $arg1
	end
	if ($arg0->d_name.name[0] != '/')
		printf "/%s", $arg0->d_name.name
	end

end

define print_mount

	if ($arg0 != $arg1)
		print_mount $arg0->mnt_parent $arg1
	end

	print_mount_path $arg0->mnt_mountpoint $arg0->mnt_mountpoint->d_parent

end

define mounts

	current
	set $vfsmount_off=((size_t)&((struct vfsmount *)0)->mnt_list)
	set $root = $current->nsproxy->mnt_ns->root
	set $r_prev = $root->mnt_list.prev
	set $r_next = $root->mnt_list.next
	set $mnt=(struct vfsmount *)((char *)($r_next) - $vfsmount_off)
	while ($r_next != $r_prev)
		printf "%-20s %p %-10s ", $mnt->mnt_devname, $mnt, $mnt->mnt_sb->s_id
		if ($mnt->mnt_parent == $root)
			printf "/"
		else
			print_mount $mnt $root
		end
		printf "\n"

		set $r_next = $mnt->mnt_list.next
		set $mnt=(struct vfsmount *)((char *)($r_next) - $vfsmount_off)
	end

end
document mounts
prints out all mounts
end

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

#1 lore raw

PATCH v2 1/2 kexec: introduce phys_to_virt() function

This function is used by ELF crashdump code which prepares crash memory headers for the dump capture kernel. Most architecture can use default version which just adds PAGE_OFFSET to the virtual address but some architectures might need some special handling.

---
 kexec/Makefile        |    2 ++
 kexec/crashdump-elf.c |    2 +-
 kexec/crashdump.h     |    3 +++
 kexec/phys_to_virt.c  |   16 ++++++++++++++++
 4 files changed, 22 insertions(+), 1 deletions(-)
 create mode 100644 kexec/phys_to_virt.c
kexec/Makefile +2 -0
index 4e091ba..77f37ae 100644
@@ -39,6 +39,8 @@ $(ARCH)_PROC_IOMEM		= kexec/proc_iomem.c
 KEXEC_SRCS += $($(ARCH)_PROC_IOMEM)
 $(ARCH)_VIRT_TO_PHYS		= kexec/virt_to_phys.c
 KEXEC_SRCS += $($(ARCH)_VIRT_TO_PHYS)
+$(ARCH)_PHYS_TO_VIRT		= kexec/phys_to_virt.c
+KEXEC_SRCS += $($(ARCH)_PHYS_TO_VIRT)
 $(ARCH)_ADD_SEGMENT		= kexec/add_segment.c
 KEXEC_SRCS += $($(ARCH)_ADD_SEGMENT)
 $(ARCH)_ADD_BUFFER		= kexec/add_buffer.c
kexec/crashdump-elf.c +1 -1
index 6bcef8d..f000e42 100644
@@ -236,7 +236,7 @@ int FUNC(struct kexec_info *info,
 		 * memory region.
 		 */
 		phdr->p_paddr = mstart;
-		phdr->p_vaddr = mstart + elf_info->page_offset;
+		phdr->p_vaddr = phys_to_virt(elf_info, mstart);
 		phdr->p_filesz	= phdr->p_memsz	= mend - mstart + 1;
 		/* Do we need any alignment of segments? */
 		phdr->p_align	= 0;
kexec/crashdump.h +3 -0
index 30d6f29..b6e60cc 100644
@@ -46,6 +46,9 @@ int crash_create_elf64_headers(struct kexec_info *info,
 
 unsigned long crash_architecture(struct crash_elf_info *elf_info);
 
+unsigned long phys_to_virt(struct crash_elf_info *elf_info,
+			   unsigned long paddr);
+
 int xen_present(void);
 unsigned long xen_architecture(struct crash_elf_info *elf_info);
 int xen_get_nr_phys_cpus(void);
kexec/phys_to_virt.c new file +16 -0
new file mode 100644
index 0000000..91b6d01
@@ -0,0 +1,16 @@
+#include "kexec.h"
+#include "crashdump.h"
+
+/**
+ * phys_to_virt() - translate physical address to virtual address
+ * @paddr: physical address to translate
+ *
+ * For most architectures physical address is simply virtual address minus
+ * PAGE_OFFSET. Architectures that don't follow this convention should provide
+ * their own implementation.
+ */
+unsigned long
+phys_to_virt(struct crash_elf_info *elf_info, unsigned long paddr)
+{
+	return paddr + elf_info->page_offset;
+}
Signature · 7 lines
1.5.6.5


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

PATCH v2 2/2 kexec: implement ARM crashdump support

In reply to Mika Westerberg

Implement support for loading dump capture kernels for ARM architecture. ARM doesn't need any backup memory regions so only elfcore header is allocated from the top of the reserved memory region. Only zImages are supported.

The dump capture kernel needs to be loaded to physical address corresponding to the memory region reserved with 'crashkernel=size@start' kernel command line parameter.

---
 kexec/arch/arm/Makefile           |    3 +
 kexec/arch/arm/crashdump-arm.c    |  320 +++++++++++++++++++++++++++++++++++++
 kexec/arch/arm/crashdump-arm.h    |   21 +++
 kexec/arch/arm/kexec-arm.c        |    5 -
 kexec/arch/arm/kexec-zImage-arm.c |   47 +++++-
 kexec/arch/arm/phys_to_virt.c     |   20 +++
 6 files changed, 409 insertions(+), 7 deletions(-)
 create mode 100644 kexec/arch/arm/crashdump-arm.c
 create mode 100644 kexec/arch/arm/crashdump-arm.h
 create mode 100644 kexec/arch/arm/phys_to_virt.c
kexec/arch/arm/Makefile +3 -0
index 2ecdb66..7419621 100644
@@ -5,8 +5,11 @@ arm_KEXEC_SRCS=  kexec/arch/arm/kexec-elf-rel-arm.c
 arm_KEXEC_SRCS+= kexec/arch/arm/kexec-zImage-arm.c
 arm_KEXEC_SRCS+= kexec/arch/arm/kexec-uImage-arm.c
 arm_KEXEC_SRCS+= kexec/arch/arm/kexec-arm.c
+arm_KEXEC_SRCS+= kexec/arch/arm/crashdump-arm.c
 arm_KEXEC_SRCS+= kexec/kexec-uImage.c
 
+arm_PHYS_TO_VIRT = kexec/arch/arm/phys_to_virt.c
+
 dist += kexec/arch/arm/Makefile $(arm_KEXEC_SRCS)			\
 	kexec/arch/arm/kexec-arm.h					\
 	kexec/arch/arm/include/arch/options.h
kexec/arch/arm/crashdump-arm.c new file +320 -0

320 lines not on this page · raw message

kexec/arch/arm/crashdump-arm.h new file +21 -0
new file mode 100644
index 0000000..a2e7824
@@ -0,0 +1,21 @@
+#ifndef CRASHDUMP_ARM_H
+#define CRASHDUMP_ARM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define COMMAND_LINE_SIZE	1024
+#define PAGE_OFFSET		0xc0000000
+#define CRASH_MAX_MEMORY_RANGES	32
+
+struct kexec_info;
+
+extern unsigned long phys_offset;
+extern int load_crashdump_segments(struct kexec_info *, char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CRASHDUMP_ARM_H */
kexec/arch/arm/kexec-arm.c +0 -5
index 06ed8fd..55c76a6 100644
@@ -121,8 +121,3 @@ int arch_compat_trampoline(struct kexec_info *UNUSED(info))
 void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
-
-int is_crashkernel_mem_reserved(void)
-{
-	return 0; /* kdump is not supported on this platform (yet) */
-}
kexec/arch/arm/kexec-zImage-arm.c +45 -2

68 lines not on this page · raw message

kexec/arch/arm/phys_to_virt.c new file +20 -0
new file mode 100644
index 0000000..bcced52
@@ -0,0 +1,20 @@
+#include "../../kexec.h"
+#include "../../crashdump.h"
+#include "crashdump-arm.h"
+
+/**
+ * phys_to_virt() - translate physical address to virtual address
+ * @paddr: physical address to translate
+ *
+ * For ARM we have following equation to translate from virtual address to
+ * physical:
+ *	paddr = vaddr - PAGE_OFFSET + PHYS_OFFSET
+ *
+ * See also:
+ * http://lists.arm.linux.org.uk/lurker/message/20010723.185051.94ce743c.en.html
+ */
+unsigned long
+phys_to_virt(struct crash_elf_info *elf_info, unsigned long paddr)
+{
+	return paddr + elf_info->page_offset - phys_offset;
+}
Signature · 7 lines
1.5.6.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw
In reply to Mika Westerberg
Quoted 12 lines · Mika Westerberg

Hello,

These patches bring ARM kernel crashdump support for kexec-tools. Only zImage format is currently supported.

Changes to v1:
- removed virtual address calculation based on phys_offset and moved this to a separate function (phys_to_virt()) which can then be redefined by archs if needed.
- ARM version redefines this function and uses phys_offset for calculating virtual addresses for kernel direct mapped region.

Quoted 3 lines

In addition, I have modified sample gdb macros from kernel/Documentation/kdump/gdbmacrox.txt to work with ARM crashdumps. They are included in the end of this email in case someone finds them useful.

Thanks, both patches applied.

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