Skip to contentSkip to conversation

UAPI: Document auxvec AT_* namespace policy and note reservations

RFC PATCH In review Dave Martin 5 participants 7 messages May 16, 2018 – May 17, 2018

Subsystems (15)
Arm (32-bit) x86 PowerPC MIPS +11 more subsystems
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 UAPI: Document auxvec AT_* namespace policy and note reservations

There are constraints on defining AT_* auxvec tags that are not obvious to the casual maintainer of either the global <uapi/linux/auxvec.h> or the arch-specific headers. This is likely to lead to mistakes. (I certainly fell foul of it...)

For the benefit of future maintainers, this patch collects the relevant information in one place, documenting how the namespace needs to be managed, and noting all the values currently in use.

Maintaining a global list may result in some merge conflicts, but AT_* values are not added frequently. I'm open to suggestions on the best approach.

I also assume that values 38 and 39 may have been used for historical purposes, such as an architecture that is no longer supported. If they have definitely never been used for anything, they could be removed from the "reserved" list.

Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc Russell King <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Michal Simek <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc James Hogan <[email protected]>
Cc Greentime Hu <[email protected]>
Cc Vincent Chen <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
Cc Yoshinori Sato <[email protected]>
Cc Rich Felker <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Chris Zankel <[email protected]>
Cc Max Filippov <[email protected]>
---
 arch/alpha/include/uapi/asm/auxvec.h      |  5 ++++
 arch/arm/include/uapi/asm/auxvec.h        |  5 ++++
 arch/arm64/include/uapi/asm/auxvec.h      |  5 ++++
 arch/ia64/include/uapi/asm/auxvec.h       |  5 ++++
 arch/microblaze/include/uapi/asm/auxvec.h |  4 ++++
 arch/mips/include/uapi/asm/auxvec.h       |  5 ++++
 arch/nds32/include/uapi/asm/auxvec.h      |  5 ++++
 arch/powerpc/include/uapi/asm/auxvec.h    |  5 ++++
 arch/riscv/include/uapi/asm/auxvec.h      |  5 ++++
 arch/s390/include/uapi/asm/auxvec.h       |  5 ++++
 arch/sh/include/uapi/asm/auxvec.h         |  5 ++++
 arch/sparc/include/uapi/asm/auxvec.h      |  8 ++++---
 arch/x86/include/uapi/asm/auxvec.h        |  5 ++++
 arch/xtensa/include/uapi/asm/auxvec.h     |  5 ++++
 include/uapi/linux/auxvec.h               | 40 ++++++++++++++++++++++++++++---
 15 files changed, 106 insertions(+), 6 deletions(-)
arch/alpha/include/uapi/asm/auxvec.h +5 -0
index 57cae87..9370d78 100644
@@ -22,6 +22,11 @@
 #define AT_L2_CACHESHAPE	36
 #define AT_L3_CACHESHAPE	37
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 4 /* entries in ARCH_DLINFO */
 
 #endif /* __ASM_ALPHA_AUXVEC_H */
arch/arm/include/uapi/asm/auxvec.h +5 -0
index 5c09da5..b5cfba2 100644
@@ -5,4 +5,9 @@
 /* VDSO location */
 #define AT_SYSINFO_EHDR	33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #endif
arch/arm64/include/uapi/asm/auxvec.h +5 -0
index ec0a86d..3da03fc 100644
@@ -20,6 +20,11 @@
 /* vDSO location */
 #define AT_SYSINFO_EHDR	33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
 
 #endif
arch/ia64/include/uapi/asm/auxvec.h +5 -0
index 09969a5..a81aec5 100644
@@ -9,6 +9,11 @@
 #define AT_SYSINFO	32
 #define AT_SYSINFO_EHDR	33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 2 /* entries in ARCH_DLINFO */
 
 #endif /* _ASM_IA64_AUXVEC_H */
arch/microblaze/include/uapi/asm/auxvec.h +4 -0
index 93dd07b..b08c6dc 100644
@@ -1,2 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
arch/mips/include/uapi/asm/auxvec.h +5 -0
index 612c2c4..ee94899 100644
@@ -15,6 +15,11 @@
 /* Location of VDSO image. */
 #define AT_SYSINFO_EHDR		33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
 
 #endif /* __ASM_AUXVEC_H */
arch/nds32/include/uapi/asm/auxvec.h +5 -0
index 56043ce..0173da1 100644
@@ -7,6 +7,11 @@
 /* VDSO location */
 #define AT_SYSINFO_EHDR	33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 1
 
 #endif
arch/powerpc/include/uapi/asm/auxvec.h +5 -0
index 7af21dc..3da0713 100644
@@ -48,6 +48,11 @@
 #define AT_L3_CACHESIZE		46
 #define AT_L3_CACHEGEOMETRY	47
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH	14 /* entries in ARCH_DLINFO */
 
 #endif
arch/riscv/include/uapi/asm/auxvec.h +5 -0
index 1376515..0dd7983 100644
@@ -21,4 +21,9 @@
 /* vDSO location */
 #define AT_SYSINFO_EHDR 33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #endif /* _UAPI_ASM_RISCV_AUXVEC_H */
arch/s390/include/uapi/asm/auxvec.h +5 -0
index a056c46..c30090a 100644
@@ -4,6 +4,11 @@
 
 #define AT_SYSINFO_EHDR		33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
 
 #endif
arch/sh/include/uapi/asm/auxvec.h +5 -0
index 8eb47ed..e5b6ebc 100644
@@ -34,6 +34,11 @@
 #define AT_L1D_CACHESHAPE	35
 #define AT_L2_CACHESHAPE	36
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH 5 /* entries in ARCH_DLINFO */
 
 #endif /* __ASM_SH_AUXVEC_H */
arch/sparc/include/uapi/asm/auxvec.h +5 -3
index ab8780f..76aba18 100644
@@ -3,13 +3,15 @@
 
 #define AT_SYSINFO_EHDR		33
 
-/* Avoid overlap with other AT_* values since they are consolidated in
- * glibc and any overlaps can cause problems
- */
 #define AT_ADI_BLKSZ	48
 #define AT_ADI_NBITS	49
 #define AT_ADI_UEONADI	50
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #define AT_VECTOR_SIZE_ARCH	4
 
 #endif /* !(__ASMSPARC_AUXVEC_H) */
arch/x86/include/uapi/asm/auxvec.h +5 -0
index 580e3c5..700c0fc 100644
@@ -10,6 +10,11 @@
 #endif
 #define AT_SYSINFO_EHDR		33
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 /* entries in ARCH_DLINFO: */
 #if defined(CONFIG_IA32_EMULATION) || !defined(CONFIG_X86_64)
 # define AT_VECTOR_SIZE_ARCH 2
arch/xtensa/include/uapi/asm/auxvec.h +5 -0
index 257dec7..995bbd8 100644
@@ -1,4 +1,9 @@
 #ifndef __XTENSA_AUXVEC_H
 #define __XTENSA_AUXVEC_H
 
+/*
+ * Do not add new AT_* definitions here without coordinating with
+ * <uapi/linux/auxvec.h>
+ */
+
 #endif
include/uapi/linux/auxvec.h +37 -3
index abe5f2b..c19c043 100644
@@ -4,8 +4,19 @@
 
 #include <asm/auxvec.h>
 
-/* Symbolic values for the entries in the auxiliary table
-   put on the initial stack */
+/*
+ * Symbolic values for the entries in the auxiliary table
+ * put on the initial stack.
+ *
+ * Values with definitions here are common to all architectures.
+ * Individual architectures may define additional values in their
+ * <uapi/asm/auxvec.h>.
+ *
+ * NOTE: Userspace may treat these numbers as a global namespace.
+ * Any per-architecture definition must not overlap with these or with
+ * any other architecture's definitions, unless it has identical name
+ * and number and compatible meaning.
+ */
 #define AT_NULL   0	/* end of vector */
 #define AT_IGNORE 1	/* entry should be ignored */
 #define AT_EXECFD 2	/* file descriptor of program */
@@ -24,7 +35,11 @@
 #define AT_PLATFORM 15  /* string identifying CPU for optimizations */
 #define AT_HWCAP  16    /* arch dependent hints at CPU capabilities */
 #define AT_CLKTCK 17	/* frequency at which times() increments */
-/* AT_* values 18 through 22 are reserved */
+/* 18 reserved for AT_FPUCW		(sh) */
+/* 19 reserved for AT_DCACHEBSIZE	(powerpc) */
+/* 20 reserved for AT_ICACHEBSIZE	(powerpc) */
+/* 21 reserved for AT_UCACHEBSIZE	(powerpc) */
+/* 22 reserved for AT_IGNOREPPC		(powerpc) */
 #define AT_SECURE 23   /* secure mode boolean */
 #define AT_BASE_PLATFORM 24	/* string identifying real platform, may
 				 * differ from AT_PLATFORM. */
@@ -33,5 +48,24 @@
 
 #define AT_EXECFN  31	/* filename of program */
 
+/* 32 reserved for AT_SYSINFO		(alpha ia64 um x86) */
+/* 33 reserved for AT_SYSINFO_EHDR	(various architectures) */
+/* 34 reserved for AT_L1I_CACHESHAPE	(alpha sh) */
+/* 35 reserved for AT_L1D_CACHESHAPE	(alpha sh) */
+/* 36 reserved for AT_L2_CACHESHAPE	(alpha sh) */
+/* 37 reserved for AT_L3_CACHESHAPE	(alpha) */
+/* 38 reserved, do not allocate */
+/* 39 reserved, do not allocate */
+/* 40 reserved for AT_L1I_CACHESIZE	(powerpc) */
+/* 41 reserved for AT_L1I_CACHEGEOMETRY	(powerpc) */
+/* 42 reserved for AT_L1D_CACHESIZE	(powerpc) */
+/* 43 reserved for AT_L1D_CACHEGEOMETRY	(powerpc) */
+/* 44 reserved for AT_L2_CACHESIZE	(powerpc) */
+/* 45 reserved for AT_L2_CACHEGEOMETRY	(powerpc) */
+/* 46 reserved for AT_L3_CACHESIZE	(powerpc) */
+/* 47 reserved for AT_L3_CACHEGEOMETRY	(powerpc) */
+/* 48 reserved for AT_ADI_BLKSZ		(sparc) */
+/* 49 reserved for AT_ADI_NBITS		(sparc) */
+/* 50 reserved for AT_ADI_UEONADI	(sparc) */
 
 #endif /* _UAPI_LINUX_AUXVEC_H */
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 9 lines · Dave Martin

There are constraints on defining AT_* auxvec tags that are not obvious to the casual maintainer of either the global <uapi/linux/auxvec.h> or the arch-specific headers. This is likely to lead to mistakes. (I certainly fell foul of it...)

For the benefit of future maintainers, this patch collects the relevant information in one place, documenting how the namespace needs to be managed, and noting all the values currently in use.

Quoted 8 lines

Maintaining a global list may result in some merge conflicts, but AT_* values are not added frequently. I'm open to suggestions on the best approach.

I also assume that values 38 and 39 may have been used for historical purposes, such as an architecture that is no longer supported. If they have definitely never been used for anything, they could be removed from the "reserved" list.

On the userspace side (elf.h) all the AT_* constants are in one file. Why don't we just do the same here and eliminate the arch/*/include/uapi/asm/auxvec.h files and likewise the need to manually maintain consistency of the comments about reservations?

If there are reasons not to do that, I'm not opposed to this patch as-is.

Rich

#2 lore raw
Quoted 19 lines · Rich Felker
Quoted 9 lines · Dave Martin

There are constraints on defining AT_* auxvec tags that are not obvious to the casual maintainer of either the global <uapi/linux/auxvec.h> or the arch-specific headers. This is likely to lead to mistakes. (I certainly fell foul of it...)

For the benefit of future maintainers, this patch collects the relevant information in one place, documenting how the namespace needs to be managed, and noting all the values currently in use.

Quoted 8 lines

Maintaining a global list may result in some merge conflicts, but AT_* values are not added frequently. I'm open to suggestions on the best approach.

I also assume that values 38 and 39 may have been used for historical purposes, such as an architecture that is no longer supported. If they have definitely never been used for anything, they could be removed from the "reserved" list.

Quoted 7 lines

On the userspace side (elf.h) all the AT_* constants are in one file. Why don't we just do the same here and eliminate the arch/*/include/uapi/asm/auxvec.h files and likewise the need to manually maintain consistency of the comments about reservations?

If there are reasons not to do that, I'm not opposed to this patch as-is.

I agree, it would be better to merge them.

My concern was that the correct way to get these definitions from userspace is very unclear, so there may be software out there including <asm/auxvec.h> directly, which would now lack expected definitions.

codesearch.debian.net shows no real hits for that, so maybe I'm too paranoid.

Since <linux/auxvec.h> only contains #defines, it may be enough for arch <asm/auxvec.h> headers to include <linux/auxvec.h>.

Thoughts?

Cheers
---Dave

#3 lore raw
Quoted 4 lines · Dave Martin

Since <linux/auxvec.h> only contains #defines, it may be enough for arch <asm/auxvec.h> headers to include <linux/auxvec.h>.

<asm/auxvec.h> doesn't seem to have any reason to exist at all. If anyone includes it now, they are Doing It Wrong[TM] since <linux/auxvec.h> includes <asm/auxvec.h>.

-hpa

maintainer
#4 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 4 lines · Dave Martin

Since <linux/auxvec.h> only contains #defines, it may be enough for arch <asm/auxvec.h> headers to include <linux/auxvec.h>.

<asm/auxvec.h> doesn't seem to have any reason to exist at all. If anyone includes it now, they are Doing It Wrong[TM] since <linux/auxvec.h> includes <asm/auxvec.h>.

Sounds good. BTW there probably does need to be a check for kernel-internal use of #ifdef AT_* etc. I saw some instances in arch/um and a few other weird places. They might not matter but there might be code that's indirectly enabled only for certain archs via the AT_* macros.

Rich

#5 lore raw
In reply to Dave Martin
Quoted 4 lines · Dave Martin

There are constraints on defining AT_* auxvec tags that are not obvious to the casual maintainer of either the global <uapi/linux/auxvec.h> or the arch-specific headers. This is likely to lead to mistakes. (I certainly fell foul of it...)

Thanks for cleaning this up.

It looks like us (powerpc) / me is the main offender here.

My excuse is it was glibc folk who asked us to add all those new AT_ entries in the first place. </buckpassing>

Quoted 7 lines

For the benefit of future maintainers, this patch collects the relevant information in one place, documenting how the namespace needs to be managed, and noting all the values currently in use.

Maintaining a global list may result in some merge conflicts, but AT_* values are not added frequently. I'm open to suggestions on the best approach.

Yeah I agree with Rich that having a global list would be best. That is the most reliable to make people think twice about adding new entries.

Quoted 4 lines

I also assume that values 38 and 39 may have been used for historical purposes, such as an architecture that is no longer supported. If they have definitely never been used for anything, they could be removed from the "reserved" list.

I don't know why we added the new entries starting at 40, maybe Ben remembers. Quite likely it was just an accident.

I don't see any sign of 38 or 39 in glibc history.

cheers

#6 lore raw
In reply to Dave Martin

Hi,

Quoted 9 lines · Dave Martin

There are constraints on defining AT_* auxvec tags that are not obvious to the casual maintainer of either the global <uapi/linux/auxvec.h> or the arch-specific headers. This is likely to lead to mistakes. (I certainly fell foul of it...)

For the benefit of future maintainers, this patch collects the relevant information in one place, documenting how the namespace needs to be managed, and noting all the values currently in use.

Quoted 9 lines

Maintaining a global list may result in some merge conflicts, but AT_* values are not added frequently. I'm open to suggestions on the best approach.

I also assume that values 38 and 39 may have been used for historical purposes, such as an architecture that is no longer supported. If they have definitely never been used for anything, they could be removed from the "reserved" list.

Some of those AT_* values are described in getauxval(3) man-page:

http://man7.org/linux/man-pages/man3/getauxval.3.html

https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/man3/g
etauxval.3?id=4eae8eb731386d81797d5c30365426722410874e

And glibc provides <elf.h> with definitions for almost all AT_*, regardless of the current target architecture:

https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/elf.h;h=954f3266f7
11ab83996670ea504a17dcf668e061;hb=23158b08a0908f381459f273a984c6fd32836 3cb#l1135

Also, despite not being listed as a reserved namespace by POSIX, one should try to avoid name collision with other AT_ constants, those used with *at() functions (openat(), etc.):

- AT_EACCESS
- AT_EMPTY_PATH
- AT_FDCWD
- AT_NO_AUTOMOUNT
- AT_REMOVEDIR
- AT_STATX_DONT_SYNC
- AT_STATX_FORCE_SYNC
- AT_STATX_SYNC_AS_STAT
- AT_SYMLINK_FOLLOW
- AT_SYMLINK_NOFOLLOW

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html

http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.htm
l#tag_15_02_02

https://sourceware.org/git/?p=glibc.git;a=blob;f=io/fcntl.h;h=3d239e8f0
9f7ce0a3106621be327e1ea4cd1a3e7;hb=23158b08a0908f381459f273a984c6fd3283 63cb#l142

And there's also AT_ANYNET and AT_ANYNODE from ddp (aka. AppleTalk)

http://man7.org/linux/man-pages/man7/ddp.7.html

Regards.

Signature · 2 lines
Yann Droneaud
OPTEYA