mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] timekeeping: publish suspend_timing_needed with release semantics
@ 2026-09-22  1:23 Jaidev Shastri via B4 Relay
  2026-09-29 12:05 ` Thomas Gleixner
  0 siblings, 1 reply; 2+ messages in thread
From: Jaidev Shastri via B4 Relay @ 2026-09-22  1:23 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner, Stephen Boyd, Miroslav Lichvar
  Cc: linux-kernel, Jaidev Shastri

From: Jaidev Shastri <jaidevshastri@vt.edu>

timekeeping_suspend() sets suspend_timing_needed with a plain store
after it has read the persistent clock. timekeeping_rtc_skipresume()
reads it with a plain load on behalf of the RTC class during resume.

Set it with smp_store_release() and read it with smp_load_acquire().

Found with MBCheck, a static herd7-based memory consistency checker.

Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>
---
 kernel/time/timekeeping.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index ea2e6e55f..2b15268c3 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -2141,7 +2141,8 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
  */
 bool timekeeping_rtc_skipresume(void)
 {
-	return !suspend_timing_needed;
+	/* Pairs with the smp_store_release() in timekeeping_suspend(). */
+	return !smp_load_acquire(&suspend_timing_needed);
 }
 
 /*
@@ -2272,7 +2273,8 @@ int timekeeping_suspend(void)
 	if (timekeeping_suspend_time.tv_sec || timekeeping_suspend_time.tv_nsec)
 		persistent_clock_exists = true;
 
-	suspend_timing_needed = true;
+	/* Pairs with the smp_load_acquire() in timekeeping_rtc_skipresume(). */
+	smp_store_release(&suspend_timing_needed, true);
 
 	raw_spin_lock_irqsave(&tk_core.lock, flags);
 	timekeeping_forward_now(tks);

---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260921-mb-timekeeping-ab8fe52810ec

Best regards,
--  
Jaidev Shastri <jaidevshastri@vt.edu>



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] timekeeping: publish suspend_timing_needed with release semantics
  2026-09-22  1:23 [PATCH] timekeeping: publish suspend_timing_needed with release semantics Jaidev Shastri via B4 Relay
@ 2026-09-29 12:05 ` Thomas Gleixner
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2026-09-29 12:05 UTC (permalink / raw)
  To: Jaidev Shastri via B4 Relay, John Stultz, Stephen Boyd, Miroslav Lichvar
  Cc: linux-kernel, Jaidev Shastri

On Mon, Sep 21 2026 at 21:23, Jaidev Shastri via wrote:
> From: Jaidev Shastri <jaidevshastri@vt.edu>
>
> timekeeping_suspend() sets suspend_timing_needed with a plain store
> after it has read the persistent clock. timekeeping_rtc_skipresume()
> reads it with a plain load on behalf of the RTC class during resume.

> Set it with smp_store_release() and read it with smp_load_acquire().
>
> Found with MBCheck, a static herd7-based memory consistency checker.

And what exactly is this release/acquire solving?

1) timekeeping_suspend()
        suspend_timing_needed = true
   ...

2) system suspends

3) system resumes

4) timekeeping_resume()
        if (inject_sleeptime)
            suspend_timing_needed = false

5) system continues to resume

6) timekeeping_rtc_skipresume()

The store in #1 is completely uninteresting because suspend/resume is a big
pile of memory barriers so there is _ZERO_ chance that #6 cannot observe
the store in #1.

The more interesting case would be the conditional store in #4 which in
a pretty far fetched theory could lead to the case that
timekeeping_rtc_skipresume() would not observe it.

But if you actually look at the sequence which is between #4 and #6 this
theory becomes a myth.

Please analyze your tool findings properly before blindly claiming that
the tool actually found something problematic.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-29 12:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-22  1:23 [PATCH] timekeeping: publish suspend_timing_needed with release semantics Jaidev Shastri via B4 Relay
2026-09-29 12:05 ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®