powerpc/vdso: Add support for time namespaces
cover powerpc/vdso: Add support for time namespaces
This series adds support for time namespaces on powerpc.
All timens selftests are successfull.
Christophe Leroy (3):
lib/vdso: Mark do_hres_timens() and do_coarse_timens()
__always_inline()
lib/vdso: Add vdso_data pointer as input to
__arch_get_timens_vdso_data()powerpc/vdso: Add support for time namespaces
Dmitry Safonov (1):
powerpc/vdso: Separate vvar vma from vdso
.../include/asm/vdso/compat_gettimeofday.h | 3 +- arch/arm64/include/asm/vdso/gettimeofday.h | 2 +- arch/powerpc/Kconfig | 3 +- arch/powerpc/include/asm/mmu_context.h | 2 +- arch/powerpc/include/asm/vdso/gettimeofday.h | 10 ++ arch/powerpc/include/asm/vdso_datapage.h | 2 - arch/powerpc/kernel/vdso.c | 138 ++++++++++++++++-- arch/powerpc/kernel/vdso32/vdso32.lds.S | 2 +- arch/powerpc/kernel/vdso64/vdso64.lds.S | 2 +- arch/s390/include/asm/vdso/gettimeofday.h | 3 +- arch/x86/include/asm/vdso/gettimeofday.h | 3 +- lib/vdso/gettimeofday.c | 31 ++-- 12 files changed, 162 insertions(+), 39 deletions(-)
Signature · 1 line
2.25.0
PATCH 2/4 lib/vdso: Add vdso_data pointer as input to __arch_get_timens_vdso_data()
For the same reason as commit e876f0b69dc9 ("lib/vdso: Allow architectures to provide the vdso data pointer"), powerpc wants to avoid calculation of relative position to code.
As the timens_vdso_data is next page to vdso_data, provide vdso_data pointer to __arch_get_timens_vdso_data() in order to ease the calculation on powerpc in following patches.
--- arch/arm64/include/asm/vdso/compat_gettimeofday.h | 3 ++- arch/arm64/include/asm/vdso/gettimeofday.h | 2 +- arch/s390/include/asm/vdso/gettimeofday.h | 3 ++- arch/x86/include/asm/vdso/gettimeofday.h | 3 ++- lib/vdso/gettimeofday.c | 15 +++++++++------ 5 files changed, 16 insertions(+), 10 deletions(-)
arch/arm64/include/asm/vdso/compat_gettimeofday.h +2 -1
@@ -155,7 +155,8 @@ static __always_inline const struct vdso_data *__arch_get_vdso_data(void) }#ifdef CONFIG_TIME_NS -static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void) +static __always_inline +const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) {const struct vdso_data *ret;
arch/arm64/include/asm/vdso/gettimeofday.h +1 -1
@@ -100,7 +100,7 @@ const struct vdso_data *__arch_get_vdso_data(void)#ifdef CONFIG_TIME_NS static __always_inline -const struct vdso_data *__arch_get_timens_vdso_data(void) +const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) {return _timens_data; }
arch/s390/include/asm/vdso/gettimeofday.h +2 -1
@@ -68,7 +68,8 @@ long clock_getres_fallback(clockid_t clkid, struct __kernel_timespec *ts) }#ifdef CONFIG_TIME_NS -static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void) +static __always_inline +const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) {return _timens_data; }
arch/x86/include/asm/vdso/gettimeofday.h +2 -1
@@ -58,7 +58,8 @@ extern struct ms_hyperv_tsc_page hvclock_page#endif #ifdef CONFIG_TIME_NS -static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void) +static __always_inline +const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) {return __timens_vdso_data; }
lib/vdso/gettimeofday.c +9 -6
@@ -49,13 +49,15 @@ static inline bool vdso_cycles_ok(u64 cycles) static __always_inline int do_hres_timens(const struct vdso_data *vdns, clockid_t clk,struct __kernel_timespec *ts) { -const struct vdso_data *vd =__arch_get_timens_vdso_data (); +const struct vdso_data *vd;const struct timens_offset *offs = &vdns->offset[clk];const struct vdso_timestamp *vdso_ts;u64 cycles, last, ns;u32 seq;s64 sec; + vd = vdns - (clk ==CLOCK_MONOTONIC_RAW ?CS_RAW :CS_HRES_COARSE ); + vd =__arch_get_timens_vdso_data (vd);if (clk !=CLOCK_MONOTONIC_RAW ) vd = &vd[CS_HRES_COARSE ];else
@@ -92,7 +94,8 @@ static __always_inline int do_hres_timens(const struct vdso_data *vdns, clockid_return 0 ; }#else -static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void) +static __always_inline +const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) {return NULL ; }
@@ -162,7 +165,7 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk, static __always_inline int do_coarse_timens(const struct vdso_data *vdns, clockid_t clk,struct __kernel_timespec *ts) { -const struct vdso_data *vd =__arch_get_timens_vdso_data (); +const struct vdso_data *vd =__arch_get_timens_vdso_data (vdns);const struct vdso_timestamp *vdso_ts = &vd->basetime[clk];const struct timens_offset *offs = &vdns->offset[clk];u64 nsec;
@@ -310,7 +313,7 @@ __cvdso_gettimeofday_data(const struct vdso_data *vd,if (unlikely (tz !=NULL )) {if (IS_ENABLED (CONFIG_TIME_NS ) && vd->clock_mode ==VDSO_CLOCKMODE_TIMENS ) - vd =__arch_get_timens_vdso_data (); + vd =__arch_get_timens_vdso_data (vd); tz->tz_minuteswest = vd[CS_HRES_COARSE ].tz_minuteswest; tz->tz_dsttime = vd[CS_HRES_COARSE ].tz_dsttime;
@@ -333,7 +336,7 @@ __cvdso_time_data(const struct vdso_data *vd, __kernel_old_time_t *time)if (IS_ENABLED (CONFIG_TIME_NS ) && vd->clock_mode ==VDSO_CLOCKMODE_TIMENS ) - vd =__arch_get_timens_vdso_data (); + vd =__arch_get_timens_vdso_data (vd); t =READ_ONCE (vd[CS_HRES_COARSE ].basetime[CLOCK_REALTIME ].sec);
@@ -363,7 +366,7 @@ int __cvdso_clock_getres_common(const struct vdso_data *vd, clockid_t clock,if (IS_ENABLED (CONFIG_TIME_NS ) && vd->clock_mode ==VDSO_CLOCKMODE_TIMENS ) - vd =__arch_get_timens_vdso_data (); + vd =__arch_get_timens_vdso_data (vd);/* * Convert the clockid to a bitmask and use it to check which
Signature · 1 line
2.25.0
PATCH 1/4 lib/vdso: Mark do_hres_timens() and do_coarse_timens() __always_inline()
In reply to Christophe LeroyIn the same spirit as commit c966533f8c6c ("lib/vdso: Mark do_hres() and do_coarse() as __always_inline"), mark do_hres_timens() and do_coarse_timens() __always_inline.
The measurement below in on a non timens process, ie on the fastest path.
On powerpc32, without the patch:
clock-gettime-monotonic-raw: vdso: 1155 nsec/call clock-gettime-monotonic-coarse: vdso: 813 nsec/call clock-gettime-monotonic: vdso: 1076 nsec/call
With the patch:
clock-gettime-monotonic-raw: vdso: 1100 nsec/call clock-gettime-monotonic-coarse: vdso: 667 nsec/call clock-gettime-monotonic: vdso: 1025 nsec/call
--- lib/vdso/gettimeofday.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
lib/vdso/gettimeofday.c +8 -8
@@ -46,8 +46,8 @@ static inline bool vdso_cycles_ok(u64 cycles)#endif #ifdef CONFIG_TIME_NS -static int do_hres_timens (const struct vdso_data *vdns,clockid_t clk, -struct __kernel_timespec *ts) +static __always_inline int do_hres_timens(const struct vdso_data *vdns, clockid_t clk, +struct __kernel_timespec *ts) {const struct vdso_data *vd =__arch_get_timens_vdso_data ();const struct timens_offset *offs = &vdns->offset[clk];
@@ -97,8 +97,8 @@ static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void)return NULL ; } -static int do_hres_timens (const struct vdso_data *vdns,clockid_t clk, -struct __kernel_timespec *ts) +static __always_inline int do_hres_timens(const struct vdso_data *vdns, clockid_t clk, +struct __kernel_timespec *ts) {return -EINVAL ; }
@@ -159,8 +159,8 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk, }#ifdef CONFIG_TIME_NS -static int do_coarse_timens (const struct vdso_data *vdns,clockid_t clk, -struct __kernel_timespec *ts) +static __always_inline int do_coarse_timens(const struct vdso_data *vdns, clockid_t clk, +struct __kernel_timespec *ts) {const struct vdso_data *vd =__arch_get_timens_vdso_data ();const struct vdso_timestamp *vdso_ts = &vd->basetime[clk];
@@ -188,8 +188,8 @@ static int do_coarse_timens(const struct vdso_data *vdns, clockid_t clk,return 0 ; }#else -static int do_coarse_timens (const struct vdso_data *vdns,clockid_t clk, -struct __kernel_timespec *ts) +static __always_inline int do_coarse_timens(const struct vdso_data *vdns, clockid_t clk, +struct __kernel_timespec *ts) {return -1 ; }
Signature · 1 line
2.25.0
PATCH 3/4 powerpc/vdso: Separate vvar vma from vdso
In reply to Christophe LeroyFrom: Dmitry Safonov <[email protected]>
Since commit 511157ab641e ("powerpc/vdso: Move vdso datapage up front") VVAR page is in front of the VDSO area. In result it breaks CRIU (Checkpoint Restore In Userspace) [1], where CRIU expects that "[vdso]" from /proc/../maps points at ELF/vdso image, rather than at VVAR data page. Laurent made a patch to keep CRIU working (by reading aux vector). But I think it still makes sence to separate two mappings into different VMAs. It will also make ppc64 less "special" for userspace and as a side-bonus will make VVAR page un-writable by debugger (which previously would COW page and can be unexpected).
I opportunistically Cc stable on it: I understand that usually such stuff isn't a stable material, but that will allow us in CRIU have one workaround less that is needed just for one release (v5.11) on one platform (ppc64), which we otherwise have to maintain. I wouldn't go as far as to say that the commit 511157ab641e is ABI regression as no other userspace got broken, but I'd really appreciate if it gets backported to v5.11 after v5.12 is released, so as not to complicate already non-simple CRIU-vdso code. Thanks!
Cc: Andrei Vagin <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Laurent Dufour <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: [email protected]
Cc: [email protected] # v5.11
[1]: https://github.com/checkpoint-restore/criu/issues/1417
--- arch/powerpc/include/asm/mmu_context.h | 2 +- arch/powerpc/kernel/vdso.c | 54 +++++++++++++++++++------- 2 files changed, 40 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/mmu_context.h +1 -1
@@ -263,7 +263,7 @@ extern void arch_exit_mmap(struct mm_struct *mm);static inline void arch_unmap (struct mm_struct *mm,unsigned long start,unsigned long end) { -unsigned long vdso_base = (unsigned long )mm->context.vdso -PAGE_SIZE ; +unsigned long vdso_base = (unsigned long )mm->context.vdso;if (start <= vdso_base && vdso_base < end) mm->context.vdso =NULL ;
arch/powerpc/kernel/vdso.c +39 -15
116 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH 4/4 powerpc/vdso: Add support for time namespaces
In reply to Christophe LeroyThis patch adds the necessary glue to provide time namespaces.
Things are mainly copied from ARM64.
__arch_get_timens_vdso_data() calculates timens vdso data position based on the vdso data position, knowing it is the next page in vvar. This avoids having to redo the mflr/bcl/mflr/mtlr dance to locate the page relative to running code position.
--- arch/powerpc/Kconfig | 3 +- arch/powerpc/include/asm/vdso/gettimeofday.h | 10 ++ arch/powerpc/include/asm/vdso_datapage.h | 2 - arch/powerpc/kernel/vdso.c | 116 ++++++++++++++++--- arch/powerpc/kernel/vdso32/vdso32.lds.S | 2 +- arch/powerpc/kernel/vdso64/vdso64.lds.S | 2 +- 6 files changed, 114 insertions(+), 21 deletions(-)
arch/powerpc/Kconfig +2 -1
@@ -172,6 +172,7 @@ config PPC select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_VULNERABILITIES if PPC_BARRIER_NOSPEC select GENERIC_EARLY_IOREMAP + select GENERIC_GETTIMEOFDAY select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAP if PCI
@@ -179,7 +180,7 @@ config PPC select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL - select GENERIC_GETTIMEOFDAY + select GENERIC_VDSO_TIME_NS select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_HUGE_VMAP if PPC_BOOK3S_64 && PPC_RADIX_MMU select HAVE_ARCH_JUMP_LABEL
arch/powerpc/include/asm/vdso/gettimeofday.h +10 -0
@@ -2,6 +2,8 @@#ifndef _ASM_POWERPC_VDSO_GETTIMEOFDAY_H#define _ASM_POWERPC_VDSO_GETTIMEOFDAY_H +#include <asm/page.h> +#ifdef __ASSEMBLY__#include <asm/ppc_asm.h>
@@ -153,6 +155,14 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,const struct vdso_data *__arch_get_vdso_data (void ); +#ifdef CONFIG_TIME_NS +static __always_inline +const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) +{ +return (void *)vd +PAGE_SIZE ; +} +#endif +static inline bool vdso_clocksource_ok (const struct vdso_data *vd) {return true;
arch/powerpc/include/asm/vdso_datapage.h +0 -2
@@ -107,9 +107,7 @@ extern struct vdso_arch_data *vdso_data; bcl 20, 31, .+4 999: mflr \ptr -#if CONFIG_PPC_PAGE_SHIFT >14 addis \ptr, \ptr, (_vdso_datapage - 999b)@ha -#endif addi \ptr, \ptr, (_vdso_datapage - 999b)@l .endm
arch/powerpc/kernel/vdso.c +100 -16
160 lines not on this page · raw message
arch/powerpc/kernel/vdso32/vdso32.lds.S +1 -1
@@ -17,7 +17,7 @@ ENTRY(_start) SECTIONS { - PROVIDE(_vdso_datapage = . - PAGE_SIZE); + PROVIDE(_vdso_datapage = . - 2 * PAGE_SIZE); . = SIZEOF_HEADERS; .hash : { *(.hash) } :text
arch/powerpc/kernel/vdso64/vdso64.lds.S +1 -1
@@ -17,7 +17,7 @@ ENTRY(_start) SECTIONS { - PROVIDE(_vdso_datapage = . - PAGE_SIZE); + PROVIDE(_vdso_datapage = . - 2 * PAGE_SIZE); . = SIZEOF_HEADERS; .hash : { *(.hash) } :text
Signature · 1 line
2.25.0