All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hari Bathini <hbathini@linux.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Pingfan Liu <piliu@redhat.com>,
	Kexec-ml <kexec@lists.infradead.org>,
	Mimi Zohar <zohar@linux.ibm.com>, Petr Tesarik <ptesarik@suse.cz>,
	Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
	Sourabh Jain <sourabhjain@linux.ibm.com>,
	lkml <linux-kernel@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@ozlabs.org>,
	Eric Biederman <ebiederm@xmission.com>,
	Thiago Jung Bauermann <bauerman@linux.ibm.com>,
	Dave Young <dyoung@redhat.com>, Vivek Goyal <vgoyal@redhat.com>
Subject: [PATCH 11/11] ppc64/kexec_file: add appropriate regions for memory reserve map
Date: Sat, 27 Jun 2020 00:36:18 +0530	[thread overview]
Message-ID: <159319837868.16351.14592923589220822484.stgit@hbathini.in.ibm.com> (raw)
In-Reply-To: <159319825403.16351.7253978047621755765.stgit@hbathini.in.ibm.com>

While initrd, elfcorehdr and backup regions are already added to the
reserve map, there are a few missing regions that need to be added to
the memory reserve map. Add them here. And now that all the changes
to load panic kernel are in place, claim likewise.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
 arch/powerpc/kexec/file_load_64.c |   61 ++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index 58fc2d8..813453d 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -185,6 +185,38 @@ static int get_crash_memory_ranges(struct crash_mem **mem_ranges)
 }
 
 /**
+ * get_reserved_memory_ranges - Get reserve memory ranges. This list includes
+ *                              memory regions that should be added to the
+ *                              memory reserve map to ensure the region is
+ *                              protected from any mischeif.
+ * @mem_ranges:                 Range list to add the memory ranges to.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+static int get_reserved_memory_ranges(struct crash_mem **mem_ranges)
+{
+	int ret;
+
+	ret = add_rtas_mem_range(mem_ranges, false);
+	if (ret)
+		goto out;
+
+	ret = add_opal_mem_range(mem_ranges, false);
+	if (ret)
+		goto out;
+
+	ret = add_tce_mem_ranges(mem_ranges);
+	if (ret)
+		goto out;
+
+	ret = add_reserved_ranges(mem_ranges);
+out:
+	if (ret)
+		pr_err("Failed to setup reserved memory ranges\n");
+	return ret;
+}
+
+/**
  * __locate_mem_hole_ppc64 - Tests if the memory hole between buf_min & buf_max
  *                           is large enough for the buffer. If true, sets
  *                           kbuf->mem to the buffer.
@@ -1182,8 +1214,8 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 			unsigned long initrd_load_addr,
 			unsigned long initrd_len, const char *cmdline)
 {
-	struct crash_mem *umem = NULL;
-	int chosen_node, ret;
+	struct crash_mem *umem = NULL, *rmem = NULL;
+	int i, chosen_node, ret;
 
 	/* Remove memory reservation for the current device tree. */
 	ret = delete_fdt_mem_rsv(fdt, __pa(initial_boot_params),
@@ -1229,6 +1261,24 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 		}
 	}
 
+	/* Update memory reserve map */
+	ret = get_reserved_memory_ranges(&rmem);
+	if (ret)
+		goto out;
+
+	for (i = 0; i < rmem->nr_ranges; i++) {
+		u64 base, size;
+
+		base = rmem->ranges[i].start;
+		size = rmem->ranges[i].end - base + 1;
+		ret = fdt_add_mem_rsv(fdt, base, size);
+		if (ret) {
+			pr_err("Error updating memory reserve map: %s\n",
+			       fdt_strerror(ret));
+			goto out;
+		}
+	}
+
 	ret = setup_new_fdt(image, fdt, initrd_load_addr, initrd_len,
 			    cmdline, &chosen_node);
 	if (ret)
@@ -1239,6 +1289,7 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 		pr_err("Failed to update device-tree with linux,booted-from-kexec\n");
 out:
 	kfree(umem);
+	kfree(rmem);
 	return ret;
 }
 
@@ -1378,10 +1429,10 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 
 		/* Get exclude memory ranges needed for setting up kdump segments */
 		ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges));
-		if (ret)
+		if (ret) {
 			pr_err("Failed to setup exclude memory ranges for buffer lookup\n");
-		/* Return this until all changes for panic kernel are in */
-		return -EOPNOTSUPP;
+			return ret;
+		}
 	}
 
 	return kexec_image_probe_default(image, buf, buf_len);


WARNING: multiple messages have this Message-ID (diff)
From: Hari Bathini <hbathini@linux.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Pingfan Liu <piliu@redhat.com>,
	Kexec-ml <kexec@lists.infradead.org>,
	Petr Tesarik <ptesarik@suse.cz>,
	Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
	Sourabh Jain <sourabhjain@linux.ibm.com>,
	lkml <linux-kernel@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@ozlabs.org>,
	Mimi Zohar <zohar@linux.ibm.com>, Vivek Goyal <vgoyal@redhat.com>,
	Dave Young <dyoung@redhat.com>,
	Thiago Jung Bauermann <bauerman@linux.ibm.com>,
	Eric Biederman <ebiederm@xmission.com>
Subject: [PATCH 11/11] ppc64/kexec_file: add appropriate regions for memory reserve map
Date: Sat, 27 Jun 2020 00:36:18 +0530	[thread overview]
Message-ID: <159319837868.16351.14592923589220822484.stgit@hbathini.in.ibm.com> (raw)
In-Reply-To: <159319825403.16351.7253978047621755765.stgit@hbathini.in.ibm.com>

While initrd, elfcorehdr and backup regions are already added to the
reserve map, there are a few missing regions that need to be added to
the memory reserve map. Add them here. And now that all the changes
to load panic kernel are in place, claim likewise.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
 arch/powerpc/kexec/file_load_64.c |   61 ++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index 58fc2d8..813453d 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -185,6 +185,38 @@ static int get_crash_memory_ranges(struct crash_mem **mem_ranges)
 }
 
 /**
+ * get_reserved_memory_ranges - Get reserve memory ranges. This list includes
+ *                              memory regions that should be added to the
+ *                              memory reserve map to ensure the region is
+ *                              protected from any mischeif.
+ * @mem_ranges:                 Range list to add the memory ranges to.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+static int get_reserved_memory_ranges(struct crash_mem **mem_ranges)
+{
+	int ret;
+
+	ret = add_rtas_mem_range(mem_ranges, false);
+	if (ret)
+		goto out;
+
+	ret = add_opal_mem_range(mem_ranges, false);
+	if (ret)
+		goto out;
+
+	ret = add_tce_mem_ranges(mem_ranges);
+	if (ret)
+		goto out;
+
+	ret = add_reserved_ranges(mem_ranges);
+out:
+	if (ret)
+		pr_err("Failed to setup reserved memory ranges\n");
+	return ret;
+}
+
+/**
  * __locate_mem_hole_ppc64 - Tests if the memory hole between buf_min & buf_max
  *                           is large enough for the buffer. If true, sets
  *                           kbuf->mem to the buffer.
@@ -1182,8 +1214,8 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 			unsigned long initrd_load_addr,
 			unsigned long initrd_len, const char *cmdline)
 {
-	struct crash_mem *umem = NULL;
-	int chosen_node, ret;
+	struct crash_mem *umem = NULL, *rmem = NULL;
+	int i, chosen_node, ret;
 
 	/* Remove memory reservation for the current device tree. */
 	ret = delete_fdt_mem_rsv(fdt, __pa(initial_boot_params),
@@ -1229,6 +1261,24 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 		}
 	}
 
+	/* Update memory reserve map */
+	ret = get_reserved_memory_ranges(&rmem);
+	if (ret)
+		goto out;
+
+	for (i = 0; i < rmem->nr_ranges; i++) {
+		u64 base, size;
+
+		base = rmem->ranges[i].start;
+		size = rmem->ranges[i].end - base + 1;
+		ret = fdt_add_mem_rsv(fdt, base, size);
+		if (ret) {
+			pr_err("Error updating memory reserve map: %s\n",
+			       fdt_strerror(ret));
+			goto out;
+		}
+	}
+
 	ret = setup_new_fdt(image, fdt, initrd_load_addr, initrd_len,
 			    cmdline, &chosen_node);
 	if (ret)
@@ -1239,6 +1289,7 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 		pr_err("Failed to update device-tree with linux,booted-from-kexec\n");
 out:
 	kfree(umem);
+	kfree(rmem);
 	return ret;
 }
 
@@ -1378,10 +1429,10 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 
 		/* Get exclude memory ranges needed for setting up kdump segments */
 		ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges));
-		if (ret)
+		if (ret) {
 			pr_err("Failed to setup exclude memory ranges for buffer lookup\n");
-		/* Return this until all changes for panic kernel are in */
-		return -EOPNOTSUPP;
+			return ret;
+		}
 	}
 
 	return kexec_image_probe_default(image, buf, buf_len);


WARNING: multiple messages have this Message-ID (diff)
From: Hari Bathini <hbathini@linux.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Pingfan Liu <piliu@redhat.com>,
	Kexec-ml <kexec@lists.infradead.org>,
	Petr Tesarik <ptesarik@suse.cz>,
	Mahesh J Salgaonkar <mahesh@linux.ibm.com>,
	Sourabh Jain <sourabhjain@linux.ibm.com>,
	lkml <linux-kernel@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@ozlabs.org>,
	Mimi Zohar <zohar@linux.ibm.com>, Vivek Goyal <vgoyal@redhat.com>,
	Dave Young <dyoung@redhat.com>,
	Thiago Jung Bauermann <bauerman@linux.ibm.com>,
	Eric Biederman <ebiederm@xmission.com>
Subject: [PATCH 11/11] ppc64/kexec_file: add appropriate regions for memory reserve map
Date: Sat, 27 Jun 2020 00:36:18 +0530	[thread overview]
Message-ID: <159319837868.16351.14592923589220822484.stgit@hbathini.in.ibm.com> (raw)
In-Reply-To: <159319825403.16351.7253978047621755765.stgit@hbathini.in.ibm.com>

While initrd, elfcorehdr and backup regions are already added to the
reserve map, there are a few missing regions that need to be added to
the memory reserve map. Add them here. And now that all the changes
to load panic kernel are in place, claim likewise.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
 arch/powerpc/kexec/file_load_64.c |   61 ++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index 58fc2d8..813453d 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -185,6 +185,38 @@ static int get_crash_memory_ranges(struct crash_mem **mem_ranges)
 }
 
 /**
+ * get_reserved_memory_ranges - Get reserve memory ranges. This list includes
+ *                              memory regions that should be added to the
+ *                              memory reserve map to ensure the region is
+ *                              protected from any mischeif.
+ * @mem_ranges:                 Range list to add the memory ranges to.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+static int get_reserved_memory_ranges(struct crash_mem **mem_ranges)
+{
+	int ret;
+
+	ret = add_rtas_mem_range(mem_ranges, false);
+	if (ret)
+		goto out;
+
+	ret = add_opal_mem_range(mem_ranges, false);
+	if (ret)
+		goto out;
+
+	ret = add_tce_mem_ranges(mem_ranges);
+	if (ret)
+		goto out;
+
+	ret = add_reserved_ranges(mem_ranges);
+out:
+	if (ret)
+		pr_err("Failed to setup reserved memory ranges\n");
+	return ret;
+}
+
+/**
  * __locate_mem_hole_ppc64 - Tests if the memory hole between buf_min & buf_max
  *                           is large enough for the buffer. If true, sets
  *                           kbuf->mem to the buffer.
@@ -1182,8 +1214,8 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 			unsigned long initrd_load_addr,
 			unsigned long initrd_len, const char *cmdline)
 {
-	struct crash_mem *umem = NULL;
-	int chosen_node, ret;
+	struct crash_mem *umem = NULL, *rmem = NULL;
+	int i, chosen_node, ret;
 
 	/* Remove memory reservation for the current device tree. */
 	ret = delete_fdt_mem_rsv(fdt, __pa(initial_boot_params),
@@ -1229,6 +1261,24 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 		}
 	}
 
+	/* Update memory reserve map */
+	ret = get_reserved_memory_ranges(&rmem);
+	if (ret)
+		goto out;
+
+	for (i = 0; i < rmem->nr_ranges; i++) {
+		u64 base, size;
+
+		base = rmem->ranges[i].start;
+		size = rmem->ranges[i].end - base + 1;
+		ret = fdt_add_mem_rsv(fdt, base, size);
+		if (ret) {
+			pr_err("Error updating memory reserve map: %s\n",
+			       fdt_strerror(ret));
+			goto out;
+		}
+	}
+
 	ret = setup_new_fdt(image, fdt, initrd_load_addr, initrd_len,
 			    cmdline, &chosen_node);
 	if (ret)
@@ -1239,6 +1289,7 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 		pr_err("Failed to update device-tree with linux,booted-from-kexec\n");
 out:
 	kfree(umem);
+	kfree(rmem);
 	return ret;
 }
 
@@ -1378,10 +1429,10 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 
 		/* Get exclude memory ranges needed for setting up kdump segments */
 		ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges));
-		if (ret)
+		if (ret) {
 			pr_err("Failed to setup exclude memory ranges for buffer lookup\n");
-		/* Return this until all changes for panic kernel are in */
-		return -EOPNOTSUPP;
+			return ret;
+		}
 	}
 
 	return kexec_image_probe_default(image, buf, buf_len);


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2020-06-26 19:06 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26 19:04 [PATCH 00/11] ppc64: enable kdump support for kexec_file_load syscall Hari Bathini
2020-06-26 19:04 ` Hari Bathini
2020-06-26 19:04 ` Hari Bathini
2020-06-26 19:04 ` [PATCH 01/11] kexec_file: allow archs to handle special regions while locating memory hole Hari Bathini
2020-06-26 19:04   ` Hari Bathini
2020-06-26 19:04   ` Hari Bathini
2020-06-27  6:30   ` Christophe Leroy
2020-06-27  6:30     ` Christophe Leroy
2020-06-27  6:30     ` Christophe Leroy
2020-06-28  2:28   ` piliu
2020-06-28  2:28     ` piliu
2020-06-28  2:28     ` piliu
2020-06-29  6:00     ` Hari Bathini
2020-06-29  6:00       ` Hari Bathini
2020-06-29  6:00       ` Hari Bathini
2020-06-29 11:39   ` Petr Tesarik
2020-06-29 11:39     ` Petr Tesarik
2020-06-29 11:39     ` Petr Tesarik
2020-06-29 11:56     ` Hari Bathini
2020-06-29 11:56       ` Hari Bathini
2020-06-29 11:56       ` Hari Bathini
2020-07-01  7:46       ` Dave Young
2020-07-01  7:46         ` Dave Young
2020-07-01  7:46         ` Dave Young
2020-07-01 18:31         ` Hari Bathini
2020-07-01 18:31           ` Hari Bathini
2020-07-01 18:31           ` Hari Bathini
2020-07-02 11:47           ` Dave Young
2020-07-02 11:47             ` Dave Young
2020-07-02 11:47             ` Dave Young
2020-06-26 19:04 ` [PATCH 02/11] powerpc/kexec_file: mark PPC64 specific code Hari Bathini
2020-06-26 19:04   ` Hari Bathini
2020-06-26 19:04   ` Hari Bathini
2020-06-27  6:42   ` Christophe Leroy
2020-06-27  6:42     ` Christophe Leroy
2020-06-27  6:42     ` Christophe Leroy
2020-06-29  6:23     ` Hari Bathini
2020-06-29  6:23       ` Hari Bathini
2020-06-29  6:23       ` Hari Bathini
2020-06-26 19:05 ` [PATCH 03/11] powerpc/kexec_file: add helper functions for getting memory ranges Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05 ` [PATCH 04/11] ppc64/kexec_file: avoid stomping memory used by special regions Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-27 10:45   ` kernel test robot
2020-06-27 10:45     ` kernel test robot
2020-06-27 10:45     ` kernel test robot
2020-06-28  2:14   ` piliu
2020-06-28  2:14     ` piliu
2020-06-28  2:14     ` piliu
2020-06-29  5:55     ` Hari Bathini
2020-06-29  5:55       ` Hari Bathini
2020-06-29  5:55       ` Hari Bathini
2020-06-30  3:30       ` piliu
2020-06-30  3:30         ` piliu
2020-06-30  3:30         ` piliu
2020-06-30  6:10         ` Hari Bathini
2020-06-30  6:10           ` Hari Bathini
2020-06-30  6:10           ` Hari Bathini
2020-06-30  8:13           ` piliu
2020-06-30  8:13             ` piliu
2020-06-30  8:13             ` piliu
2020-07-01  7:40   ` Dave Young
2020-07-01  7:40     ` Dave Young
2020-07-01  7:40     ` Dave Young
2020-07-01 12:53     ` piliu
2020-07-01 12:53       ` piliu
2020-07-01 12:53       ` piliu
2020-07-02 11:59       ` Dave Young
2020-07-02 11:59         ` Dave Young
2020-07-02 11:59         ` Dave Young
2020-07-01 18:18     ` Hari Bathini
2020-07-01 18:18       ` Hari Bathini
2020-07-01 18:18       ` Hari Bathini
2020-07-02 11:54       ` Dave Young
2020-07-02 11:54         ` Dave Young
2020-07-02 11:54         ` Dave Young
2020-06-26 19:05 ` [PATCH 05/11] powerpc/drmem: make lmb walk a bit more flexible Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05 ` [PATCH 06/11] ppc64/kexec_file: restrict memory usage of kdump kernel Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05 ` [PATCH 07/11] ppc64/kexec_file: add support to relocate purgatory Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-27 11:52   ` kernel test robot
2020-06-27 11:52     ` kernel test robot
2020-06-27 11:52     ` kernel test robot
2020-06-26 19:05 ` [PATCH 08/11] ppc64/kexec_file: setup the stack for purgatory Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05 ` [PATCH 09/11] ppc64/kexec_file: setup backup region for kdump kernel Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-26 19:05   ` Hari Bathini
2020-06-27 13:02   ` kernel test robot
2020-06-27 13:02     ` kernel test robot
2020-06-27 13:02     ` kernel test robot
2020-06-26 19:06 ` [PATCH 10/11] ppc64/kexec_file: prepare elfcore header for crashing kernel Hari Bathini
2020-06-26 19:06   ` Hari Bathini
2020-06-26 19:06   ` Hari Bathini
2020-06-26 19:06 ` Hari Bathini [this message]
2020-06-26 19:06   ` [PATCH 11/11] ppc64/kexec_file: add appropriate regions for memory reserve map Hari Bathini
2020-06-26 19:06   ` 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=159319837868.16351.14592923589220822484.stgit@hbathini.in.ibm.com \
    --to=hbathini@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bauerman@linux.ibm.com \
    --cc=dyoung@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mahesh@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=piliu@redhat.com \
    --cc=ptesarik@suse.cz \
    --cc=sourabhjain@linux.ibm.com \
    --cc=vgoyal@redhat.com \
    --cc=zohar@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.