arm64: assembler: introduce ldr_this_cpu
authorMark Rutland <mark.rutland@arm.com>
Fri, 20 Jul 2018 09:56:12 +0000 (10:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 22 Jul 2018 12:27:40 +0000 (14:27 +0200)
Commit 1b7e2296a822dfd2349960addc42a139360ce769 upstream.

Shortly we will want to load a percpu variable in the return from
userspace path. We can save an instruction by folding the addition of
the percpu offset into the load instruction, and this patch adds a new
helper to do so.

At the same time, we clean up this_cpu_ptr for consistency. As with
{adr,ldr,str}_l, we change the template to take the destination register
first, and name this dst. Secondly, we rename the macro to adr_this_cpu,
following the scheme of adr_l, and matching the newly added
ldr_this_cpu.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Laura Abbott <labbott@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: James Morse <james.morse@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/include/asm/assembler.h
arch/arm64/kernel/entry.S

index bfcfec3590f6b740b618580f4ca448d5afe930aa..a4f227f6a4001c6e897a2889b57174cfc45f0cb7 100644 (file)
@@ -239,14 +239,25 @@ lr        .req    x30             // link register
        .endm
 
        /*
+        * @dst: Result of per_cpu(sym, smp_processor_id())
         * @sym: The name of the per-cpu variable
-        * @reg: Result of per_cpu(sym, smp_processor_id())
         * @tmp: scratch register
         */
-       .macro this_cpu_ptr, sym, reg, tmp
-       adr_l   \reg, \sym
+       .macro adr_this_cpu, dst, sym, tmp
+       adr_l   \dst, \sym
+       mrs     \tmp, tpidr_el1
+       add     \dst, \dst, \tmp
+       .endm
+
+       /*
+        * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id()))
+        * @sym: The name of the per-cpu variable
+        * @tmp: scratch register
+        */
+       .macro ldr_this_cpu dst, sym, tmp
+       adr_l   \dst, \sym
        mrs     \tmp, tpidr_el1
-       add     \reg, \reg, \tmp
+       ldr     \dst, [\dst, \tmp]
        .endm
 
 /*
index b79e302d2a3e959af52a886a8bff821327259d88..7fed00b476927192c7f1f76c965615f893f6c5fb 100644 (file)
@@ -243,7 +243,7 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0
        cmp     x25, tsk
        b.ne    9998f
 
-       this_cpu_ptr irq_stack, x25, x26
+       adr_this_cpu x25, irq_stack, x26
        mov     x26, #IRQ_STACK_START_SP
        add     x26, x25, x26