All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86_64: fix a deadlock in set_rtc_mmss()
@ 2007-11-15 16:55 Dan Aloni
  2007-11-15 18:30 ` Aristeu Rozanski
  2007-11-20  7:59 ` Thomas Gleixner
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Aloni @ 2007-11-15 16:55 UTC (permalink / raw)
  To: Linux Kernel List

Patch is valid only for 2.6.23.x, guessing from the recent arch/ changes 
in 2.6.24-rc.

set_rtc_mmss() was used to be called from interrupt context in 2.6.22,
however in 2.6.23, it is called from a timer context, where interrupts
are enabled. This patch ensures that rtc_interrupt() won't dead-lock 
with set_rtc_mmss().

--
BUG: spinlock recursion on CPU#1, swapper/0

lock: ffffffff8063ffe0, .magic: dead4ead, .owner: swapper/0, .owner_cpu: 1

Call Trace:
<IRQ>  [<ffffffff80361297>] spin_bug+0xa7/0x100
[<ffffffff803614d5>] _raw_spin_lock+0x145/0x150
[<ffffffff80228751>] inc_nr_running+0x31/0x40
[<ffffffff8024b4a0>] sync_cmos_clock+0x0/0xc0
[<ffffffff804fa839>] _spin_lock+0x9/0x10
[<ffffffff803ae770>] rtc_interrupt+0x10/0xe0
[<ffffffff80258975>] handle_IRQ_event+0x35/0x70
[<ffffffff80259f6c>] handle_edge_irq+0xcc/0x150
[<ffffffff8020e600>] do_IRQ+0x80/0x100
[<ffffffff8020c441>] ret_from_intr+0x0/0xa
[<ffffffff8020f4e7>] update_persistent_clock+0x47/0x1f0
[<ffffffff8024b54d>] sync_cmos_clock+0xad/0xc0
[<ffffffff8023aa58>] run_timer_softirq+0x178/0x1e0
[<ffffffff802370e4>] __do_softirq+0x74/0xe0
[<ffffffff8020d0bc>] call_softirq+0x1c/0x30
[<ffffffff8020e52d>] do_softirq+0x3d/0x90
[<ffffffff80237065>] irq_exit+0x45/0x50
[<ffffffff802182a5>] smp_apic_timer_interrupt+0x55/0x70
[<ffffffff8020b050>] default_idle+0x0/0x50
[<ffffffff8020cb66>] apic_timer_interrupt+0x66/0x70
<EOI>  [<ffffffff8020b07d>] default_idle+0x2d/0x50
[<ffffffff8020a922>] enter_idle+0x22/0x30
[<ffffffff8020b0fc>] cpu_idle+0x5c/0x80
[<ffffffff806c0298>] start_secondary+0x258/0x360

Signed-off-by: Dan Aloni <da-x@monatomic.org>

---
commit df9b0fba29fec2479d4c106ccdc3524fd8a61be8
tree 85b6a0f6285ab4f363291ca429ff86557a839378
parent 1915566e8113fc9cd1c6c0b9d1f5e7ee99080850
author Dan Aloni <da-x@monatomic.org> Thu, 15 Nov 2007 15:11:39 +0200
committer Dan Aloni <da-x@monatomic.org> Thu, 15 Nov 2007 15:11:39 +0200

 arch/x86_64/kernel/time.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
index 6241b50..8414236 100644
--- a/arch/x86_64/kernel/time.c
+++ b/arch/x86_64/kernel/time.c
@@ -87,13 +87,14 @@ static int set_rtc_mmss(unsigned long nowtime)
 	int retval = 0;
 	int real_seconds, real_minutes, cmos_minutes;
 	unsigned char control, freq_select;
+	unsigned long flags;
 
 /*
  * IRQs are disabled when we're called from the timer interrupt,
  * no need for spin_lock_irqsave()
  */
 
-	spin_lock(&rtc_lock);
+	spin_lock_irqsave(&rtc_lock, flags);
 
 /*
  * Tell the clock it's being set and stop it.
@@ -143,7 +144,7 @@ static int set_rtc_mmss(unsigned long nowtime)
 	CMOS_WRITE(control, RTC_CONTROL);
 	CMOS_WRITE(freq_select, RTC_FREQ_SELECT);
 
-	spin_unlock(&rtc_lock);
+	spin_unlock_irqrestore(&rtc_lock, flags);
 
 	return retval;
 }

-- 
Dan Aloni
XIV LTD, http://www.xivstorage.com
da-x (at) monatomic.org, dan (at) xiv.co.il

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

* Re: [PATCH] x86_64: fix a deadlock in set_rtc_mmss()
  2007-11-15 16:55 [PATCH] x86_64: fix a deadlock in set_rtc_mmss() Dan Aloni
@ 2007-11-15 18:30 ` Aristeu Rozanski
  2007-11-16  3:26   ` Li Zefan
  2007-11-20  7:59 ` Thomas Gleixner
  1 sibling, 1 reply; 5+ messages in thread
From: Aristeu Rozanski @ 2007-11-15 18:30 UTC (permalink / raw)
  To: Dan Aloni; +Cc: Linux Kernel List

Hello Dan,
> Patch is valid only for 2.6.23.x, guessing from the recent arch/ changes 
> in 2.6.24-rc.
> 
> set_rtc_mmss() was used to be called from interrupt context in 2.6.22,
> however in 2.6.23, it is called from a timer context, where interrupts
> are enabled. This patch ensures that rtc_interrupt() won't dead-lock 
> with set_rtc_mmss().

> diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
> index 6241b50..8414236 100644
> --- a/arch/x86_64/kernel/time.c
> +++ b/arch/x86_64/kernel/time.c
> @@ -87,13 +87,14 @@ static int set_rtc_mmss(unsigned long nowtime)
>  	int retval = 0;
>  	int real_seconds, real_minutes, cmos_minutes;
>  	unsigned char control, freq_select;
> +	unsigned long flags;
>  
>  /*
>   * IRQs are disabled when we're called from the timer interrupt,
>   * no need for spin_lock_irqsave()
>   */
>  
> -	spin_lock(&rtc_lock);
> +	spin_lock_irqsave(&rtc_lock, flags);
I think it's a good idea to update or just remove the comment above.

-- 
Aristeu


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

* Re: [PATCH] x86_64: fix a deadlock in set_rtc_mmss()
  2007-11-15 18:30 ` Aristeu Rozanski
@ 2007-11-16  3:26   ` Li Zefan
  2007-11-17  8:34     ` Dan Aloni
  0 siblings, 1 reply; 5+ messages in thread
From: Li Zefan @ 2007-11-16  3:26 UTC (permalink / raw)
  To: Dan Aloni; +Cc: Aristeu Rozanski, Linux Kernel List

Aristeu Rozanski wrote:
> Hello Dan,
>> Patch is valid only for 2.6.23.x, guessing from the recent arch/ changes 
>> in 2.6.24-rc.
>>
>> set_rtc_mmss() was used to be called from interrupt context in 2.6.22,
>> however in 2.6.23, it is called from a timer context, where interrupts
>> are enabled. This patch ensures that rtc_interrupt() won't dead-lock 
>> with set_rtc_mmss().
> 
>> diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
>> index 6241b50..8414236 100644
>> --- a/arch/x86_64/kernel/time.c
>> +++ b/arch/x86_64/kernel/time.c
>> @@ -87,13 +87,14 @@ static int set_rtc_mmss(unsigned long nowtime)
>>  	int retval = 0;
>>  	int real_seconds, real_minutes, cmos_minutes;
>>  	unsigned char control, freq_select;
>> +	unsigned long flags;
>>  
>>  /*
>>   * IRQs are disabled when we're called from the timer interrupt,
>>   * no need for spin_lock_irqsave()
>>   */
>>  
>> -	spin_lock(&rtc_lock);
>> +	spin_lock_irqsave(&rtc_lock, flags);
> I think it's a good idea to update or just remove the comment above.
> 

David P. Reed has sent a patch to fix this bug before you.

http://lkml.org/lkml/2007/11/14/435


Li Zefan

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

* Re: [PATCH] x86_64: fix a deadlock in set_rtc_mmss()
  2007-11-16  3:26   ` Li Zefan
@ 2007-11-17  8:34     ` Dan Aloni
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Aloni @ 2007-11-17  8:34 UTC (permalink / raw)
  To: Li Zefan; +Cc: Aristeu Rozanski, Greg Kroah-Hartman, Linux Kernel List

On Fri, Nov 16, 2007 at 11:26:17AM +0800, Li Zefan wrote:
> Aristeu Rozanski wrote:
> > Hello Dan,
> >> Patch is valid only for 2.6.23.x, guessing from the recent arch/ changes 
> >> in 2.6.24-rc.
> >>
> >> set_rtc_mmss() was used to be called from interrupt context in 2.6.22,
> >> however in 2.6.23, it is called from a timer context, where interrupts
> >> are enabled. This patch ensures that rtc_interrupt() won't dead-lock 
> >> with set_rtc_mmss().
> > 
> >> diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
> >> index 6241b50..8414236 100644
> >> --- a/arch/x86_64/kernel/time.c
> >> +++ b/arch/x86_64/kernel/time.c
> >> @@ -87,13 +87,14 @@ static int set_rtc_mmss(unsigned long nowtime)
> >>  	int retval = 0;
> >>  	int real_seconds, real_minutes, cmos_minutes;
> >>  	unsigned char control, freq_select;
> >> +	unsigned long flags;
> >>  
> >>  /*
> >>   * IRQs are disabled when we're called from the timer interrupt,
> >>   * no need for spin_lock_irqsave()
> >>   */
> >>  
> >> -	spin_lock(&rtc_lock);
> >> +	spin_lock_irqsave(&rtc_lock, flags);
> > I think it's a good idea to update or just remove the comment above.
> > 
> 
> David P. Reed has sent a patch to fix this bug before you.
> 
> http://lkml.org/lkml/2007/11/14/435

Yes, missed by a day. Although that patch was aimed for 2.6.24-rc, 
I am currently more concerned about the 2.6.23.x tree.

Greg, can this be added to 2.6.23-stable?

Signed-off-by: Dan Aloni <da-x@monatomic.org>

---
commit 26c05aa66d10e95de63d95a348023ada4827ceed
tree 7c12f2b35fcba31c9f62ba278b9d232406f80e83
parent ad1765c56c2178a09e87d123548a35f221e1fc05
author Dan Aloni <da-x@monatomic.org> Sat, 17 Nov 2007 10:31:01 +0200
committer Dan Aloni <da-x@monatomic.org> Sat, 17 Nov 2007 10:31:01 +0200

 arch/x86_64/kernel/time.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
index 6d48a4e..fde5796 100644
--- a/arch/x86_64/kernel/time.c
+++ b/arch/x86_64/kernel/time.c
@@ -87,13 +87,9 @@ static int set_rtc_mmss(unsigned long nowtime)
 	int retval = 0;
 	int real_seconds, real_minutes, cmos_minutes;
 	unsigned char control, freq_select;
+	unsigned long flags;
 
-/*
- * IRQs are disabled when we're called from the timer interrupt,
- * no need for spin_lock_irqsave()
- */
-
-	spin_lock(&rtc_lock);
+	spin_lock_irqsave(&rtc_lock, flags);
 
 /*
  * Tell the clock it's being set and stop it.
@@ -143,7 +139,7 @@ static int set_rtc_mmss(unsigned long nowtime)
 	CMOS_WRITE(control, RTC_CONTROL);
 	CMOS_WRITE(freq_select, RTC_FREQ_SELECT);
 
-	spin_unlock(&rtc_lock);
+	spin_unlock_irqrestore(&rtc_lock, flags);
 
 	return retval;
 }


-- 
Dan Aloni
XIV LTD, http://www.xivstorage.com
da-x (at) monatomic.org, dan (at) xiv.co.il

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

* Re: [PATCH] x86_64: fix a deadlock in set_rtc_mmss()
  2007-11-15 16:55 [PATCH] x86_64: fix a deadlock in set_rtc_mmss() Dan Aloni
  2007-11-15 18:30 ` Aristeu Rozanski
@ 2007-11-20  7:59 ` Thomas Gleixner
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Gleixner @ 2007-11-20  7:59 UTC (permalink / raw)
  To: Dan Aloni; +Cc: Linux Kernel List

On Thu, 15 Nov 2007, Dan Aloni wrote:

> Patch is valid only for 2.6.23.x, guessing from the recent arch/ changes 
> in 2.6.24-rc.

There is a backported patch already queued in the stable branch.

Thanks,

	tglx

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

end of thread, other threads:[~2007-11-20  8:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-15 16:55 [PATCH] x86_64: fix a deadlock in set_rtc_mmss() Dan Aloni
2007-11-15 18:30 ` Aristeu Rozanski
2007-11-16  3:26   ` Li Zefan
2007-11-17  8:34     ` Dan Aloni
2007-11-20  7:59 ` Thomas Gleixner

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.