1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * CoProcessor (SPU/AFU) mm fault handler
5 * (C) Copyright IBM Deutschland Entwicklung GmbH 2007
7 * Author: Arnd Bergmann <arndb@de.ibm.com>
8 * Author: Jeremy Kerr <jk@ozlabs.org>
10 #include <linux/sched.h>
12 #include <linux/export.h>
14 #include <asm/copro.h>
17 * This ought to be kept in sync with the powerpc specific do_page_fault
18 * function. Currently, there are a few corner cases that we haven't had
19 * to handle fortunately.
21 int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
22 unsigned long dsisr, vm_fault_t *flt)
24 struct vm_area_struct *vma;
25 unsigned long is_write;
34 vma = lock_mm_and_find_vma(mm, ea, NULL);
39 is_write = dsisr & DSISR_ISSTORE;
41 if (!(vma->vm_flags & VM_WRITE))
44 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
47 * PROT_NONE is covered by the VMA check above.
48 * and hash should get a NOHPTE fault instead of
49 * a PROTFAULT in case fixup is needed for things
53 WARN_ON_ONCE(dsisr & DSISR_PROTFAULT);
57 *flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0, NULL);
59 /* The fault is fully completed (including releasing mmap lock) */
60 if (*flt & VM_FAULT_COMPLETED)
63 if (unlikely(*flt & VM_FAULT_ERROR)) {
64 if (*flt & VM_FAULT_OOM) {
67 } else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) {
78 EXPORT_SYMBOL_GPL(copro_handle_mm_fault);
80 #ifdef CONFIG_PPC_64S_HASH_MMU
81 int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
86 switch (get_region_id(ea)) {
88 pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea);
91 psize = get_slice_psize(mm, ea);
92 ssize = user_segment_size(ea);
93 vsid = get_user_vsid(&mm->context, ea, ssize);
94 vsidkey = SLB_VSID_USER;
96 case VMALLOC_REGION_ID:
97 pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea);
98 psize = mmu_vmalloc_psize;
99 ssize = mmu_kernel_ssize;
100 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
101 vsidkey = SLB_VSID_KERNEL;
104 pr_devel("%s: 0x%llx -- IO_REGION_ID\n", __func__, ea);
105 psize = mmu_io_psize;
106 ssize = mmu_kernel_ssize;
107 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
108 vsidkey = SLB_VSID_KERNEL;
110 case LINEAR_MAP_REGION_ID:
111 pr_devel("%s: 0x%llx -- LINEAR_MAP_REGION_ID\n", __func__, ea);
112 psize = mmu_linear_psize;
113 ssize = mmu_kernel_ssize;
114 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
115 vsidkey = SLB_VSID_KERNEL;
118 pr_debug("%s: invalid region access at %016llx\n", __func__, ea);
125 vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey;
127 vsid |= mmu_psize_defs[psize].sllp |
128 ((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0);
130 slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V;
135 EXPORT_SYMBOL_GPL(copro_calculate_slb);