From: NeilBrown <neilb@suse.de>
To: Alessandro Zummo <a.zummo@towertech.it>
Cc: rtc-linux@googlegroups.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] RTC: Avoid races between RTC alarm wakeup and suspend.
Date: Mon, 30 Jul 2012 11:35:47 +1000 [thread overview]
Message-ID: <20120730113547.2c425ea9@notabene.brown> (raw)
[-- Attachment #1: Type: text/plain, Size: 1585 bytes --]
If an RTC alarm fires just as suspend is happening, it is possible for
suspend to complete and the alarm to be missed.
To avoid the race, we must register the event with the PM core.
As the event is made visible to userspace through a thread which is
only scheduled by the interrupt, we need a pm_stay_awake/pm_relax
pair preventing suspend from the interrupt until the thread completes
its work.
Signed-off-by: NeilBrown <neilb@suse.de>
--
This makes the pm_wakeup_event() call in cmos_interrupt unnecessary as it
provides suspend protection for all RTCs that use rtc_update_irq.
I think the pm_stay_awake//pm_relax is needed - just pm_wakup_event() is
theoretically not sufficient.
This is because there is no guarantee (that I know of) that the workqueue
thread will actually get scheduled before 'suspend' takes over.
Thanks,
NeilBrown
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index eb415bd..9592b93 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -582,6 +582,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
void rtc_update_irq(struct rtc_device *rtc,
unsigned long num, unsigned long events)
{
+ pm_stay_awake(rtc->dev.parent);
schedule_work(&rtc->irqwork);
}
EXPORT_SYMBOL_GPL(rtc_update_irq);
@@ -844,6 +845,7 @@ void rtc_timer_do_work(struct work_struct *work)
mutex_lock(&rtc->ops_lock);
again:
+ pm_relax(rtc->dev.parent);
__rtc_read_time(rtc, &tm);
now = rtc_tm_to_ktime(tm);
while ((next = timerqueue_getnext(&rtc->timerqueue))) {
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
next reply other threads:[~2012-07-30 1:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-30 1:35 NeilBrown [this message]
2012-07-30 21:01 ` [PATCH] RTC: Avoid races between RTC alarm wakeup and suspend Rafael J. Wysocki
2012-07-31 2:51 ` NeilBrown
2012-08-05 21:11 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120730113547.2c425ea9@notabene.brown \
--to=neilb@suse.de \
--cc=a.zummo@towertech.it \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rtc-linux@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.