From: Pavel Tatashin <pasha.tatashin@soleen.com>
To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org,
ebiederm@xmission.com, kexec@lists.infradead.org,
linux-kernel@vger.kernel.org, corbet@lwn.net,
catalin.marinas@arm.com, will@kernel.org,
linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [v2 4/5] kexec: use reserved memory for normal kexec reboot
Date: Tue, 9 Jul 2019 14:20:13 -0400 [thread overview]
Message-ID: <20190709182014.16052-5-pasha.tatashin@soleen.com> (raw)
In-Reply-To: <20190709182014.16052-1-pasha.tatashin@soleen.com>
If memory was reserved for the given segment use it directly instead of
allocating on per-page bases. This will avoid relocating this segment to
final destination when machine is rebooted.
This is done on a per segment bases because user might decide to always
load kernel segments at the given address (i.e. non-relocatable kernel),
but load initramfs at reserved address, and thus save reboot time on
copying initramfs if it is large, and reduces reboot performance.
Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
---
kernel/kexec_core.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 932feadbeb3a..2a8d8746e0a1 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -154,6 +154,18 @@ static struct page *kimage_alloc_page(struct kimage *image,
gfp_t gfp_mask,
unsigned long dest);
+/* Check whether this segment is fully within the resource */
+static bool segment_is_reserved(struct kexec_segment *seg, struct resource *res)
+{
+ unsigned long mstart = seg->mem;
+ unsigned long mend = mstart + seg->memsz - 1;
+
+ if (mstart < phys_to_boot_phys(res->start) ||
+ mend > phys_to_boot_phys(res->end))
+ return false;
+ return true;
+}
+
int sanity_check_segment_list(struct kimage *image)
{
int i;
@@ -246,13 +258,9 @@ int sanity_check_segment_list(struct kimage *image)
if (image->type == KEXEC_TYPE_CRASH) {
for (i = 0; i < nr_segments; i++) {
- unsigned long mstart, mend;
-
- mstart = image->segment[i].mem;
- mend = mstart + image->segment[i].memsz - 1;
/* Ensure we are within the crash kernel limits */
- if ((mstart < phys_to_boot_phys(crashk_res.start)) ||
- (mend > phys_to_boot_phys(crashk_res.end)))
+ if (!segment_is_reserved(&image->segment[i],
+ &crashk_res))
return -EADDRNOTAVAIL;
}
}
@@ -848,12 +856,13 @@ static int kimage_load_normal_segment(struct kimage *image,
return result;
}
-static int kimage_load_crash_segment(struct kimage *image,
- struct kexec_segment *segment)
+static int kimage_load_crash_or_reserved_segment(struct kimage *image,
+ struct kexec_segment *segment)
{
- /* For crash dumps kernels we simply copy the data from
- * user space to it's destination.
- * We do things a page at a time for the sake of kmap.
+ /*
+ * For crash dumps and kexec-reserved kernels we simply copy the data
+ * from user space to it's destination. We do things a page at a time
+ * for the sake of kmap.
*/
unsigned long maddr;
size_t ubytes, mbytes;
@@ -923,10 +932,14 @@ int kimage_load_segment(struct kimage *image,
switch (image->type) {
case KEXEC_TYPE_DEFAULT:
- result = kimage_load_normal_segment(image, segment);
+ if (segment_is_reserved(segment, &kexeck_res))
+ result = kimage_load_crash_or_reserved_segment(image,
+ segment);
+ else
+ result = kimage_load_normal_segment(image, segment);
break;
case KEXEC_TYPE_CRASH:
- result = kimage_load_crash_segment(image, segment);
+ result = kimage_load_crash_or_reserved_segment(image, segment);
break;
}
--
2.22.0
next prev parent reply other threads:[~2019-07-09 18:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-09 18:20 [v2 0/5] arm64: allow to reserve memory for normal kexec kernel Pavel Tatashin
2019-07-09 18:20 ` [v2 1/5] kexec: quiet down kexec reboot Pavel Tatashin
2019-07-09 18:20 ` [v2 2/5] kexec: add resource for normal kexec region Pavel Tatashin
2019-07-09 18:20 ` [v2 3/5] kexec: export common crashkernel/kexeckernel parser Pavel Tatashin
2019-07-09 18:20 ` Pavel Tatashin [this message]
2019-07-09 18:20 ` [v2 5/5] arm64, kexec: reserve kexeckernel region Pavel Tatashin
2019-07-10 6:59 ` [v2 0/5] arm64: allow to reserve memory for normal kexec kernel Dave Young
2019-07-10 15:53 ` Pavel Tatashin
2019-07-10 7:32 ` Bhupesh Sharma
2019-07-10 15:54 ` Pavel Tatashin
2019-07-10 15:28 ` Matthias Brugger
2019-07-10 15:58 ` Pavel Tatashin
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=20190709182014.16052-5-pasha.tatashin@soleen.com \
--to=pasha.tatashin@soleen.com \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=ebiederm@xmission.com \
--cc=jmorris@namei.org \
--cc=kexec@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sashal@kernel.org \
--cc=will@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).