On 16/05/2018 16:45:51-0700, Trent Piepho wrote: > In order to read correctly from asynchronously updated RTC registers, > it's necessary to read repeatedly until their values do not change from > read to read. It's also necessary to wait for three RTC clock ticks for > certain operations. There are no timeouts in this code and these > operations could possibly loop forever. > > To avoid kernel hangs, put in timeouts. > > The iMX7d can be configured to stop the SRTC on a tamper event, which > will lockup the kernel inside this driver as described above. > > These hangs can happen when running under qemu, which doesn't emulate > the SNVS RTC, though currently the driver will refuse to load on qemu > due to a timeout in the driver probe method. > > It could also happen if the SRTC block where somehow placed into reset > or the slow speed clock that drives the SRTC counter (but not the CPU) > were to stop. > > The symptoms on a two core iMX7d are a work queue hang on > rtc_timer_do_work(), which eventually blocks a systemd fsnotify > operation that triggers a work queue flush, causing systemd to hang and > thus causing all services that should be started by systemd, like a > console getty, to fail to start or stop. > > Also optimize the wait code to wait less. It only needs to wait for the > clock to advance three ticks, not to see it change three times. > > Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxxxxxxxxx> > Cc: Alessandro Zummo <a.zummo@xxxxxxxxxxxx> > Cc: Fabio Estevam <fabio.estevam@xxxxxxx> > Cc: Shawn Guo <shawn.guo@xxxxxxxxxx> > Cc: Bryan O'Donoghue <pure.logic@xxxxxxxxxxxxxxxxx> > Signed-off-by: Trent Piepho <tpiepho@xxxxxxxxxx> > --- > drivers/rtc/rtc-snvs.c | 105 ++++++++++++++++++++++++++++++++----------------- > 1 file changed, 70 insertions(+), 35 deletions(-) > Applied, thanks. -- Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com