Skip to content

Commit f6a41f7

Browse files
npiggingregkh
authored andcommitted
powerpc/64s: handle ISA v3.1 local copy-paste context switches
[ Upstream commit dc46226 ] 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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d2297a2 commit f6a41f7

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

arch/powerpc/kernel/process.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,15 +1256,17 @@ struct task_struct *__switch_to(struct task_struct *prev,
12561256
restore_math(current->thread.regs);
12571257

12581258
/*
1259-
* The copy-paste buffer can only store into foreign real
1260-
* addresses, so unprivileged processes can not see the
1261-
* data or use it in any way unless they have foreign real
1262-
* mappings. If the new process has the foreign real address
1263-
* mappings, we must issue a cp_abort to clear any state and
1264-
* prevent snooping, corruption or a covert channel.
1259+
* On POWER9 the copy-paste buffer can only paste into
1260+
* foreign real addresses, so unprivileged processes can not
1261+
* see the data or use it in any way unless they have
1262+
* foreign real mappings. If the new process has the foreign
1263+
* real address mappings, we must issue a cp_abort to clear
1264+
* any state and prevent snooping, corruption or a covert
1265+
* channel. ISA v3.1 supports paste into local memory.
12651266
*/
12661267
if (current->mm &&
1267-
atomic_read(&current->mm->context.vas_windows))
1268+
(cpu_has_feature(CPU_FTR_ARCH_31) ||
1269+
atomic_read(&current->mm->context.vas_windows)))
12681270
asm volatile(PPC_CP_ABORT);
12691271
}
12701272
#endif /* CONFIG_PPC_BOOK3S_64 */

arch/powerpc/kvm/book3s_hv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,6 +3530,13 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,
35303530
*/
35313531
asm volatile("eieio; tlbsync; ptesync");
35323532

3533+
/*
3534+
* cp_abort is required if the processor supports local copy-paste
3535+
* to clear the copy buffer that was under control of the guest.
3536+
*/
3537+
if (cpu_has_feature(CPU_FTR_ARCH_31))
3538+
asm volatile(PPC_CP_ABORT);
3539+
35333540
mtspr(SPRN_LPID, vcpu->kvm->arch.host_lpid); /* restore host LPID */
35343541
isync();
35353542

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_P9_RADIX_PREFETCH_BUG)
18301830
2:
18311831
#endif /* CONFIG_PPC_RADIX_MMU */
18321832

1833+
/*
1834+
* cp_abort is required if the processor supports local copy-paste
1835+
* to clear the copy buffer that was under control of the guest.
1836+
*/
1837+
BEGIN_FTR_SECTION
1838+
PPC_CP_ABORT
1839+
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
1840+
18331841
/*
18341842
* POWER7/POWER8 guest -> host partition switch code.
18351843
* We don't have to lock against tlbies but we do

0 commit comments

Comments
 (0)