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> |
be3ebfe8 | 15 | #include <asm/spu.h> |
ec249dd8 | 16 | #include <misc/cxl-base.h> |
7cd58e43 JK |
17 | |
18 | /* | |
19 | * This ought to be kept in sync with the powerpc specific do_page_fault | |
20 | * function. Currently, there are a few corner cases that we haven't had | |
21 | * to handle fortunately. | |
22 | */ | |
e83d0169 | 23 | int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea, |
50a7ca3c | 24 | unsigned long dsisr, vm_fault_t *flt) |
7cd58e43 JK |
25 | { |
26 | struct vm_area_struct *vma; | |
27 | unsigned long is_write; | |
28 | int ret; | |
29 | ||
60ee0319 | 30 | if (mm == NULL) |
7cd58e43 | 31 | return -EFAULT; |
60ee0319 JK |
32 | |
33 | if (mm->pgd == NULL) | |
7cd58e43 | 34 | return -EFAULT; |
7cd58e43 | 35 | |
d8ed45c5 | 36 | mmap_read_lock(mm); |
60ee0319 | 37 | ret = -EFAULT; |
7cd58e43 JK |
38 | vma = find_vma(mm, ea); |
39 | if (!vma) | |
60ee0319 JK |
40 | goto out_unlock; |
41 | ||
42 | if (ea < vma->vm_start) { | |
43 | if (!(vma->vm_flags & VM_GROWSDOWN)) | |
44 | goto out_unlock; | |
45 | if (expand_stack(vma, ea)) | |
46 | goto out_unlock; | |
47 | } | |
48 | ||
e83d0169 | 49 | is_write = dsisr & DSISR_ISSTORE; |
7cd58e43 JK |
50 | if (is_write) { |
51 | if (!(vma->vm_flags & VM_WRITE)) | |
60ee0319 | 52 | goto out_unlock; |
7cd58e43 | 53 | } else { |
7cd58e43 | 54 | if (!(vma->vm_flags & (VM_READ | VM_EXEC))) |
60ee0319 | 55 | goto out_unlock; |
842915f5 | 56 | /* |
18061c17 AK |
57 | * PROT_NONE is covered by the VMA check above. |
58 | * and hash should get a NOHPTE fault instead of | |
59 | * a PROTFAULT in case fixup is needed for things | |
60 | * like autonuma. | |
842915f5 | 61 | */ |
18061c17 AK |
62 | if (!radix_enabled()) |
63 | WARN_ON_ONCE(dsisr & DSISR_PROTFAULT); | |
7cd58e43 | 64 | } |
60ee0319 | 65 | |
7cd58e43 | 66 | ret = 0; |
bce617ed | 67 | *flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0, NULL); |
7cd58e43 JK |
68 | if (unlikely(*flt & VM_FAULT_ERROR)) { |
69 | if (*flt & VM_FAULT_OOM) { | |
70 | ret = -ENOMEM; | |
60ee0319 | 71 | goto out_unlock; |
33692f27 | 72 | } else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) { |
7cd58e43 | 73 | ret = -EFAULT; |
60ee0319 | 74 | goto out_unlock; |
7cd58e43 JK |
75 | } |
76 | BUG(); | |
77 | } | |
60ee0319 | 78 | |
60ee0319 | 79 | out_unlock: |
d8ed45c5 | 80 | mmap_read_unlock(mm); |
60ee0319 | 81 | return ret; |
7cd58e43 | 82 | } |
e83d0169 | 83 | EXPORT_SYMBOL_GPL(copro_handle_mm_fault); |
73d16a6e | 84 | |
387e220a | 85 | #ifdef CONFIG_PPC_64S_HASH_MMU |
73d16a6e IM |
86 | int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb) |
87 | { | |
85a97da9 | 88 | u64 vsid, vsidkey; |
73d16a6e IM |
89 | int psize, ssize; |
90 | ||
0034d395 | 91 | switch (get_region_id(ea)) { |
73d16a6e IM |
92 | case USER_REGION_ID: |
93 | pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea); | |
d2cf909c FB |
94 | if (mm == NULL) |
95 | return 1; | |
73d16a6e IM |
96 | psize = get_slice_psize(mm, ea); |
97 | ssize = user_segment_size(ea); | |
f384796c | 98 | vsid = get_user_vsid(&mm->context, ea, ssize); |
85a97da9 | 99 | vsidkey = SLB_VSID_USER; |
73d16a6e IM |
100 | break; |
101 | case VMALLOC_REGION_ID: | |
102 | pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea); | |
0034d395 AK |
103 | psize = mmu_vmalloc_psize; |
104 | ssize = mmu_kernel_ssize; | |
105 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); | |
106 | vsidkey = SLB_VSID_KERNEL; | |
107 | break; | |
108 | case IO_REGION_ID: | |
109 | pr_devel("%s: 0x%llx -- IO_REGION_ID\n", __func__, ea); | |
110 | psize = mmu_io_psize; | |
73d16a6e IM |
111 | ssize = mmu_kernel_ssize; |
112 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); | |
85a97da9 | 113 | vsidkey = SLB_VSID_KERNEL; |
73d16a6e | 114 | break; |
5f53d286 AK |
115 | case LINEAR_MAP_REGION_ID: |
116 | pr_devel("%s: 0x%llx -- LINEAR_MAP_REGION_ID\n", __func__, ea); | |
73d16a6e IM |
117 | psize = mmu_linear_psize; |
118 | ssize = mmu_kernel_ssize; | |
119 | vsid = get_kernel_vsid(ea, mmu_kernel_ssize); | |
85a97da9 | 120 | vsidkey = SLB_VSID_KERNEL; |
73d16a6e IM |
121 | break; |
122 | default: | |
123 | pr_debug("%s: invalid region access at %016llx\n", __func__, ea); | |
124 | return 1; | |
125 | } | |
64168f42 AK |
126 | /* Bad address */ |
127 | if (!vsid) | |
128 | return 1; | |
73d16a6e | 129 | |
85a97da9 | 130 | vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey; |
73d16a6e IM |
131 | |
132 | vsid |= mmu_psize_defs[psize].sllp | | |
133 | ((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0); | |
134 | ||
03f54397 | 135 | slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V; |
73d16a6e IM |
136 | slb->vsid = vsid; |
137 | ||
138 | return 0; | |
139 | } | |
140 | EXPORT_SYMBOL_GPL(copro_calculate_slb); | |
be3ebfe8 IM |
141 | |
142 | void copro_flush_all_slbs(struct mm_struct *mm) | |
143 | { | |
144 | #ifdef CONFIG_SPU_BASE | |
145 | spu_flush_all_slbs(mm); | |
146 | #endif | |
4c6d9acc | 147 | cxl_slbia(mm); |
be3ebfe8 IM |
148 | } |
149 | EXPORT_SYMBOL_GPL(copro_flush_all_slbs); | |
387e220a | 150 | #endif |