2007-12-20 07:39:59 +00:00
|
|
|
/*
|
2014-10-08 08:54:50 +00:00
|
|
|
* CoProcessor (SPU/AFU) mm fault handler
|
2007-12-20 07:39:59 +00:00
|
|
|
*
|
|
|
|
* (C) Copyright IBM Deutschland Entwicklung GmbH 2007
|
|
|
|
*
|
|
|
|
* Author: Arnd Bergmann <arndb@de.ibm.com>
|
|
|
|
* Author: Jeremy Kerr <jk@ozlabs.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
2011-07-22 22:24:23 +00:00
|
|
|
#include <linux/export.h>
|
2014-10-08 08:54:50 +00:00
|
|
|
#include <asm/reg.h>
|
2014-10-08 08:54:51 +00:00
|
|
|
#include <asm/copro.h>
|
2014-10-08 08:54:52 +00:00
|
|
|
#include <asm/spu.h>
|
2015-05-27 06:07:16 +00:00
|
|
|
#include <misc/cxl-base.h>
|
2007-12-20 07:39:59 +00: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 08:54:50 +00:00
|
|
|
int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
|
2018-08-17 22:44:47 +00:00
|
|
|
unsigned long dsisr, vm_fault_t *flt)
|
2007-12-20 07:39:59 +00:00
|
|
|
{
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
unsigned long is_write;
|
|
|
|
int ret;
|
|
|
|
|
2009-02-17 00:44:14 +00:00
|
|
|
if (mm == NULL)
|
2007-12-20 07:39:59 +00:00
|
|
|
return -EFAULT;
|
2009-02-17 00:44:14 +00:00
|
|
|
|
|
|
|
if (mm->pgd == NULL)
|
2007-12-20 07:39:59 +00:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
down_read(&mm->mmap_sem);
|
2009-02-17 00:44:14 +00:00
|
|
|
ret = -EFAULT;
|
2007-12-20 07:39:59 +00:00
|
|
|
vma = find_vma(mm, ea);
|
|
|
|
if (!vma)
|
2009-02-17 00:44:14 +00: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 08:54:50 +00:00
|
|
|
is_write = dsisr & DSISR_ISSTORE;
|
2007-12-20 07:39:59 +00:00
|
|
|
if (is_write) {
|
|
|
|
if (!(vma->vm_flags & VM_WRITE))
|
2009-02-17 00:44:14 +00:00
|
|
|
goto out_unlock;
|
2007-12-20 07:39:59 +00:00
|
|
|
} else {
|
|
|
|
if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
|
2009-02-17 00:44:14 +00:00
|
|
|
goto out_unlock;
|
2015-02-12 22:58:25 +00:00
|
|
|
/*
|
2017-01-30 16:12:59 +00: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-12 22:58:25 +00:00
|
|
|
*/
|
2017-01-30 16:12:59 +00:00
|
|
|
if (!radix_enabled())
|
|
|
|
WARN_ON_ONCE(dsisr & DSISR_PROTFAULT);
|
2007-12-20 07:39:59 +00:00
|
|
|
}
|
2009-02-17 00:44:14 +00:00
|
|
|
|
2007-12-20 07:39:59 +00:00
|
|
|
ret = 0;
|
2016-07-26 22:25:18 +00:00
|
|
|
*flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0);
|
2007-12-20 07:39:59 +00:00
|
|
|
if (unlikely(*flt & VM_FAULT_ERROR)) {
|
|
|
|
if (*flt & VM_FAULT_OOM) {
|
|
|
|
ret = -ENOMEM;
|
2009-02-17 00:44:14 +00: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-29 18:51:32 +00:00
|
|
|
} else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) {
|
2007-12-20 07:39:59 +00:00
|
|
|
ret = -EFAULT;
|
2009-02-17 00:44:14 +00:00
|
|
|
goto out_unlock;
|
2007-12-20 07:39:59 +00:00
|
|
|
}
|
|
|
|
BUG();
|
|
|
|
}
|
2009-02-17 00:44:14 +00:00
|
|
|
|
2007-12-20 07:39:59 +00:00
|
|
|
if (*flt & VM_FAULT_MAJOR)
|
|
|
|
current->maj_flt++;
|
|
|
|
else
|
|
|
|
current->min_flt++;
|
|
|
|
|
2009-02-17 00:44:14 +00:00
|
|
|
out_unlock:
|
2007-12-20 07:39:59 +00:00
|
|
|
up_read(&mm->mmap_sem);
|
2009-02-17 00:44:14 +00:00
|
|
|
return ret;
|
2007-12-20 07:39:59 +00:00
|
|
|
}
|
2014-10-08 08:54:50 +00:00
|
|
|
EXPORT_SYMBOL_GPL(copro_handle_mm_fault);
|
2014-10-08 08:54:51 +00:00
|
|
|
|
|
|
|
int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
|
|
|
|
{
|
2015-05-27 06:06:55 +00:00
|
|
|
u64 vsid, vsidkey;
|
2014-10-08 08:54:51 +00:00
|
|
|
int psize, ssize;
|
|
|
|
|
|
|
|
switch (REGION_ID(ea)) {
|
|
|
|
case USER_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea);
|
2016-06-17 16:53:28 +00:00
|
|
|
if (mm == NULL)
|
|
|
|
return 1;
|
2014-10-08 08:54:51 +00:00
|
|
|
psize = get_slice_psize(mm, ea);
|
|
|
|
ssize = user_segment_size(ea);
|
2018-03-26 10:04:48 +00:00
|
|
|
vsid = get_user_vsid(&mm->context, ea, ssize);
|
2015-05-27 06:06:55 +00:00
|
|
|
vsidkey = SLB_VSID_USER;
|
2014-10-08 08:54:51 +00:00
|
|
|
break;
|
|
|
|
case VMALLOC_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea);
|
|
|
|
if (ea < VMALLOC_END)
|
|
|
|
psize = mmu_vmalloc_psize;
|
|
|
|
else
|
|
|
|
psize = mmu_io_psize;
|
|
|
|
ssize = mmu_kernel_ssize;
|
|
|
|
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
|
2015-05-27 06:06:55 +00:00
|
|
|
vsidkey = SLB_VSID_KERNEL;
|
2014-10-08 08:54:51 +00:00
|
|
|
break;
|
|
|
|
case KERNEL_REGION_ID:
|
|
|
|
pr_devel("%s: 0x%llx -- KERNEL_REGION_ID\n", __func__, ea);
|
|
|
|
psize = mmu_linear_psize;
|
|
|
|
ssize = mmu_kernel_ssize;
|
|
|
|
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
|
2015-05-27 06:06:55 +00:00
|
|
|
vsidkey = SLB_VSID_KERNEL;
|
2014-10-08 08:54:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_debug("%s: invalid region access at %016llx\n", __func__, ea);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-11-15 15:06:06 +00:00
|
|
|
/* Bad address */
|
|
|
|
if (!vsid)
|
|
|
|
return 1;
|
2014-10-08 08:54:51 +00:00
|
|
|
|
2015-05-27 06:06:55 +00:00
|
|
|
vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey;
|
2014-10-08 08:54:51 +00:00
|
|
|
|
|
|
|
vsid |= mmu_psize_defs[psize].sllp |
|
|
|
|
((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0);
|
|
|
|
|
2014-10-28 03:25:29 +00:00
|
|
|
slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V;
|
2014-10-08 08:54:51 +00:00
|
|
|
slb->vsid = vsid;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(copro_calculate_slb);
|
2014-10-08 08:54:52 +00:00
|
|
|
|
|
|
|
void copro_flush_all_slbs(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SPU_BASE
|
|
|
|
spu_flush_all_slbs(mm);
|
|
|
|
#endif
|
2014-10-08 08:55:00 +00:00
|
|
|
cxl_slbia(mm);
|
2014-10-08 08:54:52 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(copro_flush_all_slbs);
|