From patchwork Thu Jun 9 15:58:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 866112 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p59G1krh025249 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 9 Jun 2011 16:02:08 GMT Received: from canuck.infradead.org ([134.117.69.58]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QUhfg-0003KW-PE; Thu, 09 Jun 2011 16:01:25 +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 1QUhfg-0001GU-4y; Thu, 09 Jun 2011 16:01:24 +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 1QUhdg-0000pC-8j for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2011 15:59:25 +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 p59FvmFF002664; Thu, 9 Jun 2011 16:57:49 +0100 (BST) From: 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 Message-Id: <1307635142-11312-7-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: <1307635142-11312-1-git-send-email-will.deacon@arm.com> References: <1307635142-11312-1-git-send-email-will.deacon@arm.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110609_115920_849865_A75B7C6C X-CRM114-Status: GOOD ( 18.69 ) 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 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 (demeter1.kernel.org [140.211.167.41]); Thu, 09 Jun 2011 16:02:08 +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..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 +#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, 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(); }