Skip to content

Commit

Permalink
mm: fault feedback #2
Browse files Browse the repository at this point in the history
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).

[[email protected]: fix alpha build]
[[email protected]: fix s390 build]
[[email protected]: fix sparc build]
[[email protected]: fix sparc64 build]
[[email protected]: fix ia64 build]
Signed-off-by: Nick Piggin <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Ivan Kokshaysky <[email protected]>
Cc: Russell King <[email protected]>
Cc: Ian Molton <[email protected]>
Cc: Bryan Wu <[email protected]>
Cc: Mikael Starvik <[email protected]>
Cc: David Howells <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: "Luck, Tony" <[email protected]>
Cc: Hirokazu Takata <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Roman Zippel <[email protected]>
Cc: Greg Ungerer <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Paul Mundt <[email protected]>
Cc: Kazumoto Kojima <[email protected]>
Cc: Richard Curnow <[email protected]>
Cc: William Lee Irwin III <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Paolo 'Blaisorblade' Giarrusso <[email protected]>
Cc: Miles Bader <[email protected]>
Cc: Chris Zankel <[email protected]>
Acked-by: Kyle McMartin <[email protected]>
Acked-by: Haavard Skinnemoen <[email protected]>
Acked-by: Ralf Baechle <[email protected]>
Acked-by: Andi Kleen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
[ Still apparently needs some ARM and PPC loving - Linus ]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Nick Piggin authored and Linus Torvalds committed Jul 19, 2007
1 parent d0217ac commit 83c5407
Show file tree
Hide file tree
Showing 32 changed files with 373 additions and 419 deletions.
22 changes: 9 additions & 13 deletions arch/alpha/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,17 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
the fault. */
fault = handle_mm_fault(mm, vma, address, cause > 0);
up_read(&mm->mmap_sem);

switch (fault) {
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;
default:
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
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++;
return;

/* Something tried to access memory that isn't in our memory map.
Expand Down
36 changes: 16 additions & 20 deletions arch/arm/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
*/
survive:
fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, fsr & (1 << 11));

/*
* Handle the "normal" cases first - successful and sigbus
*/
switch (fault) {
case VM_FAULT_MAJOR:
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
return fault;
BUG();
}
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
return fault;
case VM_FAULT_MINOR:
else
tsk->min_flt++;
case VM_FAULT_SIGBUS:
return fault;
}
return fault;

out_of_memory:
if (!is_init(tsk))
goto out;

Expand Down Expand Up @@ -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
*/
if (fault >= VM_FAULT_MINOR)
if (likely(!(fault & VM_FAULT_ERROR)))
return 0;

/*
Expand All @@ -259,8 +259,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
if (!user_mode(regs))
goto no_context;

switch (fault) {
case VM_FAULT_OOM:
if (fault & VM_FAULT_OOM) {
/*
* We ran out of memory, or some other thing
* happened to us that made us unable to handle
Expand All @@ -269,25 +268,22 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
printk("VM: killing process %s\n", tsk->comm);
do_exit(SIGKILL);
return 0;

case VM_FAULT_SIGBUS:
}
if (fault & VM_FAULT_SIGBUS) {
/*
* We had some memory, but were unable to
* successfully fix up this page fault.
*/
sig = SIGBUS;
code = BUS_ADRERR;
break;

default:
} else {
/*
* Something tried to access memory that
* isn't in our memory map..
*/
sig = SIGSEGV;
code = fault == VM_FAULT_BADACCESS ?
SEGV_ACCERR : SEGV_MAPERR;
break;
}

__do_user_fault(tsk, addr, fsr, sig, code, regs);
Expand Down
30 changes: 14 additions & 16 deletions arch/arm26/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,20 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
*/
survive:
fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, DO_COW(fsr));

/*
* Handle the "normal" cases first - successful and sigbus
*/
switch (fault) {
case VM_FAULT_MAJOR:
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
goto out_of_memory;
else if (fault & VM_FAULT_SIGBUS)
return fault;
BUG();
}
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
return fault;
case VM_FAULT_MINOR:
else
tsk->min_flt++;
case VM_FAULT_SIGBUS:
return fault;
}
return fault;

out_of_memory:
fault = -3; /* out of memory */
if (!is_init(tsk))
goto out;
Expand Down Expand Up @@ -225,13 +225,11 @@ int do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
/*
* Handle the "normal" case first
*/
switch (fault) {
case VM_FAULT_MINOR:
case VM_FAULT_MAJOR:
if (likely(!(fault & VM_FAULT_ERROR)))
return 0;
case VM_FAULT_SIGBUS:
if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
}
/* else VM_FAULT_OOM */

/*
* If we are in kernel mode at this point, we
Expand Down
23 changes: 11 additions & 12 deletions arch/avr32/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs)
int writeaccess;
long signr;
int code;
int fault;

if (notify_page_fault(regs, ecr))
return;
Expand Down Expand Up @@ -132,20 +133,18 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs)
* fault.
*/
survive:
switch (handle_mm_fault(mm, vma, address, writeaccess)) {
case VM_FAULT_MINOR:
tsk->min_flt++;
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
goto out_of_memory;
default:
fault = handle_mm_fault(mm, vma, address, writeaccess);
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
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);
return;
Expand Down
23 changes: 12 additions & 11 deletions arch/cris/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ do_page_fault(unsigned long address, struct pt_regs *regs,
struct mm_struct *mm;
struct vm_area_struct * vma;
siginfo_t info;
int fault;

D(printk("Page fault for %lX on %X at %lX, prot %d write %d\n",
address, smp_processor_id(), instruction_pointer(regs),
Expand Down Expand Up @@ -283,18 +284,18 @@ do_page_fault(unsigned long address, struct pt_regs *regs,
* the fault.
*/

switch (handle_mm_fault(mm, vma, address, writeaccess & 1)) {
case VM_FAULT_MINOR:
tsk->min_flt++;
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
default:
goto out_of_memory;
fault = handle_mm_fault(mm, vma, address, writeaccess & 1);
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
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);
return;
Expand Down
23 changes: 12 additions & 11 deletions arch/frv/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ asmlinkage void do_page_fault(int datammu, unsigned long esr0, unsigned long ear
pud_t *pue;
pte_t *pte;
int write;
int fault;

#if 0
const char *atxc[16] = {
Expand Down Expand Up @@ -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
* the fault.
*/
switch (handle_mm_fault(mm, vma, ear0, write)) {
case VM_FAULT_MINOR:
current->min_flt++;
break;
case VM_FAULT_MAJOR:
current->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
default:
goto out_of_memory;
fault = handle_mm_fault(mm, vma, ear0, write);
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
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);
return;
Expand Down
23 changes: 11 additions & 12 deletions arch/i386/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ fastcall void __kprobes do_page_fault(struct pt_regs *regs,
struct vm_area_struct * vma;
unsigned long address;
int write, si_code;
int fault;

/* get the address */
address = read_cr2();
Expand Down Expand Up @@ -422,20 +423,18 @@ fastcall void __kprobes do_page_fault(struct pt_regs *regs,
* make sure we exit gracefully rather than endlessly redo
* the fault.
*/
switch (handle_mm_fault(mm, vma, address, write)) {
case VM_FAULT_MINOR:
tsk->min_flt++;
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
fault = handle_mm_fault(mm, vma, address, write);
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
goto out_of_memory;
default:
BUG();
else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
}
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;

/*
* Did it hit the DOS screen memory VA from vm86 mode?
Expand Down
26 changes: 13 additions & 13 deletions arch/ia64/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 siginfo si;
unsigned long mask;
int fault;

/* mmap_sem is performance critical.... */
prefetchw(&mm->mmap_sem);
Expand Down Expand Up @@ -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
* fault.
*/
switch (handle_mm_fault(mm, vma, address, (mask & VM_WRITE) != 0)) {
case VM_FAULT_MINOR:
++current->min_flt;
break;
case VM_FAULT_MAJOR:
++current->maj_flt;
break;
case VM_FAULT_SIGBUS:
fault = handle_mm_fault(mm, vma, address, (mask & VM_WRITE) != 0);
if (unlikely(fault & VM_FAULT_ERROR)) {
/*
* We ran out of memory, or some other thing happened
* to us that made us unable to handle the page fault
* gracefully.
*/
signal = SIGBUS;
goto bad_area;
case VM_FAULT_OOM:
goto out_of_memory;
default:
if (fault & VM_FAULT_OOM) {
goto out_of_memory;
} else if (fault & VM_FAULT_SIGBUS) {
signal = SIGBUS;
goto bad_area;
}
BUG();
}
if (fault & VM_FAULT_MAJOR)
current->maj_flt++;
else
current->min_flt++;
up_read(&mm->mmap_sem);
return;

Expand Down
23 changes: 11 additions & 12 deletions arch/m32r/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
struct vm_area_struct * vma;
unsigned long page, addr;
int write;
int fault;
siginfo_t info;

/*
Expand Down Expand Up @@ -195,20 +196,18 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
*/
addr = (address & PAGE_MASK);
set_thread_fault_code(error_code);
switch (handle_mm_fault(mm, vma, addr, write)) {
case VM_FAULT_MINOR:
tsk->min_flt++;
break;
case VM_FAULT_MAJOR:
tsk->maj_flt++;
break;
case VM_FAULT_SIGBUS:
goto do_sigbus;
case VM_FAULT_OOM:
fault = handle_mm_fault(mm, vma, addr, write);
if (unlikely(fault & VM_FAULT_ERROR)) {
if (fault & VM_FAULT_OOM)
goto out_of_memory;
default:
BUG();
else if (fault & VM_FAULT_SIGBUS)
goto do_sigbus;
BUG();
}
if (fault & VM_FAULT_MAJOR)
tsk->maj_flt++;
else
tsk->min_flt++;
set_thread_fault_code(0);
up_read(&mm->mmap_sem);
return;
Expand Down
Loading

0 comments on commit 83c5407

Please sign in to comment.