• Thomas Gleixner's avatar
    lib/vdso: Provide sanity check for cycles (again) · 72ce7780
    Thomas Gleixner authored
    The original x86 VDSO implementation checked for the validity of the clock
    source read by testing whether the returned signed cycles value is less
    than zero. This check was also used by the vdso read function to signal
    that the current selected clocksource is not VDSO capable.
    
    During the rework of the VDSO code the check was removed and replaced with
    a check for the clocksource mode being != NONE.
    
    This turned out to be a mistake because the check is necessary for paravirt
    and hyperv clock sources. The reason is that these clock sources have their
    own internal sequence counter to validate the clocksource at the point of
    reading it. This is necessary because the hypervisor can invalidate the
    clocksource asynchronously so a check during the VDSO data update is not
    sufficient. Having a separate indicator for the validity is slower than
    just validating the cycles value. The check for it being negative turned
    out to be the fastest implementation and safe as it would require an uptime
    of ~73 years with a 4GHz counter frequency to result in a false positive.
    
    Add an optional function to validate the cycles with a default
    implementation which allows the compiler to optimize it out for
    architectures which do not require it.
    
    Fixes: 5d51bee7 ("clocksource: Add common vdso clock mode storage")
    Reported-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Tested-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20200606221531.963970768@linutronix.de
    72ce7780
gettimeofday.c 10.3 KB