^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __VDSO_DATAPAGE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __VDSO_DATAPAGE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <uapi/linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <uapi/linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <uapi/asm-generic/errno-base.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <vdso/bits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <vdso/clocksource.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <vdso/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <vdso/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <vdso/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <vdso/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <vdso/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <vdso/time32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <vdso/time64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #ifdef CONFIG_ARCH_HAS_VDSO_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/vdso/data.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct arch_vdso_data {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define VDSO_BASES (CLOCK_TAI + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define VDSO_HRES (BIT(CLOCK_REALTIME) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) BIT(CLOCK_MONOTONIC) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) BIT(CLOCK_BOOTTIME) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) BIT(CLOCK_TAI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define VDSO_COARSE (BIT(CLOCK_REALTIME_COARSE) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) BIT(CLOCK_MONOTONIC_COARSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define VDSO_RAW (BIT(CLOCK_MONOTONIC_RAW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define CS_HRES_COARSE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define CS_RAW 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define CS_BASES (CS_RAW + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * struct vdso_timestamp - basetime per clock_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @sec: seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @nsec: nanoseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * There is one vdso_timestamp object in vvar for each vDSO-accelerated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * clock_id. For high-resolution clocks, this encodes the time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * corresponding to vdso_data.cycle_last. For coarse clocks this encodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * the actual time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * To be noticed that for highres clocks nsec is left-shifted by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * vdso_data.cs[x].shift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct vdso_timestamp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u64 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u64 nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * struct vdso_data - vdso datapage representation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @seq: timebase sequence counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @clock_mode: clock mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @cycle_last: timebase at clocksource init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @mask: clocksource mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @mult: clocksource multiplier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @shift: clocksource shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @basetime[clock_id]: basetime per clock_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @offset[clock_id]: time namespace offset per clock_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @tz_minuteswest: minutes west of Greenwich
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @tz_dsttime: type of DST correction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @hrtimer_res: hrtimer resolution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @__unused: unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @arch_data: architecture specific data (optional, defaults
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * to an empty struct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * vdso_data will be accessed by 64 bit and compat code at the same time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * so we should be careful before modifying this structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @basetime is used to store the base time for the system wide time getter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * VVAR page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * @offset is used by the special time namespace VVAR pages which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * installed instead of the real VVAR page. These namespace pages must set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @seq to 1 and @clock_mode to VDSO_CLOCKMODE_TIMENS to force the code into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * the time namespace slow path. The namespace aware functions retrieve the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * real system wide VVAR page, read host time and add the per clock offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * For clocks which are not affected by time namespace adjustment the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * offset must be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct vdso_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u32 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) s32 clock_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u64 cycle_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u64 mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u32 mult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u32 shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct vdso_timestamp basetime[VDSO_BASES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct timens_offset offset[VDSO_BASES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) s32 tz_minuteswest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) s32 tz_dsttime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u32 hrtimer_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u32 __unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct arch_vdso_data arch_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * We use the hidden visibility to prevent the compiler from generating a GOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * relocation. Not only is going through a GOT useless (the entry couldn't and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * must not be overridden by another library), it does not even work: the linker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * cannot generate an absolute address to the data page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * With the hidden visibility, the compiler simply generates a PC-relative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * relocation, and this is what we need.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) extern struct vdso_data _timens_data[CS_BASES] __attribute__((visibility("hidden")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * The generic vDSO implementation requires that gettimeofday.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * provides:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * - __arch_get_vdso_data(): to get the vdso datapage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * - __arch_get_hw_counter(): to get the hw counter based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * clock_mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * - gettimeofday_fallback(): fallback for gettimeofday.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * - clock_gettime_fallback(): fallback for clock_gettime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * - clock_getres_fallback(): fallback for clock_getres.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #ifdef ENABLE_COMPAT_VDSO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #include <asm/vdso/compat_gettimeofday.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #include <asm/vdso/gettimeofday.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #endif /* ENABLE_COMPAT_VDSO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #endif /* !__ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #endif /* __VDSO_DATAPAGE_H */