arm64: fix potential deadlock in arm64-provide-pseudo-NMI-with-GICv3
PATCH 1/1 arm64: fix potential deadlock in arm64-provide-pseudo-NMI-with-GICv3
In some exception handlers, the interrupt is not reenabled by daifclr at first. The later process may call local_irq_enable() to enable the interrupt, like gic_handle_irq(). As we known, function local_irq_enable() just change the pmr now. The following codes what i found may cause a deadlock or some issues else:
do_sp_pc_abort <- el0_sp_pcdo_el0_ia_bp_hardening <- el0_iakgdb_roundup_cpus <- el1_dbg
--- arch/arm64/kernel/kgdb.c | 4 ++++ arch/arm64/mm/fault.c | 6 ++++++ 2 files changed, 10 insertions(+)
arch/arm64/kernel/kgdb.c +4 -0
@@ -25,6 +25,7 @@#include <linux/kgdb.h> #include <linux/kprobes.h> #include <linux/sched/task_stack.h> +#include <linux/irqchip/arm-gic-v3.h> #include <asm/debug-monitors.h> #include <asm/insn.h>
@@ -291,6 +292,9 @@ static void kgdb_call_nmi_hook(void *ignored)void kgdb_roundup_cpus (unsigned long flags) { +if (gic_prio_masking_enabled ()) +gic_arch_enable_irqs (); +local_irq_enable ();smp_call_function (kgdb_call_nmi_hook,NULL ,0 );local_irq_disable ();
arch/arm64/mm/fault.c +6 -0
@@ -32,6 +32,7 @@#include <linux/perf_event.h> #include <linux/preempt.h> #include <linux/hugetlb.h> +#include <linux/irqchip/arm-gic-v3.h> #include <asm/bug.h> #include <asm/cmpxchg.h>
@@ -780,6 +781,8 @@ asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr,if (addr >TASK_SIZE )arm64_apply_bp_hardening (); +if (gic_prio_masking_enabled ()) +gic_arch_enable_irqs ();local_irq_enable ();do_mem_abort (addr, esr, regs); }
@@ -794,6 +797,9 @@ asmlinkage void __exception do_sp_pc_abort(unsigned long addr,if (user_mode (regs)) {if (instruction_pointer (regs) >TASK_SIZE )arm64_apply_bp_hardening (); + +if (gic_prio_masking_enabled ()) +gic_arch_enable_irqs ();local_irq_enable (); }
Signature · 1 line
2.17.1
Hi Wei,
Thanks testing the series.
Quoted 3 lines · Wei Li
In some exception handlers, the interrupt is not reenabled by daifclr at first. The later process may call
local_irq_enable()to enable the interrupt, likegic_handle_irq(). As we known, functionlocal_irq_enable()just change the pmr now.
This is not yet in, so it might be useful to point to the series that adds this:
https://lkml.org/lkml/2019/1/21/1060
Quoted 25 lines
The following codes what i found may cause a deadlock or some issues else:
do_sp_pc_abort<-el0_sp_pcdo_el0_ia_bp_hardening<-el0_iakgdb_roundup_cpus<-el1_dbgSigned-off-by Wei Li <[email protected]>--- arch/arm64/kernel/kgdb.c | 4 ++++ arch/arm64/mm/fault.c | 6 ++++++ 2 files changed, 10 insertions(+)arch/arm64/kernel/kgdb.c +1
-0@@ -25,6 +25,7 @@#include <linux/kgdb.h> #include <linux/kprobes.h> #include <linux/sched/task_stack.h> +#include <linux/irqchip/arm-gic-v3.h> #include <asm/debug-monitors.h> #include <asm/insn.h>
arch/arm64/kernel/kgdb.c static void kgdb_call_nmi_hook(void *ignored) · line 293
Quoted 2 lines
arch/arm64/kernel/kgdb.c +0
-0@@ -291,6 +292,9 @@ static void kgdb_call_nmi_hook(void *ignored)void kgdb_roundup_cpus (unsigned long flags)
Hmm, I don't see this function defined in arch/arm64/kernel/kgdb.c in v5.0-rc*. Was it removed? or is that something in your local tree.
arch/arm64/kernel/kgdb.c static void kgdb_call_nmi_hook(void *ignored) · line 298
Quoted 5 lines
arch/arm64/kernel/kgdb.c +3
-0{ +if (gic_prio_masking_enabled ()) +gic_arch_enable_irqs (); +local_irq_enable ();
Seeing we introduce the daifflags functions, with the relation described at the top of arch/arm64/include/asm/daifflags.h. I think just calling local_irq_enable() might not comply with this, as PSR.I would be clear while PSR.D is set.
Maybe it should be using:
local_daif_restore(DAIF_PROCCTX);
arch/arm64/kernel/kgdb.c static void kgdb_call_nmi_hook(void *ignored) · line 300
Quoted 2 lines
arch/arm64/kernel/kgdb.c +0
-0smp_call_function (kgdb_call_nmi_hook,NULL ,0 );local_irq_disable ();
and here
local_daif_mask();
Although I'd like to understand what you are applying the pseudo-NMI series on first.
Quoted 13 lines
arch/arm64/mm/fault.c +1
-0@@ -32,6 +32,7 @@#include <linux/perf_event.h> #include <linux/preempt.h> #include <linux/hugetlb.h> +#include <linux/irqchip/arm-gic-v3.h> #include <asm/bug.h> #include <asm/cmpxchg.h>
arch/arm64/mm/fault.c asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr, · line 786
Quoted 6 lines
arch/arm64/mm/fault.c +2
-0@@ -780,6 +781,8 @@ asmlinkage void __exception do_el0_ia_bp_hardening(unsigned long addr,if (addr >TASK_SIZE )arm64_apply_bp_hardening (); +if (gic_prio_masking_enabled ()) +gic_arch_enable_irqs ();local_irq_enable ();
This is not in mainline, in v5.0-rc1 there is:
local_daif_restore(DAIF_PROCCTX);
Which my series updates to modify both DAIF and PMR if needed.
So you wouldn't need to have the gic_arch_enable_irqs().
arch/arm64/mm/fault.c asmlinkage void __exception do_sp_pc_abort(unsigned long addr, · line 803
Quoted 10 lines
arch/arm64/mm/fault.c +3
-0do_mem_abort (addr, esr, regs); }@@ -794,6 +797,9 @@ asmlinkage void __exception do_sp_pc_abort(unsigned long addr,if (user_mode (regs)) {if (instruction_pointer (regs) >TASK_SIZE )arm64_apply_bp_hardening (); + +if (gic_prio_masking_enabled ()) +gic_arch_enable_irqs ();local_irq_enable ();
Same here.
Thanks,
Signature · 1 line
Julien Thierry