powerpc/vdso: Prepare for switching VDSO to generic C implementation.
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 26 Nov 2020 13:10:03 +0000 (00:10 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 3 Dec 2020 14:01:10 +0000 (01:01 +1100)
commitce7d8056e38b770f070fc4499c577322b6ccb9c7
treef02c93e953ba4c907e33ac6d08936519d2858934
parent1f1676bb2dd52c1054db8476d6387e6dcf62a1ba
powerpc/vdso: Prepare for switching VDSO to generic C implementation.

Prepare for switching VDSO to generic C implementation in following
patch. Here, we:
- 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 always return true.

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

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201126131006.2431205-6-mpe@ellerman.id.au
arch/powerpc/include/asm/clocksource.h [new file with mode: 0644]
arch/powerpc/include/asm/ppc_asm.h
arch/powerpc/include/asm/vdso/clocksource.h [new file with mode: 0644]
arch/powerpc/include/asm/vdso/gettimeofday.h [new file with mode: 0644]
arch/powerpc/kernel/vdso32/vgettimeofday.c [new file with mode: 0644]
arch/powerpc/kernel/vdso64/vgettimeofday.c [new file with mode: 0644]