All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clocksource/i8253: Acquire the lock disabled interrupts.
@ 2025-04-04 13:31 Sebastian Andrzej Siewior
  2025-05-05  8:30 ` Sebastian Andrzej Siewior
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-04-04 13:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Daniel Lezcano, Thomas Gleixner

On x86 during boot, clockevent_i8253_disable() can be invoked via
x86_late_time_init -> hpet_time_init() -> pit_timer_init() which happens
with enabled interrupts.
If some of the old i8253 hardware is actually used then lockdep will
notice that i8253_lock is used in hardirq context. This causes lockdep
to complain because it observed the lock being acquired with enabled
interrupts and in hardirq context.

Make clockevent_i8253_disable() acquire the lock with disabled
interrupts.

Fixes: c8c4076723dac ("x86/timer: Skip PIT initialization on modern chipsets")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/clocksource/i8253.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
index 39f7c2d736d16..67dcd9c8f1875 100644
--- a/drivers/clocksource/i8253.c
+++ b/drivers/clocksource/i8253.c
@@ -103,8 +103,9 @@ int __init clocksource_i8253_init(void)
 #ifdef CONFIG_CLKEVT_I8253
 void clockevent_i8253_disable(void)
 {
-	raw_spin_lock(&i8253_lock);
+	unsigned long flags;
 
+	raw_spin_lock_irqsave(&i8253_lock, flags);
 	/*
 	 * Writing the MODE register should stop the counter, according to
 	 * the datasheet. This appears to work on real hardware (well, on
@@ -133,7 +134,7 @@ void clockevent_i8253_disable(void)
 
 	outb_p(0x30, PIT_MODE);
 
-	raw_spin_unlock(&i8253_lock);
+	raw_spin_unlock_irqrestore(&i8253_lock, flags);
 }
 
 static int pit_shutdown(struct clock_event_device *evt)
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] clocksource/i8253: Acquire the lock disabled interrupts.
  2025-04-04 13:31 [PATCH] clocksource/i8253: Acquire the lock disabled interrupts Sebastian Andrzej Siewior
@ 2025-05-05  8:30 ` Sebastian Andrzej Siewior
  2025-05-05 13:29 ` Thomas Gleixner
  2025-05-05 13:48 ` [tip: timers/urgent] clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable() tip-bot2 for Sebastian Andrzej Siewior
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-05-05  8:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: Daniel Lezcano, Thomas Gleixner

On 2025-04-04 15:31:17 [+0200], To linux-kernel@vger.kernel.org wrote:
> On x86 during boot, clockevent_i8253_disable() can be invoked via
> x86_late_time_init -> hpet_time_init() -> pit_timer_init() which happens
> with enabled interrupts.
> If some of the old i8253 hardware is actually used then lockdep will
> notice that i8253_lock is used in hardirq context. This causes lockdep
> to complain because it observed the lock being acquired with enabled
> interrupts and in hardirq context.
> 
> Make clockevent_i8253_disable() acquire the lock with disabled
> interrupts.
> 
> Fixes: c8c4076723dac ("x86/timer: Skip PIT initialization on modern chipsets")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

A gentle reminder.

Sebastian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clocksource/i8253: Acquire the lock disabled interrupts.
  2025-04-04 13:31 [PATCH] clocksource/i8253: Acquire the lock disabled interrupts Sebastian Andrzej Siewior
  2025-05-05  8:30 ` Sebastian Andrzej Siewior
@ 2025-05-05 13:29 ` Thomas Gleixner
  2025-05-05 13:48 ` [tip: timers/urgent] clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable() tip-bot2 for Sebastian Andrzej Siewior
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2025-05-05 13:29 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel; +Cc: Daniel Lezcano

On Fri, Apr 04 2025 at 15:31, Sebastian Andrzej Siewior wrote:
> On x86 during boot, clockevent_i8253_disable() can be invoked via
> x86_late_time_init -> hpet_time_init() -> pit_timer_init() which happens
> with enabled interrupts.
> If some of the old i8253 hardware is actually used then lockdep will
> notice that i8253_lock is used in hardirq context. This causes lockdep
> to complain because it observed the lock being acquired with enabled
> interrupts and in hardirq context.
>
> Make clockevent_i8253_disable() acquire the lock with disabled
> interrupts.

This sentence does not make sense. I'll fix it up...

> Fixes: c8c4076723dac ("x86/timer: Skip PIT initialization on modern chipsets")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  drivers/clocksource/i8253.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
> index 39f7c2d736d16..67dcd9c8f1875 100644
> --- a/drivers/clocksource/i8253.c
> +++ b/drivers/clocksource/i8253.c
> @@ -103,8 +103,9 @@ int __init clocksource_i8253_init(void)
>  #ifdef CONFIG_CLKEVT_I8253
>  void clockevent_i8253_disable(void)
>  {
> -	raw_spin_lock(&i8253_lock);
> +	unsigned long flags;
>  
> +	raw_spin_lock_irqsave(&i8253_lock, flags);
>  	/*
>  	 * Writing the MODE register should stop the counter, according to
>  	 * the datasheet. This appears to work on real hardware (well, on
> @@ -133,7 +134,7 @@ void clockevent_i8253_disable(void)
>  
>  	outb_p(0x30, PIT_MODE);
>  
> -	raw_spin_unlock(&i8253_lock);
> +	raw_spin_unlock_irqrestore(&i8253_lock, flags);
>  }
>  
>  static int pit_shutdown(struct clock_event_device *evt)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: timers/urgent] clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable()
  2025-04-04 13:31 [PATCH] clocksource/i8253: Acquire the lock disabled interrupts Sebastian Andrzej Siewior
  2025-05-05  8:30 ` Sebastian Andrzej Siewior
  2025-05-05 13:29 ` Thomas Gleixner
@ 2025-05-05 13:48 ` tip-bot2 for Sebastian Andrzej Siewior
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-05-05 13:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Thomas Gleixner, stable, x86,
	linux-kernel

The following commit has been merged into the timers/urgent branch of tip:

Commit-ID:     94cff94634e506a4a44684bee1875d2dbf782722
Gitweb:        https://git.kernel.org/tip/94cff94634e506a4a44684bee1875d2dbf782722
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Fri, 04 Apr 2025 15:31:16 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 05 May 2025 15:34:49 +02:00

clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable()

On x86 during boot, clockevent_i8253_disable() can be invoked via
x86_late_time_init -> hpet_time_init() -> pit_timer_init() which happens
with enabled interrupts.

If some of the old i8253 hardware is actually used then lockdep will notice
that i8253_lock is used in hard interrupt context. This causes lockdep to
complain because it observed the lock being acquired with interrupts
enabled and in hard interrupt context.

Make clockevent_i8253_disable() acquire the lock with
raw_spinlock_irqsave() to cure this.

[ tglx: Massage change log and use guard() ]

Fixes: c8c4076723dac ("x86/timer: Skip PIT initialization on modern chipsets")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20250404133116.p-XRWJXf@linutronix.de
---
 drivers/clocksource/i8253.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
index 39f7c2d..b603c25 100644
--- a/drivers/clocksource/i8253.c
+++ b/drivers/clocksource/i8253.c
@@ -103,7 +103,7 @@ int __init clocksource_i8253_init(void)
 #ifdef CONFIG_CLKEVT_I8253
 void clockevent_i8253_disable(void)
 {
-	raw_spin_lock(&i8253_lock);
+	guard(raw_spinlock_irqsave)(&i8253_lock);
 
 	/*
 	 * Writing the MODE register should stop the counter, according to
@@ -132,8 +132,6 @@ void clockevent_i8253_disable(void)
 	outb_p(0, PIT_CH0);
 
 	outb_p(0x30, PIT_MODE);
-
-	raw_spin_unlock(&i8253_lock);
 }
 
 static int pit_shutdown(struct clock_event_device *evt)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-05 13:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-04 13:31 [PATCH] clocksource/i8253: Acquire the lock disabled interrupts Sebastian Andrzej Siewior
2025-05-05  8:30 ` Sebastian Andrzej Siewior
2025-05-05 13:29 ` Thomas Gleixner
2025-05-05 13:48 ` [tip: timers/urgent] clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable() tip-bot2 for Sebastian Andrzej Siewior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.