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