diff mbox series

[v3,6/7] arm64: entry: centralize premeption decision

Message ID 20220209153535.818830-7-mark.rutland@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64 / sched/preempt: support PREEMPT_DYNAMIC with static keys | expand

Commit Message

Mark Rutland Feb. 9, 2022, 3:35 p.m. UTC
For historical reasons, the decision of whether or not to preempt is
spread across arm64_preempt_schedule_irq() and __el1_irq(), and it would
be clearer if this were all in one place.

Also, arm64_preempt_schedule_irq() calls lockdep_assert_irqs_disabled(),
but this is redundant, as we have a subsequent identical assertion in
__exit_to_kernel_mode(), and preempt_schedule_irq() will
BUG_ON(!irqs_disabled()) anyway.

This patch removes the redundant assertion and centralizes the
preemption decision making within arm64_preempt_schedule_irq().

Other than the slight change to assertion behaviour, there should be no
functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Valentin Schneider <valentin.schneider@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kernel/entry-common.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Catalin Marinas Feb. 9, 2022, 6:10 p.m. UTC | #1
On Wed, Feb 09, 2022 at 03:35:34PM +0000, Mark Rutland wrote:
> For historical reasons, the decision of whether or not to preempt is
> spread across arm64_preempt_schedule_irq() and __el1_irq(), and it would
> be clearer if this were all in one place.
> 
> Also, arm64_preempt_schedule_irq() calls lockdep_assert_irqs_disabled(),
> but this is redundant, as we have a subsequent identical assertion in
> __exit_to_kernel_mode(), and preempt_schedule_irq() will
> BUG_ON(!irqs_disabled()) anyway.
> 
> This patch removes the redundant assertion and centralizes the
> preemption decision making within arm64_preempt_schedule_irq().
> 
> Other than the slight change to assertion behaviour, there should be no
> functional change as a result of this patch.
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Joey Gouly <joey.gouly@arm.com>
> Cc: Valentin Schneider <valentin.schneider@arm.com>
> Cc: Will Deacon <will@kernel.org>

I acked this patch in v2, has anything changed? Well, here it is again:

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

BTW, you have a typo in the subject.
Mark Rutland Feb. 10, 2022, 9:19 a.m. UTC | #2
On Wed, Feb 09, 2022 at 06:10:52PM +0000, Catalin Marinas wrote:
> On Wed, Feb 09, 2022 at 03:35:34PM +0000, Mark Rutland wrote:
> > For historical reasons, the decision of whether or not to preempt is
> > spread across arm64_preempt_schedule_irq() and __el1_irq(), and it would
> > be clearer if this were all in one place.
> > 
> > Also, arm64_preempt_schedule_irq() calls lockdep_assert_irqs_disabled(),
> > but this is redundant, as we have a subsequent identical assertion in
> > __exit_to_kernel_mode(), and preempt_schedule_irq() will
> > BUG_ON(!irqs_disabled()) anyway.
> > 
> > This patch removes the redundant assertion and centralizes the
> > preemption decision making within arm64_preempt_schedule_irq().
> > 
> > Other than the slight change to assertion behaviour, there should be no
> > functional change as a result of this patch.
> > 
> > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: James Morse <james.morse@arm.com>
> > Cc: Joey Gouly <joey.gouly@arm.com>
> > Cc: Valentin Schneider <valentin.schneider@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> 
> I acked this patch in v2, has anything changed? Well, here it is again:

Sorry; I had meant to add your acks.

This patch is the same as in v2; the other patch has some minor changes as in
the cover letter (adding includes and always exposing a couple of function
prototypes).

> Acked-by: Catalin Marinas <catalin.marinas@arm.com>

Thanks!

> BTW, you have a typo in the subject.

I'll go fix that now.

Mark.
diff mbox series

Patch

diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index ef7fcefb96bd..2c639b6b676d 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -222,7 +222,16 @@  static void noinstr arm64_exit_el1_dbg(struct pt_regs *regs)
 
 static void __sched arm64_preempt_schedule_irq(void)
 {
-	lockdep_assert_irqs_disabled();
+	if (!IS_ENABLED(CONFIG_PREEMPTION))
+		return;
+
+	/*
+	 * Note: thread_info::preempt_count includes both thread_info::count
+	 * and thread_info::need_resched, and is not equivalent to
+	 * preempt_count().
+	 */
+	if (READ_ONCE(current_thread_info()->preempt_count) != 0)
+		return;
 
 	/*
 	 * DAIF.DA are cleared at the start of IRQ/FIQ handling, and when GIC
@@ -438,14 +447,7 @@  static __always_inline void __el1_irq(struct pt_regs *regs,
 	do_interrupt_handler(regs, handler);
 	irq_exit_rcu();
 
-	/*
-	 * Note: thread_info::preempt_count includes both thread_info::count
-	 * and thread_info::need_resched, and is not equivalent to
-	 * preempt_count().
-	 */
-	if (IS_ENABLED(CONFIG_PREEMPTION) &&
-	    READ_ONCE(current_thread_info()->preempt_count) == 0)
-		arm64_preempt_schedule_irq();
+	arm64_preempt_schedule_irq();
 
 	exit_to_kernel_mode(regs);
 }