sparc: Improve VDSO instruction patching.
authorDavid S. Miller <davem@davemloft.net>
Mon, 22 Oct 2018 04:44:33 +0000 (21:44 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Oct 2018 22:22:14 +0000 (15:22 -0700)
commit2f6c9bf31a0b16aeccb42b73f8d0ddf9bea88f3f
tree444fc78d32340f45e56c8e217cded18a2d2b736a
parent46b8306480fb424abd525acc1763da1c63a27d8a
sparc: Improve VDSO instruction patching.

The current VDSO patch mechanism has several problems:

1) It assumes how gcc will emit a function, with a register
   window, an initial save instruction and then immediately
   the %tick read when compiling vread_tick().

   There is no such guarantees, code generation could change
   at any time, gcc could put a nop between the save and
   the %tick read, etc.

   So this is extremely fragile and would fail some day.

2) It disallows us to properly inline vread_tick() into the callers
   and thus get the best possible code sequences.

So fix this to patch properly, with location based annotations.

We have to be careful because we cannot do it the way we do
patches elsewhere in the kernel.  Those use a sequence like:

1:
insn
.section .whatever_patch, "ax"
.word 1b
replacement_insn
.previous

This is a dynamic shared object, so that .word cannot be resolved at
build time, and thus cannot be used to execute the patches when the
kernel initializes the images.

Even trying to use label difference equations doesn't work in the
above kind of scheme:

1:
insn
.section .whatever_patch, "ax"
.word . - 1b
replacement_insn
.previous

The assembler complains that it cannot resolve that computation.
The issue is that this is contained in an executable section.

Borrow the sequence used by x86 alternatives, which is:

1:
insn
.pushsection .whatever_patch, "a"
.word . - 1b, . - 1f
.popsection
.pushsection .whatever_patch_replacements, "ax"
1:
replacement_insn
.previous

This works, allows us to inline vread_tick() as much as we like, and
can be used for arbitrary kinds of VDSO patching in the future.

Also, reverse the condition for patching.  Most systems are %stick
based, so if we only patch on %tick systems the patching code will
get little or no testing.

Signed-off-by: David S. Miller <davem@davemloft.net>
arch/sparc/include/asm/vdso.h
arch/sparc/kernel/time_64.c
arch/sparc/vdso/vclock_gettime.c
arch/sparc/vdso/vdso-layout.lds.S
arch/sparc/vdso/vdso2c.c
arch/sparc/vdso/vdso2c.h
arch/sparc/vdso/vma.c