]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
powerpc/64s: Avoid cpabort in context switch when possible
authorNicholas Piggin <npiggin@gmail.com>
Thu, 8 Jun 2017 15:36:09 +0000 (01:36 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 15 Jun 2017 06:34:39 +0000 (16:34 +1000)
The ISA v3.0B copy-paste facility only requires cpabort when switching
to a process that has foreign real addresses mapped (direct access to
accelerators), to clear a potential copy buffer filled by a previous
thread. There is no accelerator driver implemented yet, so cpabort can
be removed. It can be be re-added when a driver is implemented.

POWER9 DD1 requires the copy buffer to always be cleared on context
switch, but if accelerators are not in use, then an unpaired copy from
a dummy region is sufficient to clear data out of the copy buffer.

This increases context switch performance by about 5% on POWER9.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/ppc-opcode.h
arch/powerpc/kernel/entry_64.S
arch/powerpc/kernel/process.c

index 3a8d278e742103720b6c8605c87f41c09e9a5323..3b6bbf5a86836bf02890e76a235b724ad34fc844 100644 (file)
 /* sorted alphabetically */
 #define PPC_INST_BHRBE                 0x7c00025c
 #define PPC_INST_CLRBHRB               0x7c00035c
-#define PPC_INST_COPY                  0x7c00060c
-#define PPC_INST_COPY_FIRST            0x7c20060c
+#define PPC_INST_COPY                  0x7c20060c
 #define PPC_INST_CP_ABORT              0x7c00068c
 #define PPC_INST_DCBA                  0x7c0005ec
 #define PPC_INST_DCBA_MASK             0xfc0007fe
 #define PPC_INST_MSGSNDP               0x7c00011c
 #define PPC_INST_MTTMR                 0x7c0003dc
 #define PPC_INST_NOP                   0x60000000
-#define PPC_INST_PASTE                 0x7c00070c
-#define PPC_INST_PASTE_LAST            0x7c20070d
+#define PPC_INST_PASTE                 0x7c20070d
 #define PPC_INST_POPCNTB               0x7c0000f4
 #define PPC_INST_POPCNTB_MASK          0xfc0007fe
 #define PPC_INST_POPCNTD               0x7c0003f4
 
 /* Deal with instructions that older assemblers aren't aware of */
 #define        PPC_CP_ABORT            stringify_in_c(.long PPC_INST_CP_ABORT)
+#define        PPC_COPY(a, b)          stringify_in_c(.long PPC_INST_COPY | \
+                                       ___PPC_RA(a) | ___PPC_RB(b))
 #define        PPC_DCBAL(a, b)         stringify_in_c(.long PPC_INST_DCBAL | \
                                        __PPC_RA(a) | __PPC_RB(b))
 #define        PPC_DCBZL(a, b)         stringify_in_c(.long PPC_INST_DCBZL | \
index fb143859cc687d9c0fc9ebeb9500b539d0b36c18..da9486e2fd89b5f93f06dc5ed57837d6742d4d1b 100644 (file)
@@ -536,15 +536,6 @@ _GLOBAL(_switch)
         * which contains larx/stcx, which will clear any reservation
         * of the task being switched.
         */
-
-BEGIN_FTR_SECTION
-/*
- * A cp_abort (copy paste abort) here ensures that when context switching, a
- * copy from one process can't leak into the paste of another.
- */
-       PPC_CP_ABORT
-END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
-
 #ifdef CONFIG_PPC_BOOK3S
 /* Cancel all explict user streams as they will have no use after context
  * switch and will stop the HW from creating streams itself
index 45faa9a32a0190325908e5986daed62972bf4296..6273b5d5baece8f5eea1ef3305ca1f062f161b84 100644 (file)
@@ -1137,6 +1137,11 @@ static inline void restore_sprs(struct thread_struct *old_thread,
 #endif
 }
 
+#ifdef CONFIG_PPC_BOOK3S_64
+#define CP_SIZE 128
+static const u8 dummy_copy_buffer[CP_SIZE] __attribute__((aligned(CP_SIZE)));
+#endif
+
 struct task_struct *__switch_to(struct task_struct *prev,
        struct task_struct *new)
 {
@@ -1226,8 +1231,28 @@ struct task_struct *__switch_to(struct task_struct *prev,
                batch->active = 1;
        }
 
-       if (current_thread_info()->task->thread.regs)
+       if (current_thread_info()->task->thread.regs) {
                restore_math(current_thread_info()->task->thread.regs);
+
+               /*
+                * The copy-paste buffer can only store into foreign real
+                * addresses, so unprivileged processes can not see the
+                * data or use it in any way unless they have foreign real
+                * mappings. We don't have a VAS driver that allocates those
+                * yet, so no cpabort is required.
+                */
+               if (cpu_has_feature(CPU_FTR_POWER9_DD1)) {
+                       /*
+                        * DD1 allows paste into normal system memory, so we
+                        * do an unpaired copy here to clear the buffer and
+                        * prevent a covert channel being set up.
+                        *
+                        * cpabort is not used because it is quite expensive.
+                        */
+                       asm volatile(PPC_COPY(%0, %1)
+                                       : : "r"(dummy_copy_buffer), "r"(0));
+               }
+       }
 #endif /* CONFIG_PPC_STD_MMU_64 */
 
        return last;