2019-05-27 14:55:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-12-20 15:39:59 +08:00
|
|
|
/*
|
2014-10-08 16:54:50 +08:00
|
|
|
* CoProcessor (SPU/AFU) mm fault handler
|
2007-12-20 15:39:59 +08:00
|
|
|
*
|
|
|
|
* (C) Copyright IBM Deutschland Entwicklung GmbH 2007
|
|
|
|
*
|
|
|
|
* Author: Arnd Bergmann <arndb@de.ibm.com>
|
|
|
|
* Author: Jeremy Kerr <jk@ozlabs.org>
|
|
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
2011-07-23 06:24:23 +08:00
|
|
|
#include <linux/export.h>
|
2014-10-08 16:54:50 +08:00
|
|
|
#include <asm/reg.h>
|
2014-10-08 16:54:51 +08:00
|
|
|
#include <asm/copro.h>
|
2014-10-08 16:54:52 +08:00
|
|
|
#include <asm/spu.h>
|
2015-05-27 14:07:16 +08:00
|
|
|
#include <misc/cxl-base.h>
|
2007-12-20 15:39:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This ought to be kept in sync with the powerpc specific do_page_fault
|
|
|
|
* function. Currently, there are a few corner cases that we haven't had
|
|
|
|
* to handle fortunately.
|
|
|
|
*/
|
2014-10-08 16:54:50 +08:00
|
|
|
int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
|
2018-08-18 06:44:47 +08:00
|
|
|
unsigned long dsisr, vm_fault_t *flt)
|
2007-12-20 15:39:59 +08:00
|
|
|
{
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
unsigned long is_write;
|
|
|
|
int ret;
|
|
|
|
|
2009-02-17 08:44:14 +08:00
|
|
|
if (mm == NULL)
|
2007-12-20 15:39:59 +08:00
|
|
|
return -EFAULT;
|
2009-02-17 08:44:14 +08:00
|
|
|
|
|
|
|
if (mm->pgd == NULL)
|
2007-12-20 15:39:59 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2020-06-09 12:33:25 +08:00
|
|
|
mmap_read_lock(mm);
|
2009-02-17 08:44:14 +08:00
|
|
|
ret = -EFAULT;
|
2007-12-20 15:39:59 +08:00
|
|
|
vma = find_vma(mm, ea);
|
|
|
|
if (!vma)
|
2009-02-17 08:44:14 +08:00
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
if (ea < vma->vm_start) {
|
|
|
|
if (!(vma->vm_flags & VM_GROWSDOWN))
|
|
|
|
goto out_unlock;
|
|
|
|
if (expand_stack(vma, ea))
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
2014-10-08 16:54:50 +08:00
|
|
|
is_write = dsisr & DSISR_ISSTORE;
|
2007-12-20 15:39:59 +08:00
|
|
|
if (is_write) {
|
|
|
|
if (!(vma->vm_flags & VM_WRITE))
|
2009-02-17 08:44:14 +08:00
|
|
|
goto out_unlock;
|
2007-12-20 15:39:59 +08:00
|
|
|
} else {
|
|
|
|
if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
|
2009-02-17 08:44:14 +08:00
|
|
|
goto out_unlock;
|
2015-02-13 06:58:25 +08:00
|
|
|
/*
|
2017-01-31 00:12:59 +08:00
|
|
|
* PROT_NONE is covered by the VMA check above.
|
|
|
|
* and hash should get a NOHPTE fault instead of
|
|
|
|
* a PROTFAULT in case fixup is needed for things
|
|
|
|
* like autonuma.
|
2015-02-13 06:58:25 +08:00
|
|
|
*/
|
2017-01-31 00:12:59 +08:00
|
|
|
if (!radix_enabled())
|
|
|
|
WARN_ON_ONCE(dsisr & DSISR_PROTFAULT);
|
2007-12-20 15:39:59 +08:00
|
|
|
}
|
2009-02-17 08:44:14 +08:00
|
|
|
|
2007-12-20 15:39:59 +08:00
|
|
|
ret = 0;
|
mm: do page fault accounting in handle_mm_fault
Patch series "mm: Page fault accounting cleanups", v5.
This is v5 of the pf accounting cleanup series. It originates from Gerald
Schaefer's report on an issue a week ago regarding to incorrect page fault
accountings for retried page fault after commit 4064b9827063 ("mm: allow
VM_FAULT_RETRY for multiple times"):
https://lore.kernel.org/lkml/20200610174811.44b94525@thinkpad/
What this series did:
- Correct page fault accounting: we do accounting for a page fault
(no matter whether it's from #PF handling, or gup, or anything else)
only with the one that completed the fault. For example, page fault
retries should not be counted in page fault counters. Same to the
perf events.
- Unify definition of PERF_COUNT_SW_PAGE_FAULTS: currently this perf
event is used in an adhoc way across different archs.
Case (1): for many archs it's done at the entry of a page fault
handler, so that it will also cover e.g. errornous faults.
Case (2): for some other archs, it is only accounted when the page
fault is resolved successfully.
Case (3): there're still quite some archs that have not enabled
this perf event.
Since this series will touch merely all the archs, we unify this
perf event to always follow case (1), which is the one that makes most
sense. And since we moved the accounting into handle_mm_fault, the
other two MAJ/MIN perf events are well taken care of naturally.
- Unify definition of "major faults": the definition of "major
fault" is slightly changed when used in accounting (not
VM_FAULT_MAJOR). More information in patch 1.
- Always account the page fault onto the one that triggered the page
fault. This does not matter much for #PF handlings, but mostly for
gup. More information on this in patch 25.
Patchset layout:
Patch 1: Introduced the accounting in handle_mm_fault(), not enabled.
Patch 2-23: Enable the new accounting for arch #PF handlers one by one.
Patch 24: Enable the new accounting for the rest outliers (gup, iommu, etc.)
Patch 25: Cleanup GUP task_struct pointer since it's not needed any more
This patch (of 25):
This is a preparation patch to move page fault accountings into the
general code in handle_mm_fault(). This includes both the per task
flt_maj/flt_min counters, and the major/minor page fault perf events. To
do this, the pt_regs pointer is passed into handle_mm_fault().
PERF_COUNT_SW_PAGE_FAULTS should still be kept in per-arch page fault
handlers.
So far, all the pt_regs pointer that passed into handle_mm_fault() is
NULL, which means this patch should have no intented functional change.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Cain <bcain@codeaurora.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Greentime Hu <green.hu@gmail.com>
Cc: Guo Ren <guoren@kernel.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Nick Hu <nickhu@andestech.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Rich Felker <dalias@libc.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Link: http://lkml.kernel.org/r/20200707225021.200906-1-peterx@redhat.com
Link: http://lkml.kernel.org/r/20200707225021.200906-2-peterx@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-12 09:37:44 +08:00
|
|
|
*flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0, NULL);
|
2007-12-20 15:39:59 +08:00
|
|
|
if (unlikely(*flt & VM_FAULT_ERROR)) {
|
|
|
|
if (*flt & VM_FAULT_OOM) {
|
|
|
|
ret = -ENOMEM;
|
2009-02-17 08:44:14 +08:00
|
|
|
goto out_unlock;
|
vm: add VM_FAULT_SIGSEGV handling support
The core VM already knows about VM_FAULT_SIGBUS, but cannot return a
"you should SIGSEGV" error, because the SIGSEGV case was generally
handled by the caller - usually the architecture fault handler.
That results in lots of duplication - all the architecture fault
handlers end up doing very similar "look up vma, check permissions, do
retries etc" - but it generally works. However, there are cases where
the VM actually wants to SIGSEGV, and applications _expect_ SIGSEGV.
In particular, when accessing the stack guard page, libsigsegv expects a
SIGSEGV. And it usually got one, because the stack growth is handled by
that duplicated architecture fault handler.
However, when the generic VM layer started propagating the error return
from the stack expansion in commit fee7e49d4514 ("mm: propagate error
from stack expansion even for guard page"), that now exposed the
existing VM_FAULT_SIGBUS result to user space. And user space really
expected SIGSEGV, not SIGBUS.
To fix that case, we need to add a VM_FAULT_SIGSEGV, and teach all those
duplicate architecture fault handlers about it. They all already have
the code to handle SIGSEGV, so it's about just tying that new return
value to the existing code, but it's all a bit annoying.
This is the mindless minimal patch to do this. A more extensive patch
would be to try to gather up the mostly shared fault handling logic into
one generic helper routine, and long-term we really should do that
cleanup.
Just from this patch, you can generally see that most architectures just
copied (directly or indirectly) the old x86 way of doing things, but in
the meantime that original x86 model has been improved to hold the VM
semaphore for shorter times etc and to handle VM_FAULT_RETRY and other
"newer" things, so it would be a good idea to bring all those
improvements to the generic case and teach other architectures about
them too.
Reported-and-tested-by: Takashi Iwai <tiwai@suse.de>
Tested-by: Jan Engelhardt <jengelh@inai.de>
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com> # "s390 still compiles and boots"
Cc: linux-arch@vger.kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-01-30 02:51:32 +08:00
|
|
|
} else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) {
|
2007-12-20 15:39:59 +08:00
|
|
|
ret = -EFAULT;
|
2009-02-17 08:44:14 +08:00
|
|
|
goto out_unlock;
|
2007-12-20 15:39:59 +08:00
|
|
|
}
|
|
|
|
BUG();
|
|
|
|
}
|
2009-02-17 08:44:14 +08:00
|
|
|
|
|
|
|
out_unlock:
|
2020-06-09 12:33:25 +08:00
|
|
|
mmap_read_unlock(mm);
|
2009-02-17 08:44:14 +08:00
|
|
|
return ret;
|
2007-12-20 15:39:59 +08:00
|
|
|
}
|
2014-10-08 16:54:50 +08:00
|
|
|
EXPORT_SYMBOL_GPL(copro_handle_mm_fault);
|
2014-10-08 16:54:51 +08:00
|
|
|
|
|
|
|
int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
|
|
|
|
{
|
2015-05-27 14:06:55 +08:00
|
|
|
u64 vsid, vsidkey;
|
2014-10-08 16:54:51 +08:00
|
|
|
int psize, ssize;
|
|
|
|
|
2019-04-17 20:59:14 +08:00
|
|
|
switch (get_region_id(ea)) {
|
2014-10-08 16:54:51 +08:00
|
|
|
case USER_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea);
|
2016-06-18 00:53:28 +08:00
|
|
|
if (mm == NULL)
|
|
|
|
return 1;
|
2014-10-08 16:54:51 +08:00
|
|
|
psize = get_slice_psize(mm, ea);
|
|
|
|
ssize = user_segment_size(ea);
|
2018-03-26 18:04:48 +08:00
|
|
|
vsid = get_user_vsid(&mm->context, ea, ssize);
|
2015-05-27 14:06:55 +08:00
|
|
|
vsidkey = SLB_VSID_USER;
|
2014-10-08 16:54:51 +08:00
|
|
|
break;
|
|
|
|
case VMALLOC_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea);
|
2019-04-17 20:59:14 +08:00
|
|
|
psize = mmu_vmalloc_psize;
|
|
|
|
ssize = mmu_kernel_ssize;
|
|
|
|
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
|
|
|
|
vsidkey = SLB_VSID_KERNEL;
|
|
|
|
break;
|
|
|
|
case IO_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- IO_REGION_ID\n", __func__, ea);
|
|
|
|
psize = mmu_io_psize;
|
2014-10-08 16:54:51 +08:00
|
|
|
ssize = mmu_kernel_ssize;
|
|
|
|
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
|
2015-05-27 14:06:55 +08:00
|
|
|
vsidkey = SLB_VSID_KERNEL;
|
2014-10-08 16:54:51 +08:00
|
|
|
break;
|
2019-04-17 20:59:19 +08:00
|
|
|
case LINEAR_MAP_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- LINEAR_MAP_REGION_ID\n", __func__, ea);
|
2014-10-08 16:54:51 +08:00
|
|
|
psize = mmu_linear_psize;
|
|
|
|
ssize = mmu_kernel_ssize;
|
|
|
|
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
|
2015-05-27 14:06:55 +08:00
|
|
|
vsidkey = SLB_VSID_KERNEL;
|
2014-10-08 16:54:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_debug("%s: invalid region access at %016llx\n", __func__, ea);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-11-15 23:06:06 +08:00
|
|
|
/* Bad address */
|
|
|
|
if (!vsid)
|
|
|
|
return 1;
|
2014-10-08 16:54:51 +08:00
|
|
|
|
2015-05-27 14:06:55 +08:00
|
|
|
vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey;
|
2014-10-08 16:54:51 +08:00
|
|
|
|
|
|
|
vsid |= mmu_psize_defs[psize].sllp |
|
|
|
|
((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0);
|
|
|
|
|
2014-10-28 11:25:29 +08:00
|
|
|
slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V;
|
2014-10-08 16:54:51 +08:00
|
|
|
slb->vsid = vsid;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(copro_calculate_slb);
|
2014-10-08 16:54:52 +08:00
|
|
|
|
|
|
|
void copro_flush_all_slbs(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SPU_BASE
|
|
|
|
spu_flush_all_slbs(mm);
|
|
|
|
#endif
|
2014-10-08 16:55:00 +08:00
|
|
|
cxl_slbia(mm);
|
2014-10-08 16:54:52 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(copro_flush_all_slbs);
|