blob: d04d394db064aec1283366e5abf57bc4c010d9ea [file] [log] [blame]
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +01001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __VDSO_DATAPAGE_H
3#define __VDSO_DATAPAGE_H
4
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +01005#ifndef __ASSEMBLY__
6
Vincenzo Frascino8c59ab82020-03-20 14:53:50 +00007#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 Frascino361f8ae2019-06-21 10:52:28 +010021
Sven Schnelled60d7de2020-08-04 17:01:22 +020022#ifdef CONFIG_ARCH_HAS_VDSO_DATA
23#include <asm/vdso/data.h>
24#else
25struct arch_vdso_data {};
26#endif
27
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +010028#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 */
54struct 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
Adrian Hunterd2e58ab2024-03-25 08:40:10 +020064 * @max_cycles: maximum cycles which won't overflow 64bit multiplication
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +010065 * @mask: clocksource mask
66 * @mult: clocksource multiplier
67 * @shift: clocksource shift
68 * @basetime[clock_id]: basetime per clock_id
Thomas Gleixner660fd042019-11-12 01:27:09 +000069 * @offset[clock_id]: time namespace offset per clock_id
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +010070 * @tz_minuteswest: minutes west of Greenwich
71 * @tz_dsttime: type of DST correction
72 * @hrtimer_res: hrtimer resolution
73 * @__unused: unused
Sven Schnelled60d7de2020-08-04 17:01:22 +020074 * @arch_data: architecture specific data (optional, defaults
75 * to an empty struct)
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +010076 *
77 * vdso_data will be accessed by 64 bit and compat code at the same time
78 * so we should be careful before modifying this structure.
Thomas Gleixner660fd042019-11-12 01:27:09 +000079 *
80 * @basetime is used to store the base time for the system wide time getter
81 * VVAR page.
82 *
83 * @offset is used by the special time namespace VVAR pages which are
84 * installed instead of the real VVAR page. These namespace pages must set
Christian Braunerac84bac2020-04-20 12:06:15 +020085 * @seq to 1 and @clock_mode to VDSO_CLOCKMODE_TIMENS to force the code into
86 * the time namespace slow path. The namespace aware functions retrieve the
Thomas Gleixner660fd042019-11-12 01:27:09 +000087 * real system wide VVAR page, read host time and add the per clock offset.
88 * For clocks which are not affected by time namespace adjustment the
89 * offset must be zero.
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +010090 */
91struct vdso_data {
92 u32 seq;
93
94 s32 clock_mode;
95 u64 cycle_last;
Adrian Hunterd2e58ab2024-03-25 08:40:10 +020096#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT
97 u64 max_cycles;
98#endif
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +010099 u64 mask;
100 u32 mult;
101 u32 shift;
102
Thomas Gleixner660fd042019-11-12 01:27:09 +0000103 union {
104 struct vdso_timestamp basetime[VDSO_BASES];
105 struct timens_offset offset[VDSO_BASES];
106 };
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +0100107
108 s32 tz_minuteswest;
109 s32 tz_dsttime;
110 u32 hrtimer_res;
111 u32 __unused;
Sven Schnelled60d7de2020-08-04 17:01:22 +0200112
113 struct arch_vdso_data arch_data;
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +0100114};
115
116/*
117 * We use the hidden visibility to prevent the compiler from generating a GOT
118 * relocation. Not only is going through a GOT useless (the entry couldn't and
119 * must not be overridden by another library), it does not even work: the linker
120 * cannot generate an absolute address to the data page.
121 *
122 * With the hidden visibility, the compiler simply generates a PC-relative
123 * relocation, and this is what we need.
124 */
125extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden")));
Andrei Vagin3503d562020-06-24 01:33:18 -0700126extern struct vdso_data _timens_data[CS_BASES] __attribute__((visibility("hidden")));
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +0100127
Anna-Maria Behnsena0d2fcd2024-02-19 16:39:33 +0100128/**
129 * union vdso_data_store - Generic vDSO data page
130 */
131union vdso_data_store {
132 struct vdso_data data[CS_BASES];
Arnd Bergmanncffaefd2024-03-20 19:02:15 +0100133 u8 page[1U << CONFIG_PAGE_SHIFT];
Anna-Maria Behnsena0d2fcd2024-02-19 16:39:33 +0100134};
135
Vincenzo Frascino8c59ab82020-03-20 14:53:50 +0000136/*
137 * The generic vDSO implementation requires that gettimeofday.h
138 * provides:
139 * - __arch_get_vdso_data(): to get the vdso datapage.
140 * - __arch_get_hw_counter(): to get the hw counter based on the
141 * clock_mode.
142 * - gettimeofday_fallback(): fallback for gettimeofday.
143 * - clock_gettime_fallback(): fallback for clock_gettime.
144 * - clock_getres_fallback(): fallback for clock_getres.
145 */
146#ifdef ENABLE_COMPAT_VDSO
147#include <asm/vdso/compat_gettimeofday.h>
148#else
149#include <asm/vdso/gettimeofday.h>
150#endif /* ENABLE_COMPAT_VDSO */
151
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +0100152#endif /* !__ASSEMBLY__ */
153
Vincenzo Frascino361f8ae2019-06-21 10:52:28 +0100154#endif /* __VDSO_DATAPAGE_H */