Skip to content

Commit 38c052f

Browse files
author
Ingo Molnar
committed
rtc: fix deadlock
if get_rtc_time() is _ever_ called with IRQs off, we deadlock badly in it, waiting for jiffies to increment. So make the code more robust by doing an explicit mdelay(20). This solves a very hard to reproduce/debug hard lockup reported by Mikael Pettersson. Reported-by: Mikael Pettersson <mikpe@it.uu.se> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 3c4fbe5 commit 38c052f

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

‎include/asm-generic/rtc.h‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/mc146818rtc.h>
1616
#include <linux/rtc.h>
1717
#include <linux/bcd.h>
18+
#include <linux/delay.h>
1819

1920
#define RTC_PIE 0x40 /* periodic interrupt enable */
2021
#define RTC_AIE 0x20 /* alarm interrupt enable */
@@ -43,7 +44,6 @@ static inline unsigned char rtc_is_updating(void)
4344

4445
static inline unsigned int get_rtc_time(struct rtc_time *time)
4546
{
46-
unsigned long uip_watchdog = jiffies;
4747
unsigned char ctrl;
4848
unsigned long flags;
4949

@@ -53,19 +53,15 @@ static inline unsigned int get_rtc_time(struct rtc_time *time)
5353

5454
/*
5555
* read RTC once any update in progress is done. The update
56-
* can take just over 2ms. We wait 10 to 20ms. There is no need to
56+
* can take just over 2ms. We wait 20ms. There is no need to
5757
* to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
5858
* If you need to know *exactly* when a second has started, enable
5959
* periodic update complete interrupts, (via ioctl) and then
6060
* immediately read /dev/rtc which will block until you get the IRQ.
6161
* Once the read clears, read the RTC time (again via ioctl). Easy.
6262
*/
63-
64-
if (rtc_is_updating() != 0)
65-
while (jiffies - uip_watchdog < 2*HZ/100) {
66-
barrier();
67-
cpu_relax();
68-
}
63+
if (rtc_is_updating())
64+
mdelay(20);
6965

7066
/*
7167
* Only the values that we read from the RTC are set. We leave

0 commit comments

Comments
 (0)