powerpc: switch VDSO to C implementation
Subsystems (3)
v8 cover powerpc: switch VDSO to C implementation
This is the seventh version of a series to switch powerpc VDSO to generic C implementation.
Main changes since v7 are:
- Added gettime64 on PPC32
This series applies on today's powerpc/merge branch.
See the last patches for details on changes and performance.
Christophe Leroy (8):
powerpc/vdso64: Switch from __get_datapage() to get_datapage inline
macro
powerpc/vdso: Remove __kernel_datapage_offset and simplify
__get_datapage()
powerpc/vdso: Remove unused \tmp param in __get_datapage() powerpc/processor: Move cpu_relax() into asm/vdso/processor.h powerpc/vdso: Prepare for switching VDSO to generic C implementation. powerpc/vdso: Switch VDSO to generic C implementation. lib/vdso: force inlining of __cvdso_clock_gettime_common() powerpc/vdso: Provide __kernel_clock_gettime64() on vdso32
arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/clocksource.h | 7 + arch/powerpc/include/asm/processor.h | 10 +- arch/powerpc/include/asm/vdso/clocksource.h | 7 + arch/powerpc/include/asm/vdso/gettimeofday.h | 175 +++++++++++ arch/powerpc/include/asm/vdso/processor.h | 23 ++ arch/powerpc/include/asm/vdso/vsyscall.h | 25 ++ arch/powerpc/include/asm/vdso_datapage.h | 50 ++-- arch/powerpc/kernel/asm-offsets.c | 49 +-- arch/powerpc/kernel/time.c | 91 +----- arch/powerpc/kernel/vdso.c | 58 +--- arch/powerpc/kernel/vdso32/Makefile | 32 +- arch/powerpc/kernel/vdso32/cacheflush.S | 2 +- arch/powerpc/kernel/vdso32/config-fake32.h | 34 +++ arch/powerpc/kernel/vdso32/datapage.S | 7 +- arch/powerpc/kernel/vdso32/gettimeofday.S | 300 +------------------ arch/powerpc/kernel/vdso32/vdso32.lds.S | 8 +- arch/powerpc/kernel/vdso32/vgettimeofday.c | 35 +++ arch/powerpc/kernel/vdso64/Makefile | 23 +- arch/powerpc/kernel/vdso64/cacheflush.S | 9 +- arch/powerpc/kernel/vdso64/datapage.S | 31 +- arch/powerpc/kernel/vdso64/gettimeofday.S | 243 +-------------- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 +- arch/powerpc/kernel/vdso64/vgettimeofday.c | 29 ++ lib/vdso/gettimeofday.c | 2 +- 25 files changed, 460 insertions(+), 799 deletions(-) create mode 100644 arch/powerpc/include/asm/clocksource.h create mode 100644 arch/powerpc/include/asm/vdso/clocksource.h create mode 100644 arch/powerpc/include/asm/vdso/gettimeofday.h create mode 100644 arch/powerpc/include/asm/vdso/processor.h create mode 100644 arch/powerpc/include/asm/vdso/vsyscall.h create mode 100644 arch/powerpc/kernel/vdso32/config-fake32.h create mode 100644 arch/powerpc/kernel/vdso32/vgettimeofday.c create mode 100644 arch/powerpc/kernel/vdso64/vgettimeofday.c
Signature · 1 line
2.25.0
PATCH v8 1/8 powerpc/vdso64: Switch from __get_datapage() to get_datapage inline macro
On the same way as already done on PPC32, drop __get_datapage() function and use get_datapage inline macro instead.
See commit ec0895f08f99 ("powerpc/vdso32: inline __get_datapage()")
--- arch/powerpc/kernel/vdso64/cacheflush.S | 9 ++++---- arch/powerpc/kernel/vdso64/datapage.S | 28 +++-------------------- arch/powerpc/kernel/vdso64/gettimeofday.S | 8 +++---- 3 files changed, 11 insertions(+), 34 deletions(-)
arch/powerpc/kernel/vdso64/cacheflush.S +4 -5
@@ -8,6 +8,7 @@ #include <asm/processor.h> #include <asm/ppc_asm.h> #include <asm/vdso.h> +#include <asm/vdso_datapage.h> #include <asm/asm-offsets.h> .text
@@ -24,14 +25,12 @@ V_FUNCTION_BEGIN(__kernel_sync_dicache) .cfi_startproc mflr r12 .cfi_register lr,r12 - mr r11,r3 - bl V_LOCAL_FUNC(__get_datapage) + get_datapage r10, r0 mtlr r12 - mr r10,r3 lwz r7,CFG_DCACHE_BLOCKSZ(r10) addi r5,r7,-1 - andc r6,r11,r5 /* round low to line bdy */ + andc r6,r3,r5 /* round low to line bdy */ subf r8,r6,r4 /* compute length */ add r8,r8,r5 /* ensure we get enough */ lwz r9,CFG_DCACHE_LOGBLOCKSZ(r10)
@@ -48,7 +47,7 @@ V_FUNCTION_BEGIN(__kernel_sync_dicache) lwz r7,CFG_ICACHE_BLOCKSZ(r10) addi r5,r7,-1 - andc r6,r11,r5 /* round low to line bdy */ + andc r6,r3,r5 /* round low to line bdy */ subf r8,r6,r4 /* compute length */ add r8,r8,r5 lwz r9,CFG_ICACHE_LOGBLOCKSZ(r10)
arch/powerpc/kernel/vdso64/datapage.S +3 -25
@@ -10,35 +10,13 @@ #include <asm/asm-offsets.h> #include <asm/unistd.h> #include <asm/vdso.h> +#include <asm/vdso_datapage.h> .text .global __kernel_datapage_offset; __kernel_datapage_offset: .long 0 -V_FUNCTION_BEGIN(__get_datapage) - .cfi_startproc - /* We don't want that exposed or overridable as we want other objects - * to be able to bl directly to here - */ - .protected __get_datapage - .hidden __get_datapage - - mflr r0 - .cfi_register lr,r0 - - bcl 20,31,data_page_branch -data_page_branch: - mflr r3 - mtlr r0 - addi r3, r3, __kernel_datapage_offset-data_page_branch - lwz r0,0(r3) - .cfi_restore lr - add r3,r0,r3 - blr - .cfi_endproc -V_FUNCTION_END(__get_datapage) - /* * void *__kernel_get_syscall_map(unsigned int *syscall_count) ; *
@@ -53,7 +31,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map) mflr r12 .cfi_register lr,r12 mr r4,r3 - bl V_LOCAL_FUNC(__get_datapage) + get_datapage r3, r0 mtlr r12 addi r3,r3,CFG_SYSCALL_MAP64 cmpldi cr0,r4,0
@@ -75,7 +53,7 @@ V_FUNCTION_BEGIN(__kernel_get_tbfreq) .cfi_startproc mflr r12 .cfi_register lr,r12 - bl V_LOCAL_FUNC(__get_datapage) + get_datapage r3, r0 ld r3,CFG_TB_TICKS_PER_SEC(r3) mtlr r12 crclr cr0*4+so
arch/powerpc/kernel/vdso64/gettimeofday.S +4 -4
@@ -26,7 +26,7 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday) mr r11,r3 /* r11 holds tv */ mr r10,r4 /* r10 holds tz */ - bl V_LOCAL_FUNC(__get_datapage) /* get data page */ + get_datapage r3, r0 cmpldi r11,0 /* check if tv is NULL */ beq 2f lis r7,1000000@ha /* load up USEC_PER_SEC */
@@ -71,7 +71,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) mflr r12 /* r12 saves lr */ .cfi_register lr,r12 mr r11,r4 /* r11 saves tp */ - bl V_LOCAL_FUNC(__get_datapage) /* get data page */ + get_datapage r3, r0 lis r7,NSEC_PER_SEC@h /* want nanoseconds */ ori r7,r7,NSEC_PER_SEC@l beq cr5,70f
@@ -188,7 +188,7 @@ V_FUNCTION_BEGIN(__kernel_clock_getres) mflr r12 .cfi_register lr,r12 - bl V_LOCAL_FUNC(__get_datapage) + get_datapage r3, r0 lwz r5, CLOCK_HRTIMER_RES(r3) mtlr r12 li r3,0
@@ -221,7 +221,7 @@ V_FUNCTION_BEGIN(__kernel_time) .cfi_register lr,r12 mr r11,r3 /* r11 holds t */ - bl V_LOCAL_FUNC(__get_datapage) + get_datapage r3, r0 ld r4,STAMP_XTIME_SEC(r3)
Signature · 1 line
2.25.0
PATCH v8 2/8 powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
In reply to Christophe LeroyThe VDSO datapage and the text pages are always located immediately next to each other, so it can be hardcoded without an indirection through __kernel_datapage_offset
In order to ease things, move the data page in front like other arches, that way there is no need to know the size of the library to locate the data page.
Before:
clock-getres-realtime-coarse: vdso: 714 nsec/call clock-gettime-realtime-coarse: vdso: 792 nsec/call clock-gettime-realtime: vdso: 1243 nsec/call
After:
clock-getres-realtime-coarse: vdso: 699 nsec/call clock-gettime-realtime-coarse: vdso: 784 nsec/call clock-gettime-realtime: vdso: 1231 nsec/call
---
v7:
- Moved the removal of the tmp param of __get_datapage() in a subsequent patch
- Included the addition of the offset param to __get_datapage() in the further preparatory patch
--- arch/powerpc/include/asm/vdso_datapage.h | 8 ++-- arch/powerpc/kernel/vdso.c | 53 ++++-------------------- arch/powerpc/kernel/vdso32/datapage.S | 3 -- arch/powerpc/kernel/vdso32/vdso32.lds.S | 7 +--- arch/powerpc/kernel/vdso64/datapage.S | 3 -- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 +--- 6 files changed, 16 insertions(+), 65 deletions(-)
arch/powerpc/include/asm/vdso_datapage.h +5 -3
@@ -118,10 +118,12 @@ extern struct vdso_data *vdso_data; .macro get_datapage ptr, tmp bcl 20, 31, .+4 +999: mflr \ptr - addi \ptr, \ptr, (__kernel_datapage_offset - (.-4))@l - lwz \tmp, 0(\ptr) - add \ptr, \tmp, \ptr +#if CONFIG_PPC_PAGE_SHIFT > 14 + addis \ptr, \ptr, (_vdso_datapage - 999b)@ha +#endif + addi \ptr, \ptr, (_vdso_datapage - 999b)@l .endm #endif /* __ASSEMBLY__ */
arch/powerpc/kernel/vdso.c +7 -46
91 lines not on this page · raw message
arch/powerpc/kernel/vdso32/datapage.S +0 -3
@@ -13,9 +13,6 @@ #include <asm/vdso_datapage.h> .text - .global __kernel_datapage_offset; -__kernel_datapage_offset: - .long 0 /* * void *__kernel_get_syscall_map(unsigned int *syscall_count) ;
arch/powerpc/kernel/vdso32/vdso32.lds.S +2 -5
@@ -4,6 +4,7 @@ * library */ #include <asm/vdso.h> +#include <asm/page.h> #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf32-powerpcle", "elf32-powerpcle", "elf32-powerpcle")
@@ -15,6 +16,7 @@ ENTRY(_start) SECTIONS { + PROVIDE(_vdso_datapage = . - PAGE_SIZE); . = VDSO32_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text
@@ -138,11 +140,6 @@ VERSION { VDSO_VERSION_STRING { global: - /* - * Has to be there for the kernel to find - */ - __kernel_datapage_offset; - __kernel_get_syscall_map; #ifndef CONFIG_PPC_BOOK3S_601 __kernel_gettimeofday;
arch/powerpc/kernel/vdso64/datapage.S +0 -3
@@ -13,9 +13,6 @@ #include <asm/vdso_datapage.h> .text -.global __kernel_datapage_offset; -__kernel_datapage_offset: - .long 0 /* * void *__kernel_get_syscall_map(unsigned int *syscall_count) ;
arch/powerpc/kernel/vdso64/vdso64.lds.S +2 -5
@@ -4,6 +4,7 @@ * library */ #include <asm/vdso.h> +#include <asm/page.h> #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf64-powerpcle", "elf64-powerpcle", "elf64-powerpcle")
@@ -15,6 +16,7 @@ ENTRY(_start) SECTIONS { + PROVIDE(_vdso_datapage = . - PAGE_SIZE); . = VDSO64_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text
@@ -138,11 +140,6 @@ VERSION { VDSO_VERSION_STRING { global: - /* - * Has to be there for the kernel to find - */ - __kernel_datapage_offset; - __kernel_get_syscall_map; __kernel_gettimeofday; __kernel_clock_gettime;
Signature · 1 line
2.25.0
PATCH v8 3/8 powerpc/vdso: Remove unused \tmp param in __get_datapage()
In reply to Christophe LeroyThe \tmp param is not used anymore, remove it.
---
v7: New patch, splitted out of preceding patch
--- arch/powerpc/include/asm/vdso_datapage.h | 2 +- arch/powerpc/kernel/vdso32/cacheflush.S | 2 +- arch/powerpc/kernel/vdso32/datapage.S | 4 ++-- arch/powerpc/kernel/vdso32/gettimeofday.S | 8 ++++---- arch/powerpc/kernel/vdso64/cacheflush.S | 2 +- arch/powerpc/kernel/vdso64/datapage.S | 4 ++-- arch/powerpc/kernel/vdso64/gettimeofday.S | 8 ++++---- 7 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/vdso_datapage.h +1 -1
@@ -116,7 +116,7 @@ extern struct vdso_data *vdso_data;#else /* __ASSEMBLY__ */ -.macro get_datapage ptr, tmp +.macro get_datapage ptr bcl 20, 31, .+4 999: mflr \ptr
arch/powerpc/kernel/vdso32/cacheflush.S +1 -1
@@ -27,7 +27,7 @@ V_FUNCTION_BEGIN(__kernel_sync_dicache) #ifdef CONFIG_PPC64 mflr r12 .cfi_register lr,r12 - get_datapage r10, r0 + get_datapage r10 mtlr r12 #endif
arch/powerpc/kernel/vdso32/datapage.S +2 -2
@@ -28,7 +28,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map) mflr r12 .cfi_register lr,r12 mr. r4,r3 - get_datapage r3, r0 + get_datapage r3 mtlr r12 addi r3,r3,CFG_SYSCALL_MAP32 beqlr
@@ -49,7 +49,7 @@ V_FUNCTION_BEGIN(__kernel_get_tbfreq) .cfi_startproc mflr r12 .cfi_register lr,r12 - get_datapage r3, r0 + get_datapage r3 lwz r4,(CFG_TB_TICKS_PER_SEC + 4)(r3) lwz r3,CFG_TB_TICKS_PER_SEC(r3) mtlr r12
arch/powerpc/kernel/vdso32/gettimeofday.S +4 -4
@@ -34,7 +34,7 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday) mr. r10,r3 /* r10 saves tv */ mr r11,r4 /* r11 saves tz */ - get_datapage r9, r0 + get_datapage r9 beq 3f LOAD_REG_IMMEDIATE(r7, 1000000) /* load up USEC_PER_SEC */ bl __do_get_tspec@local /* get sec/usec from tb & kernel */
@@ -79,7 +79,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) mflr r12 /* r12 saves lr */ .cfi_register lr,r12 mr r11,r4 /* r11 saves tp */ - get_datapage r9, r0 + get_datapage r9 LOAD_REG_IMMEDIATE(r7, NSEC_PER_SEC) /* load up NSEC_PER_SEC */ beq cr5, .Lcoarse_clocks .Lprecise_clocks:
@@ -206,7 +206,7 @@ V_FUNCTION_BEGIN(__kernel_clock_getres) mflr r12 .cfi_register lr,r12 - get_datapage r3, r0 + get_datapage r3 lwz r5, CLOCK_HRTIMER_RES(r3) mtlr r12 1: li r3,0
@@ -240,7 +240,7 @@ V_FUNCTION_BEGIN(__kernel_time) .cfi_register lr,r12 mr r11,r3 /* r11 holds t */ - get_datapage r9, r0 + get_datapage r9 lwz r3,STAMP_XTIME_SEC+LOPART(r9)
arch/powerpc/kernel/vdso64/cacheflush.S +1 -1
@@ -25,7 +25,7 @@ V_FUNCTION_BEGIN(__kernel_sync_dicache) .cfi_startproc mflr r12 .cfi_register lr,r12 - get_datapage r10, r0 + get_datapage r10 mtlr r12 lwz r7,CFG_DCACHE_BLOCKSZ(r10)
arch/powerpc/kernel/vdso64/datapage.S +2 -2
@@ -28,7 +28,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map) mflr r12 .cfi_register lr,r12 mr r4,r3 - get_datapage r3, r0 + get_datapage r3 mtlr r12 addi r3,r3,CFG_SYSCALL_MAP64 cmpldi cr0,r4,0
@@ -50,7 +50,7 @@ V_FUNCTION_BEGIN(__kernel_get_tbfreq) .cfi_startproc mflr r12 .cfi_register lr,r12 - get_datapage r3, r0 + get_datapage r3 ld r3,CFG_TB_TICKS_PER_SEC(r3) mtlr r12 crclr cr0*4+so
arch/powerpc/kernel/vdso64/gettimeofday.S +4 -4
@@ -26,7 +26,7 @@ V_FUNCTION_BEGIN(__kernel_gettimeofday) mr r11,r3 /* r11 holds tv */ mr r10,r4 /* r10 holds tz */ - get_datapage r3, r0 + get_datapage r3 cmpldi r11,0 /* check if tv is NULL */ beq 2f lis r7,1000000@ha /* load up USEC_PER_SEC */
@@ -71,7 +71,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) mflr r12 /* r12 saves lr */ .cfi_register lr,r12 mr r11,r4 /* r11 saves tp */ - get_datapage r3, r0 + get_datapage r3 lis r7,NSEC_PER_SEC@h /* want nanoseconds */ ori r7,r7,NSEC_PER_SEC@l beq cr5,70f
@@ -188,7 +188,7 @@ V_FUNCTION_BEGIN(__kernel_clock_getres) mflr r12 .cfi_register lr,r12 - get_datapage r3, r0 + get_datapage r3 lwz r5, CLOCK_HRTIMER_RES(r3) mtlr r12 li r3,0
@@ -221,7 +221,7 @@ V_FUNCTION_BEGIN(__kernel_time) .cfi_register lr,r12 mr r11,r3 /* r11 holds t */ - get_datapage r3, r0 + get_datapage r3 ld r4,STAMP_XTIME_SEC(r3)
Signature · 1 line
2.25.0
PATCH v8 5/8 powerpc/vdso: Prepare for switching VDSO to generic C implementation.
In reply to Christophe LeroyPrepare for switching VDSO to generic C implementation in following patch. Here, we:
- Modify __get_datapage() to take an offset
- Prepare the helpers to call the C VDSO functions
- Prepare the required callbacks for the C VDSO functions
- Prepare the clocksource.h files to define VDSO_ARCH_CLOCKMODES
- Add the C trampolines to the generic C VDSO functions
powerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
Implementing __arch_get_vdso_data() would clobber the link register, requiring the caller to save it. As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter.
Implement __arch_vdso_capable() and:
- When the timebase is used, make it always return true.
- When the RTC clock is used, make it always return false.
Provide vdso_shift_ns(), as the generic x >> s gives the following bad result:
18: 35 25 ff e0 addic. r9,r5,-32 1c: 41 80 00 10 blt 2c <shift+0x14> 20: 7c 64 4c 30 srw r4,r3,r9 24: 38 60 00 00 li r3,0 ... 2c: 54 69 08 3c rlwinm r9,r3,1,0,30 30: 21 45 00 1f subfic r10,r5,31 34: 7c 84 2c 30 srw r4,r4,r5 38: 7d 29 50 30 slw r9,r9,r10 3c: 7c 63 2c 30 srw r3,r3,r5 40: 7d 24 23 78 or r4,r9,r4
In our case the shift is always <= 32. In addition, the upper 32 bits of the result are likely nul. Lets GCC know it, it also optimises the following calculations.
With the patch, we get:
0: 21 25 00 20 subfic r9,r5,32 4: 7c 69 48 30 slw r9,r3,r9 8: 7c 84 2c 30 srw r4,r4,r5 c: 7d 24 23 78 or r4,r9,r4 10: 7c 63 2c 30 srw r3,r3,r5
---
v8:
- New, splitted out of last patch of the series
--- arch/powerpc/include/asm/clocksource.h | 7 + arch/powerpc/include/asm/vdso/clocksource.h | 7 + arch/powerpc/include/asm/vdso/gettimeofday.h | 175 +++++++++++++++++++ arch/powerpc/include/asm/vdso_datapage.h | 6 +- arch/powerpc/kernel/vdso32/vgettimeofday.c | 29 +++ arch/powerpc/kernel/vdso64/vgettimeofday.c | 29 +++ 6 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/include/asm/clocksource.h create mode 100644 arch/powerpc/include/asm/vdso/clocksource.h create mode 100644 arch/powerpc/include/asm/vdso/gettimeofday.h create mode 100644 arch/powerpc/kernel/vdso32/vgettimeofday.c create mode 100644 arch/powerpc/kernel/vdso64/vgettimeofday.c
arch/powerpc/include/asm/clocksource.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_CLOCKSOURCE_H +#define _ASM_CLOCKSOURCE_H + +#include <asm/vdso/clocksource.h> + +#endif
arch/powerpc/include/asm/vdso/clocksource.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSOCLOCKSOURCE_H +#define __ASM_VDSOCLOCKSOURCE_H + +#define VDSO_ARCH_CLOCKMODES VDSO_CLOCKMODE_ARCHTIMER + +#endif
arch/powerpc/include/asm/vdso/gettimeofday.h new file +175 -0
175 lines not on this page · raw message
arch/powerpc/include/asm/vdso_datapage.h +3 -3
@@ -116,14 +116,14 @@ extern struct vdso_data *vdso_data; #else /* __ASSEMBLY__ */ -.macro get_datapage ptr +.macro get_datapage ptr, offset=0 bcl 20, 31, .+4 999: mflr \ptr #if CONFIG_PPC_PAGE_SHIFT > 14 - addis \ptr, \ptr, (_vdso_datapage - 999b)@ha + addis \ptr, \ptr, (_vdso_datapage + \offset - 999b)@ha #endif - addi \ptr, \ptr, (_vdso_datapage - 999b)@l + addi \ptr, \ptr, (_vdso_datapage + \offset - 999b)@l .endm #endif /* __ASSEMBLY__ */
arch/powerpc/kernel/vdso32/vgettimeofday.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Powerpc userspace implementations of gettimeofday() and similar. +*/ +#include <linux/time.h> +#include <linux/types.h> + +int __c_kernel_clock_gettime (clockid_t clock,struct old_timespec32 *ts, +const struct vdso_data *vd) +{ +return __cvdso_clock_gettime32_data (vd, clock, ts); +} + +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz, +const struct vdso_data *vd) +{ +return __cvdso_gettimeofday_data (vd, tv, tz); +} + +int __c_kernel_clock_getres (clockid_t clock_id,struct old_timespec32 *res, +const struct vdso_data *vd) +{ +return __cvdso_clock_getres_time32_data (vd, clock_id, res); +} + +__kernel_old_time_t __c_kernel_time (__kernel_old_time_t *time,const struct vdso_data *vd) +{ +return __cvdso_time_data (vd, time); +}
arch/powerpc/kernel/vdso64/vgettimeofday.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Powerpc userspace implementations of gettimeofday() and similar. +*/ +#include <linux/time.h> +#include <linux/types.h> + +int __c_kernel_clock_gettime (clockid_t clock,struct __kernel_timespec *ts, +const struct vdso_data *vd) +{ +return __cvdso_clock_gettime_data (vd, clock, ts); +} + +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz, +const struct vdso_data *vd) +{ +return __cvdso_gettimeofday_data (vd, tv, tz); +} + +int __c_kernel_clock_getres (clockid_t clock_id,struct __kernel_timespec *res, +const struct vdso_data *vd) +{ +return __cvdso_clock_getres_data (vd, clock_id, res); +} + +__kernel_old_time_t __c_kernel_time (__kernel_old_time_t *time,const struct vdso_data *vd) +{ +return __cvdso_time_data (vd, time); +}
Signature · 1 line
2.25.0
PATCH v8 6/8 powerpc/vdso: Switch VDSO to generic C implementation.
In reply to Christophe LeroyFor VDSO32 on PPC64, we create a fake 32 bits config, on the same principle as MIPS architecture, in order to get the correct parts of the different asm header files.
With the C VDSO, the performance is slightly lower, but it is worth it as it will ease maintenance and evolution, and also brings clocks that are not supported with the ASM VDSO.
On an 8xx at 132 MHz, vdsotest with the ASM VDSO:
gettimeofday: vdso: 828 nsec/call clock-getres-realtime-coarse: vdso: 391 nsec/call clock-gettime-realtime-coarse: vdso: 614 nsec/call clock-getres-realtime: vdso: 460 nsec/call clock-gettime-realtime: vdso: 876 nsec/call clock-getres-monotonic-coarse: vdso: 399 nsec/call clock-gettime-monotonic-coarse: vdso: 691 nsec/call clock-getres-monotonic: vdso: 460 nsec/call clock-gettime-monotonic: vdso: 1026 nsec/call
On an 8xx at 132 MHz, vdsotest with the C VDSO:
gettimeofday: vdso: 955 nsec/call clock-getres-realtime-coarse: vdso: 545 nsec/call clock-gettime-realtime-coarse: vdso: 592 nsec/call clock-getres-realtime: vdso: 545 nsec/call clock-gettime-realtime: vdso: 941 nsec/call clock-getres-monotonic-coarse: vdso: 545 nsec/call clock-gettime-monotonic-coarse: vdso: 591 nsec/call clock-getres-monotonic: vdso: 545 nsec/call clock-gettime-monotonic: vdso: 940 nsec/call
It is even better for gettime with monotonic clocks.
Unsupported clocks with ASM VDSO:
clock-gettime-boottime: vdso: 3851 nsec/call clock-gettime-tai: vdso: 3852 nsec/call clock-gettime-monotonic-raw: vdso: 3396 nsec/call
Same clocks with C VDSO:
clock-gettime-tai: vdso: 941 nsec/call clock-gettime-monotonic-raw: vdso: 1001 nsec/call clock-gettime-monotonic-coarse: vdso: 591 nsec/call
On an 8321E at 333 MHz, vdsotest with the ASM VDSO:
gettimeofday: vdso: 220 nsec/call clock-getres-realtime-coarse: vdso: 102 nsec/call clock-gettime-realtime-coarse: vdso: 178 nsec/call clock-getres-realtime: vdso: 129 nsec/call clock-gettime-realtime: vdso: 235 nsec/call clock-getres-monotonic-coarse: vdso: 105 nsec/call clock-gettime-monotonic-coarse: vdso: 208 nsec/call clock-getres-monotonic: vdso: 129 nsec/call clock-gettime-monotonic: vdso: 274 nsec/call
On an 8321E at 333 MHz, vdsotest with the C VDSO:
gettimeofday: vdso: 272 nsec/call clock-getres-realtime-coarse: vdso: 160 nsec/call clock-gettime-realtime-coarse: vdso: 184 nsec/call clock-getres-realtime: vdso: 166 nsec/call clock-gettime-realtime: vdso: 281 nsec/call clock-getres-monotonic-coarse: vdso: 160 nsec/call clock-gettime-monotonic-coarse: vdso: 184 nsec/call clock-getres-monotonic: vdso: 169 nsec/call clock-gettime-monotonic: vdso: 275 nsec/call
---
v7:
- Split out preparatory changes in a new preceding patch
- Added -fasynchronous-unwind-tables to CC flags.
v6:
- Added missing prototypes in asm/vdso/gettimeofday.h for __c_kernel_ functions.
- Using STACK_FRAME_OVERHEAD instead of INT_FRAME_SIZE
- Rebased on powerpc/merge as of 7 Apr 2020
- Fixed build failure with gcc 9
- Added a patch to create asm/vdso/processor.h and more cpu_relax() in it
--- arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/vdso/vsyscall.h | 25 ++ arch/powerpc/include/asm/vdso_datapage.h | 40 +-- arch/powerpc/kernel/asm-offsets.c | 49 +--- arch/powerpc/kernel/time.c | 91 +------ arch/powerpc/kernel/vdso.c | 5 +- arch/powerpc/kernel/vdso32/Makefile | 32 ++- arch/powerpc/kernel/vdso32/config-fake32.h | 34 +++ arch/powerpc/kernel/vdso32/gettimeofday.S | 291 +-------------------- arch/powerpc/kernel/vdso64/Makefile | 23 +- arch/powerpc/kernel/vdso64/gettimeofday.S | 243 +---------------- 11 files changed, 144 insertions(+), 691 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/vsyscall.h create mode 100644 arch/powerpc/kernel/vdso32/config-fake32.h
arch/powerpc/Kconfig +2 -0
@@ -166,6 +166,7 @@ config PPC select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL + select GENERIC_GETTIMEOFDAY select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_HUGE_VMAP if PPC_BOOK3S_64 && PPC_RADIX_MMU select HAVE_ARCH_JUMP_LABEL
@@ -197,6 +198,7 @@ config PPC select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC + select HAVE_GENERIC_VDSO select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx) select HAVE_IDE select HAVE_IOREMAP_PROT
arch/powerpc/include/asm/vdso/vsyscall.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_VSYSCALL_H +#define __ASM_VDSO_VSYSCALL_H + +#ifndef __ASSEMBLY__ + +#include <linux/timekeeper_internal.h> +#include <asm/vdso_datapage.h> + +/* +* Update the vDSO data page to keep in sync with kernel timekeeping. +*/ +static __always_inline +struct vdso_data *__arch_get_k_vdso_data(void) +{ +return vdso_data->data; +} +#define __arch_get_k_vdso_data __arch_get_k_vdso_data + +/* The asm-generic header needs to be included after the definitions above */ +#include <asm-generic/vdso/vsyscall.h> + +#endif /* !__ASSEMBLY__ */ + +#endif /* __ASM_VDSO_VSYSCALL_H */
arch/powerpc/include/asm/vdso_datapage.h +13 -27
@@ -36,6 +36,7 @@#include <linux/unistd.h> #include <linux/time.h> +#include <vdso/datapage.h> #define SYSCALL_MAP_SIZE ((NR_syscalls + 31) / 32)
@@ -45,7 +46,7 @@ #ifdef CONFIG_PPC64 -struct vdso_data { +struct vdso_arch_data { __u8 eye_catcher[16]; /* Eyecatcher: SYSTEMCFG:PPC64 0x00 */ struct { /* Systemcfg version numbers */ __u32 major; /* Major number 0x10 */
@@ -59,13 +60,13 @@ struct vdso_data {__u32 processor;/* Processor type 0x1C */ __u64 processorCount;/* # of physical processors 0x20 */ __u64 physicalMemorySize;/* Size of real memory(B) 0x28 */ -__u64 tb_orig_stamp;/* Timebase at boot 0x30 */ +__u64 tb_orig_stamp;/* (NU) Timebase at boot 0x30 */ __u64 tb_ticks_per_sec;/* Timebase tics / sec 0x38 */ -__u64 tb_to_xs;/* Inverse of TB to 2^20 0x40 */ -__u64 stamp_xsec;/* 0x48 */ -__u64 tb_update_count;/* Timebase atomicity ctr 0x50 */ -__u32 tz_minuteswest;/* Minutes west of Greenwich 0x58 */ -__u32 tz_dsttime;/* Type of dst correction 0x5C */ +__u64 tb_to_xs;/* (NU) Inverse of TB to 2^20 0x40 */ +__u64 stamp_xsec;/* (NU) 0x48 */ +__u64 tb_update_count;/* (NU) Timebase atomicity ctr 0x50 */ +__u32 tz_minuteswest;/* (NU) Min. west of Greenwich 0x58 */ +__u32 tz_dsttime;/* (NU) Type of dst correction 0x5C */ __u32 dcache_size;/* L1 d-cache size 0x60 */ __u32 dcache_line_size;/* L1 d-cache line size 0x64 */ __u32 icache_size;/* L1 i-cache size 0x68 */
@@ -78,14 +79,10 @@ struct vdso_data {__u32 icache_block_size;/* L1 i-cache block size */ __u32 dcache_log_block_size;/* L1 d-cache log block size */ __u32 icache_log_block_size;/* L1 i-cache log block size */ -__u32 stamp_sec_fraction;/* fractional seconds of stamp_xtime */ -__s32 wtom_clock_nsec;/* Wall to monotonic clock nsec */ -__s64 wtom_clock_sec;/* Wall to monotonic clock sec */ -__s64 stamp_xtime_sec;/* xtime secs as at tb_orig_stamp */ -__s64 stamp_xtime_nsec;/* xtime nsecs as at tb_orig_stamp */ -__u32 hrtimer_res;/* hrtimer resolution */ __u32 syscall_map_64[SYSCALL_MAP_SIZE ];/* map of syscalls */ __u32 syscall_map_32[SYSCALL_MAP_SIZE ];/* map of syscalls */ + + struct vdso_data data[CS_BASES]; };#else /* CONFIG_PPC64 */
@@ -93,26 +90,15 @@ struct vdso_data {/* * And here is the simpler 32 bits version */ -struct vdso_data { -__u64 tb_orig_stamp;/* Timebase at boot 0x30 */ +struct vdso_arch_data {__u64 tb_ticks_per_sec;/* Timebase tics / sec 0x38 */ -__u64 tb_to_xs;/* Inverse of TB to 2^20 0x40 */ -__u64 stamp_xsec;/* 0x48 */ -__u32 tb_update_count;/* Timebase atomicity ctr 0x50 */ -__u32 tz_minuteswest;/* Minutes west of Greenwich 0x58 */ -__u32 tz_dsttime;/* Type of dst correction 0x5C */ -__s32 wtom_clock_sec;/* Wall to monotonic clock */ -__s32 wtom_clock_nsec; -__s32 stamp_xtime_sec;/* xtime seconds as at tb_orig_stamp */ -__s32 stamp_xtime_nsec;/* xtime nsecs as at tb_orig_stamp */ -__u32 stamp_sec_fraction;/* fractional seconds of stamp_xtime */ -__u32 hrtimer_res;/* hrtimer resolution */ __u32 syscall_map_32[SYSCALL_MAP_SIZE ];/* map of syscalls */ +struct vdso_data data[CS_BASES ]; };#endif /* CONFIG_PPC64 */ -extern struct vdso_data *vdso_data; +extern struct vdso_arch_data *vdso_data;#else /* __ASSEMBLY__ */
arch/powerpc/kernel/asm-offsets.c +9 -40
56 lines not on this page · raw message
arch/powerpc/kernel/time.c +1 -90
109 lines not on this page · raw message
arch/powerpc/kernel/vdso.c +3 -2
@@ -17,6 +17,7 @@#include <linux/elf.h> #include <linux/security.h> #include <linux/memblock.h> +#include <vdso/datapage.h> #include <asm/pgtable.h> #include <asm/processor.h>
@@ -71,10 +72,10 @@ static int vdso_ready;* with it, it will become dynamically allocated */ static union { -struct vdso_data data; +struct vdso_arch_data data;u8 page[PAGE_SIZE ]; } vdso_data_store __page_aligned_data; -struct vdso_data *vdso_data = &vdso_data_store.data; +struct vdso_arch_data *vdso_data = &vdso_data_store.data;/* Format of the patch table */ struct vdso_patch_def
arch/powerpc/kernel/vdso32/Makefile +27 -5
@@ -2,7 +2,23 @@ # List of files in the vdso, has to be asm only for now -obj-vdso32 = sigtramp.o gettimeofday.o datapage.o cacheflush.o note.o getcpu.o +ARCH_REL_TYPE_ABS := R_PPC_JUMP_SLOT|R_PPC_GLOB_DAT|R_PPC_ADDR32|R_PPC_ADDR24|R_PPC_ADDR16|R_PPC_ADDR16_LO|R_PPC_ADDR16_HI|R_PPC_ADDR16_HA|R_PPC_ADDR14|R_PPC_ADDR14_BRTAKEN|R_PPC_ADDR14_BRNTAKEN +include $(srctree)/lib/vdso/Makefile + +obj-vdso32 = sigtramp.o datapage.o cacheflush.o note.o getcpu.o $(obj-vdso32-y) +obj-vdso32 += gettimeofday.o + +ifneq ($(c-gettimeofday-y),) + ifdef CONFIG_PPC64 + CFLAGS_vgettimeofday.o += -include $(srctree)/$(src)/config-fake32.h + endif + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) + CFLAGS_vgettimeofday.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) + CFLAGS_vgettimeofday.o += $(call cc-option, -fno-stack-protector) + CFLAGS_vgettimeofday.o += -DDISABLE_BRANCH_PROFILING + CFLAGS_vgettimeofday.o += -ffreestanding -fasynchronous-unwind-tables + CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) +endif # Build rules
@@ -15,6 +31,7 @@ endif CC32FLAGS := ifdef CONFIG_PPC64 CC32FLAGS += -m32 +KBUILD_CFLAGS := $(filter-out -mcmodel=medium,$(KBUILD_CFLAGS)) endif targets := $(obj-vdso32) vdso32.so vdso32.so.dbg
@@ -23,6 +40,7 @@ obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) GCOV_PROFILE := n KCOV_INSTRUMENT := n UBSAN_SANITIZE := n +KASAN_SANITIZE := n ccflags-y := -shared -fno-common -fno-builtin -nostdlib \ -Wl,-soname=linux-vdso32.so.1 -Wl,--hash-style=both
@@ -36,8 +54,8 @@ CPPFLAGS_vdso32.lds += -P -C -Upowerpc $(obj)/vdso32_wrapper.o : $(obj)/vdso32.so # link rule for the .so file, .lds has to be first -$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) FORCE - $(call if_changed,vdso32ld) +$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday.o FORCE + $(call if_changed,vdso32ld_and_check) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -47,12 +65,16 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # assembly rules for the .S files $(obj-vdso32): %.o: %.S FORCE $(call if_changed_dep,vdso32as) +$(obj)/vgettimeofday.o: %.o: %.c FORCE + $(call if_changed_dep,vdso32cc) # actual build commands -quiet_cmd_vdso32ld = VDSO32L $@ - cmd_vdso32ld = $(VDSOCC) $(c_flags) $(CC32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) +quiet_cmd_vdso32ld_and_check = VDSO32L $@ + cmd_vdso32ld_and_check = $(VDSOCC) $(c_flags) $(CC32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) ; $(cmd_vdso_check) quiet_cmd_vdso32as = VDSO32A $@ cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) -c -o $@ $< +quiet_cmd_vdso32cc = VDSO32C $@ + cmd_vdso32cc = $(VDSOCC) $(c_flags) $(CC32FLAGS) -c -o $@ $< # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@
arch/powerpc/kernel/vdso32/config-fake32.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* In case of a 32 bit VDSO for a 64 bit kernel fake a 32 bit kernel +* configuration. +*/ + +#undef CONFIG_PPC64 +#undef CONFIG_64BIT +#define CONFIG_PPC32 +#define CONFIG_32BIT 1 +#define CONFIG_GENERIC_ATOMIC64 1 + +#ifdef CONFIG_PPC_BOOK3S_64 +#undef CONFIG_PPC_BOOK3S_64 +#undef CONFIG_PPC_PSERIES +#define CONFIG_PPC_BOOK3S_32 +#else +#define CONFIG_PPC_MMU_NOHASH_32 +#define CONFIG_FSL_BOOKE +#endif + +#define CONFIG_TASK_SIZE 0 +#undef CONFIG_MMIOWB +#undef CONFIG_PPC_SPLPAR +#undef CONFIG_SPARSEMEM +#undef CONFIG_PGTABLE_LEVELS +#define CONFIG_PGTABLE_LEVELS 2 +#undef CONFIG_TRANSPARENT_HUGEPAGE +#undef CONFIG_SPARSEMEM_VMEMMAP +#undef CONFIG_FLATMEM +#define CONFIG_FLATMEM +#undef CONFIG_PPC_INDIRECT_MMIO +#undef CONFIG_PPC_INDIRECT_PIO +#undef CONFIG_EEH
arch/powerpc/kernel/vdso32/gettimeofday.S +5 -286
319 lines not on this page · raw message
arch/powerpc/kernel/vdso64/Makefile +19 -4
@@ -1,8 +1,20 @@ # SPDX-License-Identifier: GPL-2.0 # List of files in the vdso, has to be asm only for now +ARCH_REL_TYPE_ABS := R_PPC_JUMP_SLOT|R_PPC_GLOB_DAT|R_PPC_ADDR32|R_PPC_ADDR24|R_PPC_ADDR16|R_PPC_ADDR16_LO|R_PPC_ADDR16_HI|R_PPC_ADDR16_HA|R_PPC_ADDR14|R_PPC_ADDR14_BRTAKEN|R_PPC_ADDR14_BRNTAKEN +include $(srctree)/lib/vdso/Makefile + obj-vdso64 = sigtramp.o gettimeofday.o datapage.o cacheflush.o note.o getcpu.o +ifneq ($(c-gettimeofday-y),) + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) + CFLAGS_vgettimeofday.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) + CFLAGS_vgettimeofday.o += $(call cc-option, -fno-stack-protector) + CFLAGS_vgettimeofday.o += -DDISABLE_BRANCH_PROFILING + CFLAGS_vgettimeofday.o += -ffreestanding -fasynchronous-unwind-tables + CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) +endif + # Build rules targets := $(obj-vdso64) vdso64.so vdso64.so.dbg
@@ -11,6 +23,7 @@ obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) GCOV_PROFILE := n KCOV_INSTRUMENT := n UBSAN_SANITIZE := n +KASAN_SANITIZE := n ccflags-y := -shared -fno-common -fno-builtin -nostdlib \ -Wl,-soname=linux-vdso64.so.1 -Wl,--hash-style=both
@@ -20,12 +33,14 @@ obj-y += vdso64_wrapper.o extra-y += vdso64.lds CPPFLAGS_vdso64.lds += -P -C -U$(ARCH) +$(obj)/vgettimeofday.o: %.o: %.c FORCE + # Force dependency (incbin is bad) $(obj)/vdso64_wrapper.o : $(obj)/vdso64.so # link rule for the .so file, .lds has to be first -$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) FORCE - $(call if_changed,vdso64ld) +$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday.o FORCE + $(call if_changed,vdso64ld_and_check) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -33,8 +48,8 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE $(call if_changed,objcopy) # actual build commands -quiet_cmd_vdso64ld = VDSO64L $@ - cmd_vdso64ld = $(CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) +quiet_cmd_vdso64ld_and_check = VDSO64L $@ + cmd_vdso64ld_and_check = $(CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) ; $(cmd_vdso_check) # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@
arch/powerpc/kernel/vdso64/gettimeofday.S +6 -237
273 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v8 4/8 powerpc/processor: Move cpu_relax() into asm/vdso/processor.h
In reply to Christophe Leroycpu_relax() need to be in asm/vdso/processor.h to be used by the C VDSO generic library.
Move it there.
--- arch/powerpc/include/asm/processor.h | 10 ++-------- arch/powerpc/include/asm/vdso/processor.h | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/processor.h
arch/powerpc/include/asm/processor.h +2 -8
@@ -6,6 +6,8 @@* Copyright (C) 2001 PPC 64 Team, IBM Corp */ +#include <vdso/processor.h> +#include <asm/reg.h> #ifdef CONFIG_VSX
@@ -63,14 +65,6 @@ extern int _chrp_type;#endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */ -/* Macros for adjusting thread priority (hardware multi-threading) */ -#define HMT_very_low () asm volatile("or 31,31,31 # very low priority") -#define HMT_low () asm volatile("or 1,1,1 # low priority") -#define HMT_medium_low () asm volatile("or 6,6,6 # medium low priority") -#define HMT_medium () asm volatile("or 2,2,2 # medium priority") -#define HMT_medium_high () asm volatile("or 5,5,5 # medium high priority") -#define HMT_high () asm volatile("or 3,3,3 # high priority") -#ifdef __KERNEL__#ifdef CONFIG_PPC64
arch/powerpc/include/asm/vdso/processor.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_VDSO_PROCESSOR_H +#define __ASM_VDSO_PROCESSOR_H + +#ifndef __ASSEMBLY__ + +/* Macros for adjusting thread priority (hardware multi-threading) */ +#define HMT_very_low () asm volatile("or 31, 31, 31 # very low priority") +#define HMT_low () asm volatile("or 1, 1, 1 # low priority") +#define HMT_medium_low () asm volatile("or 6, 6, 6 # medium low priority") +#define HMT_medium () asm volatile("or 2, 2, 2 # medium priority") +#define HMT_medium_high () asm volatile("or 5, 5, 5 # medium high priority") +#define HMT_high () asm volatile("or 3, 3, 3 # high priority") + +#ifdef CONFIG_PPC64 +#define cpu_relax () do { HMT_low(); HMT_medium(); barrier(); } while (0) +#else +#define cpu_relax () barrier() +#endif + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_VDSO_PROCESSOR_H */
Signature · 1 line
2.25.0
PATCH v8 7/8 lib/vdso: force inlining of __cvdso_clock_gettime_common()
In reply to Christophe LeroyWhen adding gettime64() to a 32 bit architecture (namely powerpc/32) it has been noticed that GCC doesn't inline anymore __cvdso_clock_gettime_common() because it is called twice (Once by __cvdso_clock_gettime() and once by __cvdso_clock_gettime32).
This has the effect of seriously degrading the performance:
Before the implementation of gettime64(), gettime() runs in:
clock-gettime-monotonic-raw: vdso: 1003 nsec/call
clock-gettime-monotonic-coarse: vdso: 592 nsec/call
clock-gettime-monotonic: vdso: 942 nsec/call
When adding a gettime64() entry point, the standard gettime() performance is degraded by 30% to 50%:
clock-gettime-monotonic-raw: vdso: 1300 nsec/call
clock-gettime-monotonic-coarse: vdso: 900 nsec/call
clock-gettime-monotonic: vdso: 1232 nsec/call
Adding __always_inline() to __cvdso_clock_gettime_common() regains the original performance.
In terms of code size, the inlining increases the code size by only 176 bytes. This is in the noise for a kernel image.
--- lib/vdso/gettimeofday.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vdso/gettimeofday.c +1 -1
@@ -210,7 +210,7 @@ static __always_inline int do_coarse(const struct vdso_data *vd, clockid_t clk,return 0 ; } -static __maybe_unused int +static __always_inline int__cvdso_clock_gettime_common (const struct vdso_data *vd,clockid_t clock,struct __kernel_timespec *ts) {
Signature · 1 line
2.25.0
PATCH v8 8/8 powerpc/vdso: Provide __kernel_clock_gettime64() on vdso32
In reply to Christophe LeroyProvides __kernel_clock_gettime64() on vdso32. This is the 64 bits version of __kernel_clock_gettime() which is y2038 compliant.
--- arch/powerpc/kernel/vdso32/gettimeofday.S | 9 +++++++++ arch/powerpc/kernel/vdso32/vdso32.lds.S | 1 + arch/powerpc/kernel/vdso32/vgettimeofday.c | 6 ++++++ 3 files changed, 16 insertions(+)
arch/powerpc/kernel/vdso32/gettimeofday.S +9 -0
@@ -35,6 +35,15 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) cvdso_call __c_kernel_clock_gettime V_FUNCTION_END(__kernel_clock_gettime) +/* + * Exact prototype of clock_gettime64() + * + * int __kernel_clock_gettime64(clockid_t clock_id, struct __timespec64 *ts); + * + */ +V_FUNCTION_BEGIN(__kernel_clock_gettime64) + cvdso_call __c_kernel_clock_gettime64 +V_FUNCTION_END(__kernel_clock_gettime64) /* * Exact prototype of clock_getres()
arch/powerpc/kernel/vdso32/vdso32.lds.S +1 -0
@@ -144,6 +144,7 @@ VERSION #ifndef CONFIG_PPC_BOOK3S_601 __kernel_gettimeofday; __kernel_clock_gettime; + __kernel_clock_gettime64; __kernel_clock_getres; __kernel_time; __kernel_get_tbfreq;
arch/powerpc/kernel/vdso32/vgettimeofday.c +6 -0
@@ -11,6 +11,12 @@ int __c_kernel_clock_gettime(clockid_t clock, struct old_timespec32 *ts,return __cvdso_clock_gettime32_data (vd, clock, ts); } +int __c_kernel_clock_gettime64 (clockid_t clock,struct __kernel_timespec *ts, +const struct vdso_data *vd) +{ +return __cvdso_clock_gettime_data (vd, clock, ts); +} +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz,const struct vdso_data *vd) {
Signature · 1 line
2.25.0
Re: [PATCH v8 8/8] powerpc/vdso: Provide __kernel_clock_gettime64() on vdso32
Hi,
Quoted 5 lines · Christophe Leroy
Provides
__kernel_clock_gettime64()on vdso32. This is the 64 bits version of__kernel_clock_gettime()which is y2038 compliant.Signed-off-by Christophe Leroy <[email protected]>
Why does snowpatch still report upstream failure ? This is fixed in latest powerpc/merge which is
commit d9e4eabb775e1ba56d83bd4047de2413a21f87ce
Merge: 54dc28ff5e0b 51184ae37e05
Author: Michael Ellerman <[email protected]>
Date: Tue Apr 28 09:01:47 2020 +1000
Automatic merge of branches 'master', 'next' and 'fixes' into merge
Looks like snowpatch is still using
commit 54dc28ff5e0b3585224d49a31b53e030342ca5c3
Merge: 5d23fec1ac1d b2768df24ec4
Author: Michael Ellerman <[email protected]>
Date: Sun Apr 26 09:44:18 2020 +1000
Automatic merge of branches 'master', 'next' and 'fixes' into merge
Why ?
Christophe
Quoted 55 lines
--- arch/powerpc/kernel/vdso32/gettimeofday.S | 9 +++++++++ arch/powerpc/kernel/vdso32/vdso32.lds.S | 1 + arch/powerpc/kernel/vdso32/vgettimeofday.c | 6 ++++++ 3 files changed, 16 insertions(+)arch/powerpc/kernel/vdso32/gettimeofday.S +9
-0@@ -35,6 +35,15 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime) cvdso_call __c_kernel_clock_gettime V_FUNCTION_END(__kernel_clock_gettime) +/* + * Exact prototype of clock_gettime64() + * + * int __kernel_clock_gettime64(clockid_t clock_id, struct __timespec64 *ts); + * + */ +V_FUNCTION_BEGIN(__kernel_clock_gettime64) + cvdso_call __c_kernel_clock_gettime64 +V_FUNCTION_END(__kernel_clock_gettime64) /* * Exact prototype of clock_getres()arch/powerpc/kernel/vdso32/vdso32.lds.S +1
-0@@ -144,6 +144,7 @@ VERSION #ifndef CONFIG_PPC_BOOK3S_601 __kernel_gettimeofday; __kernel_clock_gettime; + __kernel_clock_gettime64; __kernel_clock_getres; __kernel_time; __kernel_get_tbfreq;arch/powerpc/kernel/vdso32/vgettimeofday.c +6
-0@@ -11,6 +11,12 @@ int __c_kernel_clock_gettime(clockid_t clock, struct old_timespec32 *ts,return __cvdso_clock_gettime32_data (vd, clock, ts); } +int __c_kernel_clock_gettime64 (clockid_t clock,struct __kernel_timespec *ts, +const struct vdso_data *vd) +{ +return __cvdso_clock_gettime_data (vd, clock, ts); +} +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz,const struct vdso_data *vd) {
Re: [PATCH v8 8/8] powerpc/vdso: Provide __kernel_clock_gettime64() on vdso32
In reply to Christophe LeroyQuoted 6 lines · Christophe Leroy
Provides
__kernel_clock_gettime64()on vdso32. This is the 64 bits version of__kernel_clock_gettime()which is y2038 compliant.Signed-off-by Christophe Leroy <[email protected]>
Looks good to me
There was a bug on ARM for the corresponding function, so far it is unclear if this was a problem related to particular hardware, the 32-bit kernel code, or the common implementation of clock_gettime64 in the vdso library, see https://github.com/richfelker/musl-cross-make/issues/96
Just to be sure that powerpc is not affected by the same issue, can you confirm that repeatedly calling clock_gettime64 on powerpc32, alternating between vdso and syscall, results in monotically increasing times?
Arnd
Re: [PATCH v8 8/8] powerpc/vdso: Provide __kernel_clock_gettime64() on vdso32
Le 28/04/2020 à 18:05, Arnd Bergmann a écrit :
Quoted 13 lines
Quoted 6 lines · Christophe Leroy
Provides
__kernel_clock_gettime64()on vdso32. This is the 64 bits version of__kernel_clock_gettime()which is y2038 compliant.Signed-off-by Christophe Leroy <[email protected]>Looks good to me
Reviewed-by Arnd Bergmann <[email protected]>
Quoted 9 lines
There was a bug on ARM for the corresponding function, so far it is unclear if this was a problem related to particular hardware, the 32-bit kernel code, or the common implementation of
clock_gettime64in the vdso library, see https://github.com/richfelker/musl-cross-make/issues/96Just to be sure that powerpc is not affected by the same issue, can you confirm that repeatedly calling
clock_gettime64on powerpc32, alternating between vdso and syscall, results in monotically increasing times?
I think that's one of the things vdsotest checks, so yes that's ok I think.
Christophe
Re: [PATCH v8 8/8] powerpc/vdso: Provide __kernel_clock_gettime64() on vdso32
Le 09/05/2020 à 17:54, Christophe Leroy a écrit :
Quoted 21 lines
Le 28/04/2020 à 18:05, Arnd Bergmann a écrit :
Quoted 18 lines
Quoted 6 lines · Christophe Leroy
Provides
__kernel_clock_gettime64()on vdso32. This is the 64 bits version of__kernel_clock_gettime()which is y2038 compliant.Signed-off-by Christophe Leroy <[email protected]>Looks good to me
Reviewed-by Arnd Bergmann <[email protected]>There was a bug on ARM for the corresponding function, so far it is unclear if this was a problem related to particular hardware, the 32-bit kernel code, or the common implementation of
clock_gettime64in the vdso library, see https://github.com/richfelker/musl-cross-make/issues/96
Quoted 7 lines
Quoted 4 lines
Just to be sure that powerpc is not affected by the same issue, can you confirm that repeatedly calling
clock_gettime64on powerpc32, alternating between vdso and syscall, results in monotically increasing times?I think that's one of the things vdsotest checks, so yes that's ok I think.
Here is the full result with vdsotest:
gettimeofday: syscall: 3715 nsec/call gettimeofday: libc: 794 nsec/call gettimeofday: vdso: 947 nsec/call getcpu: syscall: 1614 nsec/call getcpu: libc: 484 nsec/call getcpu: vdso: 184 nsec/call clock-gettime64-realtime-coarse: syscall: 3152 nsec/call clock-gettime64-realtime-coarse: libc: not tested clock-gettime64-realtime-coarse: vdso: 653 nsec/call clock-getres-realtime-coarse: syscall: 2963 nsec/call clock-getres-realtime-coarse: libc: 745 nsec/call clock-getres-realtime-coarse: vdso: 553 nsec/call clock-gettime-realtime-coarse: syscall: 5120 nsec/call clock-gettime-realtime-coarse: libc: 731 nsec/call clock-gettime-realtime-coarse: vdso: 577 nsec/call clock-gettime64-realtime: syscall: 3719 nsec/call clock-gettime64-realtime: libc: not tested clock-gettime64-realtime: vdso: 976 nsec/call clock-getres-realtime: syscall: 2496 nsec/call clock-getres-realtime: libc: 745 nsec/call clock-getres-realtime: vdso: 546 nsec/call clock-gettime-realtime: syscall: 4800 nsec/call clock-gettime-realtime: libc: 1080 nsec/call clock-gettime-realtime: vdso: 1798 nsec/call clock-gettime64-boottime: syscall: 4132 nsec/call clock-gettime64-boottime: libc: not tested clock-gettime64-boottime: vdso: 975 nsec/call clock-getres-boottime: syscall: 2497 nsec/call clock-getres-boottime: libc: 730 nsec/call clock-getres-boottime: vdso: 546 nsec/call clock-gettime-boottime: syscall: 3728 nsec/call clock-gettime-boottime: libc: 1079 nsec/call clock-gettime-boottime: vdso: 941 nsec/call clock-gettime64-tai: syscall: 4148 nsec/call clock-gettime64-tai: libc: not tested clock-gettime64-tai: vdso: 955 nsec/call clock-getres-tai: syscall: 2494 nsec/call clock-getres-tai: libc: 730 nsec/call clock-getres-tai: vdso: 545 nsec/call clock-gettime-tai: syscall: 3729 nsec/call clock-gettime-tai: libc: 1079 nsec/call clock-gettime-tai: vdso: 927 nsec/call clock-gettime64-monotonic-raw: syscall: 3677 nsec/call clock-gettime64-monotonic-raw: libc: not tested clock-gettime64-monotonic-raw: vdso: 1032 nsec/call clock-getres-monotonic-raw: syscall: 2494 nsec/call clock-getres-monotonic-raw: libc: 745 nsec/call clock-getres-monotonic-raw: vdso: 545 nsec/call clock-gettime-monotonic-raw: syscall: 3276 nsec/call clock-gettime-monotonic-raw: libc: 1140 nsec/call clock-gettime-monotonic-raw: vdso: 1002 nsec/call clock-gettime64-monotonic-coarse: syscall: 4099 nsec/call clock-gettime64-monotonic-coarse: libc: not tested clock-gettime64-monotonic-coarse: vdso: 653 nsec/call clock-getres-monotonic-coarse: syscall: 2962 nsec/call clock-getres-monotonic-coarse: libc: 745 nsec/call clock-getres-monotonic-coarse: vdso: 545 nsec/call clock-gettime-monotonic-coarse: syscall: 4297 nsec/call clock-gettime-monotonic-coarse: libc: 730 nsec/call clock-gettime-monotonic-coarse: vdso: 592 nsec/call clock-gettime64-monotonic: syscall: 3863 nsec/call clock-gettime64-monotonic: libc: not tested clock-gettime64-monotonic: vdso: 975 nsec/call clock-getres-monotonic: syscall: 2494 nsec/call clock-getres-monotonic: libc: 745 nsec/call clock-getres-monotonic: vdso: 545 nsec/call clock-gettime-monotonic: syscall: 3465 nsec/call clock-gettime-monotonic: libc: 1079 nsec/call clock-gettime-monotonic: vdso: 927 nsec/call
Christophe
Hi Michael,
Le 28/04/2020 à 15:16, Christophe Leroy a écrit :
Quoted 9 lines
This is the seventh version of a series to switch powerpc VDSO to generic C implementation.
Main changes since v7 are:
- Added gettime64 on PPC32This series applies on today's powerpc/merge branch.
See the last patches for details on changes and performance.
Do you have any plans for this series ?
Even if you don't feel like merging it this cycle, I think patches 1 to 3 are worth it.
Christophe
Quoted 48 lines
Christophe Leroy (8):
powerpc/vdso64: Switch from__get_datapage()toget_datapageinline
macro
powerpc/vdso: Remove__kernel_datapage_offsetand simplify__get_datapage()powerpc/vdso: Remove unused \tmp param in
__get_datapage()powerpc/processor: Movecpu_relax()intoasm/vdso/processor.hpowerpc/vdso: Prepare for switching VDSO to generic C implementation. powerpc/vdso: Switch VDSO to generic C implementation. lib/vdso: force inlining of__cvdso_clock_gettime_common()powerpc/vdso: Provide__kernel_clock_gettime64()on vdso32arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/clocksource.h | 7 + arch/powerpc/include/asm/processor.h | 10 +- arch/powerpc/include/asm/vdso/clocksource.h | 7 + arch/powerpc/include/asm/vdso/gettimeofday.h | 175 +++++++++++ arch/powerpc/include/asm/vdso/processor.h | 23 ++ arch/powerpc/include/asm/vdso/vsyscall.h | 25 ++ arch/powerpc/include/asm/vdso_datapage.h | 50 ++-- arch/powerpc/kernel/asm-offsets.c | 49 +-- arch/powerpc/kernel/time.c | 91 +----- arch/powerpc/kernel/vdso.c | 58 +--- arch/powerpc/kernel/vdso32/Makefile | 32 +- arch/powerpc/kernel/vdso32/cacheflush.S | 2 +- arch/powerpc/kernel/vdso32/config-fake32.h | 34 +++ arch/powerpc/kernel/vdso32/datapage.S | 7 +- arch/powerpc/kernel/vdso32/gettimeofday.S | 300 +------------------ arch/powerpc/kernel/vdso32/vdso32.lds.S | 8 +- arch/powerpc/kernel/vdso32/vgettimeofday.c | 35 +++ arch/powerpc/kernel/vdso64/Makefile | 23 +- arch/powerpc/kernel/vdso64/cacheflush.S | 9 +- arch/powerpc/kernel/vdso64/datapage.S | 31 +- arch/powerpc/kernel/vdso64/gettimeofday.S | 243 +-------------- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 +- arch/powerpc/kernel/vdso64/vgettimeofday.c | 29 ++ lib/vdso/gettimeofday.c | 2 +- 25 files changed, 460 insertions(+), 799 deletions(-)create mode 100644
arch/powerpc/include/asm/clocksource.hcreate mode 100644arch/powerpc/include/asm/vdso/clocksource.hcreate mode 100644arch/powerpc/include/asm/vdso/gettimeofday.hcreate mode 100644arch/powerpc/include/asm/vdso/processor.hcreate mode 100644arch/powerpc/include/asm/vdso/vsyscall.hcreate mode 100644arch/powerpc/kernel/vdso32/config-fake32.hcreate mode 100644arch/powerpc/kernel/vdso32/vgettimeofday.ccreate mode 100644arch/powerpc/kernel/vdso64/vgettimeofday.c
Michael Ellerman
reviewerQuoted 6 lines · Christophe Leroy
Hi Michael,
Le 28/04/2020 à 15:16, Christophe Leroy a écrit :
Quoted 3 lines
This is the seventh version of a series to switch powerpc VDSO to generic C implementation.
Quoted 8 lines
Quoted 6 lines
Main changes since v7 are:
- Added gettime64 on PPC32This series applies on today's powerpc/merge branch.
See the last patches for details on changes and performance.
Do you have any plans for this series ?
Review it and merge it one day :/
Quoted 2 lines
Even if you don't feel like merging it this cycle, I think patches 1 to 3 are worth it.
I'd rather take the whole series for v5.9.
Sorry it missed this window, I just didn't get time to look at it.
cheers
Michael Ellerman
reviewerRe: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
In reply to Christophe LeroyQuoted 16 lines · Christophe Leroy
Prepare for switching VDSO to generic C implementation in following patch. Here, we:
- Modify__get_datapage()to take an offset
- Prepare the helpers to call the C VDSO functions
- Prepare the required callbacks for the C VDSO functions
- Prepare theclocksource.hfiles to defineVDSO_ARCH_CLOCKMODES
- Add the C trampolines to the generic C VDSO functionspowerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
Implementing
__arch_get_vdso_data()would clobber the link register, requiring the caller to save it. As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter.
...
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +4
-0@@ -0,0 +1,175 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_GETTIMEOFDAY_H +#define __ASM_VDSO_GETTIMEOFDAY_H +
arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +10
-0+#include <asm/ptrace.h> + +#ifdef __ASSEMBLY__ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) + mflr r0 + .cfi_register lr, r0 + PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)
This doesn't work for me on ppc64(le) with glibc.
glibc doesn't create a stack frame before making the VDSO call, so the store of r0 (LR) goes into the caller's frame, corrupting the saved LR, leading to an infinite loop.
This is an example from a statically built program that calls clock_gettime():
0000000010030cb0 <__clock_gettime>:
10030cb0: 0e 10 40 3c lis r2,4110
10030cb4: 00 7a 42 38 addi r2,r2,31232
10030cb8: a6 02 08 7c mflr r0
10030cbc: ff ff 22 3d addis r9,r2,-1
10030cc0: 58 6d 29 39 addi r9,r9,27992
10030cc4: f0 ff c1 fb std r30,-16(r1) <-- redzone store
10030cc8: 78 23 9e 7c mr r30,r4
10030ccc: f8 ff e1 fb std r31,-8(r1) <-- redzone store
10030cd0: 78 1b 7f 7c mr r31,r3
10030cd4: 10 00 01 f8 std r0,16(r1) <-- save LR to caller's frame
10030cd8: 00 00 09 e8 ld r0,0(r9)
10030cdc: 00 00 20 2c cmpdi r0,0
10030ce0: 50 00 82 41 beq 10030d30 <__clock_gettime+0x80>
10030ce4: a6 03 09 7c mtctr r0
10030ce8: 21 04 80 4e bctrl <-- vdso call
10030cec: 26 00 00 7c mfcr r0
10030cf0: 00 10 09 74 andis. r9,r0,4096
10030cf4: 78 1b 69 7c mr r9,r3
10030cf8: 28 00 82 40 bne 10030d20 <__clock_gettime+0x70>
10030cfc: b4 07 23 7d extsw r3,r9
10030d00: 10 00 01 e8 ld r0,16(r1) <-- load saved LR, since clobbered by the VDSO
10030d04: f0 ff c1 eb ld r30,-16(r1)
10030d08: f8 ff e1 eb ld r31,-8(r1)
10030d0c: a6 03 08 7c mtlr r0 <-- restore LR
10030d10: 20 00 80 4e blr <-- jumps to 10030cecI'm kind of confused how it worked for you on 32-bit.
There's also no code to load/restore the TOC pointer on BE, which I think we'll need to handle.
cheers
Re: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
Michael Ellerman <[email protected]> a écrit :
Quoted 42 lines
Quoted 16 lines · Christophe Leroy
Prepare for switching VDSO to generic C implementation in following patch. Here, we:
- Modify__get_datapage()to take an offset
- Prepare the helpers to call the C VDSO functions
- Prepare the required callbacks for the C VDSO functions
- Prepare theclocksource.hfiles to defineVDSO_ARCH_CLOCKMODES
- Add the C trampolines to the generic C VDSO functionspowerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
Implementing
__arch_get_vdso_data()would clobber the link register, requiring the caller to save it. As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter....
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +4
-0@@ -0,0 +1,175 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_GETTIMEOFDAY_H +#define __ASM_VDSO_GETTIMEOFDAY_H +arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +10
-0+#include <asm/ptrace.h> + +#ifdef __ASSEMBLY__ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) + mflr r0 + .cfi_register lr, r0 + PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)This doesn't work for me on ppc64(le) with glibc.
Quoted 3 lines
glibc doesn't create a stack frame before making the VDSO call, so the store of r0 (LR) goes into the caller's frame, corrupting the saved LR, leading to an infinite loop.
Where should it be saved if it can't be saved in the standard location ?
Quoted 34 lines
This is an example from a statically built program that calls
clock_gettime():
0000000010030cb0<__clock_gettime>:10030cb0: 0e 10 40 3c lis r2,4110 10030cb4: 00 7a 42 38 addi r2,r2,31232 10030cb8: a6 02 08 7c mflr r0 10030cbc: ff ff 22 3d addis r9,r2,-1 10030cc0: 58 6d 29 39 addi r9,r9,27992 10030cc4: f0 ff c1 fb std r30,-16(r1) <-- redzone store 10030cc8: 78 23 9e 7c mr r30,r4 10030ccc: f8 ff e1 fb std r31,-8(r1) <-- redzone store 10030cd0: 78 1b 7f 7c mr r31,r3 10030cd4: 10 00 01 f8 std r0,16(r1) <-- save LR to caller's frame 10030cd8: 00 00 09 e8 ld r0,0(r9) 10030cdc: 00 00 20 2c cmpdi r0,0 10030ce0: 50 00 82 41 beq 10030d30 <__clock_gettime+0x80> 10030ce4: a6 03 09 7c mtctr r0 10030ce8: 21 04 80 4e bctrl <-- vdso call 10030cec: 26 00 00 7c mfcr r0 10030cf0: 00 10 09 74 andis. r9,r0,4096 10030cf4: 78 1b 69 7c mr r9,r3 10030cf8: 28 00 82 40 bne 10030d20 <__clock_gettime+0x70> 10030cfc: b4 07 23 7d extsw r3,r9 10030d00: 10 00 01 e8 ld r0,16(r1) <-- load saved LR, since clobbered by the VDSO 10030d04: f0 ff c1 eb ld r30,-16(r1) 10030d08: f8 ff e1 eb ld r31,-8(r1) 10030d0c: a6 03 08 7c mtlr r0 <-- restore LR 10030d10: 20 00 80 4e blr <-- jumps to 10030cec
Quoted 1 line
I'm kind of confused how it worked for you on 32-bit.
So am I then. I'm away for 3 weeks, summer break. I'll check when I'm back.
Quoted 3 lines
There's also no code to load/restore the TOC pointer on BE, which I think we'll need to handle.
What does it means exactly ? Just saving r2 all the time ? Is there a dedicated location in the stack frame for it ? Is that only for 64 be ?
Christophe
Michael Ellerman
reviewerRe: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
In reply to Christophe LeroyQuoted 59 lines · Christophe Leroy
The VDSO datapage and the text pages are always located immediately next to each other, so it can be hardcoded without an indirection through
__kernel_datapage_offsetIn order to ease things, move the data page in front like other arches, that way there is no need to know the size of the library to locate the data page.
Before:
clock-getres-realtime-coarse: vdso: 714 nsec/call clock-gettime-realtime-coarse: vdso: 792 nsec/call clock-gettime-realtime: vdso: 1243 nsec/callAfter:
clock-getres-realtime-coarse: vdso: 699 nsec/call clock-gettime-realtime-coarse: vdso: 784 nsec/call clock-gettime-realtime: vdso: 1231 nsec/callSigned-off-by Christophe Leroy <[email protected]>---
v7:
- Moved the removal of the tmp param of__get_datapage()in a subsequent patch
- Included the addition of the offset param to__get_datapage()in the further preparatory patch--- arch/powerpc/include/asm/vdso_datapage.h | 8 ++-- arch/powerpc/kernel/vdso.c | 53 ++++-------------------- arch/powerpc/kernel/vdso32/datapage.S | 3 -- arch/powerpc/kernel/vdso32/vdso32.lds.S | 7 +--- arch/powerpc/kernel/vdso64/datapage.S | 3 -- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 +--- 6 files changed, 16 insertions(+), 65 deletions(-)arch/powerpc/include/asm/vdso_datapage.h +5
-3@@ -118,10 +118,12 @@ extern struct vdso_data *vdso_data; .macro get_datapage ptr, tmp bcl 20, 31, .+4 +999: mflr \ptr - addi \ptr, \ptr, (__kernel_datapage_offset - (.-4))@l - lwz \tmp, 0(\ptr) - add \ptr, \tmp, \ptr +#if CONFIG_PPC_PAGE_SHIFT > 14 + addis \ptr, \ptr, (_vdso_datapage - 999b)@ha +#endif + addi \ptr, \ptr, (_vdso_datapage - 999b)@l .endm #endif /* __ASSEMBLY__ */arch/powerpc/kernel/vdso.c +0
-0
arch/powerpc/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 193
Quoted 5 lines
arch/powerpc/kernel/vdso.c +1
-1@@ -190,7 +190,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)* install_special_mapping or the perf counter mmap tracking code * will fail to recognise it as a vDSO (since arch_vma_name fails). */ - current->mm->context.vdso_base = vdso_base; + current->mm->context.vdso_base = vdso_base +PAGE_SIZE ;
I merged this but then realised it breaks the display of the vdso in /proc/self/maps.
ie. the vdso vma gets no name:
# cat /proc/self/maps 110f90000-110fa0000 r-xp 00000000 08:03 17021844 /usr/bin/cat 110fa0000-110fb0000 r--p 00000000 08:03 17021844 /usr/bin/cat 110fb0000-110fc0000 rw-p 00010000 08:03 17021844 /usr/bin/cat 126000000-126030000 rw-p 00000000 00:00 0 [heap] 7fffa8790000-7fffa87d0000 rw-p 00000000 00:00 0 7fffa87d0000-7fffa8830000 r--p 00000000 08:03 17521786 /usr/lib/locale/en_AU.utf8/LC_CTYPE 7fffa8830000-7fffa8840000 r--p 00000000 08:03 16958337 /usr/lib/locale/en_AU.utf8/LC_NUMERIC 7fffa8840000-7fffa8850000 r--p 00000000 08:03 8501358 /usr/lib/locale/en_AU.utf8/LC_TIME 7fffa8850000-7fffa8ad0000 r--p 00000000 08:03 16870886 /usr/lib/locale/en_AU.utf8/LC_COLLATE 7fffa8ad0000-7fffa8ae0000 r--p 00000000 08:03 8509433 /usr/lib/locale/en_AU.utf8/LC_MONETARY 7fffa8ae0000-7fffa8af0000 r--p 00000000 08:03 25383753 /usr/lib/locale/en_AU.utf8/LC_MESSAGES/SYS_LC_MESSAGES 7fffa8af0000-7fffa8b00000 r--p 00000000 08:03 17521790 /usr/lib/locale/en_AU.utf8/LC_PAPER 7fffa8b00000-7fffa8b10000 r--p 00000000 08:03 8501354 /usr/lib/locale/en_AU.utf8/LC_NAME 7fffa8b10000-7fffa8b20000 r--p 00000000 08:03 8509431 /usr/lib/locale/en_AU.utf8/LC_ADDRESS 7fffa8b20000-7fffa8b30000 r--p 00000000 08:03 8509434 /usr/lib/locale/en_AU.utf8/LC_TELEPHONE 7fffa8b30000-7fffa8b40000 r--p 00000000 08:03 17521787 /usr/lib/locale/en_AU.utf8/LC_MEASUREMENT 7fffa8b40000-7fffa8b50000 r--s 00000000 08:03 25623315 /usr/lib64/gconv/gconv-modules.cache 7fffa8b50000-7fffa8d40000 r-xp 00000000 08:03 25383789 /usr/lib64/libc-2.30.so 7fffa8d40000-7fffa8d50000 r--p 001e0000 08:03 25383789 /usr/lib64/libc-2.30.so 7fffa8d50000-7fffa8d60000 rw-p 001f0000 08:03 25383789 /usr/lib64/libc-2.30.so 7fffa8d60000-7fffa8d70000 r--p 00000000 08:03 8509432 /usr/lib/locale/en_AU.utf8/LC_IDENTIFICATION 7fffa8d70000-7fffa8d90000 r-xp 00000000 00:00 0 <--- missing 7fffa8d90000-7fffa8dc0000 r-xp 00000000 08:03 25383781 /usr/lib64/ld-2.30.so 7fffa8dc0000-7fffa8dd0000 r--p 00020000 08:03 25383781 /usr/lib64/ld-2.30.so 7fffa8dd0000-7fffa8de0000 rw-p 00030000 08:03 25383781 /usr/lib64/ld-2.30.so 7fffc31c0000-7fffc31f0000 rw-p 00000000 00:00 0 [stack]
And it's also going to break the logic in arch_unmap() to detect if we're unmapping (part of) the VDSO. And it will break arch_remap() too.
And the logic to recognise the signal trampoline in arch/powerpc/perf/callchain_*.c as well.
So I'm going to rebase and drop this for now.
Basically we have a bunch of places that assume that vdso_base is == the start of the VDSO vma, and also that the code starts there. So that will need some work to tease out all those assumptions and make them work with this change.
cheers
Quoted 9 lines · Christophe Leroy
This is the seventh version of a series to switch powerpc VDSO to generic C implementation.
Main changes since v7 are:
- Added gettime64 on PPC32This series applies on today's powerpc/merge branch.
[...]
Patch 1 applied to powerpc/next.
[1/8] powerpc/vdso64: Switch from __get_datapage() to get_datapage inline macro
https://git.kernel.org/powerpc/c/793d74a8c78e05d6833bfcf582e24e40bd92518f
cheers
Re: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
In reply to Christophe LeroyQuoted 45 lines · Christophe Leroy
Michael Ellerman <[email protected]> a écrit :
Quoted 43 lines
Quoted 16 lines · Christophe Leroy
Prepare for switching VDSO to generic C implementation in following patch. Here, we:
- Modify__get_datapage()to take an offset
- Prepare the helpers to call the C VDSO functions
- Prepare the required callbacks for the C VDSO functions
- Prepare theclocksource.hfiles to defineVDSO_ARCH_CLOCKMODES
- Add the C trampolines to the generic C VDSO functionspowerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
Implementing
__arch_get_vdso_data()would clobber the link register, requiring the caller to save it. As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter....
Quoted 11 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +4
-0@@ -0,0 +1,175 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_GETTIMEOFDAY_H +#define __ASM_VDSO_GETTIMEOFDAY_H +arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +10
-0+#include <asm/ptrace.h> + +#ifdef __ASSEMBLY__ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) + mflr r0 + .cfi_register lr, r0 + PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)This doesn't work for me on ppc64(le) with glibc.
Quoted 5 lines
Quoted 3 lines
glibc doesn't create a stack frame before making the VDSO call, so the store of r0 (LR) goes into the caller's frame, corrupting the saved LR, leading to an infinite loop.
Where should it be saved if it can't be saved in the standard location ?
As Michael pointed out, userspace doesn't treat the VDSO as a normal function call. In order to keep compatibility with existent software, LR would need to be saved on another stack frame.
Signature · 1 line
Tulio Magno
Re: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
In reply to Michael EllermanQuoted 77 lines · Michael Ellerman
Quoted 16 lines · Christophe Leroy
Prepare for switching VDSO to generic C implementation in following patch. Here, we:
- Modify__get_datapage()to take an offset
- Prepare the helpers to call the C VDSO functions
- Prepare the required callbacks for the C VDSO functions
- Prepare theclocksource.hfiles to defineVDSO_ARCH_CLOCKMODES
- Add the C trampolines to the generic C VDSO functionspowerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
Implementing
__arch_get_vdso_data()would clobber the link register, requiring the caller to save it. As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter....
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +4
-0@@ -0,0 +1,175 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_GETTIMEOFDAY_H +#define __ASM_VDSO_GETTIMEOFDAY_H +arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +10
-0+#include <asm/ptrace.h> + +#ifdef __ASSEMBLY__ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) + mflr r0 + .cfi_register lr, r0 + PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)This doesn't work for me on ppc64(le) with glibc.
glibc doesn't create a stack frame before making the VDSO call, so the store of r0 (LR) goes into the caller's frame, corrupting the saved LR, leading to an infinite loop.
This is an example from a statically built program that calls
clock_gettime():
0000000010030cb0<__clock_gettime>:10030cb0: 0e 10 40 3c lis r2,4110 10030cb4: 00 7a 42 38 addi r2,r2,31232 10030cb8: a6 02 08 7c mflr r0 10030cbc: ff ff 22 3d addis r9,r2,-1 10030cc0: 58 6d 29 39 addi r9,r9,27992 10030cc4: f0 ff c1 fb std r30,-16(r1) <-- redzone store 10030cc8: 78 23 9e 7c mr r30,r4 10030ccc: f8 ff e1 fb std r31,-8(r1) <-- redzone store 10030cd0: 78 1b 7f 7c mr r31,r3 10030cd4: 10 00 01 f8 std r0,16(r1) <-- save LR to caller's frame 10030cd8: 00 00 09 e8 ld r0,0(r9) 10030cdc: 00 00 20 2c cmpdi r0,0 10030ce0: 50 00 82 41 beq 10030d30 <__clock_gettime+0x80> 10030ce4: a6 03 09 7c mtctr r0 10030ce8: 21 04 80 4e bctrl <-- vdso call 10030cec: 26 00 00 7c mfcr r0 10030cf0: 00 10 09 74 andis. r9,r0,4096 10030cf4: 78 1b 69 7c mr r9,r3 10030cf8: 28 00 82 40 bne 10030d20 <__clock_gettime+0x70> 10030cfc: b4 07 23 7d extsw r3,r9 10030d00: 10 00 01 e8 ld r0,16(r1) <-- load saved LR, since clobbered by the VDSO 10030d04: f0 ff c1 eb ld r30,-16(r1) 10030d08: f8 ff e1 eb ld r31,-8(r1) 10030d0c: a6 03 08 7c mtlr r0 <-- restore LR 10030d10: 20 00 80 4e blr <-- jumps to 10030cec
Quoted 1 line
I'm kind of confused how it worked for you on 32-bit.
Indeed, 32-bit doesn't have a redzone, so I believe it needs a stack frame whenever it has anything to same. Here is what I have in libc.so:
000fbb60 <__clock_gettime>:
fbb60: 94 21 ff e0 stwu r1,-32(r1) fbb64: 7c 08 02 a6 mflr r0 fbb68: 48 09 75 c9 bl 193130 <_IO_stdout_+0x24b0> fbb6c: 93 c1 00 18 stw r30,24(r1) fbb70: 7f c8 02 a6 mflr r30 fbb74: 90 01 00 24 stw r0,36(r1) fbb78: 93 81 00 10 stw r28,16(r1) fbb7c: 93 a1 00 14 stw r29,20(r1) fbb80: 83 9e fc 98 lwz r28,-872(r30) fbb84: 93 e1 00 1c stw r31,28(r1) fbb88: 80 1c 00 00 lwz r0,0(r28) fbb8c: 83 82 8f f4 lwz r28,-28684(r2) fbb90: 7c 7f 1b 78 mr r31,r3 fbb94: 7c 00 e2 79 xor. r0,r0,r28 fbb98: 7c 9d 23 78 mr r29,r4 fbb9c: 41 82 00 40 beq fbbdc <__clock_gettime+0x7c> fbba0: 7c 09 03 a6 mtctr r0 fbba4: 4e 80 04 21 bctrl fbba8: 7c 00 00 26 mfcr r0 fbbac: 74 1c 10 00 andis. r28,r0,4096 fbbb0: 40 82 00 24 bne fbbd4 <__clock_gettime+0x74> fbbb4: 80 01 00 24 lwz r0,36(r1) fbbb8: 83 81 00 10 lwz r28,16(r1) fbbbc: 7c 08 03 a6 mtlr r0 fbbc0: 83 a1 00 14 lwz r29,20(r1) fbbc4: 83 c1 00 18 lwz r30,24(r1) fbbc8: 83 e1 00 1c lwz r31,28(r1) fbbcc: 38 21 00 20 addi r1,r1,32
fbbd0: 4e 80 00 20 blr
...
193130: 4e 80 00 21 blrl
But I guess if a prog has a way to avoid having anything to save, we may face the same issue. So lets create two frames:
arch/powerpc/include/asm/vdso/gettimeofday.h +4 -2
@@ -10,6 +10,7 @@ .cfi_startproc PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) mflr r0 + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)get_datapage r5, r0
@@ -19,7 +20,7 @@ cmpwi r3, 0 mtlr r0 .cfi_restore lr - addi r1, r1, STACK_FRAME_OVERHEAD + addi r1, r1, 2 * STACK_FRAME_OVERHEAD crclr so beqlr+ crset so
@@ -32,6 +33,7 @@ .cfi_startproc PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) mflr r0 + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)get_datapage r4, r0
@@ -41,7 +43,7 @@ crclr so mtlr r0 .cfi_restore lr - addi r1, r1, STACK_FRAME_OVERHEAD + addi r1, r1, 2 * STACK_FRAME_OVERHEAD blr .cfi_endproc .endm
Quoted 3 lines
There's also no code to load/restore the TOC pointer on BE, which I think we'll need to handle.
I see no code in the generated vdso64.so doing anything with r2, but if you think that's needed, just let's do it:
commit 5a704d89bd5d7aac39194fb4c775f406905bf0a4
Author: Christophe Leroy <[email protected]> Date: Tue Aug 4 06:31:48 2020 +0000
Save and restore GOT
arch/powerpc/include/asm/vdso/gettimeofday.h +12 -0
@@ -13,10 +13,16 @@ PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_STL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif get_datapage r5, r0 addi r5, r5, VDSO_DATA_OFFSET bl \funct PPC_LL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_LL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif cmpwi r3, 0 mtlr r0 .cfi_restore lr
@@ -36,10 +42,16 @@ PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_STL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif get_datapage r4, r0 addi r4, r4, VDSO_DATA_OFFSET bl \funct PPC_LL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_LL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif crclr so mtlr r0 .cfi_restore lr
Christophe
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
In reply to Michael EllermanQuoted 99 lines · Michael Ellerman
Quoted 59 lines · Christophe Leroy
The VDSO datapage and the text pages are always located immediately next to each other, so it can be hardcoded without an indirection through
__kernel_datapage_offsetIn order to ease things, move the data page in front like other arches, that way there is no need to know the size of the library to locate the data page.
Before:
clock-getres-realtime-coarse: vdso: 714 nsec/call clock-gettime-realtime-coarse: vdso: 792 nsec/call clock-gettime-realtime: vdso: 1243 nsec/callAfter:
clock-getres-realtime-coarse: vdso: 699 nsec/call clock-gettime-realtime-coarse: vdso: 784 nsec/call clock-gettime-realtime: vdso: 1231 nsec/callSigned-off-by Christophe Leroy <[email protected]>---
v7:
- Moved the removal of the tmp param of__get_datapage()in a subsequent patch
- Included the addition of the offset param to__get_datapage()in the further preparatory patch--- arch/powerpc/include/asm/vdso_datapage.h | 8 ++-- arch/powerpc/kernel/vdso.c | 53 ++++-------------------- arch/powerpc/kernel/vdso32/datapage.S | 3 -- arch/powerpc/kernel/vdso32/vdso32.lds.S | 7 +--- arch/powerpc/kernel/vdso64/datapage.S | 3 -- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 +--- 6 files changed, 16 insertions(+), 65 deletions(-)arch/powerpc/include/asm/vdso_datapage.h +5
-3@@ -118,10 +118,12 @@ extern struct vdso_data *vdso_data; .macro get_datapage ptr, tmp bcl 20, 31, .+4 +999: mflr \ptr - addi \ptr, \ptr, (__kernel_datapage_offset - (.-4))@l - lwz \tmp, 0(\ptr) - add \ptr, \tmp, \ptr +#if CONFIG_PPC_PAGE_SHIFT > 14 + addis \ptr, \ptr, (_vdso_datapage - 999b)@ha +#endif + addi \ptr, \ptr, (_vdso_datapage - 999b)@l .endm #endif /* __ASSEMBLY__ */arch/powerpc/kernel/vdso.c +0
-0arch/powerpc/kernel/vdso.c int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) · line 193
Quoted 5 lines
arch/powerpc/kernel/vdso.c +1
-1@@ -190,7 +190,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)* install_special_mapping or the perf counter mmap tracking code * will fail to recognise it as a vDSO (since arch_vma_name fails). */ - current->mm->context.vdso_base = vdso_base; + current->mm->context.vdso_base = vdso_base +PAGE_SIZE ;I merged this but then realised it breaks the display of the vdso in
/proc/self/maps.ie. the vdso vma gets no name:
# cat /proc/self/maps 110f90000-110fa0000 r-xp 00000000 08:03 17021844 /usr/bin/cat 110fa0000-110fb0000 r--p 00000000 08:03 17021844 /usr/bin/cat 110fb0000-110fc0000 rw-p 00010000 08:03 17021844 /usr/bin/cat 126000000-126030000 rw-p 00000000 00:00 0 [heap] 7fffa8790000-7fffa87d0000 rw-p 00000000 00:00 0 7fffa87d0000-7fffa8830000 r--p 00000000 08:03 17521786 /usr/lib/locale/en_AU.utf8/LC_CTYPE 7fffa8830000-7fffa8840000 r--p 00000000 08:03 16958337 /usr/lib/locale/en_AU.utf8/LC_NUMERIC 7fffa8840000-7fffa8850000 r--p 00000000 08:03 8501358 /usr/lib/locale/en_AU.utf8/LC_TIME 7fffa8850000-7fffa8ad0000 r--p 00000000 08:03 16870886 /usr/lib/locale/en_AU.utf8/LC_COLLATE 7fffa8ad0000-7fffa8ae0000 r--p 00000000 08:03 8509433 /usr/lib/locale/en_AU.utf8/LC_MONETARY 7fffa8ae0000-7fffa8af0000 r--p 00000000 08:03 25383753 /usr/lib/locale/en_AU.utf8/LC_MESSAGES/SYS_LC_MESSAGES 7fffa8af0000-7fffa8b00000 r--p 00000000 08:03 17521790 /usr/lib/locale/en_AU.utf8/LC_PAPER 7fffa8b00000-7fffa8b10000 r--p 00000000 08:03 8501354 /usr/lib/locale/en_AU.utf8/LC_NAME 7fffa8b10000-7fffa8b20000 r--p 00000000 08:03 8509431 /usr/lib/locale/en_AU.utf8/LC_ADDRESS 7fffa8b20000-7fffa8b30000 r--p 00000000 08:03 8509434 /usr/lib/locale/en_AU.utf8/LC_TELEPHONE 7fffa8b30000-7fffa8b40000 r--p 00000000 08:03 17521787 /usr/lib/locale/en_AU.utf8/LC_MEASUREMENT 7fffa8b40000-7fffa8b50000 r--s 00000000 08:03 25623315 /usr/lib64/gconv/gconv-modules.cache 7fffa8b50000-7fffa8d40000 r-xp 00000000 08:03 25383789 /usr/lib64/libc-2.30.so 7fffa8d40000-7fffa8d50000 r--p 001e0000 08:03 25383789 /usr/lib64/libc-2.30.so 7fffa8d50000-7fffa8d60000 rw-p 001f0000 08:03 25383789 /usr/lib64/libc-2.30.so 7fffa8d60000-7fffa8d70000 r--p 00000000 08:03 8509432 /usr/lib/locale/en_AU.utf8/LC_IDENTIFICATION 7fffa8d70000-7fffa8d90000 r-xp 00000000 00:00 0 <--- missing 7fffa8d90000-7fffa8dc0000 r-xp 00000000 08:03 25383781 /usr/lib64/ld-2.30.so 7fffa8dc0000-7fffa8dd0000 r--p 00020000 08:03 25383781 /usr/lib64/ld-2.30.so 7fffa8dd0000-7fffa8de0000 rw-p 00030000 08:03 25383781 /usr/lib64/ld-2.30.so 7fffc31c0000-7fffc31f0000 rw-p 00000000 00:00 0 [stack]
Quoted 5 lines
And it's also going to break the logic in
arch_unmap()to detect if we're unmapping (part of) the VDSO. And it will breakarch_remap()too.And the logic to recognise the signal trampoline in
arch/powerpc/perf/callchain_*.cas well.
I don't think it breaks that one, because ->vdsobase is still the start of text.
Quoted 7 lines
So I'm going to rebase and drop this for now.
Basically we have a bunch of places that assume that
vdso_baseis == the start of the VDSO vma, and also that the code starts there. So that will need some work to tease out all those assumptions and make them work with this change.
Ok, one day I need to look at it in more details and see how other architectures handle it etc ...
As the benefit is only 2 CPU cycles, I'll drop it for now.
Christophe
Michael Ellerman
reviewerRe: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
In reply to Christophe LeroyQuoted 78 lines · Christophe Leroy
Quoted 77 lines · Michael Ellerman
Quoted 16 lines · Christophe Leroy
Prepare for switching VDSO to generic C implementation in following patch. Here, we:
- Modify__get_datapage()to take an offset
- Prepare the helpers to call the C VDSO functions
- Prepare the required callbacks for the C VDSO functions
- Prepare theclocksource.hfiles to defineVDSO_ARCH_CLOCKMODES
- Add the C trampolines to the generic C VDSO functionspowerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
Implementing
__arch_get_vdso_data()would clobber the link register, requiring the caller to save it. As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter....
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +4
-0@@ -0,0 +1,175 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_GETTIMEOFDAY_H +#define __ASM_VDSO_GETTIMEOFDAY_H +arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h new file +10
-0+#include <asm/ptrace.h> + +#ifdef __ASSEMBLY__ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) + mflr r0 + .cfi_register lr, r0 + PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)This doesn't work for me on ppc64(le) with glibc.
glibc doesn't create a stack frame before making the VDSO call, so the store of r0 (LR) goes into the caller's frame, corrupting the saved LR, leading to an infinite loop.
This is an example from a statically built program that calls
clock_gettime():
0000000010030cb0<__clock_gettime>:10030cb0: 0e 10 40 3c lis r2,4110 10030cb4: 00 7a 42 38 addi r2,r2,31232 10030cb8: a6 02 08 7c mflr r0 10030cbc: ff ff 22 3d addis r9,r2,-1 10030cc0: 58 6d 29 39 addi r9,r9,27992 10030cc4: f0 ff c1 fb std r30,-16(r1) <-- redzone store 10030cc8: 78 23 9e 7c mr r30,r4 10030ccc: f8 ff e1 fb std r31,-8(r1) <-- redzone store 10030cd0: 78 1b 7f 7c mr r31,r3 10030cd4: 10 00 01 f8 std r0,16(r1) <-- save LR to caller's frame 10030cd8: 00 00 09 e8 ld r0,0(r9) 10030cdc: 00 00 20 2c cmpdi r0,0 10030ce0: 50 00 82 41 beq 10030d30 <__clock_gettime+0x80> 10030ce4: a6 03 09 7c mtctr r0 10030ce8: 21 04 80 4e bctrl <-- vdso call 10030cec: 26 00 00 7c mfcr r0 10030cf0: 00 10 09 74 andis. r9,r0,4096 10030cf4: 78 1b 69 7c mr r9,r3 10030cf8: 28 00 82 40 bne 10030d20 <__clock_gettime+0x70> 10030cfc: b4 07 23 7d extsw r3,r9 10030d00: 10 00 01 e8 ld r0,16(r1) <-- load saved LR, since clobbered by the VDSO 10030d04: f0 ff c1 eb ld r30,-16(r1) 10030d08: f8 ff e1 eb ld r31,-8(r1) 10030d0c: a6 03 08 7c mtlr r0 <-- restore LR 10030d10: 20 00 80 4e blr <-- jumps to 10030cec
Quoted 4 lines
Quoted 1 line
I'm kind of confused how it worked for you on 32-bit.
Indeed, 32-bit doesn't have a redzone, so I believe it needs a stack frame whenever it has anything to same.
Yeah OK that would explain it.
Quoted 32 lines
Here is what I have in libc.so:
000fbb60<__clock_gettime>:fbb60: 94 21 ff e0 stwu r1,-32(r1) fbb64: 7c 08 02 a6 mflr r0 fbb68: 48 09 75 c9 bl 193130 <_IO_stdout_+0x24b0> fbb6c: 93 c1 00 18 stw r30,24(r1) fbb70: 7f c8 02 a6 mflr r30 fbb74: 90 01 00 24 stw r0,36(r1) fbb78: 93 81 00 10 stw r28,16(r1) fbb7c: 93 a1 00 14 stw r29,20(r1) fbb80: 83 9e fc 98 lwz r28,-872(r30) fbb84: 93 e1 00 1c stw r31,28(r1) fbb88: 80 1c 00 00 lwz r0,0(r28) fbb8c: 83 82 8f f4 lwz r28,-28684(r2) fbb90: 7c 7f 1b 78 mr r31,r3 fbb94: 7c 00 e2 79 xor. r0,r0,r28 fbb98: 7c 9d 23 78 mr r29,r4 fbb9c: 41 82 00 40 beq fbbdc <__clock_gettime+0x7c> fbba0: 7c 09 03 a6 mtctr r0 fbba4: 4e 80 04 21 bctrl fbba8: 7c 00 00 26 mfcr r0 fbbac: 74 1c 10 00 andis. r28,r0,4096 fbbb0: 40 82 00 24 bne fbbd4 <__clock_gettime+0x74> fbbb4: 80 01 00 24 lwz r0,36(r1) fbbb8: 83 81 00 10 lwz r28,16(r1) fbbbc: 7c 08 03 a6 mtlr r0 fbbc0: 83 a1 00 14 lwz r29,20(r1) fbbc4: 83 c1 00 18 lwz r30,24(r1) fbbc8: 83 e1 00 1c lwz r31,28(r1) fbbcc: 38 21 00 20 addi r1,r1,32 fbbd0: 4e 80 00 20 blr
Quoted 5 lines
...
193130: 4e 80 00 21 blrlBut I guess if a prog has a way to avoid having anything to save, we may face the same issue.
Yes I think so.
Quoted 1 line
So lets create two frames:
Yeah I think that's what's required. Might need a comment explaining why though ;)
arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 11 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +1
-0@@ -10,6 +10,7 @@ .cfi_startproc PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) mflr r0 + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0
The cfi_register should come directly after the mflr I think.
Quoted 30 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +3
-2PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) get_datapage r5, r0@@ -19,7 +20,7 @@ cmpwi r3, 0 mtlr r0 .cfi_restore lr - addi r1, r1, STACK_FRAME_OVERHEAD + addi r1, r1, 2 * STACK_FRAME_OVERHEAD crclr so beqlr+ crset so@@ -32,6 +33,7 @@ .cfi_startproc PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) mflr r0 + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1)get_datapage r4, r0@@ -41,7 +43,7 @@ crclr somtlr r0 .cfi_restore lr - addi r1, r1, STACK_FRAME_OVERHEAD + addi r1, r1, 2 * STACK_FRAME_OVERHEAD blr .cfi_endproc .endm
Quoted 5 lines
Quoted 2 lines
There's also no code to load/restore the TOC pointer on BE, which I think we'll need to handle.
I see no code in the generated vdso64.so doing anything with r2, but if you think that's needed, just let's do it:
Hmm, true.
The compiler will use the toc for globals (and possibly also for large constants?)
AFAIK there's no way to disable use of the toc, or make it a build error if it's needed.
But at least currently you can't add any global to the vdso code as it won't link, because the .data and .bss are discarded.
At the same time it's much safer for us to just save/restore r2, and probably in the noise performance wise.
So yeah we should probably do as below.
Quoted 35 lines
commit
5a704d89bd5d7aac39194fb4c775f406905bf0a4Author: Christophe Leroy <[email protected]> Date: Tue Aug 4 06:31:48 2020 +0000Save and restore GOT
arch/powerpc/include/asm/vdso/gettimeofday.h +9
-0@@ -13,10 +13,16 @@ PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_STL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif get_datapage r5, r0 addi r5, r5, VDSO_DATA_OFFSET bl \funct PPC_LL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_LL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif cmpwi r3, 0 mtlr r0 .cfi_restore lr@@ -36,10 +42,16 @@ PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0 PPC_STL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_STL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif
arch/powerpc/include/asm/vdso/gettimeofday.h line 57
Quoted 10 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +3
-0get_datapage r4, r0 addi r4, r4, VDSO_DATA_OFFSET bl \funct PPC_LL r0, STACK_FRAME_OVERHEAD + PPC_LR_STKOFF(r1) +#ifdef CONFIG_PPC64 + PPC_LL r2, STACK_FRAME_OVERHEAD + STK_GOT(r1) +#endif crclr so mtlr r0 .cfi_restore lr
cheers
Re: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
Hi!
Quoted 10 lines · Michael Ellerman
Quoted 2 lines · Christophe Leroy
Indeed, 32-bit doesn't have a redzone, so I believe it needs a stack frame whenever it has anything to same.
Yeah OK that would explain it.
Quoted 4 lines
Here is what I have in libc.so:
000fbb60<__clock_gettime>:fbb60: 94 21 ff e0 stwu r1,-32(r1)
This is the *only* place where you can use a negative offset from r1:
in the stwu to extend the stack (set up a new stack frame, or make the current one bigger).
Quoted 5 lines
Quoted 5 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +0
-0
Quoted 8 lines
arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 6 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +1
-0@@ -10,6 +10,7 @@ .cfi_startproc PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) mflr r0 + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0The
cfi_registershould come directly after the mflr I think.
That is the idiomatic way to write it, and most obviously correct. But as long as the value in LR at function entry is available in multiple places (like, in LR and in R0 here), it is fine to use either for unwinding. Sometimes you can use this to optimise the unwind tables a bit -- not really worth it in hand-written code, it's more important to make it legible ;-)
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
There's also no code to load/restore the TOC pointer on BE, which I think we'll need to handle.
I see no code in the generated vdso64.so doing anything with r2, but if you think that's needed, just let's do it:
Hmm, true.
The compiler will use the toc for globals (and possibly also for large constants?)
And anything else it bloody well wants to, yeah :-)
Quoted 2 lines
AFAIK there's no way to disable use of the toc, or make it a build error if it's needed.
Yes.
Quoted 2 lines
At the same time it's much safer for us to just save/restore r2, and probably in the noise performance wise.
If you want a function to be able to work with ABI-compliant code safely (in all cases), you'll have to make it itself ABI-compliant as well, yes :-)
Quoted 1 line
So yeah we should probably do as below.
[ snip ]
Looks good yes.
Segher
Michael Ellerman
reviewerRe: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
Quoted 7 lines · Segher Boessenkool
Quoted 6 lines · Michael Ellerman
Quoted 2 lines · Christophe Leroy
Indeed, 32-bit doesn't have a redzone, so I believe it needs a stack frame whenever it has anything to same.
Yeah OK that would explain it.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Here is what I have in libc.so:
000fbb60<__clock_gettime>:fbb60: 94 21 ff e0 stwu r1,-32(r1)This is the *only* place where you can use a negative offset from r1:
in the stwu to extend the stack (set up a new stack frame, or make the current one bigger).
(You're talking about 32-bit code here right?)
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +0
-0Quoted 8 lines
arch/powerpc/include/asm/vdso/gettimeofday.h line 14
Quoted 6 lines
arch/powerpc/include/asm/vdso/gettimeofday.h +1
-0@@ -10,6 +10,7 @@ .cfi_startproc PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) mflr r0 + PPC_STLU r1, -STACK_FRAME_OVERHEAD(r1) .cfi_register lr, r0The
cfi_registershould come directly after the mflr I think.
Quoted 6 lines
That is the idiomatic way to write it, and most obviously correct. But as long as the value in LR at function entry is available in multiple places (like, in LR and in R0 here), it is fine to use either for unwinding. Sometimes you can use this to optimise the unwind tables a bit -- not really worth it in hand-written code, it's more important to make it legible ;-)
OK. Because LR still holds the LR value until it's clobbered later, by which point the cfi_register has taken effect.
But yeah I think for readability it's best to keep the cfi_register next to the mflr.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
There's also no code to load/restore the TOC pointer on BE, which I think we'll need to handle.
I see no code in the generated vdso64.so doing anything with r2, but if you think that's needed, just let's do it:
Quoted 6 lines
Quoted 4 lines
Hmm, true.
The compiler will use the toc for globals (and possibly also for large constants?)
And anything else it bloody well wants to, yeah :-)
Haha yeah OK.
Quoted 11 lines
Quoted 2 lines
AFAIK there's no way to disable use of the toc, or make it a build error if it's needed.
Yes.
Quoted 2 lines
At the same time it's much safer for us to just save/restore r2, and probably in the noise performance wise.
If you want a function to be able to work with ABI-compliant code safely (in all cases), you'll have to make it itself ABI-compliant as well, yes :-)
True. Except this is the VDSO which has previously been a bit wild west as far as ABI goes :)
Quoted 5 lines
Quoted 1 line
So yeah we should probably do as below.
[ snip ]
Looks good yes.
Thanks for reviewing.
cheers
Re: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
Hi!
Quoted 5 lines · Michael Ellerman
Quoted 4 lines · Segher Boessenkool
Quoted 3 lines · Michael Ellerman
Quoted 2 lines · Christophe Leroy
Indeed, 32-bit doesn't have a redzone, so I believe it needs a stack frame whenever it has anything to same.
^^^
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
fbb60: 94 21 ff e0 stwu r1,-32(r1)This is the *only* place where you can use a negative offset from r1:
in the stwu to extend the stack (set up a new stack frame, or make the current one bigger).(You're talking about 32-bit code here right?)
The "SYSV" ELF binding, yeah, which is used for 32-bit on Linux (give or take, ho hum).
The ABIs that have a red zone are much nicer here (but less simple) :-)
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
At the same time it's much safer for us to just save/restore r2, and probably in the noise performance wise.
If you want a function to be able to work with ABI-compliant code safely (in all cases), you'll have to make it itself ABI-compliant as well, yes :-)
True. Except this is the VDSO which has previously been a bit wild west as far as ABI goes :)
It could get away with many things because it was guaranteed to be a leaf function. Some of those things even violate the ABIs, but you can get away with it easily, much reduced scope. Now if this is generated code, violating the rules will catch up with you sooner rather than later ;-)
Segher
Michael Ellerman
reviewerRe: [PATCH v8 5/8] powerpc/vdso: Prepare for switching VDSO to generic C implementation.
Quoted 15 lines · Segher Boessenkool
Quoted 5 lines · Michael Ellerman
Quoted 4 lines · Segher Boessenkool
Quoted 3 lines · Michael Ellerman
Quoted 2 lines · Christophe Leroy
Indeed, 32-bit doesn't have a redzone, so I believe it needs a stack frame whenever it has anything to same.
^^^
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
fbb60: 94 21 ff e0 stwu r1,-32(r1)This is the *only* place where you can use a negative offset from r1:
in the stwu to extend the stack (set up a new stack frame, or make the current one bigger).
Quoted 6 lines
Quoted 1 line
(You're talking about 32-bit code here right?)
The "SYSV" ELF binding, yeah, which is used for 32-bit on Linux (give or take, ho hum).
The ABIs that have a red zone are much nicer here (but less simple) :-)
Yep, just checking I wasn't misunderstanding your comment about negative offsets.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
At the same time it's much safer for us to just save/restore r2, and probably in the noise performance wise.
If you want a function to be able to work with ABI-compliant code safely (in all cases), you'll have to make it itself ABI-compliant as well, yes :-)
Quoted 8 lines
Quoted 2 lines
True. Except this is the VDSO which has previously been a bit wild west as far as ABI goes :)
It could get away with many things because it was guaranteed to be a leaf function. Some of those things even violate the ABIs, but you can get away with it easily, much reduced scope. Now if this is generated code, violating the rules will catch up with you sooner rather than later ;-)
Agreed.
cheers
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
In reply to Christophe LeroyLe 04/08/2020 à 13:17, Christophe Leroy a écrit :
Quoted 12 lines · Michael Ellerman
Quoted 9 lines
Quoted 8 lines · Christophe Leroy
The VDSO datapage and the text pages are always located immediately next to each other, so it can be hardcoded without an indirection through
__kernel_datapage_offsetIn order to ease things, move the data page in front like other arches, that way there is no need to know the size of the library to locate the data page.
[...]
Quoted 6 lines
Quoted 6 lines
I merged this but then realised it breaks the display of the vdso in
/proc/self/maps.ie. the vdso vma gets no name:
# cat /proc/self/maps
[...]
Quoted 11 lines
Quoted 7 lines
And it's also going to break the logic in
arch_unmap()to detect if we're unmapping (part of) the VDSO. And it will breakarch_remap()too.And the logic to recognise the signal trampoline in
arch/powerpc/perf/callchain_*.cas well.I don't think it breaks that one, because ->vdsobase is still the start of text.
Quoted 1 line
Quoted 9 lines
Quoted 6 lines
So I'm going to rebase and drop this for now.
Basically we have a bunch of places that assume that
vdso_baseis == the start of the VDSO vma, and also that the code starts there. So that will need some work to tease out all those assumptions and make them work with this change.Ok, one day I need to look at it in more details and see how other architectures handle it etc ...
I just sent out a series which switches powerpc to the new _install_special_mapping() API, the one powerpc uses being deprecated since commit a62c34bd2a8a ("x86, mm: Improve _install_special_mapping and fix x86 vdso naming")
arch_remap() gets replaced by vdso_remap()
For arch_unmap(), I'm wondering how/what other architectures do, because powerpc seems to be the only one to erase the vdso context pointer when unmapping the vdso. So far I updated it to take into account the pages switch.
Everything else is not impacted because our vdso_base is still the base of the text and that's what those things (signal trampoline, callchain, ...) expect.
Maybe we should change it to 'void *vdso' in the same way as other architectures, as it is not anymore the exact vdso_base but the start of VDSO text.
Note that the series applies on top of the generic C VDSO implementation series. However all but the last commit cleanly apply without that series. As that last commit is just an afterwork cleanup, it can come in a second step.
Christophe
Michael Ellerman
reviewerRe: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Quoted 49 lines · Christophe Leroy
Le 04/08/2020 à 13:17, Christophe Leroy a écrit :
Quoted 10 lines · Michael Ellerman
Quoted 9 lines
Quoted 8 lines · Christophe Leroy
The VDSO datapage and the text pages are always located immediately next to each other, so it can be hardcoded without an indirection through
__kernel_datapage_offsetIn order to ease things, move the data page in front like other arches, that way there is no need to know the size of the library to locate the data page.
[...]
Quoted 7 lines
Quoted 7 lines
I merged this but then realised it breaks the display of the vdso in
/proc/self/maps.ie. the vdso vma gets no name:
# cat /proc/self/maps[...]
Quoted 12 lines
Quoted 5 lines
And it's also going to break the logic in
arch_unmap()to detect if we're unmapping (part of) the VDSO. And it will breakarch_remap()too.And the logic to recognise the signal trampoline in
arch/powerpc/perf/callchain_*.cas well.I don't think it breaks that one, because ->vdsobase is still the start of text.
Quoted 3 lines
So I'm going to rebase and drop this for now.
Quoted 8 lines
Quoted 4 lines
Basically we have a bunch of places that assume that
vdso_baseis == the start of the VDSO vma, and also that the code starts there. So that will need some work to tease out all those assumptions and make them work with this change.Ok, one day I need to look at it in more details and see how other architectures handle it etc ...
I just sent out a series which switches powerpc to the new
_install_special_mapping()API, the one powerpc uses being deprecated since commita62c34bd2a8a("x86, mm: Improve_install_special_mappingand fix x86 vdso naming")
Quoted 5 lines
arch_remap()gets replaced byvdso_remap()For
arch_unmap(), I'm wondering how/what other architectures do, because powerpc seems to be the only one to erase the vdso context pointer when unmapping the vdso.
Yeah. The original unmap/remap stuff was added for CRIU, which I thought people tested on other architectures (more than powerpc even).
Possibly no one really cares about vdso unmap though, vs just moving the vdso.
We added a test for vdso unmap recently because it happened to trigger a KAUP failure, and someone actually hit it & reported it.
Running that test on arm64 segfaults:
# ./sigreturn_vdso VDSO is at 0xffff8191f000-0xffff8191ffff (4096 bytes) Signal delivered OK with VDSO mapped VDSO moved to 0xffff8191a000-0xffff8191afff (4096 bytes) Signal delivered OK with VDSO moved Unmapped VDSO Remapped the stack executable [ 48.556191] potentially unexpected fatal signal 11. [ 48.556752] CPU: 0 PID: 140 Comm: sigreturn_vdso Not tainted 5.9.0-rc2-00057-g2ac69819ba9e #190 [ 48.556990] Hardware name: linux,dummy-virt (DT) [ 48.557336] pstate: 60001000 (nZCv daif -PAN -UAO BTYPE=--) [ 48.557475] pc : 0000ffff8191a7bc [ 48.557603] lr : 0000ffff8191a7bc [ 48.557697] sp : 0000ffffc13c9e90 [ 48.557873] x29: 0000ffffc13cb0e0 x28: 0000000000000000 [ 48.558201] x27: 0000000000000000 x26: 0000000000000000 [ 48.558337] x25: 0000000000000000 x24: 0000000000000000 [ 48.558754] x23: 0000000000000000 x22: 0000000000000000 [ 48.558893] x21: 00000000004009b0 x20: 0000000000000000 [ 48.559046] x19: 0000000000400ff0 x18: 0000000000000000 [ 48.559180] x17: 0000ffff817da300 x16: 0000000000412010 [ 48.559312] x15: 0000000000000000 x14: 000000000000001c [ 48.559443] x13: 656c626174756365 x12: 7865206b63617473 [ 48.559625] x11: 0000000000000003 x10: 0101010101010101 [ 48.559828] x9 : 0000ffff818afda8 x8 : 0000000000000081 [ 48.559973] x7 : 6174732065687420 x6 : 64657070616d6552 [ 48.560115] x5 : 000000000e0388bd x4 : 000000000040135d [ 48.560270] x3 : 0000000000000000 x2 : 0000000000000001 [ 48.560412] x1 : 0000000000000003 x0 : 00000000004120b8 Segmentation fault #
So I think we need to keep the unmap hook. Maybe it should be handled by the special_mapping stuff generically.
cheers
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Hello,
Quoted 1 line · Michael Ellerman
Christophe Leroy <[email protected]> writes:
[..]
Quoted 6 lines
Quoted 5 lines
arch_remap()gets replaced byvdso_remap()For
arch_unmap(), I'm wondering how/what other architectures do, because powerpc seems to be the only one to erase the vdso context pointer when unmapping the vdso.
Quoted 8 lines
Yeah. The original unmap/remap stuff was added for CRIU, which I thought people tested on other architectures (more than powerpc even).
Possibly no one really cares about vdso unmap though, vs just moving the vdso.
We added a test for vdso unmap recently because it happened to trigger a KAUP failure, and someone actually hit it & reported it.
You right, CRIU cares much more about moving vDSO.
It's done for each restoree and as on most setups vDSO is premapped and used by the application - it's actively tested.
Speaking about vDSO unmap - that's concerning only for heterogeneous C/R, i.e when an application is migrated from a system that uses vDSO to the one which doesn't - it's much rare scenario.
(for arm it's !CONFIG_VDSO, for x86 it's vdso=0 boot parameter)
Looking at the code, it seems quite easy to provide/maintain .close() for vm_special_mapping. A bit harder to add a test from CRIU side (as glibc won't know on restore that it can't use vdso anymore), but totally not impossible.
Quoted 34 lines
Running that test on arm64 segfaults:
# ./sigreturn_vdso VDSO is at 0xffff8191f000-0xffff8191ffff (4096 bytes) Signal delivered OK with VDSO mapped VDSO moved to 0xffff8191a000-0xffff8191afff (4096 bytes) Signal delivered OK with VDSO moved Unmapped VDSO Remapped the stack executable [ 48.556191] potentially unexpected fatal signal 11. [ 48.556752] CPU: 0 PID: 140 Comm: sigreturn_vdso Not tainted 5.9.0-rc2-00057-g2ac69819ba9e #190 [ 48.556990] Hardware name: linux,dummy-virt (DT) [ 48.557336] pstate: 60001000 (nZCv daif -PAN -UAO BTYPE=--) [ 48.557475] pc : 0000ffff8191a7bc [ 48.557603] lr : 0000ffff8191a7bc [ 48.557697] sp : 0000ffffc13c9e90 [ 48.557873] x29: 0000ffffc13cb0e0 x28: 0000000000000000 [ 48.558201] x27: 0000000000000000 x26: 0000000000000000 [ 48.558337] x25: 0000000000000000 x24: 0000000000000000 [ 48.558754] x23: 0000000000000000 x22: 0000000000000000 [ 48.558893] x21: 00000000004009b0 x20: 0000000000000000 [ 48.559046] x19: 0000000000400ff0 x18: 0000000000000000 [ 48.559180] x17: 0000ffff817da300 x16: 0000000000412010 [ 48.559312] x15: 0000000000000000 x14: 000000000000001c [ 48.559443] x13: 656c626174756365 x12: 7865206b63617473 [ 48.559625] x11: 0000000000000003 x10: 0101010101010101 [ 48.559828] x9 : 0000ffff818afda8 x8 : 0000000000000081 [ 48.559973] x7 : 6174732065687420 x6 : 64657070616d6552 [ 48.560115] x5 : 000000000e0388bd x4 : 000000000040135d [ 48.560270] x3 : 0000000000000000 x2 : 0000000000000001 [ 48.560412] x1 : 0000000000000003 x0 : 00000000004120b8 Segmentation fault #
Quoted 2 lines
So I think we need to keep the unmap hook. Maybe it should be handled by the
special_mappingstuff generically.
I'll cook a patch for vm_special_mapping if you don't mind :-)
Thanks,
Dmitry
Michael Ellerman
reviewerRe: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Quoted 20 lines · Dmitry Safonov
Hello,
Quoted 1 line · Michael Ellerman
Christophe Leroy <[email protected]> writes:
[..]
Quoted 6 lines
Quoted 5 lines
arch_remap()gets replaced byvdso_remap()For
arch_unmap(), I'm wondering how/what other architectures do, because powerpc seems to be the only one to erase the vdso context pointer when unmapping the vdso.Quoted 8 lines
Yeah. The original unmap/remap stuff was added for CRIU, which I thought people tested on other architectures (more than powerpc even).
Possibly no one really cares about vdso unmap though, vs just moving the vdso.
We added a test for vdso unmap recently because it happened to trigger a KAUP failure, and someone actually hit it & reported it.
Quoted 7 lines
You right, CRIU cares much more about moving vDSO.
It's done for each restoree and as on most setups vDSO is premapped and used by the application - it's actively tested.
Speaking about vDSO unmap - that's concerning only for heterogeneous C/R, i.e when an application is migrated from a system that uses vDSO to the one which doesn't - it's much rare scenario.
(for arm it's !CONFIG_VDSO, for x86 it'svdso=0boot parameter)
Ah OK that explains it.
The case we hit of VDSO unmapping was some strange "library OS" thing which had explicitly unmapped the VDSO, so also very rare.
Quoted 39 lines
Looking at the code, it seems quite easy to provide/maintain .close() for
vm_special_mapping. A bit harder to add a test from CRIU side (as glibc won't know on restore that it can't use vdso anymore), but totally not impossible.Quoted 34 lines
Running that test on arm64 segfaults:
# ./sigreturn_vdso VDSO is at 0xffff8191f000-0xffff8191ffff (4096 bytes) Signal delivered OK with VDSO mapped VDSO moved to 0xffff8191a000-0xffff8191afff (4096 bytes) Signal delivered OK with VDSO moved Unmapped VDSO Remapped the stack executable [ 48.556191] potentially unexpected fatal signal 11. [ 48.556752] CPU: 0 PID: 140 Comm: sigreturn_vdso Not tainted 5.9.0-rc2-00057-g2ac69819ba9e #190 [ 48.556990] Hardware name: linux,dummy-virt (DT) [ 48.557336] pstate: 60001000 (nZCv daif -PAN -UAO BTYPE=--) [ 48.557475] pc : 0000ffff8191a7bc [ 48.557603] lr : 0000ffff8191a7bc [ 48.557697] sp : 0000ffffc13c9e90 [ 48.557873] x29: 0000ffffc13cb0e0 x28: 0000000000000000 [ 48.558201] x27: 0000000000000000 x26: 0000000000000000 [ 48.558337] x25: 0000000000000000 x24: 0000000000000000 [ 48.558754] x23: 0000000000000000 x22: 0000000000000000 [ 48.558893] x21: 00000000004009b0 x20: 0000000000000000 [ 48.559046] x19: 0000000000400ff0 x18: 0000000000000000 [ 48.559180] x17: 0000ffff817da300 x16: 0000000000412010 [ 48.559312] x15: 0000000000000000 x14: 000000000000001c [ 48.559443] x13: 656c626174756365 x12: 7865206b63617473 [ 48.559625] x11: 0000000000000003 x10: 0101010101010101 [ 48.559828] x9 : 0000ffff818afda8 x8 : 0000000000000081 [ 48.559973] x7 : 6174732065687420 x6 : 64657070616d6552 [ 48.560115] x5 : 000000000e0388bd x4 : 000000000040135d [ 48.560270] x3 : 0000000000000000 x2 : 0000000000000001 [ 48.560412] x1 : 0000000000000003 x0 : 00000000004120b8 Segmentation fault #
Quoted 4 lines
Quoted 2 lines
So I think we need to keep the unmap hook. Maybe it should be handled by the
special_mappingstuff generically.I'll cook a patch for
vm_special_mappingif you don't mind :-)
That would be great, thanks!
cheers
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Quoted 58 lines · Michael Ellerman
Quoted 5 lines · Dmitry Safonov
Quoted 3 lines · Michael Ellerman
Christophe Leroy <[email protected]> writes:
We added a test for vdso unmap recently because it happened to trigger a KAUP failure, and someone actually hit it & reported it.Quoted 7 lines
You right, CRIU cares much more about moving vDSO.
It's done for each restoree and as on most setups vDSO is premapped and used by the application - it's actively tested.
Speaking about vDSO unmap - that's concerning only for heterogeneous C/R, i.e when an application is migrated from a system that uses vDSO to the one which doesn't - it's much rare scenario.
(for arm it's !CONFIG_VDSO, for x86 it'svdso=0boot parameter)Ah OK that explains it.
The case we hit of VDSO unmapping was some strange "library OS" thing which had explicitly unmapped the VDSO, so also very rare.
Quoted 39 lines
Looking at the code, it seems quite easy to provide/maintain .close() for
vm_special_mapping. A bit harder to add a test from CRIU side (as glibc won't know on restore that it can't use vdso anymore), but totally not impossible.Quoted 34 lines
Running that test on arm64 segfaults:
# ./sigreturn_vdso VDSO is at 0xffff8191f000-0xffff8191ffff (4096 bytes) Signal delivered OK with VDSO mapped VDSO moved to 0xffff8191a000-0xffff8191afff (4096 bytes) Signal delivered OK with VDSO moved Unmapped VDSO Remapped the stack executable [ 48.556191] potentially unexpected fatal signal 11. [ 48.556752] CPU: 0 PID: 140 Comm: sigreturn_vdso Not tainted 5.9.0-rc2-00057-g2ac69819ba9e #190 [ 48.556990] Hardware name: linux,dummy-virt (DT) [ 48.557336] pstate: 60001000 (nZCv daif -PAN -UAO BTYPE=--) [ 48.557475] pc : 0000ffff8191a7bc [ 48.557603] lr : 0000ffff8191a7bc [ 48.557697] sp : 0000ffffc13c9e90 [ 48.557873] x29: 0000ffffc13cb0e0 x28: 0000000000000000 [ 48.558201] x27: 0000000000000000 x26: 0000000000000000 [ 48.558337] x25: 0000000000000000 x24: 0000000000000000 [ 48.558754] x23: 0000000000000000 x22: 0000000000000000 [ 48.558893] x21: 00000000004009b0 x20: 0000000000000000 [ 48.559046] x19: 0000000000400ff0 x18: 0000000000000000 [ 48.559180] x17: 0000ffff817da300 x16: 0000000000412010 [ 48.559312] x15: 0000000000000000 x14: 000000000000001c [ 48.559443] x13: 656c626174756365 x12: 7865206b63617473 [ 48.559625] x11: 0000000000000003 x10: 0101010101010101 [ 48.559828] x9 : 0000ffff818afda8 x8 : 0000000000000081 [ 48.559973] x7 : 6174732065687420 x6 : 64657070616d6552 [ 48.560115] x5 : 000000000e0388bd x4 : 000000000040135d [ 48.560270] x3 : 0000000000000000 x2 : 0000000000000001 [ 48.560412] x1 : 0000000000000003 x0 : 00000000004120b8 Segmentation fault #
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
So I think we need to keep the unmap hook. Maybe it should be handled by the
special_mappingstuff generically.I'll cook a patch for
vm_special_mappingif you don't mind :-)That would be great, thanks!
I lost track of this one. Is there a patch kicking around to resolve this, or is the segfault expected behaviour?
Will
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Le 21/09/2020 à 13:26, Will Deacon a écrit :
Quoted 62 lines · Michael Ellerman
Quoted 61 lines
Quoted 5 lines · Dmitry Safonov
Quoted 3 lines · Michael Ellerman
Christophe Leroy <[email protected]> writes:
We added a test for vdso unmap recently because it happened to trigger a KAUP failure, and someone actually hit it & reported it.Quoted 7 lines
You right, CRIU cares much more about moving vDSO.
It's done for each restoree and as on most setups vDSO is premapped and used by the application - it's actively tested.
Speaking about vDSO unmap - that's concerning only for heterogeneous C/R, i.e when an application is migrated from a system that uses vDSO to the one which doesn't - it's much rare scenario.
(for arm it's !CONFIG_VDSO, for x86 it'svdso=0boot parameter)Ah OK that explains it.
The case we hit of VDSO unmapping was some strange "library OS" thing which had explicitly unmapped the VDSO, so also very rare.
Quoted 42 lines
Looking at the code, it seems quite easy to provide/maintain .close() for
vm_special_mapping. A bit harder to add a test from CRIU side (as glibc won't know on restore that it can't use vdso anymore), but totally not impossible.Quoted 36 lines
Running that test on arm64 segfaults:
# ./sigreturn_vdso VDSO is at 0xffff8191f000-0xffff8191ffff (4096 bytes) Signal delivered OK with VDSO mapped VDSO moved to 0xffff8191a000-0xffff8191afff (4096 bytes) Signal delivered OK with VDSO moved Unmapped VDSO Remapped the stack executable [ 48.556191] potentially unexpected fatal signal 11. [ 48.556752] CPU: 0 PID: 140 Comm: sigreturn_vdso Not tainted 5.9.0-rc2-00057-g2ac69819ba9e #190 [ 48.556990] Hardware name: linux,dummy-virt (DT) [ 48.557336] pstate: 60001000 (nZCv daif -PAN -UAO BTYPE=--) [ 48.557475] pc : 0000ffff8191a7bc [ 48.557603] lr : 0000ffff8191a7bc [ 48.557697] sp : 0000ffffc13c9e90 [ 48.557873] x29: 0000ffffc13cb0e0 x28: 0000000000000000 [ 48.558201] x27: 0000000000000000 x26: 0000000000000000 [ 48.558337] x25: 0000000000000000 x24: 0000000000000000 [ 48.558754] x23: 0000000000000000 x22: 0000000000000000 [ 48.558893] x21: 00000000004009b0 x20: 0000000000000000 [ 48.559046] x19: 0000000000400ff0 x18: 0000000000000000 [ 48.559180] x17: 0000ffff817da300 x16: 0000000000412010 [ 48.559312] x15: 0000000000000000 x14: 000000000000001c [ 48.559443] x13: 656c626174756365 x12: 7865206b63617473 [ 48.559625] x11: 0000000000000003 x10: 0101010101010101 [ 48.559828] x9 : 0000ffff818afda8 x8 : 0000000000000081 [ 48.559973] x7 : 6174732065687420 x6 : 64657070616d6552 [ 48.560115] x5 : 000000000e0388bd x4 : 000000000040135d [ 48.560270] x3 : 0000000000000000 x2 : 0000000000000001 [ 48.560412] x1 : 0000000000000003 x0 : 00000000004120b8 Segmentation fault #So I think we need to keep the unmap hook. Maybe it should be handled by the
special_mappingstuff generically.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
I'll cook a patch for
vm_special_mappingif you don't mind :-)That would be great, thanks!
I lost track of this one. Is there a patch kicking around to resolve this, or is the segfault expected behaviour?
IIUC dmitry said he will cook a patch. I have not seen any patch yet.
AFAIKS, among the architectures having VDSO sigreturn trampolines, only SH, X86 and POWERPC provide alternative trampoline on stack when VDSO is not there.
All other architectures just having a VDSO don't expect VDSO to not be mapped.
As far as nowadays stacks are mapped non-executable, getting a segfaut is expected behaviour. However, I think we should really make it cleaner. Today it segfaults because it is still pointing to the VDSO trampoline that has been unmapped. But should the user map some other code at the same address, we'll run in the weed on signal return instead of segfaulting.
So VDSO unmapping should really be properly managed, the reference should be properly cleared in order to segfault in a controllable manner.
Only powerpc has a hook to properly clear the VDSO pointer when VDSO is unmapped.
Christophe
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Quoted 5 lines · Christophe Leroy
Le 21/09/2020 à 13:26, Will Deacon a écrit :
Quoted 2 lines · Michael Ellerman
Quoted 1 line
Dmitry Safonov <[email protected]> writes:
[..]
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'll cook a patch for
vm_special_mappingif you don't mind :-)That would be great, thanks!
I lost track of this one. Is there a patch kicking around to resolve this,
or is the segfault expected behaviour?IIUC dmitry said he will cook a patch. I have not seen any patch yet.
Yes, sorry about the delay - I was a bit busy with xfrm patches.
I'll send patches for .close() this week, working on them now.
Quoted 7 lines
AFAIKS, among the architectures having VDSO sigreturn trampolines, only SH, X86 and POWERPC provide alternative trampoline on stack when VDSO is not there.
All other architectures just having a VDSO don't expect VDSO to not be mapped.
Quoted 6 lines
As far as nowadays stacks are mapped non-executable, getting a segfaut is expected behaviour. However, I think we should really make it cleaner. Today it segfaults because it is still pointing to the VDSO trampoline that has been unmapped. But should the user map some other code at the same address, we'll run in the weed on signal return instead of segfaulting.
+1.
Quoted 5 lines
So VDSO unmapping should really be properly managed, the reference should be properly cleared in order to segfault in a controllable manner.
Only powerpc has a hook to properly clear the VDSO pointer when VDSO is unmapped.
Thanks,
Dmitry
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Hi Dmitry,
Le 28/09/2020 à 17:08, Dmitry Safonov a écrit :
Quoted 16 lines · Christophe Leroy
Quoted 5 lines
Le 21/09/2020 à 13:26, Will Deacon a écrit :
Quoted 2 lines · Michael Ellerman
Quoted 1 line
Dmitry Safonov <[email protected]> writes:
[..]
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'll cook a patch for
vm_special_mappingif you don't mind :-)That would be great, thanks!
I lost track of this one. Is there a patch kicking around to resolve this,
or is the segfault expected behaviour?
Quoted 5 lines
Quoted 1 line
IIUC dmitry said he will cook a patch. I have not seen any patch yet.
Yes, sorry about the delay - I was a bit busy with xfrm patches.
I'll send patches for .close() this week, working on them now.
I haven't seen the patches, did you sent them out finally ?
Christophe
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Quoted 19 lines · Christophe Leroy
Hi Dmitry,
Le 28/09/2020 à 17:08, Dmitry Safonov a écrit :
Quoted 16 lines · Christophe Leroy
Quoted 5 lines
Le 21/09/2020 à 13:26, Will Deacon a écrit :
Quoted 2 lines · Michael Ellerman
Quoted 1 line
Dmitry Safonov <[email protected]> writes:
[..]
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'll cook a patch for
vm_special_mappingif you don't mind :-)That would be great, thanks!
I lost track of this one. Is there a patch kicking around to resolve this,
or is the segfault expected behaviour?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
IIUC dmitry said he will cook a patch. I have not seen any patch yet.
Yes, sorry about the delay - I was a bit busy with xfrm patches.
I'll send patches for .close() this week, working on them now.
I haven't seen the patches, did you sent them out finally ?
I think it's this series:
https://lore.kernel.org/r/[email protected]
but they look really invasive to me, so I may cook a small hack for arm64 in the meantine / for stable.
Will
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Le 23/10/2020 à 13:25, Will Deacon a écrit :
Quoted 26 lines · Christophe Leroy
Quoted 25 lines
Hi Dmitry,
Le 28/09/2020 à 17:08, Dmitry Safonov a écrit :
Quoted 21 lines · Christophe Leroy
Quoted 5 lines
Le 21/09/2020 à 13:26, Will Deacon a écrit :
Quoted 2 lines · Michael Ellerman
Quoted 1 line
Dmitry Safonov <[email protected]> writes:
[..]
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I'll cook a patch for
vm_special_mappingif you don't mind :-)That would be great, thanks!
I lost track of this one. Is there a patch kicking around to resolve this,
or is the segfault expected behaviour?IIUC dmitry said he will cook a patch. I have not seen any patch yet.
Yes, sorry about the delay - I was a bit busy with xfrm patches.
I'll send patches for .close() this week, working on them now.
Quoted 9 lines
Quoted 1 line
I haven't seen the patches, did you sent them out finally ?
I think it's this series:
https://lore.kernel.org/r/[email protected]
but they look really invasive to me, so I may cook a small hack for arm64 in the meantine / for stable.
Not sure we are talking about the same thing.
I can't see any new .close function added to vm_special_mapping in order to replace arch_unmap() hook.
Christophe
Re: [PATCH v8 2/8] powerpc/vdso: Remove __kernel_datapage_offset and simplify __get_datapage()
Hi Christophe, Will,
Quoted 5 lines · Christophe Leroy
Le 23/10/2020 à 13:25, Will Deacon a écrit :
Quoted 2 lines · Christophe Leroy
Quoted 1 line
Hi Dmitry,
[..]
Quoted 1 line
Quoted 1 line
Quoted 1 line
I haven't seen the patches, did you sent them out finally ?
I was working on .close() hook, but while cooking it, I thought it may be better to make tracking of user landing generic. Note that the vdso base address is mostly needed by kernel as an address to land in userspace after processing a signal.
I have some raw patches that add
+#ifdef CONFIG_ARCH_HAS_USER_LANDING
+ struct vm_area_struct *user_landing;
+#endif
inside mm_struct and I plan to finish them after rc1 gets released.
While working on that, I noticed that arm32 and some other architectures track vdso position in mm.context with the only reason to add AT_SYSINFO_EHDR in the elf header that's being loaded. That's quite overkill to have a pointer in mm.context that rather can be a local variable in elf binfmt loader. Also, I found some issues with mremap code. The patches series mentioned are at the base of the branch with generic user landing. I have sent only those patches not the full branch as I remember there was a policy that during merge window one should send only fixes, rather than refactoring/new code.
Quoted 6 lines
Quoted 6 lines
I think it's this series:
https://lore.kernel.org/r/[email protected]
but they look really invasive to me, so I may cook a small hack for arm64 in the meantine / for stable.
I don't mind small hacks, but I'm concerned that the suggested fix which sets mm->context.vdso_base = 0 on munmap() may have it's issue: that won't work if a user for whatever-broken-reason will mremap() vdso on 0 address. As the fix supposes to fix an issue that hasn't fired for anyone yet, it probably shouldn't introduce another. That's why I've used vm_area_struct to track vdso position in the patches set. Probably, temporary, you could use something like:
#define BAD_VDSO_ADDRESS (-1)UL
Or non-page-aligned address.
But the signal code that checks if it can land on vdso/sigpage should be also aligned with the new definition.
Quoted 4 lines
Not sure we are talking about the same thing.
I can't see any new .close function added to
vm_special_mappingin order to replacearch_unmap()hook.
Thanks,
Dmitry