Commit | Line | Data |
---|---|---|
de6cc651 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7cd58e43 | 2 | /* |
e83d0169 | 3 | * CoProcessor (SPU/AFU) mm fault handler |
7cd58e43 JK |
4 | * |
5 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2007 | |
6 | * | |
7 | * Author: Arnd Bergmann <arndb@de.ibm.com> | |
8 | * Author: Jeremy Kerr <jk@ozlabs.org> | |
7cd58e43 JK |
9 | */ |
10 | #include <linux/sched.h> | |
11 | #include <linux/mm.h> | |
4b16f8e2 | 12 | #include <linux/export.h> |
e83d0169 | 13 | #include <asm/reg.h> |
73d16a6e | 14 | #include <asm/copro.h> |
7cd58e43 JK |
15 | |
16 | /* | |
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. | |
20 | */ | |
e83d0169 | 21 | int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea, |
50a7ca3c | 22 | unsigned long dsisr, vm_fault_t *flt) |
7cd58e43 JK |
23 | { |
24 | struct vm_area_struct *vma; | |
25 | unsigned long is_write; | |
26 | int ret; | |
27 | ||
60ee0319 | 28 | if (mm == NULL) |
7cd58e43 | 29 | return -EFAULT; |
60ee0319 JK |
30 | |
31 | if (mm->pgd == NULL) | |
7cd58e43 | 32 | return -EFAULT; |
7cd58e43 | 33 | |
2cd76c50 | 34 | vma = lock_mm_and_find_vma(mm, ea, NULL); |
7cd58e43 | 35 | if (!vma) |
2cd76c50 | 36 | return -EFAULT; |
60ee0319 | 37 | |
2cd76c50 | 38 | ret = -EFAULT; |
e83d0169 | 39 | is_write = dsisr & DSISR_ISSTORE; |
7cd58e43 JK |
40 | if (is_write) { |
41 | if (!(vma->vm_flags & VM_WRITE)) | |
60ee0319 | 42 | goto out_unlock; |
7cd58e43 | 43 | } else { |
7cd58e43 | 44 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
60ee0319 | 45 | goto out_unlock; |
842915f5 | 46 | /* |
18061c17 AK |
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 | |
50 | * like autonuma. | |
842915f5 | 51 | */ |
18061c17 AK |
52 | if (!radix_enabled()) |
53 | WARN_ON_ONCE(dsisr & DSISR_PROTFAULT); | |
7cd58e43 | 54 | } |
60ee0319 | 55 | |
7cd58e43 | 56 | ret = 0; |
bce617ed | 57 | *flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0, NULL); |
d9272525 PX |
58 | |
59 | /* The fault is fully completed (including releasing mmap lock) */ | |
60 | if (*flt & VM_FAULT_COMPLETED) | |
61 | return 0; | |
62 | ||
7cd58e43 JK |
63 | if (unlikely(*flt & VM_FAULT_ERROR)) { |
64 | if (*flt & VM_FAULT_OOM) { | |
65 | ret = -ENOMEM; | |
60ee0319 | 66 | goto out_unlock; |
33692f27 | 67 | } else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) { |
7cd58e43 | 68 | ret = -EFAULT; |
60ee0319 | 69 | goto out_unlock; |
7cd58e43 JK |
70 | } |
71 | BUG(); | |
72 | } | |
60ee0319 | 73 | |
60ee0319 | 74 | out_unlock: |
d8ed45c5 | 75 | mmap_read_unlock(mm); |
60ee0319 | 76 | return ret; |
7cd58e43 | 77 | } |
e83d0169 | 78 | EXPORT_SYMBOL_GPL(copro_handle_mm_fault); |
73d16a6e | 79 | |
387e220a | 80 | #ifdef CONFIG_PPC_64S_HASH_MMU |
73d16a6e IM |
81 | int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb) |
82 | { | |
85a97da9 | 83 | u64 vsid, vsidkey; |
73d16a6e IM |
84 | int psize, ssize; |
85 | ||
0034d395 | 86 | switch (get_region_id(ea)) { |
73d16a6e IM |
87 | case USER_REGION_ID: |
88 | pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea); | |
d2cf909c FB |
89 | if (mm == NULL) |
90 | return 1; | |
73d16a6e IM |
91 | psize = get_slice_psize(mm, ea); |
92 | ssize = user_segment_size(ea); | |
f384796c | 93 | vsid = get_user_vsid(&mm->context, ea, ssize); |
85a97da9 | 94 | vsidkey = SLB_VSID_USER; |
73d16a6e IM |
95 | break; |
96 | case VMALLOC_REGION_ID: | |
97 | pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea); | |
0034d395 AK |
98 | psize = mmu_vmalloc_psize; |
99 | ssize = mmu_kernel_ssize; | |
100 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); | |
101 | vsidkey = SLB_VSID_KERNEL; | |
102 | break; | |
103 | case IO_REGION_ID: | |
104 | pr_devel("%s: 0x%llx -- IO_REGION_ID\n", __func__, ea); | |
105 | psize = mmu_io_psize; | |
73d16a6e IM |
106 | ssize = mmu_kernel_ssize; |
107 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); | |
85a97da9 | 108 | vsidkey = SLB_VSID_KERNEL; |
73d16a6e | 109 | break; |
5f53d286 AK |
110 | case LINEAR_MAP_REGION_ID: |
111 | pr_devel("%s: 0x%llx -- LINEAR_MAP_REGION_ID\n", __func__, ea); | |
73d16a6e IM |
112 | psize = mmu_linear_psize; |
113 | ssize = mmu_kernel_ssize; | |
114 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); | |
85a97da9 | 115 | vsidkey = SLB_VSID_KERNEL; |
73d16a6e IM |
116 | break; |
117 | default: | |
118 | pr_debug("%s: invalid region access at %016llx\n", __func__, ea); | |
119 | return 1; | |
120 | } | |
64168f42 AK |
121 | /* Bad address */ |
122 | if (!vsid) | |
123 | return 1; | |
73d16a6e | 124 | |
85a97da9 | 125 | vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey; |
73d16a6e IM |
126 | |
127 | vsid |= mmu_psize_defs[psize].sllp | | |
128 | ((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0); | |
129 | ||
03f54397 | 130 | slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V; |
73d16a6e IM |
131 | slb->vsid = vsid; |
132 | ||
133 | return 0; | |
134 | } | |
135 | EXPORT_SYMBOL_GPL(copro_calculate_slb); | |
387e220a | 136 | #endif |