mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-24 20:02:23 +07:00
50a7ca3c6f
Use new return type vm_fault_t for fault handler. For now, this is just
documenting that the function returns a VM_FAULT value rather than an
errno. Once all instances are converted, vm_fault_t will become a
distinct type.
Ref-> commit 1c8f422059
("mm: change return type to vm_fault_t")
In this patch all the caller of handle_mm_fault() are changed to return
vm_fault_t type.
Link: http://lkml.kernel.org/r/20180617084810.GA6730@jordon-HP-15-Notebook-PC
Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: James Hogan <jhogan@kernel.org>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Palmer Dabbelt <palmer@sifive.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: David S. Miller <davem@davemloft.net>
Cc: Richard Weinberger <richard@nod.at>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
198 lines
4.5 KiB
C
198 lines
4.5 KiB
C
/*
|
|
* Memory fault handling for Hexagon
|
|
*
|
|
* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
* only version 2 as published by the Free Software Foundation.
|
|
*
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*/
|
|
|
|
/*
|
|
* Page fault handling for the Hexagon Virtual Machine.
|
|
* Can also be called by a native port emulating the HVM
|
|
* execptions.
|
|
*/
|
|
|
|
#include <asm/pgtable.h>
|
|
#include <asm/traps.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/signal.h>
|
|
#include <linux/extable.h>
|
|
#include <linux/hardirq.h>
|
|
|
|
/*
|
|
* Decode of hardware exception sends us to one of several
|
|
* entry points. At each, we generate canonical arguments
|
|
* for handling by the abstract memory management code.
|
|
*/
|
|
#define FLT_IFETCH -1
|
|
#define FLT_LOAD 0
|
|
#define FLT_STORE 1
|
|
|
|
|
|
/*
|
|
* Canonical page fault handler
|
|
*/
|
|
void do_page_fault(unsigned long address, long cause, struct pt_regs *regs)
|
|
{
|
|
struct vm_area_struct *vma;
|
|
struct mm_struct *mm = current->mm;
|
|
int si_signo;
|
|
int si_code = SEGV_MAPERR;
|
|
vm_fault_t fault;
|
|
const struct exception_table_entry *fixup;
|
|
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
|
|
|
|
/*
|
|
* If we're in an interrupt or have no user context,
|
|
* then must not take the fault.
|
|
*/
|
|
if (unlikely(in_interrupt() || !mm))
|
|
goto no_context;
|
|
|
|
local_irq_enable();
|
|
|
|
if (user_mode(regs))
|
|
flags |= FAULT_FLAG_USER;
|
|
retry:
|
|
down_read(&mm->mmap_sem);
|
|
vma = find_vma(mm, address);
|
|
if (!vma)
|
|
goto bad_area;
|
|
|
|
if (vma->vm_start <= address)
|
|
goto good_area;
|
|
|
|
if (!(vma->vm_flags & VM_GROWSDOWN))
|
|
goto bad_area;
|
|
|
|
if (expand_stack(vma, address))
|
|
goto bad_area;
|
|
|
|
good_area:
|
|
/* Address space is OK. Now check access rights. */
|
|
si_code = SEGV_ACCERR;
|
|
|
|
switch (cause) {
|
|
case FLT_IFETCH:
|
|
if (!(vma->vm_flags & VM_EXEC))
|
|
goto bad_area;
|
|
break;
|
|
case FLT_LOAD:
|
|
if (!(vma->vm_flags & VM_READ))
|
|
goto bad_area;
|
|
break;
|
|
case FLT_STORE:
|
|
if (!(vma->vm_flags & VM_WRITE))
|
|
goto bad_area;
|
|
flags |= FAULT_FLAG_WRITE;
|
|
break;
|
|
}
|
|
|
|
fault = handle_mm_fault(vma, address, flags);
|
|
|
|
if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
|
|
return;
|
|
|
|
/* The most common case -- we are done. */
|
|
if (likely(!(fault & VM_FAULT_ERROR))) {
|
|
if (flags & FAULT_FLAG_ALLOW_RETRY) {
|
|
if (fault & VM_FAULT_MAJOR)
|
|
current->maj_flt++;
|
|
else
|
|
current->min_flt++;
|
|
if (fault & VM_FAULT_RETRY) {
|
|
flags &= ~FAULT_FLAG_ALLOW_RETRY;
|
|
flags |= FAULT_FLAG_TRIED;
|
|
goto retry;
|
|
}
|
|
}
|
|
|
|
up_read(&mm->mmap_sem);
|
|
return;
|
|
}
|
|
|
|
up_read(&mm->mmap_sem);
|
|
|
|
/* Handle copyin/out exception cases */
|
|
if (!user_mode(regs))
|
|
goto no_context;
|
|
|
|
if (fault & VM_FAULT_OOM) {
|
|
pagefault_out_of_memory();
|
|
return;
|
|
}
|
|
|
|
/* User-mode address is in the memory map, but we are
|
|
* unable to fix up the page fault.
|
|
*/
|
|
if (fault & VM_FAULT_SIGBUS) {
|
|
si_signo = SIGBUS;
|
|
si_code = BUS_ADRERR;
|
|
}
|
|
/* Address is not in the memory map */
|
|
else {
|
|
si_signo = SIGSEGV;
|
|
si_code = SEGV_ACCERR;
|
|
}
|
|
force_sig_fault(si_signo, si_code, (void __user *)address, current);
|
|
return;
|
|
|
|
bad_area:
|
|
up_read(&mm->mmap_sem);
|
|
|
|
if (user_mode(regs)) {
|
|
force_sig_fault(SIGSEGV, si_code, (void __user *)address, current);
|
|
return;
|
|
}
|
|
/* Kernel-mode fault falls through */
|
|
|
|
no_context:
|
|
fixup = search_exception_tables(pt_elr(regs));
|
|
if (fixup) {
|
|
pt_set_elr(regs, fixup->fixup);
|
|
return;
|
|
}
|
|
|
|
/* Things are looking very, very bad now */
|
|
bust_spinlocks(1);
|
|
printk(KERN_EMERG "Unable to handle kernel paging request at "
|
|
"virtual address 0x%08lx, regs %p\n", address, regs);
|
|
die("Bad Kernel VA", regs, SIGKILL);
|
|
}
|
|
|
|
|
|
void read_protection_fault(struct pt_regs *regs)
|
|
{
|
|
unsigned long badvadr = pt_badva(regs);
|
|
|
|
do_page_fault(badvadr, FLT_LOAD, regs);
|
|
}
|
|
|
|
void write_protection_fault(struct pt_regs *regs)
|
|
{
|
|
unsigned long badvadr = pt_badva(regs);
|
|
|
|
do_page_fault(badvadr, FLT_STORE, regs);
|
|
}
|
|
|
|
void execute_protection_fault(struct pt_regs *regs)
|
|
{
|
|
unsigned long badvadr = pt_badva(regs);
|
|
|
|
do_page_fault(badvadr, FLT_IFETCH, regs);
|
|
}
|