Skip to content

Commit 4ac1dd3

Browse files
paulmckrcuKAGA-KOKO
authored andcommitted
clocksource: Set cs_watchdog_read() checks based on .uncertainty_margin
Right now, cs_watchdog_read() does clocksource sanity checks based on WATCHDOG_MAX_SKEW, which sets a floor on any clocksource's .uncertainty_margin. These sanity checks can therefore act inappropriately for clocksources with large uncertainty margins. One reason for a clocksource to have a large .uncertainty_margin is when that clocksource has long read-out latency, given that it does not make sense for the .uncertainty_margin to be smaller than the read-out latency. With the current checks, cs_watchdog_read() could reject all normal reads from a clocksource with long read-out latencies, such as those from legacy clocksources that are no longer implemented in hardware. Therefore, recast the cs_watchdog_read() checks in terms of the .uncertainty_margin values of the clocksources involved in the timespan in question. The first covers two watchdog reads and one cs read, so use twice the watchdog .uncertainty_margin plus that of the cs. The second covers only a pair of watchdog reads, so use twice the watchdog .uncertainty_margin. Reported-by: Borislav Petkov <bp@alien8.de> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20240802154618.4149953-4-paulmck@kernel.org
1 parent f33a5d4 commit 4ac1dd3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/time/clocksource.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ enum wd_read_status {
244244

245245
static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow, u64 *wdnow)
246246
{
247+
int64_t md = 2 * watchdog->uncertainty_margin;
247248
unsigned int nretries, max_retries;
248249
int64_t wd_delay, wd_seq_delay;
249250
u64 wd_end, wd_end2;
@@ -258,7 +259,7 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
258259
local_irq_enable();
259260

260261
wd_delay = cycles_to_nsec_safe(watchdog, *wdnow, wd_end);
261-
if (wd_delay <= WATCHDOG_MAX_SKEW) {
262+
if (wd_delay <= md + cs->uncertainty_margin) {
262263
if (nretries > 1 && nretries >= max_retries) {
263264
pr_warn("timekeeping watchdog on CPU%d: %s retried %d times before success\n",
264265
smp_processor_id(), watchdog->name, nretries);
@@ -271,12 +272,12 @@ static enum wd_read_status cs_watchdog_read(struct clocksource *cs, u64 *csnow,
271272
* there is too much external interferences that cause
272273
* significant delay in reading both clocksource and watchdog.
273274
*
274-
* If consecutive WD read-back delay > WATCHDOG_MAX_SKEW/2,
275-
* report system busy, reinit the watchdog and skip the current
275+
* If consecutive WD read-back delay > md, report
276+
* system busy, reinit the watchdog and skip the current
276277
* watchdog test.
277278
*/
278279
wd_seq_delay = cycles_to_nsec_safe(watchdog, wd_end, wd_end2);
279-
if (wd_seq_delay > WATCHDOG_MAX_SKEW/2)
280+
if (wd_seq_delay > md)
280281
goto skip_test;
281282
}
282283

0 commit comments

Comments
 (0)