]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtc: cmos: use spin_lock_irqsave in cmos_interrupt
authorMateusz Jończyk <mat.jonczyk@o2.pl>
Sat, 7 Jun 2025 21:06:08 +0000 (23:06 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 23 Jun 2025 22:27:51 +0000 (00:27 +0200)
cmos_interrupt() can be called in a non-interrupt context, such as in
an ACPI event handler (which runs in an interrupt thread). Therefore,
usage of spin_lock(&rtc_lock) is insecure. Use spin_lock_irqsave() /
spin_unlock_irqrestore() instead.

Before a misguided
commit 6950d046eb6e ("rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ")
the cmos_interrupt() function used spin_lock_irqsave(). That commit
changed it to spin_lock() and broke locking, which was partially fixed in
commit 13be2efc390a ("rtc: cmos: Disable irq around direct invocation of cmos_interrupt()")

That second commit did not take account of the ACPI fixed event handler
pathway, however. It introduced local_irq_disable() workarounds in
cmos_check_wkalrm(), which can cause problems on PREEMPT_RT kernels
and are now unnecessary.

Add an explicit comment so that this change will not be reverted by
mistake.

Cc: stable@vger.kernel.org
Fixes: 6950d046eb6e ("rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ")
Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Tested-by: Chris Bainbridge <chris.bainbridge@gmail.com>
Reported-by: Chris Bainbridge <chris.bainbridge@gmail.com>
Closes: https://lore.kernel.org/all/aDtJ92foPUYmGheF@debian.local/
Link: https://lore.kernel.org/r/20250607210608.14835-1-mat.jonczyk@o2.pl
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-cmos.c

index 8172869bd3d79365f291894fe417f810352720fb..0743c6acd6e2c11f5838855f5f485168e1302d51 100644 (file)
@@ -692,8 +692,12 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
 {
        u8              irqstat;
        u8              rtc_control;
+       unsigned long   flags;
 
-       spin_lock(&rtc_lock);
+       /* We cannot use spin_lock() here, as cmos_interrupt() is also called
+        * in a non-irq context.
+        */
+       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
@@ -727,7 +731,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);
@@ -1295,9 +1299,7 @@ static void cmos_check_wkalrm(struct device *dev)
         * ACK the rtc irq here
         */
        if (t_now >= cmos->alarm_expires && cmos_use_acpi_alarm()) {
-               local_irq_disable();
                cmos_interrupt(0, (void *)cmos->rtc);
-               local_irq_enable();
                return;
        }