Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

timekeeping: Add auxiliary clock support to __timekeeping_inject_offset()

Redirect the relative offset adjustment to the auxiliary clock offset
instead of modifying CLOCK_REALTIME, which has no meaning in context of
these clocks.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/all/20250625183758.124057787@linutronix.de

+31 -8
+31 -8
kernel/time/timekeeping.c
··· 1431 1431 } 1432 1432 EXPORT_SYMBOL(do_settimeofday64); 1433 1433 1434 + static inline bool timekeeper_is_core_tk(struct timekeeper *tk) 1435 + { 1436 + return !IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) || tk->id == TIMEKEEPER_CORE; 1437 + } 1438 + 1434 1439 /** 1435 1440 * __timekeeping_inject_offset - Adds or subtracts from the current time. 1436 1441 * @tkd: Pointer to the timekeeper to modify ··· 1453 1448 1454 1449 timekeeping_forward_now(tks); 1455 1450 1456 - /* Make sure the proposed value is valid */ 1457 - tmp = timespec64_add(tk_xtime(tks), *ts); 1458 - if (timespec64_compare(&tks->wall_to_monotonic, ts) > 0 || 1459 - !timespec64_valid_settod(&tmp)) { 1460 - timekeeping_restore_shadow(tkd); 1461 - return -EINVAL; 1451 + if (timekeeper_is_core_tk(tks)) { 1452 + /* Make sure the proposed value is valid */ 1453 + tmp = timespec64_add(tk_xtime(tks), *ts); 1454 + if (timespec64_compare(&tks->wall_to_monotonic, ts) > 0 || 1455 + !timespec64_valid_settod(&tmp)) { 1456 + timekeeping_restore_shadow(tkd); 1457 + return -EINVAL; 1458 + } 1459 + 1460 + tk_xtime_add(tks, ts); 1461 + tk_set_wall_to_mono(tks, timespec64_sub(tks->wall_to_monotonic, *ts)); 1462 + } else { 1463 + struct tk_read_base *tkr_mono = &tks->tkr_mono; 1464 + ktime_t now, offs; 1465 + 1466 + /* Get the current time */ 1467 + now = ktime_add_ns(tkr_mono->base, timekeeping_get_ns(tkr_mono)); 1468 + /* Add the relative offset change */ 1469 + offs = ktime_add(tks->offs_aux, timespec64_to_ktime(*ts)); 1470 + 1471 + /* Prevent that the resulting time becomes negative */ 1472 + if (ktime_add(now, offs) < 0) { 1473 + timekeeping_restore_shadow(tkd); 1474 + return -EINVAL; 1475 + } 1476 + tks->offs_aux = offs; 1462 1477 } 1463 1478 1464 - tk_xtime_add(tks, ts); 1465 - tk_set_wall_to_mono(tks, timespec64_sub(tks->wall_to_monotonic, *ts)); 1466 1479 timekeeping_update_from_shadow(tkd, TK_UPDATE_ALL); 1467 1480 return 0; 1468 1481 }