| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Memory fault handling for Hexagon |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 and |
|---|
| 8 | | - * only version 2 as published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, write to the Free Software |
|---|
| 17 | | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| 18 | | - * 02110-1301, USA. |
|---|
| 19 | 6 | */ |
|---|
| 20 | 7 | |
|---|
| 21 | 8 | /* |
|---|
| .. | .. |
|---|
| 24 | 11 | * execptions. |
|---|
| 25 | 12 | */ |
|---|
| 26 | 13 | |
|---|
| 27 | | -#include <asm/pgtable.h> |
|---|
| 28 | 14 | #include <asm/traps.h> |
|---|
| 29 | 15 | #include <linux/uaccess.h> |
|---|
| 30 | 16 | #include <linux/mm.h> |
|---|
| .. | .. |
|---|
| 32 | 18 | #include <linux/signal.h> |
|---|
| 33 | 19 | #include <linux/extable.h> |
|---|
| 34 | 20 | #include <linux/hardirq.h> |
|---|
| 21 | +#include <linux/perf_event.h> |
|---|
| 35 | 22 | |
|---|
| 36 | 23 | /* |
|---|
| 37 | 24 | * Decode of hardware exception sends us to one of several |
|---|
| .. | .. |
|---|
| 54 | 41 | int si_code = SEGV_MAPERR; |
|---|
| 55 | 42 | vm_fault_t fault; |
|---|
| 56 | 43 | const struct exception_table_entry *fixup; |
|---|
| 57 | | - unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; |
|---|
| 44 | + unsigned int flags = FAULT_FLAG_DEFAULT; |
|---|
| 58 | 45 | |
|---|
| 59 | 46 | /* |
|---|
| 60 | 47 | * If we're in an interrupt or have no user context, |
|---|
| .. | .. |
|---|
| 67 | 54 | |
|---|
| 68 | 55 | if (user_mode(regs)) |
|---|
| 69 | 56 | flags |= FAULT_FLAG_USER; |
|---|
| 57 | + |
|---|
| 58 | + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); |
|---|
| 70 | 59 | retry: |
|---|
| 71 | | - down_read(&mm->mmap_sem); |
|---|
| 60 | + mmap_read_lock(mm); |
|---|
| 72 | 61 | vma = find_vma(mm, address); |
|---|
| 73 | 62 | if (!vma) |
|---|
| 74 | 63 | goto bad_area; |
|---|
| .. | .. |
|---|
| 102 | 91 | break; |
|---|
| 103 | 92 | } |
|---|
| 104 | 93 | |
|---|
| 105 | | - fault = handle_mm_fault(vma, address, flags); |
|---|
| 94 | + fault = handle_mm_fault(vma, address, flags, regs); |
|---|
| 106 | 95 | |
|---|
| 107 | | - if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) |
|---|
| 96 | + if (fault_signal_pending(fault, regs)) |
|---|
| 108 | 97 | return; |
|---|
| 109 | 98 | |
|---|
| 110 | 99 | /* The most common case -- we are done. */ |
|---|
| 111 | 100 | if (likely(!(fault & VM_FAULT_ERROR))) { |
|---|
| 112 | 101 | if (flags & FAULT_FLAG_ALLOW_RETRY) { |
|---|
| 113 | | - if (fault & VM_FAULT_MAJOR) |
|---|
| 114 | | - current->maj_flt++; |
|---|
| 115 | | - else |
|---|
| 116 | | - current->min_flt++; |
|---|
| 117 | 102 | if (fault & VM_FAULT_RETRY) { |
|---|
| 118 | | - flags &= ~FAULT_FLAG_ALLOW_RETRY; |
|---|
| 119 | 103 | flags |= FAULT_FLAG_TRIED; |
|---|
| 120 | 104 | goto retry; |
|---|
| 121 | 105 | } |
|---|
| 122 | 106 | } |
|---|
| 123 | 107 | |
|---|
| 124 | | - up_read(&mm->mmap_sem); |
|---|
| 108 | + mmap_read_unlock(mm); |
|---|
| 125 | 109 | return; |
|---|
| 126 | 110 | } |
|---|
| 127 | 111 | |
|---|
| 128 | | - up_read(&mm->mmap_sem); |
|---|
| 112 | + mmap_read_unlock(mm); |
|---|
| 129 | 113 | |
|---|
| 130 | 114 | /* Handle copyin/out exception cases */ |
|---|
| 131 | 115 | if (!user_mode(regs)) |
|---|
| .. | .. |
|---|
| 148 | 132 | si_signo = SIGSEGV; |
|---|
| 149 | 133 | si_code = SEGV_ACCERR; |
|---|
| 150 | 134 | } |
|---|
| 151 | | - force_sig_fault(si_signo, si_code, (void __user *)address, current); |
|---|
| 135 | + force_sig_fault(si_signo, si_code, (void __user *)address); |
|---|
| 152 | 136 | return; |
|---|
| 153 | 137 | |
|---|
| 154 | 138 | bad_area: |
|---|
| 155 | | - up_read(&mm->mmap_sem); |
|---|
| 139 | + mmap_read_unlock(mm); |
|---|
| 156 | 140 | |
|---|
| 157 | 141 | if (user_mode(regs)) { |
|---|
| 158 | | - force_sig_fault(SIGSEGV, si_code, (void __user *)address, current); |
|---|
| 142 | + force_sig_fault(SIGSEGV, si_code, (void __user *)address); |
|---|
| 159 | 143 | return; |
|---|
| 160 | 144 | } |
|---|
| 161 | 145 | /* Kernel-mode fault falls through */ |
|---|