Skip to contentSkip to conversation

powerpc/entry: Disable interrupts before irqentry_exit

PATCH Applied Shrikanth Hegde 4 participants 4 messages Jun 3 – Jun 19 PowerPC

lore
Share & tools
lore

Shrikanth Hegde

author reviewer
#0 lore raw

PATCH v2 1/1 powerpc/entry: Disable interrupts before irqentry_exit

Venkat reported a panic on powerpc-next tree where GENERIC_ENTRY has been enabled.

kernel BUG at kernel/sched/core.c:7512!
NIP preempt_schedule_irq+0x44/0x118
LR dynamic_irqentry_exit_cond_resched+0x40/0x1a4

Call Trace:
 dynamic_irqentry_exit_cond_resched+0x40/0x1a4
 do_page_fault+0xc0/0x104
 data_access_common_virt+0x210/0x220

This happens since __do_page_fault ends up enabling the interrupts and it could take significant time such that need_resched could be set. This leads to schedule call in irqentry_exit leading to the bug.

There are many such irq handlers which enables the interrupts. Fix it by disabling the irq before calling irqentry_exit. The same pattern exists today in interrupt_exit_kernel_prepare.

Fixes bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")

---
This applies on top on powerpc/next tree.
base: 6ed60999d33d '("powerpc: Remove unused functions")'

v1->v2:
Leave those BUG_ON alone since they are tracking the register state of userspace (Peter Zijlstra)
v1: https://lore.kernel.org/all/[email protected]/

 arch/powerpc/include/asm/entry-common.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/entry-common.h +3 -2
index de5601282755..fc636c42e89a 100644
@@ -260,9 +260,10 @@ static inline void arch_interrupt_exit_prepare(struct pt_regs *regs)
 		 * AMR can only have been unlocked if we interrupted the kernel.
 		 */
 		kuap_assert_locked();
-
-		local_irq_disable();
 	}
+
+	/* irqentry_exit expects to be called with interrupts disabled */
+	local_irq_disable();
 }
 
 static inline void arch_interrupt_async_enter_prepare(struct pt_regs *regs)
Signature · 1 line
2.47.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 55 lines · Shrikanth Hegde

Venkat reported a panic on powerpc-next tree where GENERIC_ENTRY has been enabled.

kernel BUG at kernel/sched/core.c:7512!
NIP preempt_schedule_irq+0x44/0x118
LR dynamic_irqentry_exit_cond_resched+0x40/0x1a4

Call Trace:
 dynamic_irqentry_exit_cond_resched+0x40/0x1a4
 do_page_fault+0xc0/0x104
 data_access_common_virt+0x210/0x220

This happens since __do_page_fault ends up enabling the interrupts and it could take significant time such that need_resched could be set. This leads to schedule call in irqentry_exit leading to the bug.

There are many such irq handlers which enables the interrupts. Fix it by disabling the irq before calling irqentry_exit. The same pattern exists today in interrupt_exit_kernel_prepare.

Fixes bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")

---
This applies on top on powerpc/next tree.
base: 6ed60999d33d '("powerpc: Remove unused functions")'

v1->v2:
Leave those BUG_ON alone since they are tracking the register state of userspace (Peter Zijlstra)
v1: https://lore.kernel.org/all/[email protected]/

 arch/powerpc/include/asm/entry-common.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/entry-common.h +3 -2
index de5601282755..fc636c42e89a 100644
@@ -260,9 +260,10 @@ static inline void arch_interrupt_exit_prepare(struct pt_regs *regs)
 		 * AMR can only have been unlocked if we interrupted the kernel.
 		 */
 		kuap_assert_locked();
-
-		local_irq_disable();
 	}
+
+	/* irqentry_exit expects to be called with interrupts disabled */
+	local_irq_disable();
 }
 
 static inline void arch_interrupt_async_enter_prepare(struct pt_regs *regs)
Signature · 1 line
2.47.3

LGTM

Tested-by on v2 1/1
#2 lore raw
In reply to Shrikanth Hegde
Quoted 19 lines · Shrikanth Hegde

Venkat reported a panic on powerpc-next tree where GENERIC_ENTRY has been enabled.

kernel BUG at kernel/sched/core.c:7512!
NIP preempt_schedule_irq+0x44/0x118
LR dynamic_irqentry_exit_cond_resched+0x40/0x1a4

Call Trace:
  dynamic_irqentry_exit_cond_resched+0x40/0x1a4
  do_page_fault+0xc0/0x104
  data_access_common_virt+0x210/0x220

This happens since __do_page_fault ends up enabling the interrupts and it could take significant time such that need_resched could be set. This leads to schedule call in irqentry_exit leading to the bug.

There are many such irq handlers which enables the interrupts. Fix it by disabling the irq before calling irqentry_exit. The same pattern exists today in interrupt_exit_kernel_prepare.

Quoted 5 lines
Fixes bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")

---

I was able to reproduce this issue consistently, and confirm with this patch, reproted issue is fixed. Hence,

Regards,

Venkat.

Quoted 28 lines

This applies on top on powerpc/next tree.
base: 6ed60999d33d '("powerpc: Remove unused functions")'

v1->v2:
Leave those BUG_ON alone since they are tracking the register state of userspace (Peter Zijlstra)
v1: https://lore.kernel.org/all/[email protected]/

  arch/powerpc/include/asm/entry-common.h | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/entry-common.h +3 -2
index de5601282755..fc636c42e89a 100644
@@ -260,9 +260,10 @@ static inline void arch_interrupt_exit_prepare(struct pt_regs *regs)
  		 * AMR can only have been unlocked if we interrupted the kernel.
  		 */
  		kuap_assert_locked();
-
-		local_irq_disable();
  	}
+
+	/* irqentry_exit expects to be called with interrupts disabled */
+	local_irq_disable();
  }
 
  static inline void arch_interrupt_async_enter_prepare(struct pt_regs *regs)
maintainer Applied
#3 lore raw
In reply to Shrikanth Hegde
Quoted 6 lines · Shrikanth Hegde

Venkat reported a panic on powerpc-next tree where GENERIC_ENTRY has been enabled.

kernel BUG at kernel/sched/core.c:7512!
NIP preempt_schedule_irq+0x44/0x118
LR dynamic_irqentry_exit_cond_resched+0x40/0x1a4

Quoted 6 lines
Call Trace:
 dynamic_irqentry_exit_cond_resched+0x40/0x1a4
 do_page_fault+0xc0/0x104
 data_access_common_virt+0x210/0x220

[...]

Applied to powerpc/next.

[1/1] powerpc/entry: Disable interrupts before irqentry_exit

      https://git.kernel.org/powerpc/c/334f3f6d7a1660fd65597bad9960bfa33a716d35

cheers