From: "Mateusz Jończyk" <mat.jonczyk@o2.pl>
To: linux-rtc@vger.kernel.org
Cc: "Mateusz Jończyk" <mat.jonczyk@o2.pl>,
"Alessandro Zummo" <a.zummo@towertech.it>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
"Xiaofei Tan" <tanxiaofei@huawei.com>
Subject: [PATCH 7/7] Revert "rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ"
Date: Sun, 12 Sep 2021 14:42:14 +0200 [thread overview]
Message-ID: <20210912124214.81853-8-mat.jonczyk@o2.pl> (raw)
In-Reply-To: <20210912124214.81853-1-mat.jonczyk@o2.pl>
Revert
commit 6950d046eb6e ("rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ")
and add a comment.
As described in a previous
commit 66e4f4a9cc38 ("rtc: cmos: Use spin_lock_irqsave() in cmos_interrupt()")
from February 2020:
cmos_interrupt() isn't always called from hardirq context, so
we must use spin_lock_irqsave() & co.
Indeed, cmos_interrupt() is called from cmos_check_wkalrm(), which is
called from cmos_resume() - apparently not in an interrupt context.
A later
commit 6950d046eb6e ("rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ")
did not take account of this and changed spin_lock_irqsave() to spin_lock().
This may cause a deadlock as quoted in the body of
commit 66e4f4a9cc38 ("rtc: cmos: Use spin_lock_irqsave() in cmos_interrupt()")
mentioned earlier.
Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Xiaofei Tan <tanxiaofei@huawei.com>
---
drivers/rtc/rtc-cmos.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index c24465f7bed4..508fba8746a1 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -741,10 +741,14 @@ static struct cmos_rtc cmos_rtc;
static irqreturn_t cmos_interrupt(int irq, void *p)
{
+ unsigned long flags;
u8 irqstat;
u8 rtc_control;
- spin_lock(&rtc_lock);
+ /* cmos_interrupt() may be called from cmos_check_wkalrm() not in
+ * interrupt context, so using spin_lock_irqsave() is required
+ */
+ spin_lock_irqsave(&rtc_lock, flags);
/* When the HPET interrupt handler calls us, the interrupt
* status is passed as arg1 instead of the irq number. But
@@ -778,7 +782,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
hpet_mask_rtc_irq_bit(RTC_AIE);
CMOS_READ(RTC_INTR_FLAGS);
}
- spin_unlock(&rtc_lock);
+ spin_unlock_irqrestore(&rtc_lock, flags);
if (is_intr(irqstat)) {
rtc_update_irq(p, 1, irqstat);
--
2.25.1
next prev parent reply other threads:[~2021-09-12 12:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-12 12:42 rtc,x86: CMOS RTC fixes Mateusz Jończyk
2021-09-12 12:42 ` [PATCH RESEND 1/7] rtc-cmos: take rtc_lock while reading from CMOS Mateusz Jończyk
2021-09-12 12:42 ` [PATCH 2/7] rtc-cmos: dont touch alarm registers during update Mateusz Jończyk
2021-09-12 12:44 ` [TEST PATCH] rtc-cmos: cmos_read_alarm bug demonstration Mateusz Jończyk
2021-09-12 12:42 ` [PATCH v2 3/7] rtc-mc146818-lib: fix RTC presence check Mateusz Jończyk
2021-09-12 12:42 ` [PATCH 4/7] rtc-mc146818-lib: reduce RTC_UIP polling period Mateusz Jończyk
2021-09-12 12:42 ` [PATCH 5/7] x86/rtc: mach_get_cmos_time - rm duplicated code Mateusz Jończyk
2021-09-12 12:42 ` [PATCH 6/7] x86/rtc: rename mach_set_rtc_mmss Mateusz Jończyk
2021-09-12 12:42 ` Mateusz Jończyk [this message]
2021-09-14 8:02 ` [PATCH 7/7] Revert "rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ" Ville Syrjälä
2021-09-14 8:22 ` Alexandre Belloni
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=20210912124214.81853-8-mat.jonczyk@o2.pl \
--to=mat.jonczyk@o2.pl \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-rtc@vger.kernel.org \
--cc=tanxiaofei@huawei.com \
--cc=ville.syrjala@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox