2020-04-20 16:59:54

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH v7 0/7] 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 v6 are:
- Added -fasynchronous-unwind-tables in CFLAGS
- Split patch 2 in two parts
- Split patch 5 (which was patch 4) in two parts

This series applies on today's powerpc/merge branch.

See the last two patches for details on changes and performance.

Christophe Leroy (7):
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.
[NOT TO BE MERGED] Export sysrq_mask

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 | 291 +------------------
arch/powerpc/kernel/vdso32/vdso32.lds.S | 7 +-
arch/powerpc/kernel/vdso32/vgettimeofday.c | 29 ++
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 ++
drivers/tty/sysrq.c | 1 +
25 files changed, 444 insertions(+), 798 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

--
2.25.0


2020-04-20 18:56:08

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH v7 4/7] powerpc/processor: Move cpu_relax() into asm/vdso/processor.h

cpu_relax() need to be in asm/vdso/processor.h to be used by
the C VDSO generic library.

Move it there.

Signed-off-by: Christophe Leroy <[email protected]>
---
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

diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index eedcbfb9a6ff..89c9eab8e45c 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -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
diff --git a/arch/powerpc/include/asm/vdso/processor.h b/arch/powerpc/include/asm/vdso/processor.h
new file mode 100644
index 000000000000..39b9beace9ca
--- /dev/null
+++ b/arch/powerpc/include/asm/vdso/processor.h
@@ -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 */
--
2.25.0

2020-04-20 19:59:30

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH v7 0/7] powerpc: switch VDSO to C implementation

On Mon, Apr 20, 2020 at 6:56 PM Christophe Leroy
<[email protected]> wrote:
>
> This is the seventh version of a series to switch powerpc VDSO to
> generic C implementation.
>
> Main changes since v6 are:
> - Added -fasynchronous-unwind-tables in CFLAGS
> - Split patch 2 in two parts
> - Split patch 5 (which was patch 4) in two parts
>
> This series applies on today's powerpc/merge branch.
>
> See the last two patches for details on changes and performance.
>
> Christophe Leroy (7):
> 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.

This all looks fine, but I'm a bit puzzled why you don't add a
clock_gettime64() implementation in the same series. Isn't
that the main purpose of doing all that work?

Without it, any 32-bit user space has to go through the system call
for time()/getttimeofday()/clock_gettime() when built with a
modern libc.

Arnd

2020-04-21 06:58:23

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v7 0/7] powerpc: switch VDSO to C implementation



Le 20/04/2020 à 21:57, Arnd Bergmann a écrit :
> On Mon, Apr 20, 2020 at 6:56 PM Christophe Leroy
> <[email protected]> wrote:
>>
>> This is the seventh version of a series to switch powerpc VDSO to
>> generic C implementation.
>>
>> Main changes since v6 are:
>> - Added -fasynchronous-unwind-tables in CFLAGS
>> - Split patch 2 in two parts
>> - Split patch 5 (which was patch 4) in two parts
>>
>> This series applies on today's powerpc/merge branch.
>>
>> See the last two patches for details on changes and performance.
>>
>> Christophe Leroy (7):
>> 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.
>
> This all looks fine, but I'm a bit puzzled why you don't add a
> clock_gettime64() implementation in the same series. Isn't
> that the main purpose of doing all that work?

Yes that was one of the objective, be able to add that as a second step.
First objective was adding the missing clocks and increasing
maintainability.

I can add a patch for that now, it looks easy, but how do I test it ?
vdsotest from Nathan doesn't seem to test that.

>
> Without it, any 32-bit user space has to go through the system call
> for time()/getttimeofday()/clock_gettime() when built with a
> modern libc.
>

How modern ? I have glibc 2.28, the only symbols it seems to know are
(extracted with 'strings') :

__vdso_clock_gettime
__vdso_time
__vdso_get_tbfreq
__vdso_getcpu
__vdso_clock_getres
__vdso_sigtramp32
__vdso_sigtramp_rt32
__vdso_gettimeofday

Christophe

2020-04-21 07:36:50

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH v7 0/7] powerpc: switch VDSO to C implementation

On Tue, Apr 21, 2020 at 8:56 AM Christophe Leroy
<[email protected]> wrote:
> Le 20/04/2020 à 21:57, Arnd Bergmann a écrit :
>
> Yes that was one of the objective, be able to add that as a second step.
> First objective was adding the missing clocks and increasing
> maintainability.
>
> I can add a patch for that now, it looks easy, but how do I test it ?
> vdsotest from Nathan doesn't seem to test that.

I wasn't aware of vdsotest, but I suppose it should be fixed in there
as well. It's only one extra call that is supposed to be available on
all 32-bit architectures.

The other thing to try is musl libc 1.2, or any distro based on it.
https://distfiles.adelielinux.org/adelie/1.0/iso/rc1/ has a ppc32
image file.

I think this is all you should need to do to enable vdso in musl:

--- a/arch/powerpc/syscall_arch.h
+++ b/arch/powerpc/syscall_arch.h
@@ -92,3 +92,9 @@ static inline long __syscall6(long n, long a, long
b, long c, long d, long e, lo

#define SO_RCVTIMEO_OLD 18
#define SO_SNDTIMEO_OLD 19
+
+#define VDSO_USEFUL
+#define VDSO_CGT32_SYM "__vdso_clock_gettime"
+#define VDSO_CGT32_VER "LINUX_2.6"
+#define VDSO_CGT_SYM "__vdso_clock_gettime64"
+#define VDSO_CGT_VER "LINUX_2.6"

At the moment, the vdso is just disabled for powerpc because there is no
__vdso_clock_gettime64 definition in the kernel.

> > Without it, any 32-bit user space has to go through the system call
> > for time()/getttimeofday()/clock_gettime() when built with a
> > modern libc.
> >
>
> How modern ? I have glibc 2.28, the only symbols it seems to know are
> (extracted with 'strings') :
>
> __vdso_clock_gettime
> __vdso_time
> __vdso_get_tbfreq
> __vdso_getcpu
> __vdso_clock_getres
> __vdso_sigtramp32
> __vdso_sigtramp_rt32
> __vdso_gettimeofday

Mainline glibc still doesn't have it, I don't know when it will,
presumably either
the coming 2.32 release, or 2.33. There is a tree at
https://github.com/lmajewski/y2038_glibc/commits/y2038_edge that has the
necessary changes, and it is slowly getting merged upstream.

Arnd