From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 06/10] ARM: reset: allow kernelspace mappings to be flat mapped during reset
Date: Thu, 9 Jun 2011 16:58:58 +0100 [thread overview]
Message-ID: <1307635142-11312-7-git-send-email-will.deacon@arm.com> (raw)
In-Reply-To: <1307635142-11312-1-git-send-email-will.deacon@arm.com>
Currently, switch_mm_for_reboot only takes out a 1:1 mapping from 0x0
to TASK_SIZE during reboot. For situations where we actually want to
turn off the MMU (e.g. kexec, hibernate, CPU hotplug) we want to map
as much memory as possible using the identity mapping so that we
increase the chance of mapping our reset code.
This patch introduces a new reboot mode, 'k', which remaps all of memory
apart from the kernel (PAGE_OFFSET - _end) and an additional page
immediately following it, which can be used as a temporary stack if
valid memory is available there. Note that this change makes it
necessary to manipulate and switch to the swapper page tables rather
than hijack the current task.
Reviewed-by: Dave Martin <dave.martin@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/include/asm/idmap.h | 7 +++++++
arch/arm/mm/idmap.c | 30 +++++++++++++++++++++---------
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/arch/arm/include/asm/idmap.h b/arch/arm/include/asm/idmap.h
index ea9517e..ae0697d 100644
--- a/arch/arm/include/asm/idmap.h
+++ b/arch/arm/include/asm/idmap.h
@@ -2,6 +2,7 @@
#define _ARM_IDMAP_H
#include <asm/page.h>
+#include <asm/sections.h>
void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end);
@@ -11,6 +12,12 @@ void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end);
void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end) {};
#endif
+/* Modes understood from arm_machine_{restart,reset}. */
+#define MODE_REMAP_KERNEL 'k'
+
+/* Page reserved after the kernel image. */
+#define RESERVE_STACK_PAGE ALIGN((unsigned long)_end + PAGE_SIZE, SZ_1M)
+
void setup_mm_for_reboot(char mode);
#endif /* _ARM_IDMAP_H */
diff --git a/arch/arm/mm/idmap.c b/arch/arm/mm/idmap.c
index 4ae0f09..e4ae3c5 100644
--- a/arch/arm/mm/idmap.c
+++ b/arch/arm/mm/idmap.c
@@ -75,17 +75,29 @@ void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end)
#endif
/*
- * In order to soft-boot, we need to insert a 1:1 mapping in place of
- * the user-mode pages. This will then ensure that we have predictable
- * results when turning the mmu off
+ * In order to soft-boot, we need to insert a 1:1 mapping of memory.
+ * This will then ensure that we have predictable results when turning
+ * the mmu off.
*/
void setup_mm_for_reboot(char mode)
{
- /*
- * We need to access to user-mode page tables here. For kernel threads
- * we don't have any user-mode mappings so we use the context that we
- * "borrowed".
- */
- identity_mapping_add(current->active_mm->pgd, 0, TASK_SIZE);
+
+ identity_mapping_add(swapper_pg_dir, 0, TASK_SIZE);
+ if (mode == MODE_REMAP_KERNEL) {
+ /*
+ * Extend the flat mapping into kernelspace.
+ * We leave room for the kernel image and a `reboot stack'.
+ */
+ identity_mapping_add(swapper_pg_dir, TASK_SIZE, PAGE_OFFSET);
+ identity_mapping_add(swapper_pg_dir, RESERVE_STACK_PAGE, 0);
+ }
+
+ /* Clean and invalidate L1. */
+ flush_cache_all();
+
+ /* Switch exclusively to kernel mappings. */
+ cpu_switch_mm(swapper_pg_dir, &init_mm);
+
+ /* Flush the TLB. */
local_flush_tlb_all();
}
--
1.7.0.4
next prev parent reply other threads:[~2011-06-09 15:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-09 15:58 [PATCH v2 00/10] MMU disabling code and kexec fixes Will Deacon
2011-06-09 15:58 ` [PATCH v2 01/10] ARM: l2x0: fix disabling function to avoid livelock Will Deacon
2011-06-09 15:58 ` [PATCH v2 02/10] ARM: l2x0: fix invalidate-all " Will Deacon
2011-06-09 15:58 ` [PATCH v2 03/10] ARM: proc: add definition of cpu_reset for ARMv6 and ARMv7 cores Will Deacon
2011-06-09 15:58 ` [PATCH v2 04/10] ARM: lib: add switch_stack function for safely changing stack Will Deacon
2011-06-09 16:11 ` Dave Martin
2011-06-09 16:20 ` Dave Martin
2011-06-09 15:58 ` [PATCH v2 05/10] ARM: idmap: add header file for identity mapping functions Will Deacon
2011-06-10 9:13 ` Frank Hofmann
2011-06-09 15:58 ` Will Deacon [this message]
2011-06-09 15:58 ` [PATCH v2 07/10] ARM: multi-cpu: remove arguments from CPU proc macros Will Deacon
2011-06-09 15:59 ` [PATCH v2 08/10] ARM: reset: add reset functionality for jumping to a physical address Will Deacon
2011-06-09 15:59 ` [PATCH v2 09/10] ARM: kexec: use arm_machine_reset for branching to the reboot buffer Will Deacon
2011-06-09 15:59 ` [PATCH v2 10/10] ARM: stop: execute platform callback from cpu_stop code Will Deacon
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=1307635142-11312-7-git-send-email-will.deacon@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.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).