]> git.baikalelectronics.ru Git - kernel.git/commit
lib/vdso: Provide sanity check for cycles (again)
authorThomas Gleixner <tglx@linutronix.de>
Sat, 6 Jun 2020 21:51:16 +0000 (23:51 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 9 Jun 2020 14:36:48 +0000 (16:36 +0200)
commit3ab36ebd7f8961150b7c88925ec1711a71ea88c1
tree78f343641375fbe0eb2ab6468d02ccd37813b8c4
parent45e334f843a97e5077d5c6e031941180b8abcc82
lib/vdso: Provide sanity check for cycles (again)

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: 8e577e979d58 ("clocksource: Add common vdso clock mode storage")
Reported-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20200606221531.963970768@linutronix.de
lib/vdso/gettimeofday.c