Commit 83c54070 authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds

mm: fault feedback #2

This patch completes Linus's wish that the fault return codes be made into
bit flags, which I agree makes everything nicer.  This requires requires
all handle_mm_fault callers to be modified (possibly the modifications
should go further and do things like fault accounting in handle_mm_fault --
however that would be for another patch).

[akpm@linux-foundation.org: fix alpha build]
[akpm@linux-foundation.org: fix s390 build]
[akpm@linux-foundation.org: fix sparc build]
[akpm@linux-foundation.org: fix sparc64 build]
[akpm@linux-foundation.org: fix ia64 build]
Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Russell King <rmk@arm.linux.org.uk>
Cc: Ian Molton <spyro@f2s.com>
Cc: Bryan Wu <bryan.wu@analog.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Hirokazu Takata <takata@linux-m32r.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Greg Ungerer <gerg@uclinux.org>
Cc: Matthew Wilcox <willy@debian.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
Cc: Richard Curnow <rc@rc0.org.uk>
Cc: William Lee Irwin III <wli@holomorphy.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Miles Bader <uclinux-v850@lsi.nec.co.jp>
Cc: Chris Zankel <chris@zankel.net>
Acked-by: default avatarKyle McMartin <kyle@mcmartin.ca>
Acked-by: default avatarHaavard Skinnemoen <hskinnemoen@atmel.com>
Acked-by: default avatarRalf Baechle <ralf@linux-mips.org>
Acked-by: default avatarAndi Kleen <ak@muc.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
[ Still apparently needs some ARM and PPC loving - Linus ]
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d0217ac0
...@@ -148,21 +148,17 @@ do_page_fault(unsigned long address, unsigned long mmcsr, ...@@ -148,21 +148,17 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
the fault. */ the fault. */
fault = handle_mm_fault(mm, vma, address, cause > 0); fault = handle_mm_fault(mm, vma, address, cause > 0);
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
if (unlikely(fault & VM_FAULT_ERROR)) {
switch (fault) { if (fault & VM_FAULT_OOM)
case VM_FAULT_MINOR:
current->min_flt++;
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
return; return;
/* Something tried to access memory that isn't in our memory map. /* Something tried to access memory that isn't in our memory map.
......
...@@ -183,20 +183,20 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, ...@@ -183,20 +183,20 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
*/ */
survive: survive:
fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, fsr & (1 << 11)); fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, fsr & (1 << 11));
if (unlikely(fault & VM_FAULT_ERROR)) {
/* if (fault & VM_FAULT_OOM)
* Handle the "normal" cases first - successful and sigbus goto out_of_memory;
*/ else if (fault & VM_FAULT_SIGBUS)
switch (fault) {
case VM_FAULT_MAJOR:
tsk->maj_flt++;
return fault; return fault;
case VM_FAULT_MINOR: BUG();
}
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++; tsk->min_flt++;
case VM_FAULT_SIGBUS:
return fault; return fault;
}
out_of_memory:
if (!is_init(tsk)) if (!is_init(tsk))
goto out; goto out;
...@@ -249,7 +249,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -249,7 +249,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
/* /*
* Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR * Handle the "normal" case first - VM_FAULT_MAJOR / VM_FAULT_MINOR
*/ */
if (fault >= VM_FAULT_MINOR) if (likely(!(fault & VM_FAULT_ERROR)))
return 0; return 0;
/* /*
...@@ -259,8 +259,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -259,8 +259,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
if (!user_mode(regs)) if (!user_mode(regs))
goto no_context; goto no_context;
switch (fault) { if (fault & VM_FAULT_OOM) {
case VM_FAULT_OOM:
/* /*
* We ran out of memory, or some other thing * We ran out of memory, or some other thing
* happened to us that made us unable to handle * happened to us that made us unable to handle
...@@ -269,17 +268,15 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -269,17 +268,15 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
printk("VM: killing process %s\n", tsk->comm); printk("VM: killing process %s\n", tsk->comm);
do_exit(SIGKILL); do_exit(SIGKILL);
return 0; return 0;
}
case VM_FAULT_SIGBUS: if (fault & VM_FAULT_SIGBUS) {
/* /*
* We had some memory, but were unable to * We had some memory, but were unable to
* successfully fix up this page fault. * successfully fix up this page fault.
*/ */
sig = SIGBUS; sig = SIGBUS;
code = BUS_ADRERR; code = BUS_ADRERR;
break; } else {
default:
/* /*
* Something tried to access memory that * Something tried to access memory that
* isn't in our memory map.. * isn't in our memory map..
...@@ -287,7 +284,6 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -287,7 +284,6 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
sig = SIGSEGV; sig = SIGSEGV;
code = fault == VM_FAULT_BADACCESS ? code = fault == VM_FAULT_BADACCESS ?
SEGV_ACCERR : SEGV_MAPERR; SEGV_ACCERR : SEGV_MAPERR;
break;
} }
__do_user_fault(tsk, addr, fsr, sig, code, regs); __do_user_fault(tsk, addr, fsr, sig, code, regs);
......
...@@ -170,20 +170,20 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, ...@@ -170,20 +170,20 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
*/ */
survive: survive:
fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, DO_COW(fsr)); fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, DO_COW(fsr));
if (unlikely(fault & VM_FAULT_ERROR)) {
/* if (fault & VM_FAULT_OOM)
* Handle the "normal" cases first - successful and sigbus goto out_of_memory;
*/ else if (fault & VM_FAULT_SIGBUS)
switch (fault) {
case VM_FAULT_MAJOR:
tsk->maj_flt++;
return fault; return fault;
case VM_FAULT_MINOR: BUG();
}
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++; tsk->min_flt++;
case VM_FAULT_SIGBUS:
return fault; return fault;
}
out_of_memory:
fault = -3; /* out of memory */ fault = -3; /* out of memory */
if (!is_init(tsk)) if (!is_init(tsk))
goto out; goto out;
...@@ -225,13 +225,11 @@ int do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) ...@@ -225,13 +225,11 @@ int do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
/* /*
* Handle the "normal" case first * Handle the "normal" case first
*/ */
switch (fault) { if (likely(!(fault & VM_FAULT_ERROR)))
case VM_FAULT_MINOR:
case VM_FAULT_MAJOR:
return 0; return 0;
case VM_FAULT_SIGBUS: if (fault & VM_FAULT_SIGBUS)
goto do_sigbus; goto do_sigbus;
} /* else VM_FAULT_OOM */
/* /*
* If we are in kernel mode at this point, we * If we are in kernel mode at this point, we
......
...@@ -64,6 +64,7 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs) ...@@ -64,6 +64,7 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs)
int writeaccess; int writeaccess;
long signr; long signr;
int code; int code;
int fault;
if (notify_page_fault(regs, ecr)) if (notify_page_fault(regs, ecr))
return; return;
...@@ -132,20 +133,18 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs) ...@@ -132,20 +133,18 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs)
* fault. * fault.
*/ */
survive: survive:
switch (handle_mm_fault(mm, vma, address, writeaccess)) { fault = handle_mm_fault(mm, vma, address, writeaccess);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -179,6 +179,7 @@ do_page_fault(unsigned long address, struct pt_regs *regs, ...@@ -179,6 +179,7 @@ do_page_fault(unsigned long address, struct pt_regs *regs,
struct mm_struct *mm; struct mm_struct *mm;
struct vm_area_struct * vma; struct vm_area_struct * vma;
siginfo_t info; siginfo_t info;
int fault;
D(printk("Page fault for %lX on %X at %lX, prot %d write %d\n", D(printk("Page fault for %lX on %X at %lX, prot %d write %d\n",
address, smp_processor_id(), instruction_pointer(regs), address, smp_processor_id(), instruction_pointer(regs),
...@@ -283,18 +284,18 @@ do_page_fault(unsigned long address, struct pt_regs *regs, ...@@ -283,18 +284,18 @@ do_page_fault(unsigned long address, struct pt_regs *regs,
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, address, writeaccess & 1)) { fault = handle_mm_fault(mm, vma, address, writeaccess & 1);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
default:
goto out_of_memory; goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -40,6 +40,7 @@ asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear ...@@ -40,6 +40,7 @@ asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear
pud_t *pue; pud_t *pue;
pte_t *pte; pte_t *pte;
int write; int write;
int fault;
#if 0 #if 0
const char *atxc[16] = { const char *atxc[16] = {
...@@ -162,18 +163,18 @@ asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear ...@@ -162,18 +163,18 @@ asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear
* make sure we exit gracefully rather than endlessly redo * make sure we exit gracefully rather than endlessly redo
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, ear0, write)) { fault = handle_mm_fault(mm, vma, ear0, write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
current->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
default:
goto out_of_memory; goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -303,6 +303,7 @@ fastcall void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -303,6 +303,7 @@ fastcall void __kprobes do_page_fault(struct pt_regs *regs,
struct vm_area_struct * vma; struct vm_area_struct * vma;
unsigned long address; unsigned long address;
int write, si_code; int write, si_code;
int fault;
/* get the address */ /* get the address */
address = read_cr2(); address = read_cr2();
...@@ -422,20 +423,18 @@ fastcall void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -422,20 +423,18 @@ fastcall void __kprobes do_page_fault(struct pt_regs *regs,
* make sure we exit gracefully rather than endlessly redo * make sure we exit gracefully rather than endlessly redo
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, address, write)) { fault = handle_mm_fault(mm, vma, address, write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
/* /*
* Did it hit the DOS screen memory VA from vm86 mode? * Did it hit the DOS screen memory VA from vm86 mode?
......
...@@ -80,6 +80,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re ...@@ -80,6 +80,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
struct siginfo si; struct siginfo si;
unsigned long mask; unsigned long mask;
int fault;
/* mmap_sem is performance critical.... */ /* mmap_sem is performance critical.... */
prefetchw(&mm->mmap_sem); prefetchw(&mm->mmap_sem);
...@@ -147,26 +148,25 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re ...@@ -147,26 +148,25 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
* sure we exit gracefully rather than endlessly redo the * sure we exit gracefully rather than endlessly redo the
* fault. * fault.
*/ */
switch (handle_mm_fault(mm, vma, address, (mask & VM_WRITE) != 0)) { fault = handle_mm_fault(mm, vma, address, (mask & VM_WRITE) != 0);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
++current->min_flt;
break;
case VM_FAULT_MAJOR:
++current->maj_flt;
break;
case VM_FAULT_SIGBUS:
/* /*
* We ran out of memory, or some other thing happened * We ran out of memory, or some other thing happened
* to us that made us unable to handle the page fault * to us that made us unable to handle the page fault
* gracefully. * gracefully.
*/ */
if (fault & VM_FAULT_OOM) {
goto out_of_memory;
} else if (fault & VM_FAULT_SIGBUS) {
signal = SIGBUS; signal = SIGBUS;
goto bad_area; goto bad_area;
case VM_FAULT_OOM: }
goto out_of_memory;
default:
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -80,6 +80,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, ...@@ -80,6 +80,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
struct vm_area_struct * vma; struct vm_area_struct * vma;
unsigned long page, addr; unsigned long page, addr;
int write; int write;
int fault;
siginfo_t info; siginfo_t info;
/* /*
...@@ -195,20 +196,18 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, ...@@ -195,20 +196,18 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
*/ */
addr = (address & PAGE_MASK); addr = (address & PAGE_MASK);
set_thread_fault_code(error_code); set_thread_fault_code(error_code);
switch (handle_mm_fault(mm, vma, addr, write)) { fault = handle_mm_fault(mm, vma, addr, write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
set_thread_fault_code(0); set_thread_fault_code(0);
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -159,18 +159,17 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -159,18 +159,17 @@ int do_page_fault(struct pt_regs *regs, unsigned long address,
#ifdef DEBUG #ifdef DEBUG
printk("handle_mm_fault returns %d\n",fault); printk("handle_mm_fault returns %d\n",fault);
#endif #endif
switch (fault) { if (unlikely(fault & VM_FAULT_ERROR)) {
case VM_FAULT_MINOR: if (fault & VM_FAULT_OOM)
current->min_flt++;
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto bus_err;
default:
goto out_of_memory; goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
goto bus_err;
BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return 0; return 0;
......
...@@ -39,6 +39,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write, ...@@ -39,6 +39,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
struct mm_struct *mm = tsk->mm; struct mm_struct *mm = tsk->mm;
const int field = sizeof(unsigned long) * 2; const int field = sizeof(unsigned long) * 2;
siginfo_t info; siginfo_t info;
int fault;
#if 0 #if 0
printk("Cpu%d[%s:%d:%0*lx:%ld:%0*lx]\n", raw_smp_processor_id(), printk("Cpu%d[%s:%d:%0*lx:%ld:%0*lx]\n", raw_smp_processor_id(),
...@@ -102,20 +103,18 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write, ...@@ -102,20 +103,18 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
* make sure we exit gracefully rather than endlessly redo * make sure we exit gracefully rather than endlessly redo
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, address, write)) { fault = handle_mm_fault(mm, vma, address, write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -147,6 +147,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, ...@@ -147,6 +147,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,
struct mm_struct *mm = tsk->mm; struct mm_struct *mm = tsk->mm;
const struct exception_table_entry *fix; const struct exception_table_entry *fix;
unsigned long acc_type; unsigned long acc_type;
int fault;
if (in_atomic() || !mm) if (in_atomic() || !mm)
goto no_context; goto no_context;
...@@ -173,23 +174,23 @@ void do_page_fault(struct pt_regs *regs, unsigned long code, ...@@ -173,23 +174,23 @@ void do_page_fault(struct pt_regs *regs, unsigned long code,
* fault. * fault.
*/ */
switch (handle_mm_fault(mm, vma, address, (acc_type & VM_WRITE) != 0)) { fault = handle_mm_fault(mm, vma, address, (acc_type & VM_WRITE) != 0);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
++current->min_flt;
break;
case VM_FAULT_MAJOR:
++current->maj_flt;
break;
case VM_FAULT_SIGBUS:
/* /*
* We hit a shared mapping outside of the file, or some * We hit a shared mapping outside of the file, or some
* other thing happened to us that made us unable to * other thing happened to us that made us unable to
* handle the page fault gracefully. * handle the page fault gracefully.
*/ */
goto bad_area; if (fault & VM_FAULT_OOM)
default:
goto out_of_memory; goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
goto bad_area;
BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -145,7 +145,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -145,7 +145,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
siginfo_t info; siginfo_t info;
int code = SEGV_MAPERR; int code = SEGV_MAPERR;
int is_write = 0; int is_write = 0, ret;
int trap = TRAP(regs); int trap = TRAP(regs);
int is_exec = trap == 0x400; int is_exec = trap == 0x400;
...@@ -330,22 +330,18 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -330,22 +330,18 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
* the fault. * the fault.
*/ */
survive: survive:
switch (handle_mm_fault(mm, vma, address, is_write)) { ret = handle_mm_fault(mm, vma, address, is_write);
if (unlikely(ret & VM_FAULT_ERROR)) {
case VM_FAULT_MINOR: if (ret & VM_FAULT_OOM)
current->min_flt++;
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (ret & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (ret & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return 0; return 0;
......
...@@ -74,23 +74,21 @@ static int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea, ...@@ -74,23 +74,21 @@ static int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
goto bad_area; goto bad_area;
} }
ret = 0; ret = 0;
*flt = handle_mm_fault(mm, vma, ea, is_write); fault = handle_mm_fault(mm, vma, ea, is_write);
switch (*flt) { if (unlikely(fault & VM_FAULT_ERROR)) {
case VM_FAULT_MINOR: if (fault & VM_FAULT_OOM) {
current->min_flt++;
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
ret = -EFAULT;
goto bad_area;
case VM_FAULT_OOM:
ret = -ENOMEM; ret = -ENOMEM;
goto bad_area; goto bad_area;
default: } else if (fault & VM_FAULT_SIGBUS) {
ret = -EFAULT;
goto bad_area;
}
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return ret; return ret;
......
...@@ -96,6 +96,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -96,6 +96,7 @@ int do_page_fault(struct pt_regs *regs, unsigned long address,
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
siginfo_t info; siginfo_t info;
int code = SEGV_MAPERR; int code = SEGV_MAPERR;
int fault;
#if defined(CONFIG_4xx) || defined (CONFIG_BOOKE) #if defined(CONFIG_4xx) || defined (CONFIG_BOOKE)
int is_write = error_code & ESR_DST; int is_write = error_code & ESR_DST;
#else #else
...@@ -249,20 +250,18 @@ int do_page_fault(struct pt_regs *regs, unsigned long address, ...@@ -249,20 +250,18 @@ int do_page_fault(struct pt_regs *regs, unsigned long address,
* the fault. * the fault.
*/ */
survive: survive:
switch (handle_mm_fault(mm, vma, address, is_write)) { fault = handle_mm_fault(mm, vma, address, is_write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
current->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
/* /*
......
...@@ -20,6 +20,7 @@ static int __handle_fault(struct mm_struct *mm, unsigned long address, ...@@ -20,6 +20,7 @@ static int __handle_fault(struct mm_struct *mm, unsigned long address,
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
int ret = -EFAULT; int ret = -EFAULT;
int fault;
if (in_atomic()) if (in_atomic())
return ret; return ret;
...@@ -44,20 +45,18 @@ static int __handle_fault(struct mm_struct *mm, unsigned long address, ...@@ -44,20 +45,18 @@ static int __handle_fault(struct mm_struct *mm, unsigned long address,
} }
survive: survive:
switch (handle_mm_fault(mm, vma, address, write_access)) { fault = handle_mm_fault(mm, vma, address, write_access);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
current->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto out_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto out_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
ret = 0; ret = 0;
out: out:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
......
...@@ -307,6 +307,7 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write) ...@@ -307,6 +307,7 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write)
unsigned long address; unsigned long address;
int space; int space;
int si_code; int si_code;
int fault;
if (notify_page_fault(regs, error_code)) if (notify_page_fault(regs, error_code))
return; return;
...@@ -377,23 +378,22 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write) ...@@ -377,23 +378,22 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write)
* make sure we exit gracefully rather than endlessly redo * make sure we exit gracefully rather than endlessly redo
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, address, write)) { fault = handle_mm_fault(mm, vma, address, write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM) {
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
do_sigbus(regs, error_code, address);
return;
case VM_FAULT_OOM:
if (do_out_of_memory(regs, error_code, address)) if (do_out_of_memory(regs, error_code, address))
goto survive; goto survive;
return; return;
default: } else if (fault & VM_FAULT_SIGBUS) {
do_sigbus(regs, error_code, address);
return;
}
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
/* /*
......
...@@ -33,6 +33,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -33,6 +33,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
struct mm_struct *mm; struct mm_struct *mm;
struct vm_area_struct * vma; struct vm_area_struct * vma;
int si_code; int si_code;
int fault;
siginfo_t info; siginfo_t info;
trace_hardirqs_on(); trace_hardirqs_on();
...@@ -124,20 +125,18 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -124,20 +125,18 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
* the fault. * the fault.
*/ */
survive: survive:
switch (handle_mm_fault(mm, vma, address, writeaccess)) { fault = handle_mm_fault(mm, vma, address, writeaccess);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -127,6 +127,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess, ...@@ -127,6 +127,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
struct vm_area_struct * vma; struct vm_area_struct * vma;
const struct exception_table_entry *fixup; const struct exception_table_entry *fixup;
pte_t *pte; pte_t *pte;
int fault;
#if defined(CONFIG_SH64_PROC_TLB) #if defined(CONFIG_SH64_PROC_TLB)
++calls_to_do_slow_page_fault; ++calls_to_do_slow_page_fault;
...@@ -221,18 +222,19 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess, ...@@ -221,18 +222,19 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
* the fault. * the fault.
*/ */
survive: survive:
switch (handle_mm_fault(mm, vma, address, writeaccess)) { fault = handle_mm_fault(mm, vma, address, writeaccess);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
default:
goto out_of_memory; goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
/* If we get here, the page fault has been handled. Do the TLB refill /* If we get here, the page fault has been handled. Do the TLB refill
now from the newly-setup PTE, to avoid having to fault again right now from the newly-setup PTE, to avoid having to fault again right
away on the same instruction. */ away on the same instruction. */
......
...@@ -226,6 +226,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write, ...@@ -226,6 +226,7 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
unsigned long g2; unsigned long g2;
siginfo_t info; siginfo_t info;
int from_user = !(regs->psr & PSR_PS); int from_user = !(regs->psr & PSR_PS);
int fault;
if(text_fault) if(text_fault)
address = regs->pc; address = regs->pc;
...@@ -289,19 +290,18 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write, ...@@ -289,19 +290,18 @@ asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
* make sure we exit gracefully rather than endlessly redo * make sure we exit gracefully rather than endlessly redo
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, address, write)) { fault = handle_mm_fault(mm, vma, address, write);
case VM_FAULT_SIGBUS: if (unlikely(fault & VM_FAULT_ERROR)) {
goto do_sigbus; if (fault & VM_FAULT_OOM)
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
case VM_FAULT_MAJOR: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
}
if (fault & VM_FAULT_MAJOR)
current->maj_flt++; current->maj_flt++;
break; else
case VM_FAULT_MINOR:
default:
current->min_flt++; current->min_flt++;
break;
}
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -278,7 +278,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) ...@@ -278,7 +278,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
struct vm_area_struct *vma; struct vm_area_struct *vma;
unsigned int insn = 0; unsigned int insn = 0;
int si_code, fault_code; int si_code, fault_code, fault;
unsigned long address, mm_rss; unsigned long address, mm_rss;
fault_code = get_thread_fault_code(); fault_code = get_thread_fault_code();
...@@ -415,20 +415,18 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs) ...@@ -415,20 +415,18 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
goto bad_area; goto bad_area;
} }
switch (handle_mm_fault(mm, vma, address, (fault_code & FAULT_CODE_WRITE))) { fault = handle_mm_fault(mm, vma, address, (fault_code & FAULT_CODE_WRITE));
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
current->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
......
...@@ -76,23 +76,24 @@ int handle_page_fault(unsigned long address, unsigned long ip, ...@@ -76,23 +76,24 @@ int handle_page_fault(unsigned long address, unsigned long ip,
goto out; goto out;
do { do {
int fault;
survive: survive:
switch (handle_mm_fault(mm, vma, address, is_write)){ fault = handle_mm_fault(mm, vma, address, is_write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
current->min_flt++; if (fault & VM_FAULT_OOM) {
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
err = -EACCES;
goto out;
case VM_FAULT_OOM:
err = -ENOMEM; err = -ENOMEM;
goto out_of_memory; goto out_of_memory;
default: } else if (fault & VM_FAULT_SIGBUS) {
err = -EACCES;
goto out;
}
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
pgd = pgd_offset(mm, address); pgd = pgd_offset(mm, address);
pud = pud_offset(pgd, address); pud = pud_offset(pgd, address);
pmd = pmd_offset(pud, address); pmd = pmd_offset(pud, address);
......
...@@ -317,7 +317,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -317,7 +317,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
struct vm_area_struct * vma; struct vm_area_struct * vma;
unsigned long address; unsigned long address;
const struct exception_table_entry *fixup; const struct exception_table_entry *fixup;
int write; int write, fault;
unsigned long flags; unsigned long flags;
siginfo_t info; siginfo_t info;
...@@ -450,19 +450,18 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, ...@@ -450,19 +450,18 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
* make sure we exit gracefully rather than endlessly redo * make sure we exit gracefully rather than endlessly redo
* the fault. * the fault.
*/ */
switch (handle_mm_fault(mm, vma, address, write)) { fault = handle_mm_fault(mm, vma, address, write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
tsk->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
default:
goto out_of_memory; goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
} }
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -41,6 +41,7 @@ void do_page_fault(struct pt_regs *regs) ...@@ -41,6 +41,7 @@ void do_page_fault(struct pt_regs *regs)
siginfo_t info; siginfo_t info;
int is_write, is_exec; int is_write, is_exec;
int fault;
info.si_code = SEGV_MAPERR; info.si_code = SEGV_MAPERR;
...@@ -102,20 +103,18 @@ void do_page_fault(struct pt_regs *regs) ...@@ -102,20 +103,18 @@ void do_page_fault(struct pt_regs *regs)
* the fault. * the fault.
*/ */
survive: survive:
switch (handle_mm_fault(mm, vma, address, is_write)) { fault = handle_mm_fault(mm, vma, address, is_write);
case VM_FAULT_MINOR: if (unlikely(fault & VM_FAULT_ERROR)) {
current->min_flt++; if (fault & VM_FAULT_OOM)
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory; goto out_of_memory;
default: else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG(); BUG();
} }
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return; return;
......
...@@ -112,7 +112,7 @@ static int gfs2_sharewrite_fault(struct vm_area_struct *vma, ...@@ -112,7 +112,7 @@ static int gfs2_sharewrite_fault(struct vm_area_struct *vma,
struct gfs2_holder i_gh; struct gfs2_holder i_gh;
int alloc_required; int alloc_required;
int error; int error;
int ret = VM_FAULT_MINOR; int ret = 0;
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
if (error) if (error)
...@@ -132,14 +132,19 @@ static int gfs2_sharewrite_fault(struct vm_area_struct *vma, ...@@ -132,14 +132,19 @@ static int gfs2_sharewrite_fault(struct vm_area_struct *vma,
set_bit(GFF_EXLOCK, &gf->f_flags); set_bit(GFF_EXLOCK, &gf->f_flags);
ret = filemap_fault(vma, vmf); ret = filemap_fault(vma, vmf);
clear_bit(GFF_EXLOCK, &gf->f_flags); clear_bit(GFF_EXLOCK, &gf->f_flags);
if (ret & (VM_FAULT_ERROR | FAULT_RET_NOPAGE)) if (ret & VM_FAULT_ERROR)
goto out_unlock; goto out_unlock;
if (alloc_required) { if (alloc_required) {
/* XXX: do we need to drop page lock around alloc_page_backing?*/ /* XXX: do we need to drop page lock around alloc_page_backing?*/
error = alloc_page_backing(ip, vmf->page); error = alloc_page_backing(ip, vmf->page);
if (error) { if (error) {
if (ret & FAULT_RET_LOCKED) /*
* VM_FAULT_LOCKED should always be the case for
* filemap_fault, but it may not be in a future
* implementation.
*/
if (ret & VM_FAULT_LOCKED)
unlock_page(vmf->page); unlock_page(vmf->page);
page_cache_release(vmf->page); page_cache_release(vmf->page);
ret = VM_FAULT_OOM; ret = VM_FAULT_OOM;
......
...@@ -196,25 +196,10 @@ extern pgprot_t protection_map[16]; ...@@ -196,25 +196,10 @@ extern pgprot_t protection_map[16];
#define FAULT_FLAG_NONLINEAR 0x02 /* Fault was via a nonlinear mapping */ #define FAULT_FLAG_NONLINEAR 0x02 /* Fault was via a nonlinear mapping */
#define FAULT_RET_NOPAGE 0x0100 /* ->fault did not return a page. This
* can be used if the handler installs
* their own pte.
*/
#define FAULT_RET_LOCKED 0x0200 /* ->fault locked the page, caller must
* unlock after installing the mapping.
* This is used by pagecache in
* particular, where the page lock is
* used to synchronise against truncate
* and invalidate. Mutually exclusive
* with FAULT_RET_NOPAGE.
*/
/* /*
* vm_fault is filled by the the pagefault handler and passed to the vma's * vm_fault is filled by the the pagefault handler and passed to the vma's
* ->fault function. The vma's ->fault is responsible for returning the * ->fault function. The vma's ->fault is responsible for returning a bitmask
* VM_FAULT_xxx type which occupies the lowest byte of the return code, ORed * of VM_FAULT_xxx flags that give details about how the fault was handled.
* with FAULT_RET_ flags that occupy the next byte and give details about
* how the fault was handled.
* *
* pgoff should be used in favour of virtual_address, if possible. If pgoff * pgoff should be used in favour of virtual_address, if possible. If pgoff
* is used, one may set VM_CAN_NONLINEAR in the vma->vm_flags to get nonlinear * is used, one may set VM_CAN_NONLINEAR in the vma->vm_flags to get nonlinear
...@@ -226,9 +211,9 @@ struct vm_fault { ...@@ -226,9 +211,9 @@ struct vm_fault {
void __user *virtual_address; /* Faulting virtual address */ void __user *virtual_address; /* Faulting virtual address */
struct page *page; /* ->fault handlers should return a struct page *page; /* ->fault handlers should return a
* page here, unless FAULT_RET_NOPAGE * page here, unless VM_FAULT_NOPAGE
* is set (which is also implied by * is set (which is also implied by
* VM_FAULT_OOM or SIGBUS). * VM_FAULT_ERROR).
*/ */
}; };
...@@ -712,26 +697,17 @@ static inline int page_mapped(struct page *page) ...@@ -712,26 +697,17 @@ static inline int page_mapped(struct page *page)
* just gets major/minor fault counters bumped up. * just gets major/minor fault counters bumped up.
*/ */
/* #define VM_FAULT_MINOR 0 /* For backwards compat. Remove me quickly. */
* VM_FAULT_ERROR is set for the error cases, to make some tests simpler.
*/
#define VM_FAULT_ERROR 0x20
#define VM_FAULT_OOM (0x00 | VM_FAULT_ERROR) #define VM_FAULT_OOM 0x0001
#define VM_FAULT_SIGBUS (0x01 | VM_FAULT_ERROR) #define VM_FAULT_SIGBUS 0x0002
#define VM_FAULT_MINOR 0x02 #define VM_FAULT_MAJOR 0x0004
#define VM_FAULT_MAJOR 0x03 #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */
/* #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */
* Special case for get_user_pages. #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */
* Must be in a distinct bit from the above VM_FAULT_ flags.
*/
#define VM_FAULT_WRITE 0x10
/* #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS)
* Mask of VM_FAULT_ flags
*/
#define VM_FAULT_MASK 0xff
#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK) #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
...@@ -817,16 +793,8 @@ extern int vmtruncate(struct inode * inode, loff_t offset); ...@@ -817,16 +793,8 @@ extern int vmtruncate(struct inode * inode, loff_t offset);
extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end); extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end);
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
extern int __handle_mm_fault(struct mm_struct *mm,struct vm_area_struct *vma, extern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, int write_access); unsigned long address, int write_access);
static inline int handle_mm_fault(struct mm_struct *mm,
struct vm_area_struct *vma, unsigned long address,
int write_access)
{
return __handle_mm_fault(mm, vma, address, write_access) &
(~VM_FAULT_WRITE);
}
#else #else
static inline int handle_mm_fault(struct mm_struct *mm, static inline int handle_mm_fault(struct mm_struct *mm,
struct vm_area_struct *vma, unsigned long address, struct vm_area_struct *vma, unsigned long address,
......
...@@ -346,15 +346,20 @@ static int futex_handle_fault(unsigned long address, ...@@ -346,15 +346,20 @@ static int futex_handle_fault(unsigned long address,
vma = find_vma(mm, address); vma = find_vma(mm, address);
if (vma && address >= vma->vm_start && if (vma && address >= vma->vm_start &&
(vma->vm_flags & VM_WRITE)) { (vma->vm_flags & VM_WRITE)) {
switch (handle_mm_fault(mm, vma, address, 1)) { int fault;
case VM_FAULT_MINOR: fault = handle_mm_fault(mm, vma, address, 1);
ret = 0; if (unlikely((fault & VM_FAULT_ERROR))) {
current->min_flt++; #if 0
break; /* XXX: let's do this when we verify it is OK */
case VM_FAULT_MAJOR: if (ret & VM_FAULT_OOM)
ret = -ENOMEM;
#endif
} else {
ret = 0; ret = 0;
if (fault & VM_FAULT_MAJOR)
current->maj_flt++; current->maj_flt++;
break; else
current->min_flt++;
} }
} }
if (!fshared) if (!fshared)
......
...@@ -1322,9 +1322,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -1322,9 +1322,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
struct page *page; struct page *page;
unsigned long size; unsigned long size;
int did_readaround = 0; int did_readaround = 0;
int ret; int ret = 0;
ret = VM_FAULT_MINOR;
size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
if (vmf->pgoff >= size) if (vmf->pgoff >= size)
...@@ -1408,7 +1406,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -1408,7 +1406,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
*/ */
mark_page_accessed(page); mark_page_accessed(page);
vmf->page = page; vmf->page = page;
return ret | FAULT_RET_LOCKED; return ret | VM_FAULT_LOCKED;
outside_data_content: outside_data_content:
/* /*
......
...@@ -252,7 +252,7 @@ static int xip_file_fault(struct vm_area_struct *area, struct vm_fault *vmf) ...@@ -252,7 +252,7 @@ static int xip_file_fault(struct vm_area_struct *area, struct vm_fault *vmf)
out: out:
page_cache_get(page); page_cache_get(page);
vmf->page = page; vmf->page = page;
return VM_FAULT_MINOR; return 0;
} }
static struct vm_operations_struct xip_file_vm_ops = { static struct vm_operations_struct xip_file_vm_ops = {
......
...@@ -469,7 +469,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -469,7 +469,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
avoidcopy = (page_count(old_page) == 1); avoidcopy = (page_count(old_page) == 1);
if (avoidcopy) { if (avoidcopy) {
set_huge_ptep_writable(vma, address, ptep); set_huge_ptep_writable(vma, address, ptep);
return VM_FAULT_MINOR; return 0;
} }
page_cache_get(old_page); page_cache_get(old_page);
...@@ -494,7 +494,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -494,7 +494,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
} }
page_cache_release(new_page); page_cache_release(new_page);
page_cache_release(old_page); page_cache_release(old_page);
return VM_FAULT_MINOR; return 0;
} }
static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
...@@ -551,7 +551,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -551,7 +551,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
if (idx >= size) if (idx >= size)
goto backout; goto backout;
ret = VM_FAULT_MINOR; ret = 0;
if (!pte_none(*ptep)) if (!pte_none(*ptep))
goto backout; goto backout;
...@@ -602,7 +602,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -602,7 +602,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
return ret; return ret;
} }
ret = VM_FAULT_MINOR; ret = 0;
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
/* Check for a racing update before calling hugetlb_cow */ /* Check for a racing update before calling hugetlb_cow */
...@@ -641,7 +641,7 @@ int follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -641,7 +641,7 @@ int follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
spin_unlock(&mm->page_table_lock); spin_unlock(&mm->page_table_lock);
ret = hugetlb_fault(mm, vma, vaddr, 0); ret = hugetlb_fault(mm, vma, vaddr, 0);
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
if (ret == VM_FAULT_MINOR) if (!(ret & VM_FAULT_MAJOR))
continue; continue;
remainder = 0; remainder = 0;
......
...@@ -1068,31 +1068,30 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, ...@@ -1068,31 +1068,30 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
cond_resched(); cond_resched();
while (!(page = follow_page(vma, start, foll_flags))) { while (!(page = follow_page(vma, start, foll_flags))) {
int ret; int ret;
ret = __handle_mm_fault(mm, vma, start, ret = handle_mm_fault(mm, vma, start,
foll_flags & FOLL_WRITE); foll_flags & FOLL_WRITE);
if (ret & VM_FAULT_ERROR) {
if (ret & VM_FAULT_OOM)
return i ? i : -ENOMEM;
else if (ret & VM_FAULT_SIGBUS)
return i ? i : -EFAULT;
BUG();
}
if (ret & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
/* /*
* The VM_FAULT_WRITE bit tells us that do_wp_page has * The VM_FAULT_WRITE bit tells us that
* broken COW when necessary, even if maybe_mkwrite * do_wp_page has broken COW when necessary,
* decided not to set pte_write. We can thus safely do * even if maybe_mkwrite decided not to set
* subsequent page lookups as if they were reads. * pte_write. We can thus safely do subsequent
* page lookups as if they were reads.
*/ */
if (ret & VM_FAULT_WRITE) if (ret & VM_FAULT_WRITE)
foll_flags &= ~FOLL_WRITE; foll_flags &= ~FOLL_WRITE;
switch (ret & ~VM_FAULT_WRITE) {
case VM_FAULT_MINOR:
tsk->min_flt++;
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
return i ? i : -EFAULT;
case VM_FAULT_OOM:
return i ? i : -ENOMEM;
default:
BUG();
}
cond_resched(); cond_resched();
} }
if (pages) { if (pages) {
...@@ -1639,7 +1638,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -1639,7 +1638,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
{ {
struct page *old_page, *new_page; struct page *old_page, *new_page;
pte_t entry; pte_t entry;
int reuse = 0, ret = VM_FAULT_MINOR; int reuse = 0, ret = 0;
struct page *dirty_page = NULL; struct page *dirty_page = NULL;
old_page = vm_normal_page(vma, address, orig_pte); old_page = vm_normal_page(vma, address, orig_pte);
...@@ -1835,8 +1834,8 @@ static int unmap_mapping_range_vma(struct vm_area_struct *vma, ...@@ -1835,8 +1834,8 @@ static int unmap_mapping_range_vma(struct vm_area_struct *vma,
/* /*
* files that support invalidating or truncating portions of the * files that support invalidating or truncating portions of the
* file from under mmaped areas must have their ->fault function * file from under mmaped areas must have their ->fault function
* return a locked page (and FAULT_RET_LOCKED code). This provides * return a locked page (and set VM_FAULT_LOCKED in the return).
* synchronisation against concurrent unmapping here. * This provides synchronisation against concurrent unmapping here.
*/ */
again: again:
...@@ -2140,7 +2139,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2140,7 +2139,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
struct page *page; struct page *page;
swp_entry_t entry; swp_entry_t entry;
pte_t pte; pte_t pte;
int ret = VM_FAULT_MINOR; int ret = 0;
if (!pte_unmap_same(mm, pmd, page_table, orig_pte)) if (!pte_unmap_same(mm, pmd, page_table, orig_pte))
goto out; goto out;
...@@ -2208,8 +2207,9 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2208,8 +2207,9 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
unlock_page(page); unlock_page(page);
if (write_access) { if (write_access) {
/* XXX: We could OR the do_wp_page code with this one? */
if (do_wp_page(mm, vma, address, if (do_wp_page(mm, vma, address,
page_table, pmd, ptl, pte) == VM_FAULT_OOM) page_table, pmd, ptl, pte) & VM_FAULT_OOM)
ret = VM_FAULT_OOM; ret = VM_FAULT_OOM;
goto out; goto out;
} }
...@@ -2280,7 +2280,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2280,7 +2280,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
lazy_mmu_prot_update(entry); lazy_mmu_prot_update(entry);
unlock: unlock:
pte_unmap_unlock(page_table, ptl); pte_unmap_unlock(page_table, ptl);
return VM_FAULT_MINOR; return 0;
release: release:
page_cache_release(page); page_cache_release(page);
goto unlock; goto unlock;
...@@ -2323,11 +2323,11 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2323,11 +2323,11 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
if (likely(vma->vm_ops->fault)) { if (likely(vma->vm_ops->fault)) {
ret = vma->vm_ops->fault(vma, &vmf); ret = vma->vm_ops->fault(vma, &vmf);
if (unlikely(ret & (VM_FAULT_ERROR | FAULT_RET_NOPAGE))) if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
return (ret & VM_FAULT_MASK); return ret;
} else { } else {
/* Legacy ->nopage path */ /* Legacy ->nopage path */
ret = VM_FAULT_MINOR; ret = 0;
vmf.page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret); vmf.page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret);
/* no page was available -- either SIGBUS or OOM */ /* no page was available -- either SIGBUS or OOM */
if (unlikely(vmf.page == NOPAGE_SIGBUS)) if (unlikely(vmf.page == NOPAGE_SIGBUS))
...@@ -2340,7 +2340,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2340,7 +2340,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
* For consistency in subsequent calls, make the faulted page always * For consistency in subsequent calls, make the faulted page always
* locked. * locked.
*/ */
if (unlikely(!(ret & FAULT_RET_LOCKED))) if (unlikely(!(ret & VM_FAULT_LOCKED)))
lock_page(vmf.page); lock_page(vmf.page);
else else
VM_BUG_ON(!PageLocked(vmf.page)); VM_BUG_ON(!PageLocked(vmf.page));
...@@ -2356,7 +2356,8 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2356,7 +2356,8 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
ret = VM_FAULT_OOM; ret = VM_FAULT_OOM;
goto out; goto out;
} }
page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); page = alloc_page_vma(GFP_HIGHUSER_MOVABLE,
vma, address);
if (!page) { if (!page) {
ret = VM_FAULT_OOM; ret = VM_FAULT_OOM;
goto out; goto out;
...@@ -2384,7 +2385,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2384,7 +2385,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
* is better done later. * is better done later.
*/ */
if (!page->mapping) { if (!page->mapping) {
ret = VM_FAULT_MINOR; ret = 0;
anon = 1; /* no anon but release vmf.page */ anon = 1; /* no anon but release vmf.page */
goto out; goto out;
} }
...@@ -2447,7 +2448,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2447,7 +2448,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
put_page(dirty_page); put_page(dirty_page);
} }
return (ret & VM_FAULT_MASK); return ret;
} }
static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma, static int do_linear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
...@@ -2486,7 +2487,6 @@ static noinline int do_no_pfn(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2486,7 +2487,6 @@ static noinline int do_no_pfn(struct mm_struct *mm, struct vm_area_struct *vma,
spinlock_t *ptl; spinlock_t *ptl;
pte_t entry; pte_t entry;
unsigned long pfn; unsigned long pfn;
int ret = VM_FAULT_MINOR;
pte_unmap(page_table); pte_unmap(page_table);
BUG_ON(!(vma->vm_flags & VM_PFNMAP)); BUG_ON(!(vma->vm_flags & VM_PFNMAP));
...@@ -2498,7 +2498,7 @@ static noinline int do_no_pfn(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2498,7 +2498,7 @@ static noinline int do_no_pfn(struct mm_struct *mm, struct vm_area_struct *vma,
else if (unlikely(pfn == NOPFN_SIGBUS)) else if (unlikely(pfn == NOPFN_SIGBUS))
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
else if (unlikely(pfn == NOPFN_REFAULT)) else if (unlikely(pfn == NOPFN_REFAULT))
return VM_FAULT_MINOR; return 0;
page_table = pte_offset_map_lock(mm, pmd, address, &ptl); page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
...@@ -2510,7 +2510,7 @@ static noinline int do_no_pfn(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2510,7 +2510,7 @@ static noinline int do_no_pfn(struct mm_struct *mm, struct vm_area_struct *vma,
set_pte_at(mm, address, page_table, entry); set_pte_at(mm, address, page_table, entry);
} }
pte_unmap_unlock(page_table, ptl); pte_unmap_unlock(page_table, ptl);
return ret; return 0;
} }
/* /*
...@@ -2531,7 +2531,7 @@ static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2531,7 +2531,7 @@ static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
pgoff_t pgoff; pgoff_t pgoff;
if (!pte_unmap_same(mm, pmd, page_table, orig_pte)) if (!pte_unmap_same(mm, pmd, page_table, orig_pte))
return VM_FAULT_MINOR; return 0;
if (unlikely(!(vma->vm_flags & VM_NONLINEAR) || if (unlikely(!(vma->vm_flags & VM_NONLINEAR) ||
!(vma->vm_flags & VM_CAN_NONLINEAR))) { !(vma->vm_flags & VM_CAN_NONLINEAR))) {
...@@ -2615,13 +2615,13 @@ static inline int handle_pte_fault(struct mm_struct *mm, ...@@ -2615,13 +2615,13 @@ static inline int handle_pte_fault(struct mm_struct *mm,
} }
unlock: unlock:
pte_unmap_unlock(pte, ptl); pte_unmap_unlock(pte, ptl);
return VM_FAULT_MINOR; return 0;
} }
/* /*
* By the time we get here, we already hold the mm semaphore * By the time we get here, we already hold the mm semaphore
*/ */
int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, int write_access) unsigned long address, int write_access)
{ {
pgd_t *pgd; pgd_t *pgd;
...@@ -2650,7 +2650,7 @@ int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -2650,7 +2650,7 @@ int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
return handle_pte_fault(mm, vma, address, pte, pmd, write_access); return handle_pte_fault(mm, vma, address, pte, pmd, write_access);
} }
EXPORT_SYMBOL_GPL(__handle_mm_fault); EXPORT_SYMBOL_GPL(handle_mm_fault);
#ifndef __PAGETABLE_PUD_FOLDED #ifndef __PAGETABLE_PUD_FOLDED
/* /*
......
...@@ -1103,7 +1103,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, ...@@ -1103,7 +1103,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
return -EFBIG; return -EFBIG;
if (type) if (type)
*type = VM_FAULT_MINOR; *type = 0;
/* /*
* Normally, filepage is NULL on entry, and either found * Normally, filepage is NULL on entry, and either found
...@@ -1138,9 +1138,9 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, ...@@ -1138,9 +1138,9 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
if (!swappage) { if (!swappage) {
shmem_swp_unmap(entry); shmem_swp_unmap(entry);
/* here we actually do the io */ /* here we actually do the io */
if (type && *type == VM_FAULT_MINOR) { if (type && !(*type & VM_FAULT_MAJOR)) {
__count_vm_event(PGMAJFAULT); __count_vm_event(PGMAJFAULT);
*type = VM_FAULT_MAJOR; *type |= VM_FAULT_MAJOR;
} }
spin_unlock(&info->lock); spin_unlock(&info->lock);
swappage = shmem_swapin(info, swap, idx); swappage = shmem_swapin(info, swap, idx);
...@@ -1323,7 +1323,7 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -1323,7 +1323,7 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS); return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
mark_page_accessed(vmf->page); mark_page_accessed(vmf->page);
return ret | FAULT_RET_LOCKED; return ret | VM_FAULT_LOCKED;
} }
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment