From: "Mateusz Jończyk" <mat.jonczyk@o2.pl>
To: Borislav Petkov <bp@alien8.de>,
linux-rtc@vger.kernel.org,
Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [ BUG: Invalid wait context ] rtc_lock at: mc146818_avoid_UIP
Date: Sun, 30 Mar 2025 14:32:19 +0200 [thread overview]
Message-ID: <45cee3c7-e1b2-4058-bc81-c6eb5935fad0@o2.pl> (raw)
In-Reply-To: <947b1ceb-77a3-439b-bb7b-6eba38e12cb3@o2.pl>
W dniu 30.03.2025 o 14:23, Mateusz Jończyk pisze:
> W dniu 30.03.2025 o 13:32, Borislav Petkov pisze:
>> So,
>>
>> while playing with suspend to RAM, I got this lockdep splat below.
>>
>> Poking around I found:
>>
>> ec5895c0f2d8 ("rtc: mc146818-lib: extract mc146818_avoid_UIP")
>>
>> which is doing this funky taking and dropping the rtc_lock and I
>> guess that's
>> inherited from ye olde times.
>>
>> I "fixed" it so lockdeup doesn't warn by converting rtc_lock to a raw
>> spinlock
>> but this is definitely not the right fix so let me bounce it off to
>> the folks
>> on Cc who might have a better idea perhaps...
>>
>> Thx.
>
> Hello,
>
> This problem has been reported before, see
>
> https://lore.kernel.org/all/463fbc29-b41f-4d2d-a869-108114000cdb@o2.pl/
>
> I started work on converting rtc_lock to a raw spinlock, but got stuck
> mostly to a lack
> of time etc. Only did some MIPS patches (unpublished).
>
> The problem is that timekeeping_suspend() takes a raw spinlock called
> "tk_core.lock".
> With this lock taken, this function indirectly calls
> mc146818_avoid_UIP(), which takes
> a normal spinlock called "rtc_lock". It is necessary to take the
> rtc_lock while accessing
> the RTC: the RTC access cycle consists of writing to an index register
> and then accessing
> the data register. If something else touches the index register in the
> middle, we get garbage.
>
> During a RTC tick, the RTC date/time registers are in an unspecified
> state - roughly during this
> time the UIP (Update In Progress) bit in an RTC register A is set.
> This is handled by
> mc146818_avoid_UIP(). This function takes and releases the rtc_lock
> multiple times,
> in order not to hold it for too long a time (while sleeping).
I meant "while waiting / while calling udelay()". mc146818_avoid_UIP()
does not sleep.
> But the rtc_lock does need to be taken anyway.
>
> So the solutions would be:
>
> 1. Change the rtc_lock to a raw spinlock.
>
> 2. Change the tick_freeze_lock to a normal spinlock (if possible).
>
> 3. Possibly rewrite mc146818_avoid_UIP to avoid taking the rtc_lock if
> the tick_freeze_lock is held (likely ugly).
>
> 4. Maybe something else I haven't thought about.
>
> Thanks,
>
> Mateusz
Greetings,
Mateusz
next prev parent reply other threads:[~2025-03-30 12:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-30 11:32 [ BUG: Invalid wait context ] rtc_lock at: mc146818_avoid_UIP Borislav Petkov
2025-03-30 12:23 ` Mateusz Jończyk
2025-03-30 12:32 ` Mateusz Jończyk [this message]
2025-04-03 13:12 ` Thomas Gleixner
2025-04-03 13:50 ` Sebastian Andrzej Siewior
2025-04-03 19:36 ` Sebastian Andrzej Siewior
2025-04-03 20:26 ` Thomas Gleixner
2025-04-04 6:16 ` Sebastian Andrzej Siewior
2025-04-04 13:34 ` [PATCH] timekeeping: Add a lockdep override in tick_freeze() Sebastian Andrzej Siewior
2025-04-04 18:47 ` Mateusz Jończyk
2025-04-09 19:13 ` Peter Zijlstra
2025-05-31 18:27 ` Chris Bainbridge
2025-05-31 19:16 ` Chris Bainbridge
2025-06-02 19:52 ` Mateusz Jończyk
2025-06-02 20:20 ` [DRAFT PATCH] rtc-cmos: use spin_lock_irqsave in cmos_interrupt Mateusz Jończyk
2025-06-02 21:19 ` Chris Bainbridge
2025-06-03 6:47 ` Sebastian Andrzej Siewior
2025-04-03 23:46 ` [ BUG: Invalid wait context ] rtc_lock at: mc146818_avoid_UIP Mateusz Jończyk
2025-04-04 7:39 ` Thomas Gleixner
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=45cee3c7-e1b2-4058-bc81-c6eb5935fad0@o2.pl \
--to=mat.jonczyk@o2.pl \
--cc=alexandre.belloni@bootlin.com \
--cc=anna-maria@linutronix.de \
--cc=bp@alien8.de \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).