Blame SOURCES/kexec-tools-2.0.7-makedumpfile-Support-ARM64.patch

a6d77e
From 145707b5b6495467515cb6f3e0814df81cb55404 Mon Sep 17 00:00:00 2001
a6d77e
Message-Id: <145707b5b6495467515cb6f3e0814df81cb55404.1431708455.git.panand@redhat.com>
a6d77e
From: Pratyush Anand <panand@redhat.com>
a6d77e
Date: Tue, 28 Apr 2015 15:15:15 +0530
a6d77e
Subject: [PATCH] makedumpfile: Support ARM64
a6d77e
a6d77e
Patch adds support for ARM64 in makedumpfile. It takes care of vmalloc,
a6d77e
vmemmap, module and directly map kernel memory region's translation.
a6d77e
a6d77e
Signed-off-by: Pratyush Anand <panand@redhat.com>
a6d77e
---
a6d77e
 Makefile       |   1 +
a6d77e
 arch/arm64.c   | 259 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
a6d77e
 makedumpfile.h |  49 +++++++++++
a6d77e
 3 files changed, 309 insertions(+)
a6d77e
 create mode 100644 arch/arm64.c
a6d77e
a6d77e
diff --git a/makedumpfile-1.5.7/Makefile b/makedumpfile-1.5.7/Makefile
a6d77e
index e45c3cfe5e9d..b8d77dbad856 100644
a6d77e
--- a/makedumpfile-1.5.7/Makefile
a6d77e
+++ b/makedumpfile-1.5.7/Makefile
a6d77e
@@ -49,6 +49,7 @@ SRC_BASE = makedumpfile.c makedumpfile.h diskdump_mod.h sadump_mod.h sadump_info
a6d77e
 SRC_PART = print_info.c dwarf_info.c elf_info.c erase_info.c sadump_info.c cache.c
a6d77e
 OBJ_PART=$(patsubst %.c,%.o,$(SRC_PART))
a6d77e
 SRC_ARCH = arch/arm.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c
a6d77e
+SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c
a6d77e
 OBJ_ARCH=$(patsubst %.c,%.o,$(SRC_ARCH))
a6d77e
 
a6d77e
 LIBS = -ldw -lbz2 -lebl -ldl -lelf -lz
a6d77e
diff --git a/makedumpfile-1.5.7/arch/arm64.c b/makedumpfile-1.5.7/arch/arm64.c
a6d77e
new file mode 100644
a6d77e
index 000000000000..28e2adef7ae3
a6d77e
--- /dev/null
a6d77e
+++ b/makedumpfile-1.5.7/arch/arm64.c
a6d77e
@@ -0,0 +1,259 @@
a6d77e
+/*
a6d77e
+ * arch/arm64.c : Based on arch/arm.c
a6d77e
+ *
a6d77e
+ * Copyright (C) 2015 Red Hat, Pratyush Anand <panand@redhat.com>
a6d77e
+ *
a6d77e
+ * This program is free software; you can redistribute it and/or modify
a6d77e
+ * it under the terms of the GNU General Public License as published by
a6d77e
+ * the Free Software Foundation (version 2 of the License).
a6d77e
+ *
a6d77e
+ * This program is distributed in the hope that it will be useful,
a6d77e
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
a6d77e
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a6d77e
+ * GNU General Public License for more details.
a6d77e
+ *
a6d77e
+ * You should have received a copy of the GNU General Public License
a6d77e
+ * along with this program; if not, write to the Free Software
a6d77e
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a6d77e
+ */
a6d77e
+
a6d77e
+#ifdef __aarch64__
a6d77e
+
a6d77e
+#include "../elf_info.h"
a6d77e
+#include "../makedumpfile.h"
a6d77e
+#include "../print_info.h"
a6d77e
+
a6d77e
+#if CONFIG_ARM64_PGTABLE_LEVELS == 2
a6d77e
+typedef struct {
a6d77e
+	unsigned long pgd;
a6d77e
+} pgd_t;
a6d77e
+
a6d77e
+typedef struct {
a6d77e
+	pgd_t pgd;
a6d77e
+} pud_t;
a6d77e
+
a6d77e
+typedef struct {
a6d77e
+	pud_t pud;
a6d77e
+} pmd_t;
a6d77e
+
a6d77e
+#define pud_offset(pgd, vaddr) 	((pud_t *)pgd)
a6d77e
+#define pmd_offset(pud, vaddr) 	((pmd_t *)pud)
a6d77e
+#define pgd_val(x)		((x).pgd)
a6d77e
+#define pud_val(x)		(pgd_val((x).pgd))
a6d77e
+#define pmd_val(x)		(pud_val((x).pud))
a6d77e
+
a6d77e
+#define PUD_SHIFT		PGDIR_SHIFT
a6d77e
+#define PUD_SIZE		(1UL << PUD_SHIFT)
a6d77e
+
a6d77e
+#endif
a6d77e
+
a6d77e
+typedef struct {
a6d77e
+	unsigned long pte;
a6d77e
+} pte_t;
a6d77e
+#define pte_val(x)		((x).pte)
a6d77e
+
a6d77e
+#define PAGE_SIZE		(1UL << PAGE_SHIFT)
a6d77e
+#define PAGE_MASK		(~(PAGE_SIZE - 1))
a6d77e
+#define PGDIR_SHIFT		((PAGE_SHIFT - 3) * ARM64_PGTABLE_LEVELS + 3)
a6d77e
+#define PTRS_PER_PGD		(1 << (VA_BITS - PGDIR_SHIFT))
a6d77e
+#define PMD_SHIFT		((PAGE_SHIFT - 3) * 2 + 3)
a6d77e
+#define PTRS_PER_PTE		(1 << (PAGE_SHIFT - 3))
a6d77e
+#define PMD_SHIFT		((PAGE_SHIFT - 3) * 2 + 3)
a6d77e
+#define PMD_SIZE		(1UL << PMD_SHIFT)
a6d77e
+#define PMD_MASK		(~(PMD_SIZE - 1))
a6d77e
+#define PTRS_PER_PMD		PTRS_PER_PTE
a6d77e
+
a6d77e
+#define PAGE_PRESENT		(1 << 0)
a6d77e
+#define SECTIONS_SIZE_BITS	30
a6d77e
+/*
a6d77e
+
a6d77e
+* Highest possible physical address supported.
a6d77e
+*/
a6d77e
+#define PHYS_MASK_SHIFT		48
a6d77e
+#define PHYS_MASK		((1UL << PHYS_MASK_SHIFT) - 1)
a6d77e
+
a6d77e
+#define PMD_TYPE_MASK		3
a6d77e
+#define PMD_TYPE_SECT		1
a6d77e
+#define PMD_TYPE_TABLE		3
a6d77e
+
a6d77e
+#define __va(paddr) 			((paddr) - info->phys_base + PAGE_OFFSET)
a6d77e
+#define __pa(vaddr) 			((vaddr) - PAGE_OFFSET + info->phys_base)
a6d77e
+
a6d77e
+#define pgd_index(vaddr) 		(((vaddr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
a6d77e
+#define pgd_offset(pgdir, vaddr)	((pgd_t *)(pgdir) + pgd_index(vaddr))
a6d77e
+
a6d77e
+#define pte_index(addr) 		(((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
a6d77e
+#define pmd_page_vaddr(pmd)		(__va(pmd_val(pmd) & PHYS_MASK & (int32_t)PAGE_MASK))
a6d77e
+#define pte_offset(dir, vaddr) 		((pte_t*)pmd_page_vaddr((*dir)) + pte_index(vaddr))
a6d77e
+
a6d77e
+/* kernel struct page size can be kernel version dependent, currently
a6d77e
+ * keep it constant.
a6d77e
+ */
a6d77e
+#define KERN_STRUCT_PAGE_SIZE		64
a6d77e
+#define ALIGN(x, a) 			(((x) + (a) - 1) & ~((a) - 1))
a6d77e
+#define PFN_DOWN(x)			((x) >> PAGE_SHIFT)
a6d77e
+#define VMEMMAP_SIZE			ALIGN((1UL << (VA_BITS - PAGE_SHIFT)) * KERN_STRUCT_PAGE_SIZE, PUD_SIZE)
a6d77e
+#define MODULES_END			PAGE_OFFSET
a6d77e
+#define MODULES_VADDR			(MODULES_END - 0x4000000)
a6d77e
+
a6d77e
+int is_vmalloc_addr(unsigned long vaddr)
a6d77e
+{
a6d77e
+	return (vaddr >= VMALLOC_START && vaddr <= VMALLOC_END);
a6d77e
+}
a6d77e
+
a6d77e
+static int is_vtop_from_page_table_arm64(unsigned long vaddr)
a6d77e
+{
a6d77e
+	/* If virtual address lies in vmalloc, vmemmap or module space
a6d77e
+	 * region then, get the physical address from page table.
a6d77e
+	 */
a6d77e
+	return ((vaddr >= VMALLOC_START && vaddr <= VMALLOC_END)
a6d77e
+		|| (vaddr >= VMEMMAP_START && vaddr <= VMEMMAP_END)
a6d77e
+		|| (vaddr >= MODULES_VADDR && vaddr <= MODULES_END));
a6d77e
+}
a6d77e
+
a6d77e
+int get_phys_base_arm64(void)
a6d77e
+{
a6d77e
+	unsigned long phys_base = ULONG_MAX;
a6d77e
+	unsigned long long phys_start;
a6d77e
+	int i;
a6d77e
+	/*
a6d77e
+	 * We resolve phys_base from PT_LOAD segments. LMA contains physical
a6d77e
+	 * address of the segment, and we use the lowest start as
a6d77e
+	 * phys_base.
a6d77e
+	 */
a6d77e
+	for (i = 0; get_pt_load(i, &phys_start, NULL, NULL, NULL); i++) {
a6d77e
+		if (phys_start < phys_base)
a6d77e
+			phys_base = phys_start;
a6d77e
+	}
a6d77e
+
a6d77e
+	if (phys_base == ULONG_MAX) {
a6d77e
+		ERRMSG("Can't determine phys_base\n");
a6d77e
+		return FALSE;
a6d77e
+	}
a6d77e
+
a6d77e
+	info->phys_base = phys_base;
a6d77e
+
a6d77e
+	DEBUG_MSG("phys_base    : %lx\n", phys_base);
a6d77e
+
a6d77e
+	return TRUE;
a6d77e
+}
a6d77e
+
a6d77e
+int get_machdep_info_arm64(void)
a6d77e
+{
a6d77e
+	info->max_physmem_bits = PHYS_MASK_SHIFT;
a6d77e
+	info->section_size_bits = SECTIONS_SIZE_BITS;
a6d77e
+	info->page_offset = KVBASE;
a6d77e
+	info->vmalloc_start = 0xffffffffffffffffUL << VA_BITS;
a6d77e
+	info->vmalloc_end = PAGE_OFFSET - PUD_SIZE - VMEMMAP_SIZE - 0x10000;
a6d77e
+	info->vmemmap_start = VMALLOC_END + 0x10000;
a6d77e
+	info->vmemmap_end = VMEMMAP_START + VMEMMAP_SIZE;
a6d77e
+
a6d77e
+	DEBUG_MSG("max_physmem_bits : %lx\n", info->max_physmem_bits);
a6d77e
+	DEBUG_MSG("section_size_bits: %lx\n", info->section_size_bits);
a6d77e
+	DEBUG_MSG("page_offset      : %lx\n", info->page_offset);
a6d77e
+	DEBUG_MSG("vmalloc_start    : %lx\n", info->vmalloc_start);
a6d77e
+	DEBUG_MSG("vmalloc_end      : %lx\n", info->vmalloc_end);
a6d77e
+	DEBUG_MSG("vmemmap_start    : %lx\n", info->vmemmap_start);
a6d77e
+	DEBUG_MSG("vmemmap_end      : %lx\n", info->vmemmap_end);
a6d77e
+	DEBUG_MSG("modules_start    : %lx\n", MODULES_VADDR);
a6d77e
+	DEBUG_MSG("modules_end      : %lx\n", MODULES_END);
a6d77e
+
a6d77e
+	return TRUE;
a6d77e
+}
a6d77e
+
a6d77e
+unsigned long long kvtop_xen_arm64(unsigned long kvaddr)
a6d77e
+{
a6d77e
+	return ERROR;
a6d77e
+}
a6d77e
+
a6d77e
+int get_xen_basic_info_arm64(void)
a6d77e
+{
a6d77e
+	return ERROR;
a6d77e
+}
a6d77e
+
a6d77e
+int get_xen_info_arm64(void)
a6d77e
+{
a6d77e
+	return ERROR;
a6d77e
+}
a6d77e
+
a6d77e
+int get_versiondep_info_arm64(void)
a6d77e
+{
a6d77e
+	return TRUE;
a6d77e
+}
a6d77e
+
a6d77e
+/*
a6d77e
+ * vtop_arm64() - translate arbitrary virtual address to physical
a6d77e
+ * @vaddr: virtual address to translate
a6d77e
+ *
a6d77e
+ * Function translates @vaddr into physical address using page tables. This
a6d77e
+ * address can be any virtual address. Returns physical address of the
a6d77e
+ * corresponding virtual address or %NOT_PADDR when there is no translation.
a6d77e
+ */
a6d77e
+static unsigned long long vtop_arm64(unsigned long vaddr)
a6d77e
+{
a6d77e
+	unsigned long long paddr = NOT_PADDR;
a6d77e
+	pgd_t	*pgda, pgdv;
a6d77e
+	pud_t	*puda;
a6d77e
+	pmd_t	*pmda, pmdv;
a6d77e
+	pte_t 	*ptea, ptev;
a6d77e
+
a6d77e
+	if (SYMBOL(swapper_pg_dir) == NOT_FOUND_SYMBOL) {
a6d77e
+		ERRMSG("Can't get the symbol of swapper_pg_dir.\n");
a6d77e
+		return NOT_PADDR;
a6d77e
+	}
a6d77e
+
a6d77e
+	pgda = pgd_offset(SYMBOL(swapper_pg_dir), vaddr);
a6d77e
+	if (!readmem(VADDR, (unsigned long long)pgda, &pgdv, sizeof(pgdv))) {
a6d77e
+		ERRMSG("Can't read pgd\n");
a6d77e
+		return NOT_PADDR;
a6d77e
+	}
a6d77e
+
a6d77e
+	puda = pud_offset(pgda, vaddr);
a6d77e
+	pmda = pmd_offset(puda, vaddr);
a6d77e
+	if (!readmem(VADDR, (unsigned long long)pmda, &pmdv, sizeof(pmdv))) {
a6d77e
+		ERRMSG("Can't read pmd\n");
a6d77e
+		return NOT_PADDR;
a6d77e
+	}
a6d77e
+
a6d77e
+	switch (pmd_val(pmdv) & PMD_TYPE_MASK) {
a6d77e
+	case PMD_TYPE_TABLE:
a6d77e
+		ptea = pte_offset(&pmdv, vaddr);
a6d77e
+		/* 64k page */
a6d77e
+		if (!readmem(VADDR, (unsigned long long)ptea, &ptev, sizeof(ptev))) {
a6d77e
+			ERRMSG("Can't read pte\n");
a6d77e
+			return NOT_PADDR;
a6d77e
+		}
a6d77e
+
a6d77e
+		if (!(pte_val(ptev) & PAGE_PRESENT)) {
a6d77e
+			ERRMSG("Can't get a valid pte.\n");
a6d77e
+			return NOT_PADDR;
a6d77e
+		} else {
a6d77e
+
a6d77e
+			paddr = (PAGEBASE(pte_val(ptev)) & PHYS_MASK)
a6d77e
+					+ (vaddr & (PAGESIZE() - 1));
a6d77e
+		}
a6d77e
+		break;
a6d77e
+	case PMD_TYPE_SECT:
a6d77e
+		/* 1GB section */
a6d77e
+		paddr = (pmd_val(pmdv) & PMD_MASK) + (vaddr & (PMD_SIZE - 1));
a6d77e
+		break;
a6d77e
+	}
a6d77e
+
a6d77e
+	return paddr;
a6d77e
+}
a6d77e
+
a6d77e
+unsigned long long vaddr_to_paddr_arm64(unsigned long vaddr)
a6d77e
+{
a6d77e
+	/*
a6d77e
+	 * use translation tables when a) user has explicitly requested us to
a6d77e
+	 * perform translation for a given address. b) virtual address lies in
a6d77e
+	 * vmalloc, vmemmap or modules memory region. Otherwise we assume that
a6d77e
+	 * the translation is done within the kernel direct mapped region.
a6d77e
+	 */
a6d77e
+	if ((info->vaddr_for_vtop == vaddr) ||
a6d77e
+			is_vtop_from_page_table_arm64(vaddr))
a6d77e
+		return vtop_arm64(vaddr);
a6d77e
+
a6d77e
+	return __pa(vaddr);
a6d77e
+}
a6d77e
+#endif
a6d77e
diff --git a/makedumpfile-1.5.7/makedumpfile.h b/makedumpfile-1.5.7/makedumpfile.h
a6d77e
index 96830b071f6e..2af3a8e72e0a 100644
a6d77e
--- a/makedumpfile-1.5.7/makedumpfile.h
a6d77e
+++ b/makedumpfile-1.5.7/makedumpfile.h
a6d77e
@@ -483,6 +483,33 @@ do { \
a6d77e
 #define VMEMMAP_START		(info->vmemmap_start)
a6d77e
 #define VMEMMAP_END		(info->vmemmap_end)
a6d77e
 
a6d77e
+#ifdef __aarch64__
a6d77e
+#define CONFIG_ARM64_PGTABLE_LEVELS	2
a6d77e
+#define CONFIG_ARM64_VA_BITS		42
a6d77e
+#define CONFIG_ARM64_64K_PAGES		1
a6d77e
+
a6d77e
+/* Currently we only suport following defines based on above
a6d77e
+ * config definitions.
a6d77e
+ * TODOs: We need to find a way to get above defines dynamically and
a6d77e
+ * then to support following definitions based on that
a6d77e
+ */
a6d77e
+
a6d77e
+#if CONFIG_ARM64_PGTABLE_LEVELS == 2
a6d77e
+#define ARM64_PGTABLE_LEVELS	2
a6d77e
+#endif
a6d77e
+
a6d77e
+#if CONFIG_ARM64_VA_BITS == 42
a6d77e
+#define VA_BITS			42
a6d77e
+#endif
a6d77e
+
a6d77e
+#ifdef CONFIG_ARM64_64K_PAGES
a6d77e
+#define PAGE_SHIFT		16
a6d77e
+#endif
a6d77e
+
a6d77e
+#define KVBASE_MASK		(0xffffffffffffffffUL << (VA_BITS - 1))
a6d77e
+#define KVBASE			(SYMBOL(_stext) & KVBASE_MASK)
a6d77e
+#endif /* aarch64 */
a6d77e
+
a6d77e
 #ifdef __arm__
a6d77e
 #define KVBASE_MASK		(0xffff)
a6d77e
 #define KVBASE			(SYMBOL(_stext) & ~KVBASE_MASK)
a6d77e
@@ -757,6 +784,23 @@ do { \
a6d77e
 /*
a6d77e
  * The function of dependence on machine
a6d77e
  */
a6d77e
+#ifdef __aarch64__
a6d77e
+int get_phys_base_arm64(void);
a6d77e
+int get_machdep_info_arm64(void);
a6d77e
+unsigned long long vaddr_to_paddr_arm64(unsigned long vaddr);
a6d77e
+int get_versiondep_info_arm64(void);
a6d77e
+int get_xen_basic_info_arm64(void);
a6d77e
+int get_xen_info_arm64(void);
a6d77e
+int is_vmalloc_addr_arm64(unsigned long vaddr);
a6d77e
+#define vaddr_to_paddr(X)	vaddr_to_paddr_arm64(X)
a6d77e
+#define get_phys_base()		get_phys_base_arm64()
a6d77e
+#define get_machdep_info()	get_machdep_info_arm64()
a6d77e
+#define get_versiondep_info()	get_versiondep_info_arm64()
a6d77e
+#define get_xen_basic_info_arch(X) get_xen_basic_info_arm64(X)
a6d77e
+#define get_xen_info_arch(X) 	get_xen_info_arm64(X)
a6d77e
+#define is_vmalloc_addr(X)	is_vmalloc_addr_arm64(X)
a6d77e
+#endif /* aarch64 */
a6d77e
+
a6d77e
 #ifdef __arm__
a6d77e
 int get_phys_base_arm(void);
a6d77e
 int get_machdep_info_arm(void);
a6d77e
@@ -1581,6 +1625,11 @@ struct domain_list {
a6d77e
 #define PAGES_PER_MAPWORD 	(sizeof(unsigned long) * 8)
a6d77e
 #define MFNS_PER_FRAME		(info->page_size / sizeof(unsigned long))
a6d77e
 
a6d77e
+#ifdef __aarch64__
a6d77e
+unsigned long long kvtop_xen_arm64(unsigned long kvaddr);
a6d77e
+#define kvtop_xen(X)	kvtop_xen_arm64(X)
a6d77e
+#endif /* aarch64 */
a6d77e
+
a6d77e
 #ifdef __arm__
a6d77e
 #define kvtop_xen(X)	FALSE
a6d77e
 #define get_xen_basic_info_arch(X) FALSE
a6d77e
-- 
a6d77e
2.1.0
a6d77e