From patchwork Wed Oct 14 14:48:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 7396231 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 569449F36A for ; Wed, 14 Oct 2015 14:48:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B905E207DA for ; Wed, 14 Oct 2015 14:48:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E50662086F for ; Wed, 14 Oct 2015 14:48:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754147AbbJNOsq (ORCPT ); Wed, 14 Oct 2015 10:48:46 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:50534 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752060AbbJNOsn (ORCPT ); Wed, 14 Oct 2015 10:48:43 -0400 Received: from dude.hi.4.pengutronix.de ([10.1.0.7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1ZmNM2-0007Oi-6L; Wed, 14 Oct 2015 16:48:34 +0200 From: Lucas Stach To: Russell King Cc: Hauke Mehrtens , Jason Cooper , Gregory Clement , Tony Lindgren , linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, patchwork-lst@pengutronix.de Subject: [PATCH 1/4] ARM: catch pending imprecise abort on unmask Date: Wed, 14 Oct 2015 16:48:30 +0200 Message-Id: <1444834113-18122-2-git-send-email-l.stach@pengutronix.de> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1444834113-18122-1-git-send-email-l.stach@pengutronix.de> References: <1444834113-18122-1-git-send-email-l.stach@pengutronix.de> X-SA-Exim-Connect-IP: 10.1.0.7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-omap@vger.kernel.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Install a non-faulting handler just before unmasking imprecise aborts and switch back to the regular one after unmasking is done. This catches any pending imprecise abort that the firmware/bootloader may have left behind that would normally crash the kernel at that point. As there are apparently a lot of bootlaoders out there that do such a thing it makes sense to handle it in the common startup code. Signed-off-by: Lucas Stach Acked-by: Hauke Mehrtens --- arch/arm/mm/fault.c | 15 +++++++++++++++ arch/arm/mm/fault.h | 2 ++ arch/arm/mm/mmu.c | 19 ++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 0d629b8f973f..519f694ec9db 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -538,6 +538,21 @@ hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *) fsr_info[nr].name = name; } +void * __init +swap_fault_function(int nr, + int (*fn)(unsigned long, unsigned int, struct pt_regs *)) +{ + void *old_fn; + + if (nr < 0 || nr >= ARRAY_SIZE(fsr_info)) + BUG(); + + old_fn = fsr_info[nr].fn; + fsr_info[nr].fn = fn; + + return old_fn; +} + /* * Dispatch a data abort to the relevant handler. */ diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h index cf08bdfbe0d6..2deb7494d84f 100644 --- a/arch/arm/mm/fault.h +++ b/arch/arm/mm/fault.h @@ -24,5 +24,7 @@ static inline int fsr_fs(unsigned int fsr) void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs); unsigned long search_exception_table(unsigned long addr); +void *swap_fault_function(int nr, + int (*fn)(unsigned long, unsigned int, struct pt_regs *)); #endif /* __ARCH_ARM_FAULT_H */ diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index f65a6f344b6d..78c420776f4c 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -38,6 +38,7 @@ #include #include +#include "fault.h" #include "mm.h" #include "tcm.h" @@ -1259,6 +1260,20 @@ void __init arm_mm_memblock_reserve(void) } /* + * Abort handler to be used only during unmasking of imprecise aborts. This + * makes sure that the machine will not die if the firmware/bootloader left an + * imprecise abort pending for us to trip over. + */ +static int __init early_abort_handler(unsigned long addr, unsigned int fsr, + struct pt_regs *regs) +{ + pr_warn("Hit pending imprecise external abort during first unmask, " + "this is most likely caused by a firmware/bootloader bug.\n"); + + return 0; +} + +/* * Set up the device mappings. Since we clear out the page tables for all * mappings above VMALLOC_START, except early fixmap, we might remove debug * device mappings. This means earlycon can be used to debug this function @@ -1269,7 +1284,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc) { struct map_desc map; unsigned long addr; - void *vectors; + void *vectors, *saved_fault_fn; /* * Allocate the vector page early. @@ -1365,7 +1380,9 @@ static void __init devicemaps_init(const struct machine_desc *mdesc) flush_cache_all(); /* Enable asynchronous aborts */ + saved_fault_fn = swap_fault_function(22, early_abort_handler); local_abt_enable(); + swap_fault_function(22, saved_fault_fn); } static void __init kmap_init(void)