All of lore.kernel.org
 help / color / mirror / 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>,
	Stewart Smith <stewart@linux.ibm.com>,
	Daniel Axtens <dja@axtens.net>
Subject: [PATCH v3 08/16] powerpc/fadump: consider reserved ranges while releasing memory
Date: Wed, 26 Jun 2019 02:16:50 +0530	[thread overview]
Message-ID: <156149561038.9094.3693213253808770796.stgit@hbathini.in.ibm.com> (raw)
In-Reply-To: <156149548694.9094.3211954809582123798.stgit@hbathini.in.ibm.com>

Commit 0962e8004e97 ("powerpc/prom: Scan reserved-ranges node for
memory reservations") enabled support to parse 'reserved-ranges' DT
node to reserve kernel memory falling in these ranges for firmware
purposes. Along with the preserved area memory, also ensure memory
in reserved ranges is not overlapped with memory released by capture
kernel aftering saving vmcore. Also, fix the off-by-one error in
fadump_release_reserved_area function while releasing memory.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
 arch/powerpc/kernel/fadump.c |   59 +++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 1b3df8b..ce8c0bf 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -111,7 +111,7 @@ static int __init fadump_cma_init(void) { return 1; }
  * Sort the reserved ranges in-place and merge adjacent ranges
  * to minimize the reserved ranges count.
  */
-static void __init sort_and_merge_reserved_ranges(void)
+static void sort_and_merge_reserved_ranges(void)
 {
 	unsigned long long base, size;
 	struct fadump_memory_range tmp_range;
@@ -152,8 +152,7 @@ static void __init sort_and_merge_reserved_ranges(void)
 	reserved_ranges_cnt = idx + 1;
 }
 
-static int __init add_reserved_range(unsigned long base,
-				     unsigned long size)
+static int add_reserved_range(unsigned long base, unsigned long size)
 {
 	int i;
 
@@ -1127,33 +1126,57 @@ static void fadump_release_reserved_area(unsigned long start, unsigned long end)
 			if (tend == end_pfn)
 				break;
 
-			start_pfn = tend + 1;
+			start_pfn = tend;
 		}
 	}
 }
 
 /*
- * Release the memory that was reserved in early boot to preserve the memory
- * contents. The released memory will be available for general use.
+ * Release the memory that was reserved during early boot to preserve the
+ * crash'ed kernel's memory contents except reserved dump area (permanent
+ * reservation) and reserved ranges used by F/W. The released memory will
+ * be available for general use.
  */
 static void fadump_release_memory(unsigned long begin, unsigned long end)
 {
+	int i;
 	unsigned long ra_start, ra_end;
-
-	ra_start = fw_dump.reserve_dump_area_start;
-	ra_end = ra_start + fw_dump.reserve_dump_area_size;
+	unsigned long tstart;
 
 	/*
-	 * exclude the dump reserve area. Will reuse it for next
-	 * fadump registration.
+	 * Add memory to permanently preserve to reserved ranges list
+	 * and exclude all these ranges while releasing memory.
 	 */
-	if (begin < ra_end && end > ra_start) {
-		if (begin < ra_start)
-			fadump_release_reserved_area(begin, ra_start);
-		if (end > ra_end)
-			fadump_release_reserved_area(ra_end, end);
-	} else
-		fadump_release_reserved_area(begin, end);
+	i = add_reserved_range(fw_dump.reserve_dump_area_start,
+			       fw_dump.reserve_dump_area_size);
+	if (i == 0) {
+		/*
+		 * Reached the MAX reserved ranges count. To ensure reserved
+		 * dump area is excluded (as it will be reused for next
+		 * FADump registration), ignore the last reserved range and
+		 * add reserved dump area instead.
+		 */
+		reserved_ranges_cnt--;
+		add_reserved_range(fw_dump.reserve_dump_area_start,
+				   fw_dump.reserve_dump_area_size);
+	}
+	sort_and_merge_reserved_ranges();
+
+	tstart = begin;
+	for (i = 0; i < reserved_ranges_cnt; i++) {
+		ra_start = reserved_ranges[i].base;
+		ra_end = ra_start + reserved_ranges[i].size;
+
+		if (tstart >= ra_end)
+			continue;
+
+		if (tstart < ra_start)
+			fadump_release_reserved_area(tstart, ra_start);
+		tstart = ra_end;
+	}
+
+	if (tstart < end)
+		fadump_release_reserved_area(tstart, end);
 }
 
 static void fadump_invalidate_release_mem(void)


  parent reply	other threads:[~2019-06-25 21:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25 20:45 [PATCH v3 00/16] Add FADump support on PowerNV platform Hari Bathini
2019-06-25 20:45 ` [PATCH v3 01/16] powerpc/fadump: move internal fadump code to a new file Hari Bathini
2019-06-28  4:55   ` Stewart Smith
2019-06-28  5:51     ` Hari Bathini
2019-07-03  3:30   ` Oliver O'Halloran
2019-07-03 17:36     ` Hari Bathini
2019-06-25 20:45 ` [PATCH v3 02/16] powerpc/fadump: Improve fadump documentation Hari Bathini
2019-06-25 20:46 ` [PATCH v3 03/16] pseries/fadump: move out platform specific support from generic code Hari Bathini
2019-07-03  4:04   ` Oliver O'Halloran
2019-07-03 17:48     ` Hari Bathini
2019-06-25 20:46 ` [PATCH v3 04/16] powerpc/fadump: use FADump instead of fadump for how it is pronounced Hari Bathini
2019-06-25 20:46 ` [PATCH v3 05/16] powerpc/fadump: enable fadump support on OPAL based POWER platform Hari Bathini
2019-06-25 20:46 ` [PATCH v3 06/16] powerpc/fadump: Update documentation about OPAL platform support Hari Bathini
2019-06-25 20:46 ` [PATCH v3 07/16] powerpc/fadump: consider reserved ranges while reserving memory Hari Bathini
2019-06-25 20:46 ` Hari Bathini [this message]
2019-06-25 20:46 ` [PATCH v3 09/16] powernv/fadump: process architected register state data provided by firmware Hari Bathini
2019-06-25 20:47 ` [PATCH v3 10/16] powernv/fadump: add support to preserve crash data on FADUMP disabled kernel Hari Bathini
2019-06-25 20:47 ` [PATCH v3 11/16] powerpc/fadump: update documentation about CONFIG_PRESERVE_FA_DUMP Hari Bathini
2019-06-25 20:47 ` [PATCH v3 12/16] powerpc/powernv: export /sys/firmware/opal/core for analysing opal crashes Hari Bathini
2019-06-25 20:47 ` [PATCH v3 13/16] powernv/fadump: Skip processing /proc/vmcore when only OPAL core exists Hari Bathini
2019-06-25 20:47 ` [PATCH v3 14/16] powernv/opalcore: provide an option to invalidate /sys/firmware/opal/core file Hari Bathini
2019-06-25 20:47 ` [PATCH v3 15/16] powernv/fadump: consider f/w load area Hari Bathini
2019-06-25 20:48 ` [PATCH v3 16/16] powernv/fadump: update documentation about option to release opalcore Hari Bathini

Reply instructions:

You may reply publicly 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=156149561038.9094.3693213253808770796.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 \
    --cc=stewart@linux.ibm.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.