rtc: check if __rtc_read_time was successful in rtc_timer_do_work()
PATCH 1/1 rtc: check if __rtc_read_time was successful in rtc_timer_do_work()
From: Yongliang Gao <[email protected]>
If the __rtc_read_time call fails,, the struct rtc_time tm; may contain uninitialized data, or an illegal date/time read from the RTC hardware.
When calling rtc_tm_to_ktime later, the result may be a very large value (possibly KTIME_MAX). If there are periodic timers in rtc->timerqueue, they will continually expire, may causing kernel softlockup.
--- drivers/rtc/interface.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/rtc/interface.c +6 -1
@@ -904,13 +904,18 @@ void rtc_timer_do_work(struct work_struct *work)struct timerqueue_node *next;ktime_t now;struct rtc_time tm; +int err;struct rtc_device *rtc = container_of(work, struct rtc_device, irqwork);mutex_lock (&rtc->ops_lock); again: -__rtc_read_time (rtc, &tm); + err =__rtc_read_time (rtc, &tm); +if (err) { +mutex_unlock (&rtc->ops_lock); +return ; + } now =rtc_tm_to_ktime (tm);while ((next =timerqueue_getnext (&rtc->timerqueue))) {if (next->expires > now)
Signature · 1 line
2.39.3
Quoted 8 lines · Yongliang Gao
If the
__rtc_read_timecall fails,, the structrtc_timetm; may contain uninitialized data, or an illegal date/time read from the RTC hardware.When calling
rtc_tm_to_ktimelater, the result may be a very large value (possiblyKTIME_MAX). If there are periodic timers inrtc->timerqueue, they will continually expire, may causing kernel softlockup.[...]
Applied, thanks!
[1/1] rtc: check if __rtc_read_time was successful in rtc_timer_do_work()
https://git.kernel.org/abelloni/c/e8ba8a2bc4f6
Best regards,
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hi Alexandre Belloni,
I've noticed that the post-failure process for __rtc_read_time requires careful handling.
1. Need to call pm_relax.
2. Potentially need to set the alarm to ensure subsequent interrupts can process the
expired timer? Could you give me some advice?
Should I continue to submit a fix patch or create a v2 version of the patch?
Best Regards,
Yongliang Gao
Quoted 22 lines · Alexandre Belloni
Quoted 8 lines · Yongliang Gao
If the
__rtc_read_timecall fails,, the structrtc_timetm; may contain uninitialized data, or an illegal date/time read from the RTC hardware.When calling
rtc_tm_to_ktimelater, the result may be a very large value (possiblyKTIME_MAX). If there are periodic timers inrtc->timerqueue, they will continually expire, may causing kernel softlockup.[...]
Applied, thanks!
[1/1] rtc: check if
__rtc_read_timewas successful inrtc_timer_do_work()https://git.kernel.org/abelloni/c/e8ba8a2bc4f6Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
A message that is not in the archive (sent off-list or not yet received): CAJxhyqC9hYo3E=J--EYN9uYQc6_q67X4F5DSgpMFzsWrFcbw4Q@mail.gmail.com
Alexandre Belloni
maintainerQuoted 5 lines · 高永良
Hi Alexandre Belloni,
I've noticed that the post-failure process for
__rtc_read_timerequires careful handling.
1. Need to callpm_relax.
I had a look when taking your patch and I'm not convinced calling pm_relax is necessary.
Quoted 3 lines
2. Potentially need to set the alarm to ensure subsequent interrupts can process the
expired timer? Could you give me some advice?
Same thing, if you are not able to read the current time, setting the next alarm is going to fail anyway.
Quoted 29 lines
Should I continue to submit a fix patch or create a v2 version of the patch?
Best Regards,
Yongliang GaoQuoted 22 lines · Alexandre Belloni <[email protected]> 于2024年11月12日周二 06:11写道:
Quoted 8 lines · Yongliang Gao
If the
__rtc_read_timecall fails,, the structrtc_timetm; may contain uninitialized data, or an illegal date/time read from the RTC hardware.When calling
rtc_tm_to_ktimelater, the result may be a very large value (possiblyKTIME_MAX). If there are periodic timers inrtc->timerqueue, they will continually expire, may causing kernel softlockup.[...]
Applied, thanks!
[1/1] rtc: check if
__rtc_read_timewas successful inrtc_timer_do_work()https://git.kernel.org/abelloni/c/e8ba8a2bc4f6Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 10 lines · Alexandre Belloni
Quoted 5 lines · 高永良
Hi Alexandre Belloni,
I've noticed that the post-failure process for
__rtc_read_timerequires careful handling.
1. Need to callpm_relax.I had a look when taking your patch and I'm not convinced calling
pm_relaxis necessary.
Before all the code of schedule_work(&rtc->irqwork), pm_stay_awake(rtc->dev.parent) is called. There are the following 4 functions:
- rtc_set_time
- rtc_update_irq
- rtc_timer_enqueue
- rtc_timer_remove
At the end of the normal processing flow of the rtc_timer_do_work function, pm_relax(rtc->dev.parent) is called.
So, if it fails here, pm_relax(rtc->dev.parent) should be called, right?
Quoted 7 lines
Quoted 4 lines
2. Potentially need to set the alarm to ensure subsequent interrupts can process the
expired timer? Could you give me some advice?Same thing, if you are not able to read the current time, setting the next alarm is going to fail anyway.
OK, I won't set the next alarm if it fails here. Thanks.
Quoted 35 lines
Quoted 30 lines
Should I continue to submit a fix patch or create a v2 version of the patch?
Best Regards,
Yongliang GaoQuoted 22 lines · Alexandre Belloni <[email protected]> 于2024年11月12日周二 06:11写道:
Quoted 8 lines · Yongliang Gao
If the
__rtc_read_timecall fails,, the structrtc_timetm; may contain uninitialized data, or an illegal date/time read from the RTC hardware.When calling
rtc_tm_to_ktimelater, the result may be a very large value (possiblyKTIME_MAX). If there are periodic timers inrtc->timerqueue, they will continually expire, may causing kernel softlockup.[...]
Applied, thanks!
[1/1] rtc: check if
__rtc_read_timewas successful inrtc_timer_do_work()https://git.kernel.org/abelloni/c/e8ba8a2bc4f6Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com