lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANDhNCqhaezCu=+JiJ0GOMaOAJZN6Cu8FbchW3Fy_8tzXi3K1g@mail.gmail.com>
Date: Thu, 26 Jun 2025 21:54:34 -0700
From: John Stultz <jstultz@...gle.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>, netdev@...r.kernel.org, 
	Richard Cochran <richardcochran@...il.com>, Christopher Hall <christopher.s.hall@...el.com>, 
	Frederic Weisbecker <frederic@...nel.org>, Anna-Maria Behnsen <anna-maria@...utronix.de>, 
	Miroslav Lichvar <mlichvar@...hat.com>, Werner Abt <werner.abt@...nberg-usa.com>, 
	David Woodhouse <dwmw2@...radead.org>, Stephen Boyd <sboyd@...nel.org>, 
	Thomas Weißschuh <thomas.weissschuh@...utronix.de>, 
	Kurt Kanzenbach <kurt@...utronix.de>, Nam Cao <namcao@...utronix.de>, 
	Antoine Tenart <atenart@...nel.org>
Subject: Re: [patch V3 06/11] timekeeping: Add auxiliary clock support to __timekeeping_inject_offset()

On Wed, Jun 25, 2025 at 11:38 AM Thomas Gleixner <tglx@...utronix.de> wrote:
>
> 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@...utronix.de>
> ---
>  kernel/time/timekeeping.c |   34 ++++++++++++++++++++++++++--------
>  1 file changed, 26 insertions(+), 8 deletions(-)
> ---
>
> --- a/kernel/time/timekeeping.c
> +++ b/kernel/time/timekeeping.c
> @@ -1448,16 +1448,34 @@ static int __timekeeping_inject_offset(s
>
>         timekeeping_forward_now(tks);
>
> -       /* Make sure the proposed value is valid */
> -       tmp = timespec64_add(tk_xtime(tks), *ts);
> -       if (timespec64_compare(&tks->wall_to_monotonic, ts) > 0 ||
> -           !timespec64_valid_settod(&tmp)) {
> -               timekeeping_restore_shadow(tkd);
> -               return -EINVAL;
> +       if (!IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) || tks->id == TIMEKEEPER_CORE) {

I feel like this should be in something like:
  static inline bool is_core_timekeeper(tsk)


> +               /* Make sure the proposed value is valid */
> +               tmp = timespec64_add(tk_xtime(tks), *ts);
> +               if (timespec64_compare(&tks->wall_to_monotonic, ts) > 0 ||
> +                   !timespec64_valid_settod(&tmp)) {
> +                       timekeeping_restore_shadow(tkd);
> +                       return -EINVAL;
> +               }
> +
> +               tk_xtime_add(tks, ts);
> +               tk_set_wall_to_mono(tks, timespec64_sub(tks->wall_to_monotonic, *ts));
> +       } else {
> +               struct tk_read_base *tkr_mono = &tks->tkr_mono;
> +               ktime_t now, offs;
> +
> +               /* Get the current time */
> +               now = ktime_add_ns(tkr_mono->base, timekeeping_get_ns(tkr_mono));
> +               /* Add the relative offset change */
> +               offs = ktime_add(tks->offs_aux, timespec64_to_ktime(*ts));
> +
> +               /* Prevent that the resulting time becomes negative */
> +               if (ktime_add(now, offs) < 0) {
> +                       timekeeping_restore_shadow(tkd);
> +                       return -EINVAL;
> +               }
> +               tks->offs_aux = offs;

I'd also consider moving this else into a aux helper function as well,
but I'm not 100% on that.

Other than the is_core_timekeeper (or timekeeper_is_core() maybe?)
suggestion above:
 Acked-by: John Stultz <jstultz@...gle.com>

thanks
-john

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ