/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __VDSO_DATAPAGE_H2#define __VDSO_DATAPAGE_H34#ifndef __ASSEMBLY__56#include <linux/compiler.h>7#include <uapi/linux/bits.h>8#include <uapi/linux/time.h>9#include <uapi/linux/types.h>10#include <uapi/asm-generic/errno-base.h>1112#include <vdso/align.h>13#include <vdso/bits.h>14#include <vdso/cache.h>15#include <vdso/clocksource.h>16#include <vdso/ktime.h>17#include <vdso/limits.h>18#include <vdso/math64.h>19#include <vdso/page.h>20#include <vdso/processor.h>21#include <vdso/time.h>22#include <vdso/time32.h>23#include <vdso/time64.h>2425#ifdef CONFIG_ARCH_HAS_VDSO_TIME_DATA26#include <asm/vdso/time_data.h>27#else28struct arch_vdso_time_data {};29#endif3031#if defined(CONFIG_ARCH_HAS_VDSO_ARCH_DATA)32#include <asm/vdso/arch_data.h>33#elif defined(CONFIG_GENERIC_VDSO_DATA_STORE)34struct vdso_arch_data {35/* Needed for the generic code, never actually used at runtime */36char __unused;37};38#endif3940#define VDSO_BASES (CLOCK_TAI + 1)41#define VDSO_BASE_AUX 042#define VDSO_HRES (BIT(CLOCK_REALTIME) | \43BIT(CLOCK_MONOTONIC) | \44BIT(CLOCK_BOOTTIME) | \45BIT(CLOCK_TAI))46#define VDSO_COARSE (BIT(CLOCK_REALTIME_COARSE) | \47BIT(CLOCK_MONOTONIC_COARSE))48#define VDSO_RAW (BIT(CLOCK_MONOTONIC_RAW))49#define VDSO_AUX __GENMASK(CLOCK_AUX_LAST, CLOCK_AUX)5051#define CS_HRES_COARSE 052#define CS_RAW 153#define CS_BASES (CS_RAW + 1)5455/**56* struct vdso_timestamp - basetime per clock_id57* @sec: seconds58* @nsec: nanoseconds59*60* There is one vdso_timestamp object in vvar for each vDSO-accelerated61* clock_id. For high-resolution clocks, this encodes the time62* corresponding to vdso_time_data.cycle_last. For coarse clocks this encodes63* the actual time.64*65* To be noticed that for highres clocks nsec is left-shifted by66* vdso_time_data[x].shift.67*/68struct vdso_timestamp {69u64 sec;70u64 nsec;71};7273/**74* struct vdso_clock - vdso per clocksource datapage representation75* @seq: timebase sequence counter76* @clock_mode: clock mode77* @cycle_last: timebase at clocksource init78* @max_cycles: maximum cycles which won't overflow 64bit multiplication79* @mask: clocksource mask80* @mult: clocksource multiplier81* @shift: clocksource shift82* @basetime[clock_id]: basetime per clock_id83* @offset[clock_id]: time namespace offset per clock_id84*85* See also struct vdso_time_data for basic access and ordering information as86* struct vdso_clock is used there.87*88* @basetime is used to store the base time for the system wide time getter89* VVAR page.90*91* @offset is used by the special time namespace VVAR pages which are92* installed instead of the real VVAR page. These namespace pages must set93* @seq to 1 and @clock_mode to VDSO_CLOCKMODE_TIMENS to force the code into94* the time namespace slow path. The namespace aware functions retrieve the95* real system wide VVAR page, read host time and add the per clock offset.96* For clocks which are not affected by time namespace adjustment the97* offset must be zero.98*/99struct vdso_clock {100u32 seq;101102s32 clock_mode;103u64 cycle_last;104#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT105u64 max_cycles;106#endif107u64 mask;108u32 mult;109u32 shift;110111union {112struct vdso_timestamp basetime[VDSO_BASES];113struct timens_offset offset[VDSO_BASES];114};115};116117/**118* struct vdso_time_data - vdso datapage representation119* @arch_data: architecture specific data (optional, defaults120* to an empty struct)121* @clock_data: clocksource related data (array)122* @aux_clock_data: auxiliary clocksource related data (array)123* @tz_minuteswest: minutes west of Greenwich124* @tz_dsttime: type of DST correction125* @hrtimer_res: hrtimer resolution126* @__unused: unused127*128* vdso_time_data will be accessed by 64 bit and compat code at the same time129* so we should be careful before modifying this structure.130*131* The ordering of the struct members is optimized to have fast acces to the132* often required struct members which are related to CLOCK_REALTIME and133* CLOCK_MONOTONIC. This information is stored in the first cache lines.134*/135struct vdso_time_data {136struct arch_vdso_time_data arch_data;137138struct vdso_clock clock_data[CS_BASES];139struct vdso_clock aux_clock_data[MAX_AUX_CLOCKS];140141s32 tz_minuteswest;142s32 tz_dsttime;143u32 hrtimer_res;144u32 __unused;145} ____cacheline_aligned;146147/**148* struct vdso_rng_data - vdso RNG state information149* @generation: counter representing the number of RNG reseeds150* @is_ready: boolean signaling whether the RNG is initialized151*/152struct vdso_rng_data {153u64 generation;154u8 is_ready;155};156157/*158* We use the hidden visibility to prevent the compiler from generating a GOT159* relocation. Not only is going through a GOT useless (the entry couldn't and160* must not be overridden by another library), it does not even work: the linker161* cannot generate an absolute address to the data page.162*163* With the hidden visibility, the compiler simply generates a PC-relative164* relocation, and this is what we need.165*/166#ifdef CONFIG_GENERIC_VDSO_DATA_STORE167extern struct vdso_time_data vdso_u_time_data __attribute__((visibility("hidden")));168extern struct vdso_rng_data vdso_u_rng_data __attribute__((visibility("hidden")));169extern struct vdso_arch_data vdso_u_arch_data __attribute__((visibility("hidden")));170171extern struct vdso_time_data *vdso_k_time_data;172extern struct vdso_rng_data *vdso_k_rng_data;173extern struct vdso_arch_data *vdso_k_arch_data;174175#define VDSO_ARCH_DATA_SIZE ALIGN(sizeof(struct vdso_arch_data), PAGE_SIZE)176#define VDSO_ARCH_DATA_PAGES (VDSO_ARCH_DATA_SIZE >> PAGE_SHIFT)177178enum vdso_pages {179VDSO_TIME_PAGE_OFFSET,180VDSO_TIMENS_PAGE_OFFSET,181VDSO_RNG_PAGE_OFFSET,182VDSO_ARCH_PAGES_START,183VDSO_ARCH_PAGES_END = VDSO_ARCH_PAGES_START + VDSO_ARCH_DATA_PAGES - 1,184VDSO_NR_PAGES185};186187#endif /* CONFIG_GENERIC_VDSO_DATA_STORE */188189/*190* The generic vDSO implementation requires that gettimeofday.h191* provides:192* - __arch_get_hw_counter(): to get the hw counter based on the193* clock_mode.194* - gettimeofday_fallback(): fallback for gettimeofday.195* - clock_gettime_fallback(): fallback for clock_gettime.196* - clock_getres_fallback(): fallback for clock_getres.197*/198#ifdef ENABLE_COMPAT_VDSO199#include <asm/vdso/compat_gettimeofday.h>200#else201#include <asm/vdso/gettimeofday.h>202#endif /* ENABLE_COMPAT_VDSO */203204#else /* !__ASSEMBLY__ */205206#ifdef CONFIG_VDSO_GETRANDOM207#define __vdso_u_rng_data PROVIDE(vdso_u_rng_data = vdso_u_data + 2 * PAGE_SIZE);208#else209#define __vdso_u_rng_data210#endif211212#ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA213#define __vdso_u_arch_data PROVIDE(vdso_u_arch_data = vdso_u_data + 3 * PAGE_SIZE);214#else215#define __vdso_u_arch_data216#endif217218#define VDSO_VVAR_SYMS \219PROVIDE(vdso_u_data = . - __VDSO_PAGES * PAGE_SIZE); \220PROVIDE(vdso_u_time_data = vdso_u_data); \221__vdso_u_rng_data \222__vdso_u_arch_data \223224225#endif /* !__ASSEMBLY__ */226227#endif /* __VDSO_DATAPAGE_H */228229230