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