LinuxPPC-Dev Archive on lore.kernel.org
 help / color / Atom feed
From: Hari Bathini <hbathini@linux.ibm.com>
To: linuxppc-dev <linuxppc-dev@ozlabs.org>
Cc: Ananth N Mavinakayanahalli <ananth@linux.ibm.com>,
	Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
	Vasant Hegde <hegdevasant@linux.ibm.com>,
	Oliver <oohall@gmail.com>, Nicholas Piggin <npiggin@gmail.com>,
	Daniel Axtens <dja@axtens.net>
Subject: [PATCH v6 02/36] powerpc/fadump: add helper functions
Date: Wed, 11 Sep 2019 20:16:36 +0530
Message-ID: <156821318971.5656.9281936950510635858.stgit@hbathini.in.ibm.com> (raw)
In-Reply-To: <156821308145.5656.2233728784001623843.stgit@hbathini.in.ibm.com>

Add helper functions to setup & free CPU notes buffer and to find if a
given memory area is contiguous. Also, use boolean as return type for
the function that finds if boot memory area is contiguous. While at
it, save the virtual address of CPU notes buffer instead of physical
address as virtual address is used often.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---

* New patch to add a few helper functions. Also, save vaddr for CPU notes
  buffer in fw_dump structure.


 arch/powerpc/include/asm/fadump-internal.h |    2 
 arch/powerpc/kernel/fadump.c               |  127 +++++++++++++++-------------
 2 files changed, 67 insertions(+), 62 deletions(-)

diff --git a/arch/powerpc/include/asm/fadump-internal.h b/arch/powerpc/include/asm/fadump-internal.h
index 071f377..16e2781 100644
--- a/arch/powerpc/include/asm/fadump-internal.h
+++ b/arch/powerpc/include/asm/fadump-internal.h
@@ -71,7 +71,7 @@ struct fw_dump {
 	unsigned long	boot_memory_size;
 
 	unsigned long	fadumphdr_addr;
-	unsigned long	cpu_notes_buf;
+	unsigned long	cpu_notes_buf_vaddr;
 	unsigned long	cpu_notes_buf_size;
 
 	int		ibm_configure_kernel_dump;
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 7c55044..e2b83a9 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -201,31 +201,29 @@ int is_fadump_active(void)
 }
 
 /*
- * Returns 1, if there are no holes in boot memory area,
- * 0 otherwise.
+ * Returns true, if there are no holes in memory area between d_start to d_end,
+ * false otherwise.
  */
-static int is_boot_memory_area_contiguous(void)
+static bool is_fadump_mem_area_contiguous(u64 d_start, u64 d_end)
 {
 	struct memblock_region *reg;
-	unsigned long tstart, tend;
-	unsigned long start_pfn = PHYS_PFN(RMA_START);
-	unsigned long end_pfn = PHYS_PFN(RMA_START + fw_dump.boot_memory_size);
-	unsigned int ret = 0;
+	bool ret = false;
+	u64 start, end;
 
 	for_each_memblock(memory, reg) {
-		tstart = max(start_pfn, memblock_region_memory_base_pfn(reg));
-		tend = min(end_pfn, memblock_region_memory_end_pfn(reg));
-		if (tstart < tend) {
-			/* Memory hole from start_pfn to tstart */
-			if (tstart > start_pfn)
+		start = max_t(u64, d_start, reg->base);
+		end = min_t(u64, d_end, (reg->base + reg->size));
+		if (d_start < end) {
+			/* Memory hole from d_start to start */
+			if (start > d_start)
 				break;
 
-			if (tend == end_pfn) {
-				ret = 1;
+			if (end == d_end) {
+				ret = true;
 				break;
 			}
 
-			start_pfn = tend + 1;
+			d_start = end + 1;
 		}
 	}
 
@@ -233,32 +231,25 @@ static int is_boot_memory_area_contiguous(void)
 }
 
 /*
+ * Returns true, if there are no holes in boot memory area,
+ * false otherwise.
+ */
+static bool is_boot_memory_area_contiguous(void)
+{
+	return is_fadump_mem_area_contiguous(0, fw_dump.boot_memory_size);
+}
+
+/*
  * Returns true, if there are no holes in reserved memory area,
  * false otherwise.
  */
 static bool is_reserved_memory_area_contiguous(void)
 {
-	struct memblock_region *reg;
-	unsigned long start, end;
-	unsigned long d_start = fw_dump.reserve_dump_area_start;
-	unsigned long d_end = d_start + fw_dump.reserve_dump_area_size;
+	u64 d_start, d_end;
 
-	for_each_memblock(memory, reg) {
-		start = max(d_start, (unsigned long)reg->base);
-		end = min(d_end, (unsigned long)(reg->base + reg->size));
-		if (d_start < end) {
-			/* Memory hole from d_start to start */
-			if (start > d_start)
-				break;
-
-			if (end == d_end)
-				return true;
-
-			d_start = end + 1;
-		}
-	}
-
-	return false;
+	d_start	= fw_dump.reserve_dump_area_start;
+	d_end	= d_start + fw_dump.reserve_dump_area_size;
+	return is_fadump_mem_area_contiguous(d_start, d_end);
 }
 
 /* Print firmware assisted dump configurations for debugging purpose. */
@@ -785,7 +776,7 @@ static void fadump_update_elfcore_header(char *bufp)
 	phdr = (struct elf_phdr *)bufp;
 
 	if (phdr->p_type == PT_NOTE) {
-		phdr->p_paddr = fw_dump.cpu_notes_buf;
+		phdr->p_paddr	= __pa(fw_dump.cpu_notes_buf_vaddr);
 		phdr->p_offset	= phdr->p_paddr;
 		phdr->p_filesz	= fw_dump.cpu_notes_buf_size;
 		phdr->p_memsz = fw_dump.cpu_notes_buf_size;
@@ -793,7 +784,7 @@ static void fadump_update_elfcore_header(char *bufp)
 	return;
 }
 
-static void *fadump_cpu_notes_buf_alloc(unsigned long size)
+static void *fadump_alloc_buffer(unsigned long size)
 {
 	void *vaddr;
 	struct page *page;
@@ -811,7 +802,7 @@ static void *fadump_cpu_notes_buf_alloc(unsigned long size)
 	return vaddr;
 }
 
-static void fadump_cpu_notes_buf_free(unsigned long vaddr, unsigned long size)
+static void fadump_free_buffer(unsigned long vaddr, unsigned long size)
 {
 	struct page *page;
 	unsigned long order, count, i;
@@ -824,6 +815,36 @@ static void fadump_cpu_notes_buf_free(unsigned long vaddr, unsigned long size)
 	__free_pages(page, order);
 }
 
+static s32 fadump_setup_cpu_notes_buf(u32 num_cpus)
+{
+	/* Allocate buffer to hold cpu crash notes. */
+	fw_dump.cpu_notes_buf_size = num_cpus * sizeof(note_buf_t);
+	fw_dump.cpu_notes_buf_size = PAGE_ALIGN(fw_dump.cpu_notes_buf_size);
+	fw_dump.cpu_notes_buf_vaddr =
+		(unsigned long)fadump_alloc_buffer(fw_dump.cpu_notes_buf_size);
+	if (!fw_dump.cpu_notes_buf_vaddr) {
+		pr_err("Failed to allocate %ld bytes for CPU notes buffer\n",
+		       fw_dump.cpu_notes_buf_size);
+		return -ENOMEM;
+	}
+
+	pr_debug("Allocated buffer for cpu notes of size %ld at 0x%lx\n",
+		 fw_dump.cpu_notes_buf_size,
+		 fw_dump.cpu_notes_buf_vaddr);
+	return 0;
+}
+
+static void fadump_free_cpu_notes_buf(void)
+{
+	if (!fw_dump.cpu_notes_buf_vaddr)
+		return;
+
+	fadump_free_buffer(fw_dump.cpu_notes_buf_vaddr,
+			   fw_dump.cpu_notes_buf_size);
+	fw_dump.cpu_notes_buf_vaddr = 0;
+	fw_dump.cpu_notes_buf_size = 0;
+}
+
 /*
  * Read CPU state dump data and convert it into ELF notes.
  * The CPU dump starts with magic number "REGSAVE". NumCpusOffset should be
@@ -870,19 +891,11 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
 	vaddr += sizeof(u32);
 	reg_entry = (struct fadump_reg_entry *)vaddr;
 
-	/* Allocate buffer to hold cpu crash notes. */
-	fw_dump.cpu_notes_buf_size = num_cpus * sizeof(note_buf_t);
-	fw_dump.cpu_notes_buf_size = PAGE_ALIGN(fw_dump.cpu_notes_buf_size);
-	note_buf = fadump_cpu_notes_buf_alloc(fw_dump.cpu_notes_buf_size);
-	if (!note_buf) {
-		printk(KERN_ERR "Failed to allocate 0x%lx bytes for "
-			"cpu notes buffer\n", fw_dump.cpu_notes_buf_size);
-		return -ENOMEM;
-	}
-	fw_dump.cpu_notes_buf = __pa(note_buf);
+	rc = fadump_setup_cpu_notes_buf(num_cpus);
+	if (rc != 0)
+		return rc;
 
-	pr_debug("Allocated buffer for cpu notes of size %ld at %p\n",
-			(num_cpus * sizeof(note_buf_t)), note_buf);
+	note_buf = (u32 *)fw_dump.cpu_notes_buf_vaddr;
 
 	if (fw_dump.fadumphdr_addr)
 		fdh = __va(fw_dump.fadumphdr_addr);
@@ -920,10 +933,7 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
 	return 0;
 
 error_out:
-	fadump_cpu_notes_buf_free((unsigned long)__va(fw_dump.cpu_notes_buf),
-					fw_dump.cpu_notes_buf_size);
-	fw_dump.cpu_notes_buf = 0;
-	fw_dump.cpu_notes_buf_size = 0;
+	fadump_free_cpu_notes_buf();
 	return rc;
 
 }
@@ -1470,13 +1480,8 @@ static void fadump_invalidate_release_mem(void)
 	fw_dump.reserve_dump_area_size = get_fadump_area_size();
 
 	fadump_release_memory(reserved_area_start, reserved_area_end);
-	if (fw_dump.cpu_notes_buf) {
-		fadump_cpu_notes_buf_free(
-				(unsigned long)__va(fw_dump.cpu_notes_buf),
-				fw_dump.cpu_notes_buf_size);
-		fw_dump.cpu_notes_buf = 0;
-		fw_dump.cpu_notes_buf_size = 0;
-	}
+	fadump_free_cpu_notes_buf();
+
 	/* Initialize the kernel dump memory structure for FAD registration. */
 	init_fadump_mem_struct(&fdm, fw_dump.reserve_dump_area_start);
 }


  parent reply index

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-11 14:45 [PATCH v6 00/36] Add FADump support on PowerNV platform Hari Bathini
2019-09-11 14:46 ` [PATCH v6 01/36] powerpc/fadump: move internal macros/definitions to a new header Hari Bathini
2019-09-19 10:25   ` Michael Ellerman
2019-09-11 14:46 ` Hari Bathini [this message]
2019-09-11 14:46 ` [PATCH v6 03/36] powerpc/fadump: declare helper functions in internal header file Hari Bathini
2019-09-11 14:47 ` [PATCH v6 04/36] powerpc/fadump: Improve fadump documentation Hari Bathini
2019-09-11 14:47 ` [PATCH v6 05/36] powerpc/fadump: use helper functions to reserve/release cpu notes buffer Hari Bathini
2019-09-11 14:48 ` [PATCH v6 06/36] pseries/fadump: move rtas specific definitions to platform code Hari Bathini
2019-09-11 14:48 ` [PATCH v6 07/36] pseries/fadump: introduce callbacks for platform specific operations Hari Bathini
2019-09-11 14:48 ` [PATCH v6 08/36] pseries/fadump: define RTAS register/un-register callback functions Hari Bathini
2019-09-11 14:49 ` [PATCH v6 09/36] pseries/fadump: add source info while displaying region contents Hari Bathini
2019-09-11 14:49 ` [PATCH v6 10/36] powerpc/fadump: release all the memory above boot memory size Hari Bathini
2019-09-11 14:49 ` [PATCH v6 11/36] pseries/fadump: move out platform specific support from generic code Hari Bathini
2019-09-11 14:49 ` [PATCH v6 12/36] powerpc/fadump: use FADump instead of fadump for how it is pronounced Hari Bathini
2019-09-11 14:50 ` [PATCH v6 13/36] opal: add MPIPL interface definitions Hari Bathini
2019-09-11 14:50 ` [PATCH v6 14/36] powernv/fadump: add fadump support on powernv Hari Bathini
2019-09-11 14:50 ` [PATCH v6 15/36] powerpc/fadump: improve fadump_reserve_mem() Hari Bathini
2019-09-11 14:50 ` [PATCH v6 16/36] powernv/fadump: register kernel metadata address with opal Hari Bathini
2019-09-11 14:51 ` [PATCH v6 17/36] powernv/fadump: reset metadata address during clean up Hari Bathini
2019-09-11 14:51 ` [PATCH v6 18/36] powernv/fadump: define OPAL register/un-register callback functions Hari Bathini
2019-09-11 14:51 ` [PATCH v6 19/36] powernv/fadump: support copying multiple kernel boot memory regions Hari Bathini
2019-09-11 14:51 ` [PATCH v6 20/36] powernv/fadump: process the crashdump by exporting it as /proc/vmcore Hari Bathini
2019-09-11 14:52 ` [PATCH v6 21/36] powernv/fadump: Warn before processing partial crashdump Hari Bathini
2019-09-11 14:53 ` [PATCH v6 22/36] powernv/fadump: handle invalidation of crashdump and re-registraion Hari Bathini
2019-09-11 14:53 ` [PATCH v6 23/36] powerpc/fadump: Update documentation about OPAL platform support Hari Bathini
2019-09-11 14:54 ` [PATCH v6 24/36] powerpc/fadump: make use of memblock's bottom up allocation mode Hari Bathini
2019-09-11 14:54 ` [PATCH v6 25/36] powernv/fadump: process architected register state data provided by firmware Hari Bathini
2019-09-11 14:55 ` [PATCH v6 26/36] powerpc/fadump: make crash memory ranges array allocation generic Hari Bathini
2019-09-11 14:55 ` [PATCH v6 27/36] powerpc/fadump: consider reserved ranges while releasing memory Hari Bathini
2019-09-11 14:55 ` [PATCH v6 28/36] powerpc/fadump: improve how crashed kernel's memory is reserved Hari Bathini
2019-09-11 14:56 ` [PATCH v6 29/36] powernv/fadump: add support to preserve crash data on FADUMP disabled kernel Hari Bathini
2019-09-11 14:56 ` [PATCH v6 30/36] powerpc/fadump: update documentation about CONFIG_PRESERVE_FA_DUMP Hari Bathini
2019-09-11 14:56 ` [PATCH v6 31/36] powernv/opalcore: export /sys/firmware/opal/core for analysing opal crashes Hari Bathini
2019-09-11 14:56 ` [PATCH v6 32/36] powernv/opalcore: provide an option to invalidate /sys/firmware/opal/core file Hari Bathini
2019-09-11 14:56 ` [PATCH v6 33/36] powerpc/fadump: consider f/w load area Hari Bathini
2019-09-11 14:57 ` [PATCH v6 34/36] powernv/fadump: update documentation about option to release opalcore Hari Bathini
2019-09-11 14:57 ` [PATCH v6 35/36] powerpc/fadump: remove RMA_START and RMA_END macros Hari Bathini
2019-09-11 14:57 ` [PATCH v6 36/36] powernv/fadump: support holes in kernel boot memory area Hari Bathini

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=156821318971.5656.9281936950510635858.stgit@hbathini.in.ibm.com \
    --to=hbathini@linux.ibm.com \
    --cc=ananth@linux.ibm.com \
    --cc=dja@axtens.net \
    --cc=hegdevasant@linux.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mahesh@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=oohall@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LinuxPPC-Dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linuxppc-dev/0 linuxppc-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linuxppc-dev linuxppc-dev/ https://lore.kernel.org/linuxppc-dev \
		linuxppc-dev@lists.ozlabs.org linuxppc-dev@ozlabs.org linuxppc-dev@archiver.kernel.org
	public-inbox-index linuxppc-dev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linuxppc-dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox