powerpc/mm: Rework mm_fault_error()

First, handle the normal retry failure in do_page_fault itself,
since it's a simple return statement. That allows us to remove
the "continue" special return code from mm_fault_error().

Once that's done, we can have an implementation much closer to
x86 where we only call mm_fault_error() if VM_FAULT_ERROR is set
and directly return.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:
Benjamin Herrenschmidt 2017-07-19 14:49:36 +10:00 коммит произвёл Michael Ellerman
Родитель c3350602e8
Коммит b5c8f0fd59
1 изменённых файлов: 28 добавлений и 38 удалений

Просмотреть файл

@ -147,10 +147,6 @@ static noinline int bad_area(struct pt_regs *regs, unsigned long address)
return __bad_area(regs, address, SEGV_MAPERR); return __bad_area(regs, address, SEGV_MAPERR);
} }
#define MM_FAULT_RETURN 0
#define MM_FAULT_CONTINUE -1
#define MM_FAULT_ERR(sig) (sig)
static int do_sigbus(struct pt_regs *regs, unsigned long address, static int do_sigbus(struct pt_regs *regs, unsigned long address,
unsigned int fault) unsigned int fault)
{ {
@ -158,7 +154,7 @@ static int do_sigbus(struct pt_regs *regs, unsigned long address,
unsigned int lsb = 0; unsigned int lsb = 0;
if (!user_mode(regs)) if (!user_mode(regs))
return MM_FAULT_ERR(SIGBUS); return SIGBUS;
current->thread.trap_nr = BUS_ADRERR; current->thread.trap_nr = BUS_ADRERR;
info.si_signo = SIGBUS; info.si_signo = SIGBUS;
@ -179,25 +175,17 @@ static int do_sigbus(struct pt_regs *regs, unsigned long address,
#endif #endif
info.si_addr_lsb = lsb; info.si_addr_lsb = lsb;
force_sig_info(SIGBUS, &info, current); force_sig_info(SIGBUS, &info, current);
return MM_FAULT_RETURN; return 0;
} }
static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault) static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
{ {
/* /*
* Pagefault was interrupted by SIGKILL. We have no reason to * Kernel page fault interrupted by SIGKILL. We have no reason to
* continue the pagefault. * continue processing.
*/ */
if (fatal_signal_pending(current)) { if (fatal_signal_pending(current) && !user_mode(regs))
/* Coming from kernel, we need to deal with uaccess fixups */ return SIGKILL;
if (user_mode(regs))
return MM_FAULT_RETURN;
return MM_FAULT_ERR(SIGKILL);
}
/* No fault: be happy */
if (!(fault & VM_FAULT_ERROR))
return MM_FAULT_CONTINUE;
/* Out of memory */ /* Out of memory */
if (fault & VM_FAULT_OOM) { if (fault & VM_FAULT_OOM) {
@ -206,17 +194,18 @@ static int mm_fault_error(struct pt_regs *regs, unsigned long addr, int fault)
* made us unable to handle the page fault gracefully. * made us unable to handle the page fault gracefully.
*/ */
if (!user_mode(regs)) if (!user_mode(regs))
return MM_FAULT_ERR(SIGKILL); return SIGSEGV;
pagefault_out_of_memory(); pagefault_out_of_memory();
return MM_FAULT_RETURN; } else {
if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|
VM_FAULT_HWPOISON_LARGE))
return do_sigbus(regs, addr, fault);
else if (fault & VM_FAULT_SIGSEGV)
return bad_area_nosemaphore(regs, addr);
else
BUG();
} }
return 0;
if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE))
return do_sigbus(regs, addr, fault);
/* We don't understand the fault code, this is fatal */
BUG();
return MM_FAULT_CONTINUE;
} }
/* Is this a bad kernel fault ? */ /* Is this a bad kernel fault ? */
@ -274,7 +263,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,
int is_user = user_mode(regs); int is_user = user_mode(regs);
int is_write = page_fault_is_write(error_code); int is_write = page_fault_is_write(error_code);
int fault; int fault;
int rc = 0, store_update_sp = 0; int store_update_sp = 0;
#ifdef CONFIG_PPC_ICSWX #ifdef CONFIG_PPC_ICSWX
/* /*
@ -283,7 +272,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned long address,
* look at it * look at it
*/ */
if (error_code & ICSWX_DSI_UCT) { if (error_code & ICSWX_DSI_UCT) {
rc = acop_handle_fault(regs, address, error_code); int rc = acop_handle_fault(regs, address, error_code);
if (rc) if (rc)
return rc; return rc;
} }
@ -492,18 +481,19 @@ good_area:
if (!fatal_signal_pending(current)) if (!fatal_signal_pending(current))
goto retry; goto retry;
} }
/* We will enter mm_fault_error() below */
} else
up_read(&current->mm->mmap_sem);
if (unlikely(fault & (VM_FAULT_RETRY|VM_FAULT_ERROR))) { /*
if (fault & VM_FAULT_SIGSEGV) * User mode? Just return to handle the fatal exception otherwise
return bad_area_nosemaphore(regs, address); * return to bad_page_fault
rc = mm_fault_error(regs, address, fault); */
if (rc >= MM_FAULT_RETURN) return is_user ? 0 : SIGBUS;
return rc;
} }
up_read(&current->mm->mmap_sem);
if (unlikely(fault & VM_FAULT_ERROR))
return mm_fault_error(regs, address, fault);
/* /*
* Major/minor page fault accounting. * Major/minor page fault accounting.
*/ */