Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1450346 > unrolled thread

[PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function

Started byChen-Yu Tsai <wens@csie.org>
First post2016-07-26 05:10 +0200
Last post2016-07-26 11:20 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function Chen-Yu Tsai <wens@csie.org> - 2016-07-26 05:10 +0200
    Re: [PATCH] clocksource: sun4i: Clear interrupts after stopping  timer in probe function Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-26 07:50 +0200
      Re: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer  in probe function Chen-Yu Tsai <wens@csie.org> - 2016-07-26 08:50 +0200
        Re: [PATCH] clocksource: sun4i: Clear interrupts after stopping  timer in probe function Thomas Gleixner <tglx@linutronix.de> - 2016-07-26 11:20 +0200

#1450346 — [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function

FromChen-Yu Tsai <wens@csie.org>
Date2016-07-26 05:10 +0200
Subject[PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function
Message-ID<rZ0UO-53b-23@gated-at.bofh.it>
The bootloader (U-boot) sometimes uses this timer for various delays.
It uses it as a ongoing counter, and does comparisons on the current
counter value. The timer counter is never stopped.

In some cases when the user interacts with the bootloader, or lets
it idle for some time before loading Linux, the timer may expire,
and an interrupt will be pending. This results in an unexpected
interrupt when the timer interrupt is enabled by the kernel, at
which point the event_handler isn't set yet. This results in a NULL
pointer dereference exception, panic, and no way to reboot.

Clear any pending interrupts after we stop the timer in the probe
function to avoid this.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---

I've run into this many times while working on U-boot. Finally
made time to figure it out.

---
 drivers/clocksource/sun4i_timer.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c
index 6f3719d73390..d5725c82401d 100644
--- a/drivers/clocksource/sun4i_timer.c
+++ b/drivers/clocksource/sun4i_timer.c
@@ -193,6 +193,9 @@ static void __init sun4i_timer_init(struct device_node *node)
 	/* Make sure timer is stopped before playing with interrupts */
 	sun4i_clkevt_time_stop(0);
 
+	/* clear timer0 interrupt */
+	writel(0x1, timer_base + TIMER_IRQ_ST_REG);
+
 	sun4i_clockevent.cpumask = cpu_possible_mask;
 	sun4i_clockevent.irq = irq;
 
-- 
2.8.1

[toc] | [next] | [standalone]


#1450385 — Re: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function

FromMaxime Ripard <maxime.ripard@free-electrons.com>
Date2016-07-26 07:50 +0200
SubjectRe: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function
Message-ID<rZ3pD-6vo-1@gated-at.bofh.it>
In reply to#1450346

[Multipart message — attachments visible in raw view] — view raw

On Tue, Jul 26, 2016 at 11:01:59AM +0800, Chen-Yu Tsai wrote:
> The bootloader (U-boot) sometimes uses this timer for various delays.
> It uses it as a ongoing counter, and does comparisons on the current
> counter value. The timer counter is never stopped.
> 
> In some cases when the user interacts with the bootloader, or lets
> it idle for some time before loading Linux, the timer may expire,
> and an interrupt will be pending. This results in an unexpected
> interrupt when the timer interrupt is enabled by the kernel, at
> which point the event_handler isn't set yet. This results in a NULL
> pointer dereference exception, panic, and no way to reboot.
> 
> Clear any pending interrupts after we stop the timer in the probe
> function to avoid this.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Awesome, thanks!

You should put stable in Cc though for this kind of patches.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [next] | [standalone]


#1450407 — Re: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function

FromChen-Yu Tsai <wens@csie.org>
Date2016-07-26 08:50 +0200
SubjectRe: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function
Message-ID<rZ4lI-744-9@gated-at.bofh.it>
In reply to#1450385
On Tue, Jul 26, 2016 at 1:49 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:
> On Tue, Jul 26, 2016 at 11:01:59AM +0800, Chen-Yu Tsai wrote:
>> The bootloader (U-boot) sometimes uses this timer for various delays.
>> It uses it as a ongoing counter, and does comparisons on the current
>> counter value. The timer counter is never stopped.
>>
>> In some cases when the user interacts with the bootloader, or lets
>> it idle for some time before loading Linux, the timer may expire,
>> and an interrupt will be pending. This results in an unexpected
>> interrupt when the timer interrupt is enabled by the kernel, at
>> which point the event_handler isn't set yet. This results in a NULL
>> pointer dereference exception, panic, and no way to reboot.
>>
>> Clear any pending interrupts after we stop the timer in the probe
>> function to avoid this.
>>
>> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
>
> Awesome, thanks!
>
> You should put stable in Cc though for this kind of patches.

AFAIK some maintainers prefer to add it themselves. Not sure about
clocksource so I left it out.

ChenYu

[toc] | [prev] | [next] | [standalone]


#1450492 — Re: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function

FromThomas Gleixner <tglx@linutronix.de>
Date2016-07-26 11:20 +0200
SubjectRe: [PATCH] clocksource: sun4i: Clear interrupts after stopping timer in probe function
Message-ID<rZ6GS-8I-21@gated-at.bofh.it>
In reply to#1450407
On Tue, 26 Jul 2016, Chen-Yu Tsai wrote:
> On Tue, Jul 26, 2016 at 1:49 PM, Maxime Ripard
> <maxime.ripard@free-electrons.com> wrote:
> > On Tue, Jul 26, 2016 at 11:01:59AM +0800, Chen-Yu Tsai wrote:
> >> The bootloader (U-boot) sometimes uses this timer for various delays.
> >> It uses it as a ongoing counter, and does comparisons on the current
> >> counter value. The timer counter is never stopped.
> >>
> >> In some cases when the user interacts with the bootloader, or lets
> >> it idle for some time before loading Linux, the timer may expire,
> >> and an interrupt will be pending. This results in an unexpected
> >> interrupt when the timer interrupt is enabled by the kernel, at
> >> which point the event_handler isn't set yet. This results in a NULL
> >> pointer dereference exception, panic, and no way to reboot.
> >>
> >> Clear any pending interrupts after we stop the timer in the probe
> >> function to avoid this.
> >>
> >> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> >
> > Awesome, thanks!
> >
> > You should put stable in Cc though for this kind of patches.
> 
> AFAIK some maintainers prefer to add it themselves. Not sure about
> clocksource so I left it out.

At least you should tell the maintainer, that you consider this to be stable
material. It's not an obvious stable candidate.

Thanks,

	tglx

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web