Message ID | 1444834113-18122-2-git-send-email-l.stach@pengutronix.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 10/14/2015 04:48 PM, Lucas Stach wrote: > 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 <l.stach@pengutronix.de> > --- > 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 <asm/mach/pci.h> > #include <asm/fixmap.h> > > +#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"); Why don't you add the fsr value into the print, so it is easier to debug. Otherwise: Acked-by: Hauke Mehrtens <hauke@hauke-m.de> > + > + 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) > -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Oct 14, 2015 at 04:48:30PM +0200, Lucas Stach wrote: > 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 <l.stach@pengutronix.de> > --- > 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; > +} > + Please move the abort enable and handler into fault.c - I don't want this exposed to the rest of the kernel as people will get the impression that they can make use of this, even though it's not in arch/arm/include/, as a way to hook and then subsequently unhook a handler. Thanks.
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 <asm/mach/pci.h> #include <asm/fixmap.h> +#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)
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 <l.stach@pengutronix.de> --- 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(-)