arc: Re-enable MMU upon die()

Message ID d2b588da61b35312a3126b605685f22bc30fc3ae.1504265945.git.joabreu@synopsys.com
State New
Headers show
Series
  • arc: Re-enable MMU upon die()
Related show

Commit Message

Jose Abreu Sept. 1, 2017, 11:39 a.m.
I recently came upon a scenario where I would get a double fault
after a machine check error. It turns out that for Ksymbol lookup
to work with modules we need to have MMU enabled because module
address is mapped in the cached space.

This patch re-enables the MMU before start printing the stacktrace
making stacktracing of modules work upon a fatal exception.

Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Alexey Brodkin <abrodkin@synopsys.com>
---
 arch/arc/kernel/traps.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Alexey Brodkin Sept. 1, 2017, 11:48 a.m. | #1
Hi Jose,

On Fri, 2017-09-01 at 12:39 +0100, Jose Abreu wrote:
> I recently came upon a scenario where I would get a double fault
> after a machine check error. It turns out that for Ksymbol lookup
> to work with modules we need to have MMU enabled because module
> address is mapped in the cached space.
> 
> This patch re-enables the MMU before start printing the stacktrace
> making stacktracing of modules work upon a fatal exception.

I'm wondering how do we end up with MMU disabled?
From ARC700 databook I cannot find any condition on which MMU could be
silently disabled by hardware and IIRC there's no code in Linux kernel
that disables MMU.

-Alexey
Jose Abreu Sept. 1, 2017, 12:33 p.m. | #2
Hi Alexey,

On 01-09-2017 12:48, Alexey Brodkin wrote:
> Hi Jose,
>
> On Fri, 2017-09-01 at 12:39 +0100, Jose Abreu wrote:
>> I recently came upon a scenario where I would get a double fault
>> after a machine check error. It turns out that for Ksymbol lookup
>> to work with modules we need to have MMU enabled because module
>> address is mapped in the cached space.
>>
>> This patch re-enables the MMU before start printing the stacktrace
>> making stacktracing of modules work upon a fatal exception.
> I'm wondering how do we end up with MMU disabled?
> From ARC700 databook I cannot find any condition on which MMU could be
> silently disabled by hardware and IIRC there's no code in Linux kernel
> that disables MMU.

According to ARC 700 databook a machine check exception causes
Global TLB enable to be cleared. (See ARC 700 databook, page 687).

Best regards,
Jose Miguel Abreu

>
> -Alexey
Alexey Brodkin Sept. 1, 2017, 12:42 p.m. | #3
Hi Jose,

On Fri, 2017-09-01 at 13:33 +0100, Jose Abreu wrote:
> Hi Alexey,
> 
> On 01-09-2017 12:48, Alexey Brodkin wrote:
> > 
> > Hi Jose,
> > 
> > On Fri, 2017-09-01 at 12:39 +0100, Jose Abreu wrote:
> > > 
> > > I recently came upon a scenario where I would get a double fault
> > > after a machine check error. It turns out that for Ksymbol lookup
> > > to work with modules we need to have MMU enabled because module
> > > address is mapped in the cached space.
> > > 
> > > This patch re-enables the MMU before start printing the stacktrace
> > > making stacktracing of modules work upon a fatal exception.
> > I'm wondering how do we end up with MMU disabled?
> > From ARC700 databook I cannot find any condition on which MMU could be
> > silently disabled by hardware and IIRC there's no code in Linux kernel
> > that disables MMU.
> 
> According to ARC 700 databook a machine check exception causes
> Global TLB enable to be cleared. (See ARC 700 databook, page 687).

Thanks for pointing to that.
I didn't expect to see that note far below "Global TLB enable" bit description.

So then your change makes perfect sense.

Reviwed-by: Alexey Brodkin <abrodkin@synopsys.com>
Vineet Gupta Sept. 1, 2017, 3:30 p.m. | #4
On 09/01/2017 04:40 AM, Jose Abreu wrote:
> I recently came upon a scenario where I would get a double fault
> after a machine check error. It turns out that for Ksymbol lookup
> to work with modules we need to have MMU enabled because module
> address is mapped in the cached space.
>
> This patch re-enables the MMU before start printing the stacktrace
> making stacktracing of modules work upon a fatal exception.
>
> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
> Cc: Vineet Gupta <vgupta@synopsys.com>
> Cc: Alexey Brodkin <abrodkin@synopsys.com>
> ---
>   arch/arc/kernel/traps.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/arch/arc/kernel/traps.c b/arch/arc/kernel/traps.c
> index ff83e78..9533e06 100644
> --- a/arch/arc/kernel/traps.c
> +++ b/arch/arc/kernel/traps.c
> @@ -19,6 +19,8 @@
>   #include <linux/ptrace.h>
>   #include <linux/kprobes.h>
>   #include <linux/kgdb.h>
> +#include <asm/arcregs.h>
> +#include <asm/mmu.h>
>   #include <asm/setup.h>
>   #include <asm/unaligned.h>
>   #include <asm/kprobes.h>
> @@ -30,6 +32,9 @@ void __init trap_init(void)
>   
>   void die(const char *str, struct pt_regs *regs, unsigned long address)
>   {
> +	/* MMU must be enabled for Ksymbol lookup in modules */
> +	write_aux_reg(ARC_REG_PID, MMU_ENABLE | read_aux_reg(ARC_REG_PID));

die() is a *generic* API and can even be called from other places not necessarily 
coming from machine check.
The problem with mmu disabling is specific to machine check for dup TLB exception 
and needs to be fixed there not in common code.

-Vineet

Patch

diff --git a/arch/arc/kernel/traps.c b/arch/arc/kernel/traps.c
index ff83e78..9533e06 100644
--- a/arch/arc/kernel/traps.c
+++ b/arch/arc/kernel/traps.c
@@ -19,6 +19,8 @@ 
 #include <linux/ptrace.h>
 #include <linux/kprobes.h>
 #include <linux/kgdb.h>
+#include <asm/arcregs.h>
+#include <asm/mmu.h>
 #include <asm/setup.h>
 #include <asm/unaligned.h>
 #include <asm/kprobes.h>
@@ -30,6 +32,9 @@  void __init trap_init(void)
 
 void die(const char *str, struct pt_regs *regs, unsigned long address)
 {
+	/* MMU must be enabled for Ksymbol lookup in modules */
+	write_aux_reg(ARC_REG_PID, MMU_ENABLE | read_aux_reg(ARC_REG_PID));
+
 	show_kernel_fault_diag(str, regs, address);
 
 	/* DEAD END */