powerpc/64s: handle ISA v3.1 local copy-paste context switches
authorNicholas Piggin <npiggin@gmail.com>
Tue, 25 Aug 2020 07:55:35 +0000 (17:55 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 8 Sep 2020 12:57:12 +0000 (22:57 +1000)
The ISA v3.1 the copy-paste facility has a new memory move functionality
which allows the copy buffer to be pasted to domestic memory (RAM) as
opposed to foreign memory (accelerator).

This means the POWER9 trick of avoiding the cp_abort on context switch if
the process had not mapped foreign memory does not work on POWER10. Do the
cp_abort unconditionally there.

KVM must also cp_abort on guest exit to prevent copy buffer state leaking
between contexts.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Acked-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200825075535.224536-1-npiggin@gmail.com
arch/powerpc/kernel/process.c
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/book3s_hv_rmhandlers.S

index febe9f7cda2f8692255446ca2c135f6a8522e6e0..2a6fadde58b4acf78e2feffaf3c9db4ebb6ac450 100644 (file)
@@ -1250,15 +1250,17 @@ struct task_struct *__switch_to(struct task_struct *prev,
                restore_math(current->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. If the new process has the foreign real address
-                * mappings, we must issue a cp_abort to clear any state and
-                * prevent snooping, corruption or a covert channel.
+                * On POWER9 the copy-paste buffer can only paste into
+                * foreign real addresses, so unprivileged processes can not
+                * see the data or use it in any way unless they have
+                * foreign real mappings. If the new process has the foreign
+                * real address mappings, we must issue a cp_abort to clear
+                * any state and prevent snooping, corruption or a covert
+                * channel. ISA v3.1 supports paste into local memory.
                 */
                if (current->mm &&
-                       atomic_read(&current->mm->context.vas_windows))
+                       (cpu_has_feature(CPU_FTR_ARCH_31) ||
+                       atomic_read(&current->mm->context.vas_windows)))
                        asm volatile(PPC_CP_ABORT);
        }
 #endif /* CONFIG_PPC_BOOK3S_64 */
index 4ba06a2a306cfdc166f3650516847da53c92b525..3bd3118c763307c8352061188a38782e653c129a 100644 (file)
@@ -3530,6 +3530,13 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,
         */
        asm volatile("eieio; tlbsync; ptesync");
 
+       /*
+        * cp_abort is required if the processor supports local copy-paste
+        * to clear the copy buffer that was under control of the guest.
+        */
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               asm volatile(PPC_CP_ABORT);
+
        mtspr(SPRN_LPID, vcpu->kvm->arch.host_lpid);    /* restore host LPID */
        isync();
 
index 799d6d0f4eadee541e016eeb0aec1c92e75c0b33..cd9995ee8441993dde47a1afdddfb36f077f3e42 100644 (file)
@@ -1830,6 +1830,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_P9_RADIX_PREFETCH_BUG)
 2:
 #endif /* CONFIG_PPC_RADIX_MMU */
 
+       /*
+        * cp_abort is required if the processor supports local copy-paste
+        * to clear the copy buffer that was under control of the guest.
+        */
+BEGIN_FTR_SECTION
+       PPC_CP_ABORT
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
+
        /*
         * POWER7/POWER8 guest -> host partition switch code.
         * We don't have to lock against tlbies but we do