| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * OpenRISC fault.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 8 | 9 | * Modifications for the OpenRISC architecture: |
|---|
| 9 | 10 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> |
|---|
| 10 | 11 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or |
|---|
| 13 | | - * modify it under the terms of the GNU General Public License |
|---|
| 14 | | - * as published by the Free Software Foundation; either version |
|---|
| 15 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 16 | 12 | */ |
|---|
| 17 | 13 | |
|---|
| 18 | 14 | #include <linux/mm.h> |
|---|
| 19 | 15 | #include <linux/interrupt.h> |
|---|
| 20 | 16 | #include <linux/extable.h> |
|---|
| 21 | 17 | #include <linux/sched/signal.h> |
|---|
| 18 | +#include <linux/perf_event.h> |
|---|
| 22 | 19 | |
|---|
| 23 | 20 | #include <linux/uaccess.h> |
|---|
| 24 | 21 | #include <asm/siginfo.h> |
|---|
| .. | .. |
|---|
| 54 | 51 | struct vm_area_struct *vma; |
|---|
| 55 | 52 | int si_code; |
|---|
| 56 | 53 | vm_fault_t fault; |
|---|
| 57 | | - unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; |
|---|
| 54 | + unsigned int flags = FAULT_FLAG_DEFAULT; |
|---|
| 58 | 55 | |
|---|
| 59 | 56 | tsk = current; |
|---|
| 60 | 57 | |
|---|
| .. | .. |
|---|
| 107 | 104 | if (in_interrupt() || !mm) |
|---|
| 108 | 105 | goto no_context; |
|---|
| 109 | 106 | |
|---|
| 107 | + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); |
|---|
| 108 | + |
|---|
| 110 | 109 | retry: |
|---|
| 111 | | - down_read(&mm->mmap_sem); |
|---|
| 110 | + mmap_read_lock(mm); |
|---|
| 112 | 111 | vma = find_vma(mm, address); |
|---|
| 113 | 112 | |
|---|
| 114 | 113 | if (!vma) |
|---|
| .. | .. |
|---|
| 163 | 162 | * the fault. |
|---|
| 164 | 163 | */ |
|---|
| 165 | 164 | |
|---|
| 166 | | - fault = handle_mm_fault(vma, address, flags); |
|---|
| 165 | + fault = handle_mm_fault(vma, address, flags, regs); |
|---|
| 167 | 166 | |
|---|
| 168 | | - if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) |
|---|
| 167 | + if (fault_signal_pending(fault, regs)) |
|---|
| 169 | 168 | return; |
|---|
| 170 | 169 | |
|---|
| 171 | 170 | if (unlikely(fault & VM_FAULT_ERROR)) { |
|---|
| .. | .. |
|---|
| 180 | 179 | |
|---|
| 181 | 180 | if (flags & FAULT_FLAG_ALLOW_RETRY) { |
|---|
| 182 | 181 | /*RGD modeled on Cris */ |
|---|
| 183 | | - if (fault & VM_FAULT_MAJOR) |
|---|
| 184 | | - tsk->maj_flt++; |
|---|
| 185 | | - else |
|---|
| 186 | | - tsk->min_flt++; |
|---|
| 187 | 182 | if (fault & VM_FAULT_RETRY) { |
|---|
| 188 | | - flags &= ~FAULT_FLAG_ALLOW_RETRY; |
|---|
| 189 | 183 | flags |= FAULT_FLAG_TRIED; |
|---|
| 190 | 184 | |
|---|
| 191 | | - /* No need to up_read(&mm->mmap_sem) as we would |
|---|
| 185 | + /* No need to mmap_read_unlock(mm) as we would |
|---|
| 192 | 186 | * have already released it in __lock_page_or_retry |
|---|
| 193 | 187 | * in mm/filemap.c. |
|---|
| 194 | 188 | */ |
|---|
| .. | .. |
|---|
| 197 | 191 | } |
|---|
| 198 | 192 | } |
|---|
| 199 | 193 | |
|---|
| 200 | | - up_read(&mm->mmap_sem); |
|---|
| 194 | + mmap_read_unlock(mm); |
|---|
| 201 | 195 | return; |
|---|
| 202 | 196 | |
|---|
| 203 | 197 | /* |
|---|
| .. | .. |
|---|
| 206 | 200 | */ |
|---|
| 207 | 201 | |
|---|
| 208 | 202 | bad_area: |
|---|
| 209 | | - up_read(&mm->mmap_sem); |
|---|
| 203 | + mmap_read_unlock(mm); |
|---|
| 210 | 204 | |
|---|
| 211 | 205 | bad_area_nosemaphore: |
|---|
| 212 | 206 | |
|---|
| 213 | 207 | /* User mode accesses just cause a SIGSEGV */ |
|---|
| 214 | 208 | |
|---|
| 215 | 209 | if (user_mode(regs)) { |
|---|
| 216 | | - force_sig_fault(SIGSEGV, si_code, (void __user *)address, tsk); |
|---|
| 210 | + force_sig_fault(SIGSEGV, si_code, (void __user *)address); |
|---|
| 217 | 211 | return; |
|---|
| 218 | 212 | } |
|---|
| 219 | 213 | |
|---|
| .. | .. |
|---|
| 265 | 259 | __asm__ __volatile__("l.nop 42"); |
|---|
| 266 | 260 | __asm__ __volatile__("l.nop 1"); |
|---|
| 267 | 261 | |
|---|
| 268 | | - up_read(&mm->mmap_sem); |
|---|
| 262 | + mmap_read_unlock(mm); |
|---|
| 269 | 263 | if (!user_mode(regs)) |
|---|
| 270 | 264 | goto no_context; |
|---|
| 271 | 265 | pagefault_out_of_memory(); |
|---|
| 272 | 266 | return; |
|---|
| 273 | 267 | |
|---|
| 274 | 268 | do_sigbus: |
|---|
| 275 | | - up_read(&mm->mmap_sem); |
|---|
| 269 | + mmap_read_unlock(mm); |
|---|
| 276 | 270 | |
|---|
| 277 | 271 | /* |
|---|
| 278 | 272 | * Send a sigbus, regardless of whether we were in kernel |
|---|
| 279 | 273 | * or user mode. |
|---|
| 280 | 274 | */ |
|---|
| 281 | | - force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address, tsk); |
|---|
| 275 | + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address); |
|---|
| 282 | 276 | |
|---|
| 283 | 277 | /* Kernel mode? Handle exceptions or die */ |
|---|
| 284 | 278 | if (!user_mode(regs)) |
|---|
| .. | .. |
|---|
| 300 | 294 | |
|---|
| 301 | 295 | int offset = pgd_index(address); |
|---|
| 302 | 296 | pgd_t *pgd, *pgd_k; |
|---|
| 297 | + p4d_t *p4d, *p4d_k; |
|---|
| 303 | 298 | pud_t *pud, *pud_k; |
|---|
| 304 | 299 | pmd_t *pmd, *pmd_k; |
|---|
| 305 | 300 | pte_t *pte_k; |
|---|
| .. | .. |
|---|
| 326 | 321 | * it exists. |
|---|
| 327 | 322 | */ |
|---|
| 328 | 323 | |
|---|
| 329 | | - pud = pud_offset(pgd, address); |
|---|
| 330 | | - pud_k = pud_offset(pgd_k, address); |
|---|
| 324 | + p4d = p4d_offset(pgd, address); |
|---|
| 325 | + p4d_k = p4d_offset(pgd_k, address); |
|---|
| 326 | + if (!p4d_present(*p4d_k)) |
|---|
| 327 | + goto no_context; |
|---|
| 328 | + |
|---|
| 329 | + pud = pud_offset(p4d, address); |
|---|
| 330 | + pud_k = pud_offset(p4d_k, address); |
|---|
| 331 | 331 | if (!pud_present(*pud_k)) |
|---|
| 332 | 332 | goto no_context; |
|---|
| 333 | 333 | |
|---|