xref: /openbmc/linux/arch/x86/include/asm/vvar.h (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
16776e83eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
28c49d9a7SAndy Lutomirski /*
38c49d9a7SAndy Lutomirski  * vvar.h: Shared vDSO/kernel variable declarations
48c49d9a7SAndy Lutomirski  * Copyright (c) 2011 Andy Lutomirski
58c49d9a7SAndy Lutomirski  *
68c49d9a7SAndy Lutomirski  * A handful of variables are accessible (read-only) from userspace
78c49d9a7SAndy Lutomirski  * code in the vsyscall page and the vdso.  They are declared here.
88c49d9a7SAndy Lutomirski  * Some other file must define them with DEFINE_VVAR.
98c49d9a7SAndy Lutomirski  *
108c49d9a7SAndy Lutomirski  * In normal kernel code, they are used like any other variable.
118c49d9a7SAndy Lutomirski  * In user code, they are accessed through the VVAR macro.
128c49d9a7SAndy Lutomirski  *
139fd67b4eSAndy Lutomirski  * These variables live in a page of kernel data that has an extra RO
149fd67b4eSAndy Lutomirski  * mapping for userspace.  Each variable needs a unique offset within
159fd67b4eSAndy Lutomirski  * that page; specify that offset with the DECLARE_VVAR macro.  (If
169fd67b4eSAndy Lutomirski  * you mess up, the linker will catch it.)
178c49d9a7SAndy Lutomirski  */
188c49d9a7SAndy Lutomirski 
197c03156fSStefani Seibold #ifndef _ASM_X86_VVAR_H
207c03156fSStefani Seibold #define _ASM_X86_VVAR_H
217c03156fSStefani Seibold 
2264b302abSDmitry Safonov #ifdef EMIT_VVAR
2364b302abSDmitry Safonov /*
2464b302abSDmitry Safonov  * EMIT_VVAR() is used by the kernel linker script to put vvars in the
2564b302abSDmitry Safonov  * right place. Also, it's used by kernel code to import offsets values.
268c49d9a7SAndy Lutomirski  */
278c49d9a7SAndy Lutomirski #define DECLARE_VVAR(offset, type, name) \
289fd67b4eSAndy Lutomirski 	EMIT_VVAR(name, offset)
298c49d9a7SAndy Lutomirski 
308c49d9a7SAndy Lutomirski #else
318c49d9a7SAndy Lutomirski 
32f40c3300SAndy Lutomirski extern char __vvar_page;
33ef721987SStefani Seibold 
34ef721987SStefani Seibold #define DECLARE_VVAR(offset, type, name)				\
357ac87074SVincenzo Frascino 	extern type vvar_ ## name[CS_BASES]				\
36*550a77a7SDmitry Safonov 	__attribute__((visibility("hidden")));				\
37*550a77a7SDmitry Safonov 	extern type timens_ ## name[CS_BASES]				\
38*550a77a7SDmitry Safonov 	__attribute__((visibility("hidden")));				\
39ef721987SStefani Seibold 
40ef721987SStefani Seibold #define VVAR(name) (vvar_ ## name)
41*550a77a7SDmitry Safonov #define TIMENS(name) (timens_ ## name)
42ef721987SStefani Seibold 
438c49d9a7SAndy Lutomirski #define DEFINE_VVAR(type, name)						\
447ac87074SVincenzo Frascino 	type name[CS_BASES]						\
4528596b6aSAndi Kleen 	__attribute__((section(".vvar_" #name), aligned(16))) __visible
468c49d9a7SAndy Lutomirski 
478c49d9a7SAndy Lutomirski #endif
488c49d9a7SAndy Lutomirski 
498c49d9a7SAndy Lutomirski /* DECLARE_VVAR(offset, type, name) */
508c49d9a7SAndy Lutomirski 
517ac87074SVincenzo Frascino DECLARE_VVAR(128, struct vdso_data, _vdso_data)
528c49d9a7SAndy Lutomirski 
538c49d9a7SAndy Lutomirski #undef DECLARE_VVAR
547c03156fSStefani Seibold 
557c03156fSStefani Seibold #endif
56