Skip to contentSkip to conversation

clocksource: publish finished_booting with release semantics

PATCH In review Jaidev Shastri 2 participants 2 messages Sep 22 – Sep 29 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource: publish finished_booting with release semantics

clocksource_done_booting() sets curr_clocksource and then finished_booting, both with plain stores under clocksource_mutex. clocksource_find_best() tests finished_booting with a plain load before it walks clocksource_list.

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

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

---
 kernel/time/clocksource.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/time/clocksource.c +4 -2
index f1253f579..f683a787c 100644
@@ -1086,7 +1086,8 @@ static struct clocksource *clocksource_find_best(bool oneshot, bool skipcur)
 {
 	struct clocksource *cs;
 
-	if (!finished_booting || list_empty(&clocksource_list))
+	/* Pairs with the smp_store_release() in clocksource_done_booting(). */
+	if (!smp_load_acquire(&finished_booting) || list_empty(&clocksource_list))
 		return NULL;
 
 	/*
@@ -1188,7 +1189,8 @@ static int __init clocksource_done_booting(void)
 {
 	mutex_lock(&clocksource_mutex);
 	curr_clocksource = clocksource_default_clock();
-	finished_booting = 1;
+	/* Pairs with the smp_load_acquire() in clocksource_find_best(). */
+	smp_store_release(&finished_booting, 1);
 	/*
 	 * Run the watchdog first to eliminate unstable clock sources
 	 */

---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260921-mb-clocksource-49cd0b246a89

Best regards,

Signature · 1 line
Jaidev Shastri <[email protected]>
maintainer
#1 lore raw
Quoted 11 lines · Jaidev Shastri via

From: Jaidev Shastri <[email protected]>

clocksource_done_booting() sets curr_clocksource and then finished_booting, both with plain stores under clocksource_mutex. clocksource_find_best() tests finished_booting with a plain load before it walks clocksource_list.

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

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

Unfortunately your tool is missing the point. All callchains which end up in clocksource_find_best() hold clocksource_mutex. So this acquire/release is pointless.

Thanks,

tglx