From patchwork Wed Jun 15 17:23:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 882912 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5FHRSkn019824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 15 Jun 2011 17:27:49 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QWtrv-0008Q7-7m; Wed, 15 Jun 2011 17:27:07 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QWtru-0004Hx-M6; Wed, 15 Jun 2011 17:27:06 +0000 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QWtpr-0003kq-L8 for linux-arm-kernel@lists.infradead.org; Wed, 15 Jun 2011 17:25:04 +0000 Received: from localhost.localdomain (e102144-lin.cambridge.arm.com [10.1.69.60]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id p5FHLwFE026709; Wed, 15 Jun 2011 18:22:24 +0100 (BST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 5/9] ARM: reset: allow kernelspace mappings to be flat mapped during reset Date: Wed, 15 Jun 2011 18:23:16 +0100 Message-Id: <1308158600-7169-6-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1308158600-7169-1-git-send-email-will.deacon@arm.com> References: <1308158600-7169-1-git-send-email-will.deacon@arm.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110615_132500_151020_197A5EEB X-CRM114-Status: GOOD ( 18.81 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: frank.hofmann@tomtom.com, dave.martin@linaro.org, Will Deacon , ccross@android.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 15 Jun 2011 17:27:49 +0000 (UTC) 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 Signed-off-by: Will Deacon --- 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..abe455a 100644 --- a/arch/arm/include/asm/idmap.h +++ b/arch/arm/include/asm/idmap.h @@ -2,6 +2,7 @@ #define _ARM_IDMAP_H #include +#include 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, PMD_SIZE) + 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(); }