2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
2009-02-21 02:56:40 +08:00
|
|
|
* Copyright (C) 2001, 2002 Andi Kleen, SuSE Labs.
|
2009-02-21 06:13:36 +08:00
|
|
|
* Copyright (C) 2008-2009, Red Hat Inc., Ingo Molnar
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-03-30 05:47:48 +08:00
|
|
|
#include <linux/sched.h> /* test_thread_flag(), ... */
|
2017-02-09 01:51:37 +08:00
|
|
|
#include <linux/sched/task_stack.h> /* task_stack_*(), ... */
|
2009-03-30 05:47:48 +08:00
|
|
|
#include <linux/kdebug.h> /* oops_begin/end, ... */
|
2016-10-12 14:38:39 +08:00
|
|
|
#include <linux/extable.h> /* search_exception_tables */
|
2009-03-30 05:47:48 +08:00
|
|
|
#include <linux/bootmem.h> /* max_low_pfn */
|
2014-04-17 16:18:14 +08:00
|
|
|
#include <linux/kprobes.h> /* NOKPROBE_SYMBOL, ... */
|
2009-03-30 05:47:48 +08:00
|
|
|
#include <linux/mmiotrace.h> /* kmmio_handler, ... */
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 18:02:48 +08:00
|
|
|
#include <linux/perf_event.h> /* perf_sw_event */
|
2010-09-28 04:05:55 +08:00
|
|
|
#include <linux/hugetlb.h> /* hstate_index_to_shift */
|
2011-05-21 03:50:29 +08:00
|
|
|
#include <linux/prefetch.h> /* prefetchw */
|
2013-02-24 07:23:25 +08:00
|
|
|
#include <linux/context_tracking.h> /* exception_enter(), ... */
|
2015-05-11 23:52:11 +08:00
|
|
|
#include <linux/uaccess.h> /* faulthandler_disabled() */
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2016-02-13 05:02:14 +08:00
|
|
|
#include <asm/cpufeature.h> /* boot_cpu_has, ... */
|
2009-03-30 05:47:48 +08:00
|
|
|
#include <asm/traps.h> /* dotraplinkage, ... */
|
|
|
|
#include <asm/pgalloc.h> /* pgd_*(), ... */
|
2008-04-04 06:53:23 +08:00
|
|
|
#include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
|
2014-05-06 03:19:36 +08:00
|
|
|
#include <asm/fixmap.h> /* VSYSCALL_ADDR */
|
|
|
|
#include <asm/vsyscall.h> /* emulate_vsyscall */
|
2015-07-29 13:41:21 +08:00
|
|
|
#include <asm/vm86.h> /* struct vm86 */
|
2016-02-13 05:02:14 +08:00
|
|
|
#include <asm/mmu_context.h> /* vma_pkey() */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-31 04:39:03 +08:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <asm/trace/exceptions.h>
|
|
|
|
|
2008-01-30 20:32:19 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Page fault error code bits:
|
|
|
|
*
|
|
|
|
* bit 0 == 0: no page found 1: protection fault
|
|
|
|
* bit 1 == 0: read access 1: write access
|
|
|
|
* bit 2 == 0: kernel-mode access 1: user-mode access
|
|
|
|
* bit 3 == 1: use of reserved bit detected
|
|
|
|
* bit 4 == 1: fault was an instruction fetch
|
2016-02-13 05:02:07 +08:00
|
|
|
* bit 5 == 1: protection keys block access
|
2008-01-30 20:32:19 +08:00
|
|
|
*/
|
2009-02-21 02:56:40 +08:00
|
|
|
enum x86_pf_error_code {
|
|
|
|
|
|
|
|
PF_PROT = 1 << 0,
|
|
|
|
PF_WRITE = 1 << 1,
|
|
|
|
PF_USER = 1 << 2,
|
|
|
|
PF_RSVD = 1 << 3,
|
|
|
|
PF_INSTR = 1 << 4,
|
2016-02-13 05:02:07 +08:00
|
|
|
PF_PK = 1 << 5,
|
2009-02-21 02:56:40 +08:00
|
|
|
};
|
2006-01-12 05:44:09 +08:00
|
|
|
|
2009-02-21 05:32:10 +08:00
|
|
|
/*
|
2009-02-22 17:24:18 +08:00
|
|
|
* Returns 0 if mmiotrace is disabled, or if the fault is not
|
|
|
|
* handled by mmiotrace:
|
2009-02-21 05:32:10 +08:00
|
|
|
*/
|
2014-04-17 16:18:14 +08:00
|
|
|
static nokprobe_inline int
|
2009-08-28 01:23:11 +08:00
|
|
|
kmmio_fault(struct pt_regs *regs, unsigned long addr)
|
2008-05-13 03:20:56 +08:00
|
|
|
{
|
x86: mmiotrace full patch, preview 1
kmmio.c handles the list of mmio probes with callbacks, list of traced
pages, and attaching into the page fault handler and die notifier. It
arms, traps and disarms the given pages, this is the core of mmiotrace.
mmio-mod.c is a user interface, hooking into ioremap functions and
registering the mmio probes. It also decodes the required information
from trapped mmio accesses via the pre and post callbacks in each probe.
Currently, hooking into ioremap functions works by redefining the symbols
of the target (binary) kernel module, so that it calls the traced
versions of the functions.
The most notable changes done since the last discussion are:
- kmmio.c is a built-in, not part of the module
- direct call from fault.c to kmmio.c, removing all dynamic hooks
- prepare for unregistering probes at any time
- make kmmio re-initializable and accessible to more than one user
- rewrite kmmio locking to remove all spinlocks from page fault path
Can I abuse call_rcu() like I do in kmmio.c:unregister_kmmio_probe()
or is there a better way?
The function called via call_rcu() itself calls call_rcu() again,
will this work or break? There I need a second grace period for RCU
after the first grace period for page faults.
Mmiotrace itself (mmio-mod.c) is still a module, I am going to attack
that next. At some point I will start looking into how to make mmiotrace
a tracer component of ftrace (thanks for the hint, Ingo). Ftrace should
make the user space part of mmiotracing as simple as
'cat /debug/trace/mmio > dump.txt'.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-13 03:20:57 +08:00
|
|
|
if (unlikely(is_kmmio_active()))
|
|
|
|
if (kmmio_handler(regs, addr) == 1)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2008-05-13 03:20:56 +08:00
|
|
|
}
|
|
|
|
|
2014-04-17 16:18:14 +08:00
|
|
|
static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
|
2006-06-26 15:25:25 +08:00
|
|
|
{
|
2007-10-16 16:24:07 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* kprobe_running() needs smp_processor_id() */
|
2015-03-19 09:33:33 +08:00
|
|
|
if (kprobes_built_in() && !user_mode(regs)) {
|
2007-10-16 16:24:07 +08:00
|
|
|
preempt_disable();
|
|
|
|
if (kprobe_running() && kprobe_fault_handler(regs, 14))
|
|
|
|
ret = 1;
|
|
|
|
preempt_enable();
|
|
|
|
}
|
2006-06-26 15:25:25 +08:00
|
|
|
|
2007-10-16 16:24:07 +08:00
|
|
|
return ret;
|
2008-01-30 20:32:19 +08:00
|
|
|
}
|
2006-06-26 15:25:25 +08:00
|
|
|
|
2008-01-30 20:32:35 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Prefetch quirks:
|
|
|
|
*
|
|
|
|
* 32-bit mode:
|
|
|
|
*
|
|
|
|
* Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
|
|
|
|
* Check that here and ignore it.
|
2008-01-30 20:32:35 +08:00
|
|
|
*
|
2009-02-21 02:56:40 +08:00
|
|
|
* 64-bit mode:
|
2008-01-30 20:32:35 +08:00
|
|
|
*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Sometimes the CPU reports invalid exceptions on prefetch.
|
|
|
|
* Check that here and ignore it.
|
|
|
|
*
|
|
|
|
* Opcode checker based on code by Richard Brunner.
|
2008-01-30 20:32:35 +08:00
|
|
|
*/
|
2009-02-21 03:37:05 +08:00
|
|
|
static inline int
|
|
|
|
check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
|
|
|
|
unsigned char opcode, int *prefetch)
|
|
|
|
{
|
|
|
|
unsigned char instr_hi = opcode & 0xf0;
|
|
|
|
unsigned char instr_lo = opcode & 0x0f;
|
|
|
|
|
|
|
|
switch (instr_hi) {
|
|
|
|
case 0x20:
|
|
|
|
case 0x30:
|
|
|
|
/*
|
|
|
|
* Values 0x26,0x2E,0x36,0x3E are valid x86 prefixes.
|
|
|
|
* In X86_64 long mode, the CPU will signal invalid
|
|
|
|
* opcode if some of these prefixes are present so
|
|
|
|
* X86_64 will never get here anyway
|
|
|
|
*/
|
|
|
|
return ((instr_lo & 7) == 0x6);
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
case 0x40:
|
|
|
|
/*
|
|
|
|
* In AMD64 long mode 0x40..0x4F are valid REX prefixes
|
|
|
|
* Need to figure out under what instruction mode the
|
|
|
|
* instruction was issued. Could check the LDT for lm,
|
|
|
|
* but for now it's good enough to assume that long
|
|
|
|
* mode only uses well known segments or kernel.
|
|
|
|
*/
|
2011-08-03 21:31:53 +08:00
|
|
|
return (!user_mode(regs) || user_64bit_mode(regs));
|
2009-02-21 03:37:05 +08:00
|
|
|
#endif
|
|
|
|
case 0x60:
|
|
|
|
/* 0x64 thru 0x67 are valid prefixes in all modes. */
|
|
|
|
return (instr_lo & 0xC) == 0x4;
|
|
|
|
case 0xF0:
|
|
|
|
/* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */
|
|
|
|
return !instr_lo || (instr_lo>>1) == 1;
|
|
|
|
case 0x00:
|
|
|
|
/* Prefetch instruction is 0x0F0D or 0x0F18 */
|
|
|
|
if (probe_kernel_address(instr, opcode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*prefetch = (instr_lo == 0xF) &&
|
|
|
|
(opcode == 0x0D || opcode == 0x18);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static int
|
|
|
|
is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
|
2008-01-30 20:32:19 +08:00
|
|
|
{
|
2009-02-21 02:56:40 +08:00
|
|
|
unsigned char *max_instr;
|
2006-12-07 09:14:06 +08:00
|
|
|
unsigned char *instr;
|
2008-01-30 20:32:19 +08:00
|
|
|
int prefetch = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-28 04:29:09 +08:00
|
|
|
/*
|
|
|
|
* If it was a exec (instruction fetch) fault on NX page, then
|
|
|
|
* do not ignore the fault:
|
|
|
|
*/
|
2006-01-12 05:44:09 +08:00
|
|
|
if (error_code & PF_INSTR)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2008-01-30 20:32:35 +08:00
|
|
|
|
2009-02-21 03:37:05 +08:00
|
|
|
instr = (void *)convert_ip_to_linear(current, regs);
|
2005-04-17 06:24:59 +08:00
|
|
|
max_instr = instr + 15;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-03-19 09:33:27 +08:00
|
|
|
if (user_mode(regs) && instr >= (unsigned char *)TASK_SIZE_MAX)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-02-21 03:37:05 +08:00
|
|
|
while (instr < max_instr) {
|
2009-02-21 02:56:40 +08:00
|
|
|
unsigned char opcode;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-07 09:14:06 +08:00
|
|
|
if (probe_kernel_address(instr, opcode))
|
2008-01-30 20:32:19 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
instr++;
|
|
|
|
|
2009-02-21 03:37:05 +08:00
|
|
|
if (!check_prefetch_opcode(regs, instr, opcode, &prefetch))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return prefetch;
|
|
|
|
}
|
|
|
|
|
2016-02-13 05:02:14 +08:00
|
|
|
/*
|
|
|
|
* A protection key fault means that the PKRU value did not allow
|
|
|
|
* access to some PTE. Userspace can figure out what PKRU was
|
|
|
|
* from the XSAVE state, and this function fills out a field in
|
|
|
|
* siginfo so userspace can discover which protection key was set
|
|
|
|
* on the PTE.
|
|
|
|
*
|
|
|
|
* If we get here, we know that the hardware signaled a PF_PK
|
|
|
|
* fault and that there was a VMA once we got in the fault
|
|
|
|
* handler. It does *not* guarantee that the VMA we find here
|
|
|
|
* was the one that we faulted on.
|
|
|
|
*
|
|
|
|
* 1. T1 : mprotect_key(foo, PAGE_SIZE, pkey=4);
|
|
|
|
* 2. T1 : set PKRU to deny access to pkey=4, touches page
|
|
|
|
* 3. T1 : faults...
|
|
|
|
* 4. T2: mprotect_key(foo, PAGE_SIZE, pkey=5);
|
|
|
|
* 5. T1 : enters fault handler, takes mmap_sem, etc...
|
|
|
|
* 6. T1 : reaches here, sees vma_pkey(vma)=5, when we really
|
|
|
|
* faulted on a pte with its pkey=4.
|
|
|
|
*/
|
|
|
|
static void fill_sig_info_pkey(int si_code, siginfo_t *info,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
/* This is effectively an #ifdef */
|
|
|
|
if (!boot_cpu_has(X86_FEATURE_OSPKE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Fault not from Protection Keys: nothing to do */
|
|
|
|
if (si_code != SEGV_PKUERR)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* force_sig_info_fault() is called from a number of
|
|
|
|
* contexts, some of which have a VMA and some of which
|
|
|
|
* do not. The PF_PK handing happens after we have a
|
|
|
|
* valid VMA, so we should never reach this without a
|
|
|
|
* valid VMA.
|
|
|
|
*/
|
|
|
|
if (!vma) {
|
|
|
|
WARN_ONCE(1, "PKU fault with no VMA passed in");
|
|
|
|
info->si_pkey = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* si_pkey should be thought of as a strong hint, but not
|
|
|
|
* absolutely guranteed to be 100% accurate because of
|
|
|
|
* the race explained above.
|
|
|
|
*/
|
|
|
|
info->si_pkey = vma_pkey(vma);
|
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static void
|
|
|
|
force_sig_info_fault(int si_signo, int si_code, unsigned long address,
|
2016-02-13 05:02:11 +08:00
|
|
|
struct task_struct *tsk, struct vm_area_struct *vma,
|
|
|
|
int fault)
|
2008-01-30 20:32:35 +08:00
|
|
|
{
|
2010-09-28 04:05:55 +08:00
|
|
|
unsigned lsb = 0;
|
2008-01-30 20:32:35 +08:00
|
|
|
siginfo_t info;
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
info.si_signo = si_signo;
|
|
|
|
info.si_errno = 0;
|
|
|
|
info.si_code = si_code;
|
|
|
|
info.si_addr = (void __user *)address;
|
2010-09-28 04:05:55 +08:00
|
|
|
if (fault & VM_FAULT_HWPOISON_LARGE)
|
|
|
|
lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
|
|
|
|
if (fault & VM_FAULT_HWPOISON)
|
|
|
|
lsb = PAGE_SHIFT;
|
|
|
|
info.si_addr_lsb = lsb;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2016-02-13 05:02:14 +08:00
|
|
|
fill_sig_info_pkey(si_code, &info, vma);
|
|
|
|
|
2008-01-30 20:32:35 +08:00
|
|
|
force_sig_info(si_signo, &info, tsk);
|
|
|
|
}
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
DEFINE_SPINLOCK(pgd_lock);
|
|
|
|
LIST_HEAD(pgd_list);
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
|
2008-01-30 20:32:19 +08:00
|
|
|
{
|
2009-02-21 05:50:24 +08:00
|
|
|
unsigned index = pgd_index(address);
|
|
|
|
pgd_t *pgd_k;
|
|
|
|
pud_t *pud, *pud_k;
|
|
|
|
pmd_t *pmd, *pmd_k;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
pgd += index;
|
|
|
|
pgd_k = init_mm.pgd + index;
|
|
|
|
|
|
|
|
if (!pgd_present(*pgd_k))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set_pgd(pgd, *pgd_k); here would be useless on PAE
|
|
|
|
* and redundant with the set_pmd() on non-PAE. As would
|
|
|
|
* set_pud.
|
|
|
|
*/
|
|
|
|
pud = pud_offset(pgd, address);
|
|
|
|
pud_k = pud_offset(pgd_k, address);
|
|
|
|
if (!pud_present(*pud_k))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pmd = pmd_offset(pud, address);
|
|
|
|
pmd_k = pmd_offset(pud_k, address);
|
|
|
|
if (!pmd_present(*pmd_k))
|
|
|
|
return NULL;
|
|
|
|
|
2009-02-18 15:05:19 +08:00
|
|
|
if (!pmd_present(*pmd))
|
2009-02-21 05:50:24 +08:00
|
|
|
set_pmd(pmd, *pmd_k);
|
2009-02-18 15:05:19 +08:00
|
|
|
else
|
2009-02-21 05:50:24 +08:00
|
|
|
BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
|
|
|
|
|
|
|
|
return pmd_k;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vmalloc_sync_all(void)
|
|
|
|
{
|
|
|
|
unsigned long address;
|
|
|
|
|
|
|
|
if (SHARED_KERNEL_PMD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (address = VMALLOC_START & PMD_MASK;
|
2016-05-11 05:10:29 +08:00
|
|
|
address >= TASK_SIZE_MAX && address < FIXADDR_TOP;
|
2009-02-21 05:50:24 +08:00
|
|
|
address += PMD_SIZE) {
|
|
|
|
struct page *page;
|
|
|
|
|
2011-02-17 07:45:22 +08:00
|
|
|
spin_lock(&pgd_lock);
|
2009-02-21 05:50:24 +08:00
|
|
|
list_for_each_entry(page, &pgd_list, lru) {
|
2010-09-22 03:01:51 +08:00
|
|
|
spinlock_t *pgt_lock;
|
2010-10-20 06:17:37 +08:00
|
|
|
pmd_t *ret;
|
2010-09-22 03:01:51 +08:00
|
|
|
|
2011-02-17 07:45:22 +08:00
|
|
|
/* the pgt_lock only for Xen */
|
2010-09-22 03:01:51 +08:00
|
|
|
pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
|
|
|
|
|
|
|
|
spin_lock(pgt_lock);
|
|
|
|
ret = vmalloc_sync_one(page_address(page), address);
|
|
|
|
spin_unlock(pgt_lock);
|
|
|
|
|
|
|
|
if (!ret)
|
2009-02-21 05:50:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-02-17 07:45:22 +08:00
|
|
|
spin_unlock(&pgd_lock);
|
2009-02-21 05:50:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 32-bit:
|
|
|
|
*
|
|
|
|
* Handle a fault on the vmalloc or module mapping area
|
|
|
|
*/
|
2014-04-17 16:18:14 +08:00
|
|
|
static noinline int vmalloc_fault(unsigned long address)
|
2009-02-21 05:50:24 +08:00
|
|
|
{
|
|
|
|
unsigned long pgd_paddr;
|
|
|
|
pmd_t *pmd_k;
|
|
|
|
pte_t *pte_k;
|
|
|
|
|
|
|
|
/* Make sure we are in vmalloc area: */
|
|
|
|
if (!(address >= VMALLOC_START && address < VMALLOC_END))
|
|
|
|
return -1;
|
|
|
|
|
2010-09-28 00:50:51 +08:00
|
|
|
WARN_ON_ONCE(in_nmi());
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
/*
|
|
|
|
* Synchronize this task's top level page-table
|
|
|
|
* with the 'reference' page table.
|
|
|
|
*
|
|
|
|
* Do _not_ use "current" here. We might be inside
|
|
|
|
* an interrupt in the middle of a task switch..
|
|
|
|
*/
|
|
|
|
pgd_paddr = read_cr3();
|
|
|
|
pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
|
|
|
|
if (!pmd_k)
|
|
|
|
return -1;
|
|
|
|
|
2016-02-18 09:16:54 +08:00
|
|
|
if (pmd_huge(*pmd_k))
|
|
|
|
return 0;
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
pte_k = pte_offset_kernel(pmd_k, address);
|
|
|
|
if (!pte_present(*pte_k))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-17 16:18:14 +08:00
|
|
|
NOKPROBE_SYMBOL(vmalloc_fault);
|
2009-02-21 05:50:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Did it hit the DOS screen memory VA from vm86 mode?
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
check_v8086_mode(struct pt_regs *regs, unsigned long address,
|
|
|
|
struct task_struct *tsk)
|
|
|
|
{
|
2015-07-29 13:41:16 +08:00
|
|
|
#ifdef CONFIG_VM86
|
2009-02-21 05:50:24 +08:00
|
|
|
unsigned long bit;
|
|
|
|
|
2015-07-29 13:41:16 +08:00
|
|
|
if (!v8086_mode(regs) || !tsk->thread.vm86)
|
2009-02-21 05:50:24 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
bit = (address - 0xA0000) >> PAGE_SHIFT;
|
|
|
|
if (bit < 32)
|
2015-07-29 13:41:16 +08:00
|
|
|
tsk->thread.vm86->screen_bitmap |= 1 << bit;
|
|
|
|
#endif
|
2008-01-30 20:32:19 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-27 14:35:15 +08:00
|
|
|
static bool low_pfn(unsigned long pfn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-06-27 14:35:15 +08:00
|
|
|
return pfn < max_low_pfn;
|
|
|
|
}
|
2008-01-30 20:34:10 +08:00
|
|
|
|
2009-06-27 14:35:15 +08:00
|
|
|
static void dump_pagetable(unsigned long address)
|
|
|
|
{
|
|
|
|
pgd_t *base = __va(read_cr3());
|
|
|
|
pgd_t *pgd = &base[pgd_index(address)];
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-01-30 20:34:10 +08:00
|
|
|
#ifdef CONFIG_X86_PAE
|
2009-06-27 14:35:15 +08:00
|
|
|
printk("*pdpt = %016Lx ", pgd_val(*pgd));
|
|
|
|
if (!low_pfn(pgd_val(*pgd) >> PAGE_SHIFT) || !pgd_present(*pgd))
|
|
|
|
goto out;
|
2008-01-30 20:34:10 +08:00
|
|
|
#endif
|
2009-06-27 14:35:15 +08:00
|
|
|
pmd = pmd_offset(pud_offset(pgd, address), address);
|
|
|
|
printk(KERN_CONT "*pde = %0*Lx ", sizeof(*pmd) * 2, (u64)pmd_val(*pmd));
|
2008-01-30 20:34:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We must not directly access the pte in the highpte
|
|
|
|
* case if the page table is located in highmem.
|
|
|
|
* And let's rather not kmap-atomic the pte, just in case
|
2009-02-21 02:56:40 +08:00
|
|
|
* it's allocated already:
|
2008-01-30 20:34:10 +08:00
|
|
|
*/
|
2009-06-27 14:35:15 +08:00
|
|
|
if (!low_pfn(pmd_pfn(*pmd)) || !pmd_present(*pmd) || pmd_large(*pmd))
|
|
|
|
goto out;
|
2008-01-30 20:34:10 +08:00
|
|
|
|
2009-06-27 14:35:15 +08:00
|
|
|
pte = pte_offset_kernel(pmd, address);
|
|
|
|
printk("*pte = %0*Lx ", sizeof(*pte) * 2, (u64)pte_val(*pte));
|
|
|
|
out:
|
2008-01-30 20:34:10 +08:00
|
|
|
printk("\n");
|
2009-02-21 05:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_X86_64: */
|
|
|
|
|
|
|
|
void vmalloc_sync_all(void)
|
|
|
|
{
|
2016-12-15 07:44:03 +08:00
|
|
|
sync_global_pgds(VMALLOC_START & PGDIR_MASK, VMALLOC_END);
|
2009-02-21 05:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 64-bit:
|
|
|
|
*
|
|
|
|
* Handle a fault on the vmalloc area
|
|
|
|
*/
|
2014-04-17 16:18:14 +08:00
|
|
|
static noinline int vmalloc_fault(unsigned long address)
|
2009-02-21 05:50:24 +08:00
|
|
|
{
|
|
|
|
pgd_t *pgd, *pgd_ref;
|
|
|
|
pud_t *pud, *pud_ref;
|
|
|
|
pmd_t *pmd, *pmd_ref;
|
|
|
|
pte_t *pte, *pte_ref;
|
|
|
|
|
|
|
|
/* Make sure we are in vmalloc area: */
|
|
|
|
if (!(address >= VMALLOC_START && address < VMALLOC_END))
|
|
|
|
return -1;
|
|
|
|
|
2010-09-28 00:50:51 +08:00
|
|
|
WARN_ON_ONCE(in_nmi());
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
/*
|
|
|
|
* Copy kernel mappings over when needed. This can also
|
|
|
|
* happen within a race in page table update. In the later
|
|
|
|
* case just flush:
|
|
|
|
*/
|
2016-07-15 04:22:54 +08:00
|
|
|
pgd = (pgd_t *)__va(read_cr3()) + pgd_index(address);
|
2009-02-21 05:50:24 +08:00
|
|
|
pgd_ref = pgd_offset_k(address);
|
|
|
|
if (pgd_none(*pgd_ref))
|
|
|
|
return -1;
|
|
|
|
|
2013-03-23 21:36:35 +08:00
|
|
|
if (pgd_none(*pgd)) {
|
2009-02-21 05:50:24 +08:00
|
|
|
set_pgd(pgd, *pgd_ref);
|
2013-03-23 21:36:35 +08:00
|
|
|
arch_flush_lazy_mmu_mode();
|
|
|
|
} else {
|
2009-02-21 05:50:24 +08:00
|
|
|
BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
|
2013-03-23 21:36:35 +08:00
|
|
|
}
|
2009-02-21 05:50:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Below here mismatches are bugs because these lower tables
|
|
|
|
* are shared:
|
|
|
|
*/
|
|
|
|
|
|
|
|
pud = pud_offset(pgd, address);
|
|
|
|
pud_ref = pud_offset(pgd_ref, address);
|
|
|
|
if (pud_none(*pud_ref))
|
|
|
|
return -1;
|
|
|
|
|
2016-02-18 09:16:54 +08:00
|
|
|
if (pud_none(*pud) || pud_pfn(*pud) != pud_pfn(*pud_ref))
|
2009-02-21 05:50:24 +08:00
|
|
|
BUG();
|
|
|
|
|
2016-02-18 09:16:54 +08:00
|
|
|
if (pud_huge(*pud))
|
|
|
|
return 0;
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
pmd = pmd_offset(pud, address);
|
|
|
|
pmd_ref = pmd_offset(pud_ref, address);
|
|
|
|
if (pmd_none(*pmd_ref))
|
|
|
|
return -1;
|
|
|
|
|
2016-02-18 09:16:54 +08:00
|
|
|
if (pmd_none(*pmd) || pmd_pfn(*pmd) != pmd_pfn(*pmd_ref))
|
2009-02-21 05:50:24 +08:00
|
|
|
BUG();
|
|
|
|
|
2016-02-18 09:16:54 +08:00
|
|
|
if (pmd_huge(*pmd))
|
|
|
|
return 0;
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
pte_ref = pte_offset_kernel(pmd_ref, address);
|
|
|
|
if (!pte_present(*pte_ref))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
pte = pte_offset_kernel(pmd, address);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't use pte_page here, because the mappings can point
|
|
|
|
* outside mem_map, and the NUMA hash lookup cannot handle
|
|
|
|
* that:
|
|
|
|
*/
|
|
|
|
if (!pte_present(*pte) || pte_pfn(*pte) != pte_pfn(*pte_ref))
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-17 16:18:14 +08:00
|
|
|
NOKPROBE_SYMBOL(vmalloc_fault);
|
2009-02-21 05:50:24 +08:00
|
|
|
|
2011-09-28 23:56:51 +08:00
|
|
|
#ifdef CONFIG_CPU_SUP_AMD
|
2009-02-21 05:50:24 +08:00
|
|
|
static const char errata93_warning[] =
|
2009-07-07 04:05:40 +08:00
|
|
|
KERN_ERR
|
|
|
|
"******* Your BIOS seems to not contain a fix for K8 errata #93\n"
|
|
|
|
"******* Working around it, but it may cause SEGVs or burn power.\n"
|
|
|
|
"******* Please consider a BIOS update.\n"
|
|
|
|
"******* Disabling USB legacy in the BIOS may also help.\n";
|
2011-09-28 23:56:51 +08:00
|
|
|
#endif
|
2009-02-21 05:50:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* No vm86 mode in 64-bit mode:
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
check_v8086_mode(struct pt_regs *regs, unsigned long address,
|
|
|
|
struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bad_address(void *p)
|
|
|
|
{
|
|
|
|
unsigned long dummy;
|
|
|
|
|
|
|
|
return probe_kernel_address((unsigned long *)p, dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_pagetable(unsigned long address)
|
|
|
|
{
|
2009-06-27 14:35:15 +08:00
|
|
|
pgd_t *base = __va(read_cr3() & PHYSICAL_PAGE_MASK);
|
|
|
|
pgd_t *pgd = base + pgd_index(address);
|
2005-04-17 06:20:36 +08:00
|
|
|
pud_t *pud;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
if (bad_address(pgd))
|
|
|
|
goto bad;
|
|
|
|
|
2006-02-04 04:51:47 +08:00
|
|
|
printk("PGD %lx ", pgd_val(*pgd));
|
2009-02-21 02:56:40 +08:00
|
|
|
|
|
|
|
if (!pgd_present(*pgd))
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-26 19:57:56 +08:00
|
|
|
pud = pud_offset(pgd, address);
|
2009-02-21 02:56:40 +08:00
|
|
|
if (bad_address(pud))
|
|
|
|
goto bad;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("PUD %lx ", pud_val(*pud));
|
2008-02-04 23:48:09 +08:00
|
|
|
if (!pud_present(*pud) || pud_large(*pud))
|
2009-02-21 02:56:40 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pmd = pmd_offset(pud, address);
|
2009-02-21 02:56:40 +08:00
|
|
|
if (bad_address(pmd))
|
|
|
|
goto bad;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("PMD %lx ", pmd_val(*pmd));
|
2009-02-21 02:56:40 +08:00
|
|
|
if (!pmd_present(*pmd) || pmd_large(*pmd))
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
pte = pte_offset_kernel(pmd, address);
|
2009-02-21 02:56:40 +08:00
|
|
|
if (bad_address(pte))
|
|
|
|
goto bad;
|
|
|
|
|
2008-01-30 20:32:19 +08:00
|
|
|
printk("PTE %lx", pte_val(*pte));
|
2009-02-21 02:56:40 +08:00
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("\n");
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
printk("BAD\n");
|
2009-02-21 05:12:18 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 05:50:24 +08:00
|
|
|
#endif /* CONFIG_X86_64 */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/*
|
|
|
|
* Workaround for K8 erratum #93 & buggy BIOS.
|
|
|
|
*
|
|
|
|
* BIOS SMM functions are required to use a specific workaround
|
|
|
|
* to avoid corruption of the 64bit RIP register on C stepping K8.
|
|
|
|
*
|
|
|
|
* A lot of BIOS that didn't get tested properly miss this.
|
|
|
|
*
|
|
|
|
* The OS sees this as a page fault with the upper 32bits of RIP cleared.
|
|
|
|
* Try to work around it here.
|
|
|
|
*
|
|
|
|
* Note we only handle faults in kernel here.
|
|
|
|
* Does nothing on 32-bit.
|
2008-01-30 20:33:13 +08:00
|
|
|
*/
|
2008-01-30 20:32:19 +08:00
|
|
|
static int is_errata93(struct pt_regs *regs, unsigned long address)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-09-28 23:56:51 +08:00
|
|
|
#if defined(CONFIG_X86_64) && defined(CONFIG_CPU_SUP_AMD)
|
|
|
|
if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD
|
|
|
|
|| boot_cpu_data.x86 != 0xf)
|
|
|
|
return 0;
|
|
|
|
|
2008-01-30 20:30:56 +08:00
|
|
|
if (address != regs->ip)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-01-30 20:32:19 +08:00
|
|
|
if ((address >> 32) != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
address |= 0xffffffffUL << 32;
|
2008-01-30 20:32:19 +08:00
|
|
|
if ((address >= (u64)_stext && address <= (u64)_etext) ||
|
|
|
|
(address >= MODULES_VADDR && address <= MODULES_END)) {
|
2009-05-03 16:09:03 +08:00
|
|
|
printk_once(errata93_warning);
|
2008-01-30 20:30:56 +08:00
|
|
|
regs->ip = address;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2008-01-30 20:33:13 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2008-01-30 20:32:19 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:34:09 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Work around K8 erratum #100 K8 in compat mode occasionally jumps
|
|
|
|
* to illegal addresses >4GB.
|
|
|
|
*
|
|
|
|
* We catch this in the page fault handler because these addresses
|
|
|
|
* are not reachable. Just detect this case and return. Any code
|
2008-01-30 20:34:09 +08:00
|
|
|
* segment in LDT is compatibility mode.
|
|
|
|
*/
|
|
|
|
static int is_errata100(struct pt_regs *regs, unsigned long address)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_X86_64
|
2009-02-21 02:56:40 +08:00
|
|
|
if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
|
2008-01-30 20:34:09 +08:00
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-30 20:34:09 +08:00
|
|
|
static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_X86_F00F_BUG
|
|
|
|
unsigned long nr;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-01-30 20:34:09 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Pentium F0 0F C7 C8 bug workaround:
|
2008-01-30 20:34:09 +08:00
|
|
|
*/
|
2013-03-20 22:07:24 +08:00
|
|
|
if (boot_cpu_has_bug(X86_BUG_F00F)) {
|
2008-01-30 20:34:09 +08:00
|
|
|
nr = (address - idt_descr.address) >> 3;
|
|
|
|
|
|
|
|
if (nr == 6) {
|
|
|
|
do_invalid_op(regs, 0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-21 06:00:29 +08:00
|
|
|
static const char nx_warning[] = KERN_CRIT
|
|
|
|
"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
|
2014-06-11 04:49:31 +08:00
|
|
|
static const char smep_warning[] = KERN_CRIT
|
|
|
|
"unable to execute userspace code (SMEP?) (uid: %d)\n";
|
2009-02-21 06:00:29 +08:00
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static void
|
|
|
|
show_fault_oops(struct pt_regs *regs, unsigned long error_code,
|
|
|
|
unsigned long address)
|
2008-01-30 20:34:10 +08:00
|
|
|
{
|
2008-01-30 20:34:10 +08:00
|
|
|
if (!oops_may_print())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (error_code & PF_INSTR) {
|
2008-02-02 00:49:43 +08:00
|
|
|
unsigned int level;
|
2013-12-07 05:13:04 +08:00
|
|
|
pgd_t *pgd;
|
|
|
|
pte_t *pte;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2013-12-07 05:13:04 +08:00
|
|
|
pgd = __va(read_cr3() & PHYSICAL_PAGE_MASK);
|
|
|
|
pgd += pgd_index(address);
|
|
|
|
|
|
|
|
pte = lookup_address_in_pgd(pgd, address, &level);
|
2008-01-30 20:34:10 +08:00
|
|
|
|
2009-02-21 06:00:29 +08:00
|
|
|
if (pte && pte_present(*pte) && !pte_exec(*pte))
|
2012-02-08 23:00:08 +08:00
|
|
|
printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
|
2014-06-11 04:49:31 +08:00
|
|
|
if (pte && pte_present(*pte) && pte_exec(*pte) &&
|
|
|
|
(pgd_flags(*pgd) & _PAGE_USER) &&
|
2014-10-25 06:58:08 +08:00
|
|
|
(__read_cr4() & X86_CR4_SMEP))
|
2014-06-11 04:49:31 +08:00
|
|
|
printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
|
2008-01-30 20:34:10 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 20:34:10 +08:00
|
|
|
printk(KERN_ALERT "BUG: unable to handle kernel ");
|
2008-01-30 20:34:10 +08:00
|
|
|
if (address < PAGE_SIZE)
|
2008-01-30 20:34:10 +08:00
|
|
|
printk(KERN_CONT "NULL pointer dereference");
|
2008-01-30 20:34:10 +08:00
|
|
|
else
|
2008-01-30 20:34:10 +08:00
|
|
|
printk(KERN_CONT "paging request");
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-07-01 21:38:13 +08:00
|
|
|
printk(KERN_CONT " at %p\n", (void *) address);
|
2016-10-25 22:51:12 +08:00
|
|
|
printk(KERN_ALERT "IP: %pS\n", (void *)regs->ip);
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-01-30 20:34:10 +08:00
|
|
|
dump_pagetable(address);
|
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static noinline void
|
|
|
|
pgtable_bad(struct pt_regs *regs, unsigned long error_code,
|
|
|
|
unsigned long address)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-02-21 02:56:40 +08:00
|
|
|
struct task_struct *tsk;
|
|
|
|
unsigned long flags;
|
|
|
|
int sig;
|
|
|
|
|
|
|
|
flags = oops_begin();
|
|
|
|
tsk = current;
|
|
|
|
sig = SIGKILL;
|
2005-09-13 00:49:24 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ALERT "%s: Corrupted page table at address %lx\n",
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
tsk->comm, address);
|
2005-04-17 06:20:36 +08:00
|
|
|
dump_pagetable(address);
|
2009-02-21 02:56:40 +08:00
|
|
|
|
|
|
|
tsk->thread.cr2 = address;
|
2012-03-12 17:25:55 +08:00
|
|
|
tsk->thread.trap_nr = X86_TRAP_PF;
|
2009-02-21 02:56:40 +08:00
|
|
|
tsk->thread.error_code = error_code;
|
|
|
|
|
2008-01-30 20:31:23 +08:00
|
|
|
if (__die("Bad pagetable", regs, error_code))
|
2008-10-22 18:00:09 +08:00
|
|
|
sig = 0;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-10-22 18:00:09 +08:00
|
|
|
oops_end(flags, regs, sig);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static noinline void
|
|
|
|
no_context(struct pt_regs *regs, unsigned long error_code,
|
2011-11-08 08:33:40 +08:00
|
|
|
unsigned long address, int signal, int si_code)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
unsigned long flags;
|
|
|
|
int sig;
|
2016-02-13 05:02:11 +08:00
|
|
|
/* No context means no VMA to pass down */
|
|
|
|
struct vm_area_struct *vma = NULL;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/* Are we prepared to handle this kernel fault? */
|
2016-02-18 02:20:12 +08:00
|
|
|
if (fixup_exception(regs, X86_TRAP_PF)) {
|
2014-01-11 04:06:03 +08:00
|
|
|
/*
|
|
|
|
* Any interrupt that takes a fault gets the fixup. This makes
|
|
|
|
* the below recursive fault logic only apply to a faults from
|
|
|
|
* task context.
|
|
|
|
*/
|
|
|
|
if (in_interrupt())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per the above we're !in_interrupt(), aka. task context.
|
|
|
|
*
|
|
|
|
* In this case we need to make sure we're not recursively
|
|
|
|
* faulting through the emulate_vsyscall() logic.
|
|
|
|
*/
|
2016-07-15 16:21:11 +08:00
|
|
|
if (current->thread.sig_on_uaccess_err && signal) {
|
2012-03-12 17:25:55 +08:00
|
|
|
tsk->thread.trap_nr = X86_TRAP_PF;
|
2011-11-08 08:33:40 +08:00
|
|
|
tsk->thread.error_code = error_code | PF_USER;
|
|
|
|
tsk->thread.cr2 = address;
|
|
|
|
|
|
|
|
/* XXX: hwpoison faults will set the wrong code. */
|
2016-02-13 05:02:11 +08:00
|
|
|
force_sig_info_fault(signal, si_code, address,
|
|
|
|
tsk, vma, 0);
|
2011-11-08 08:33:40 +08:00
|
|
|
}
|
2014-01-11 04:06:03 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Barring that, we can do the fixup and be happy.
|
|
|
|
*/
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return;
|
2011-11-08 08:33:40 +08:00
|
|
|
}
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
|
2016-08-31 08:27:57 +08:00
|
|
|
#ifdef CONFIG_VMAP_STACK
|
|
|
|
/*
|
|
|
|
* Stack overflow? During boot, we can fault near the initial
|
|
|
|
* stack in the direct map, but that's not an overflow -- check
|
|
|
|
* that we're in vmalloc space to avoid this.
|
|
|
|
*/
|
|
|
|
if (is_vmalloc_addr((void *)address) &&
|
|
|
|
(((unsigned long)tsk->stack - 1 - address < PAGE_SIZE) ||
|
|
|
|
address - ((unsigned long)tsk->stack + THREAD_SIZE) < PAGE_SIZE)) {
|
|
|
|
register void *__sp asm("rsp");
|
|
|
|
unsigned long stack = this_cpu_read(orig_ist.ist[DOUBLEFAULT_STACK]) - sizeof(void *);
|
|
|
|
/*
|
|
|
|
* We're likely to be running with very little stack space
|
|
|
|
* left. It's plausible that we'd hit this condition but
|
|
|
|
* double-fault even before we get this far, in which case
|
|
|
|
* we're fine: the double-fault handler will deal with it.
|
|
|
|
*
|
|
|
|
* We don't want to make it all the way into the oops code
|
|
|
|
* and then double-fault, though, because we're likely to
|
|
|
|
* break the console driver and lose most of the stack dump.
|
|
|
|
*/
|
|
|
|
asm volatile ("movq %[stack], %%rsp\n\t"
|
|
|
|
"call handle_stack_overflow\n\t"
|
|
|
|
"1: jmp 1b"
|
|
|
|
: "+r" (__sp)
|
|
|
|
: "D" ("kernel stack overflow (page fault)"),
|
|
|
|
"S" (regs), "d" (address),
|
|
|
|
[stack] "rm" (stack));
|
|
|
|
unreachable();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* 32-bit:
|
|
|
|
*
|
|
|
|
* Valid to do another page fault here, because if this fault
|
|
|
|
* had been triggered by is_prefetch fixup_exception would have
|
|
|
|
* handled it.
|
|
|
|
*
|
|
|
|
* 64-bit:
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Hall of shame of CPU/BIOS bugs.
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
*/
|
|
|
|
if (is_prefetch(regs, error_code, address))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (is_errata93(regs, address))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Oops. The kernel tried to access some bad page. We'll have to
|
2009-02-21 02:56:40 +08:00
|
|
|
* terminate things with extreme prejudice:
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
*/
|
|
|
|
flags = oops_begin();
|
|
|
|
|
|
|
|
show_fault_oops(regs, error_code, address);
|
|
|
|
|
2014-09-12 21:16:18 +08:00
|
|
|
if (task_stack_end_corrupted(tsk))
|
bugs, x86: Fix printk levels for panic, softlockups and stack dumps
rsyslog will display KERN_EMERG messages on a connected
terminal. However, these messages are useless/undecipherable
for a general user.
For example, after a softlockup we get:
Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
kernel:Stack:
Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
kernel:Call Trace:
Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
kernel:Code: ff ff a8 08 75 25 31 d2 48 8d 86 38 e0 ff ff 48 89
d1 0f 01 c8 0f ae f0 48 8b 86 38 e0 ff ff a8 08 75 08 b1 01 4c 89 e0 0f 01 c9 <e8> ea 69 dd ff 4c 29 e8 48 89 c7 e8 0f bc da ff 49 89 c4 49 89
This happens because the printk levels for these messages are
incorrect. Only an informational message should be displayed on
a terminal.
I modified the printk levels for various messages in the kernel
and tested the output by using the drivers/misc/lkdtm.c kernel
modules (ie, softlockups, panics, hard lockups, etc.) and
confirmed that the console output was still the same and that
the output to the terminals was correct.
For example, in the case of a softlockup we now see the much
more informative:
Message from syslogd@intel-s3e37-04 at Jan 25 10:18:06 ...
BUG: soft lockup - CPU4 stuck for 60s!
instead of the above confusing messages.
AFAICT, the messages no longer have to be KERN_EMERG. In the
most important case of a panic we set console_verbose(). As for
the other less severe cases the correct data is output to the
console and /var/log/messages.
Successfully tested by me using the drivers/misc/lkdtm.c module.
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: dzickus@redhat.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/1327586134-11926-1-git-send-email-prarit@redhat.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2012-01-26 21:55:34 +08:00
|
|
|
printk(KERN_EMERG "Thread overran stack, or stack corrupted\n");
|
2009-01-21 17:39:51 +08:00
|
|
|
|
2009-02-21 06:07:48 +08:00
|
|
|
tsk->thread.cr2 = address;
|
2012-03-12 17:25:55 +08:00
|
|
|
tsk->thread.trap_nr = X86_TRAP_PF;
|
2009-02-21 06:07:48 +08:00
|
|
|
tsk->thread.error_code = error_code;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
|
|
|
|
sig = SIGKILL;
|
|
|
|
if (__die("Oops", regs, error_code))
|
|
|
|
sig = 0;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
/* Executive summary in case the body of the oops scrolled away */
|
bugs, x86: Fix printk levels for panic, softlockups and stack dumps
rsyslog will display KERN_EMERG messages on a connected
terminal. However, these messages are useless/undecipherable
for a general user.
For example, after a softlockup we get:
Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
kernel:Stack:
Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
kernel:Call Trace:
Message from syslogd@intel-s3e37-04 at Jan 25 14:18:06 ...
kernel:Code: ff ff a8 08 75 25 31 d2 48 8d 86 38 e0 ff ff 48 89
d1 0f 01 c8 0f ae f0 48 8b 86 38 e0 ff ff a8 08 75 08 b1 01 4c 89 e0 0f 01 c9 <e8> ea 69 dd ff 4c 29 e8 48 89 c7 e8 0f bc da ff 49 89 c4 49 89
This happens because the printk levels for these messages are
incorrect. Only an informational message should be displayed on
a terminal.
I modified the printk levels for various messages in the kernel
and tested the output by using the drivers/misc/lkdtm.c kernel
modules (ie, softlockups, panics, hard lockups, etc.) and
confirmed that the console output was still the same and that
the output to the terminals was correct.
For example, in the case of a softlockup we now see the much
more informative:
Message from syslogd@intel-s3e37-04 at Jan 25 10:18:06 ...
BUG: soft lockup - CPU4 stuck for 60s!
instead of the above confusing messages.
AFAICT, the messages no longer have to be KERN_EMERG. In the
most important case of a panic we set console_verbose(). As for
the other less severe cases the correct data is output to the
console and /var/log/messages.
Successfully tested by me using the drivers/misc/lkdtm.c module.
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: dzickus@redhat.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/1327586134-11926-1-git-send-email-prarit@redhat.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2012-01-26 21:55:34 +08:00
|
|
|
printk(KERN_DEFAULT "CR2: %016lx\n", address);
|
2009-02-21 02:56:40 +08:00
|
|
|
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
oops_end(flags, regs, sig);
|
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/*
|
|
|
|
* Print out info about fatal segfaults, if the show_unhandled_signals
|
|
|
|
* sysctl is set:
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
show_signal_msg(struct pt_regs *regs, unsigned long error_code,
|
|
|
|
unsigned long address, struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
if (!unhandled_signal(tsk, SIGSEGV))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!printk_ratelimit())
|
|
|
|
return;
|
|
|
|
|
2009-07-11 15:10:04 +08:00
|
|
|
printk("%s%s[%d]: segfault at %lx ip %p sp %p error %lx",
|
2009-02-21 02:56:40 +08:00
|
|
|
task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
|
|
|
|
tsk->comm, task_pid_nr(tsk), address,
|
|
|
|
(void *)regs->ip, (void *)regs->sp, error_code);
|
|
|
|
|
|
|
|
print_vma_addr(KERN_CONT " in ", regs->ip);
|
|
|
|
|
|
|
|
printk(KERN_CONT "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
|
2016-02-13 05:02:11 +08:00
|
|
|
unsigned long address, struct vm_area_struct *vma,
|
|
|
|
int si_code)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
|
|
|
|
/* User mode accesses just cause a SIGSEGV */
|
|
|
|
if (error_code & PF_USER) {
|
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* It's possible to have interrupts off here:
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
*/
|
|
|
|
local_irq_enable();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Valid to do another page fault here because this one came
|
2009-02-21 02:56:40 +08:00
|
|
|
* from user space:
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
*/
|
|
|
|
if (is_prefetch(regs, error_code, address))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (is_errata100(regs, address))
|
|
|
|
return;
|
|
|
|
|
2011-08-10 23:15:32 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/*
|
|
|
|
* Instruction fetch faults in the vsyscall page might need
|
|
|
|
* emulation.
|
|
|
|
*/
|
|
|
|
if (unlikely((error_code & PF_INSTR) &&
|
2014-05-06 03:19:36 +08:00
|
|
|
((address & ~0xfff) == VSYSCALL_ADDR))) {
|
2011-08-10 23:15:32 +08:00
|
|
|
if (emulate_vsyscall(regs, address))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2016-05-11 05:10:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To avoid leaking information about the kernel page table
|
|
|
|
* layout, pretend that user-mode accesses to kernel addresses
|
|
|
|
* are always protection faults.
|
|
|
|
*/
|
|
|
|
if (address >= TASK_SIZE_MAX)
|
2013-02-08 01:44:13 +08:00
|
|
|
error_code |= PF_PROT;
|
2011-08-10 23:15:32 +08:00
|
|
|
|
2013-02-08 01:44:13 +08:00
|
|
|
if (likely(show_unhandled_signals))
|
2009-02-21 02:56:40 +08:00
|
|
|
show_signal_msg(regs, error_code, address, tsk);
|
|
|
|
|
|
|
|
tsk->thread.cr2 = address;
|
2013-02-08 01:44:13 +08:00
|
|
|
tsk->thread.error_code = error_code;
|
2012-03-12 17:25:55 +08:00
|
|
|
tsk->thread.trap_nr = X86_TRAP_PF;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
|
2016-02-13 05:02:11 +08:00
|
|
|
force_sig_info_fault(SIGSEGV, si_code, address, tsk, vma, 0);
|
2009-02-21 02:56:40 +08:00
|
|
|
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_f00f_bug(regs, address))
|
|
|
|
return;
|
|
|
|
|
2011-11-08 08:33:40 +08:00
|
|
|
no_context(regs, error_code, address, SIGSEGV, si_code);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static noinline void
|
|
|
|
bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
|
2016-02-13 05:02:11 +08:00
|
|
|
unsigned long address, struct vm_area_struct *vma)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
2016-02-13 05:02:11 +08:00
|
|
|
__bad_area_nosemaphore(regs, error_code, address, vma, SEGV_MAPERR);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static void
|
|
|
|
__bad_area(struct pt_regs *regs, unsigned long error_code,
|
2016-02-13 05:02:11 +08:00
|
|
|
unsigned long address, struct vm_area_struct *vma, int si_code)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
|
|
|
struct mm_struct *mm = current->mm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Something tried to access memory that isn't in our memory map..
|
|
|
|
* Fix it, but check if it's kernel or user first..
|
|
|
|
*/
|
|
|
|
up_read(&mm->mmap_sem);
|
|
|
|
|
2016-02-13 05:02:11 +08:00
|
|
|
__bad_area_nosemaphore(regs, error_code, address, vma, si_code);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static noinline void
|
|
|
|
bad_area(struct pt_regs *regs, unsigned long error_code, unsigned long address)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
2016-02-13 05:02:11 +08:00
|
|
|
__bad_area(regs, error_code, address, NULL, SEGV_MAPERR);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys
Today, for normal faults and page table walks, we check the VMA
and/or PTE to ensure that it is compatible with the action. For
instance, if we get a write fault on a non-writeable VMA, we
SIGSEGV.
We try to do the same thing for protection keys. Basically, we
try to make sure that if a user does this:
mprotect(ptr, size, PROT_NONE);
*ptr = foo;
they see the same effects with protection keys when they do this:
mprotect(ptr, size, PROT_READ|PROT_WRITE);
set_pkey(ptr, size, 4);
wrpkru(0xffffff3f); // access disable pkey 4
*ptr = foo;
The state to do that checking is in the VMA, but we also
sometimes have to do it on the page tables only, like when doing
a get_user_pages_fast() where we have no VMA.
We add two functions and expose them to generic code:
arch_pte_access_permitted(pte_flags, write)
arch_vma_access_permitted(vma, write)
These are, of course, backed up in x86 arch code with checks
against the PTE or VMA's protection key.
But, there are also cases where we do not want to respect
protection keys. When we ptrace(), for instance, we do not want
to apply the tracer's PKRU permissions to the PTEs from the
process being traced.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boaz Harrosh <boaz@plexistor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>
Cc: Dominik Vogt <vogt@linux.vnet.ibm.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Shachar Raindel <raindel@mellanox.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/20160212210219.14D5D715@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-13 05:02:19 +08:00
|
|
|
static inline bool bad_area_access_from_pkeys(unsigned long error_code,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
2016-02-13 05:02:22 +08:00
|
|
|
/* This code is always called on the current mm */
|
|
|
|
bool foreign = false;
|
|
|
|
|
mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys
Today, for normal faults and page table walks, we check the VMA
and/or PTE to ensure that it is compatible with the action. For
instance, if we get a write fault on a non-writeable VMA, we
SIGSEGV.
We try to do the same thing for protection keys. Basically, we
try to make sure that if a user does this:
mprotect(ptr, size, PROT_NONE);
*ptr = foo;
they see the same effects with protection keys when they do this:
mprotect(ptr, size, PROT_READ|PROT_WRITE);
set_pkey(ptr, size, 4);
wrpkru(0xffffff3f); // access disable pkey 4
*ptr = foo;
The state to do that checking is in the VMA, but we also
sometimes have to do it on the page tables only, like when doing
a get_user_pages_fast() where we have no VMA.
We add two functions and expose them to generic code:
arch_pte_access_permitted(pte_flags, write)
arch_vma_access_permitted(vma, write)
These are, of course, backed up in x86 arch code with checks
against the PTE or VMA's protection key.
But, there are also cases where we do not want to respect
protection keys. When we ptrace(), for instance, we do not want
to apply the tracer's PKRU permissions to the PTEs from the
process being traced.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boaz Harrosh <boaz@plexistor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>
Cc: Dominik Vogt <vogt@linux.vnet.ibm.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Shachar Raindel <raindel@mellanox.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/20160212210219.14D5D715@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-13 05:02:19 +08:00
|
|
|
if (!boot_cpu_has(X86_FEATURE_OSPKE))
|
|
|
|
return false;
|
|
|
|
if (error_code & PF_PK)
|
|
|
|
return true;
|
2016-02-13 05:02:22 +08:00
|
|
|
/* this checks permission keys on the VMA: */
|
2016-02-13 05:02:24 +08:00
|
|
|
if (!arch_vma_access_permitted(vma, (error_code & PF_WRITE),
|
|
|
|
(error_code & PF_INSTR), foreign))
|
2016-02-13 05:02:22 +08:00
|
|
|
return true;
|
mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys
Today, for normal faults and page table walks, we check the VMA
and/or PTE to ensure that it is compatible with the action. For
instance, if we get a write fault on a non-writeable VMA, we
SIGSEGV.
We try to do the same thing for protection keys. Basically, we
try to make sure that if a user does this:
mprotect(ptr, size, PROT_NONE);
*ptr = foo;
they see the same effects with protection keys when they do this:
mprotect(ptr, size, PROT_READ|PROT_WRITE);
set_pkey(ptr, size, 4);
wrpkru(0xffffff3f); // access disable pkey 4
*ptr = foo;
The state to do that checking is in the VMA, but we also
sometimes have to do it on the page tables only, like when doing
a get_user_pages_fast() where we have no VMA.
We add two functions and expose them to generic code:
arch_pte_access_permitted(pte_flags, write)
arch_vma_access_permitted(vma, write)
These are, of course, backed up in x86 arch code with checks
against the PTE or VMA's protection key.
But, there are also cases where we do not want to respect
protection keys. When we ptrace(), for instance, we do not want
to apply the tracer's PKRU permissions to the PTEs from the
process being traced.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boaz Harrosh <boaz@plexistor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>
Cc: Dominik Vogt <vogt@linux.vnet.ibm.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Shachar Raindel <raindel@mellanox.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/20160212210219.14D5D715@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-13 05:02:19 +08:00
|
|
|
return false;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static noinline void
|
|
|
|
bad_area_access_error(struct pt_regs *regs, unsigned long error_code,
|
2016-02-13 05:02:11 +08:00
|
|
|
unsigned long address, struct vm_area_struct *vma)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
2016-02-13 05:02:14 +08:00
|
|
|
/*
|
|
|
|
* This OSPKE check is not strictly necessary at runtime.
|
|
|
|
* But, doing it this way allows compiler optimizations
|
|
|
|
* if pkeys are compiled out.
|
|
|
|
*/
|
mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys
Today, for normal faults and page table walks, we check the VMA
and/or PTE to ensure that it is compatible with the action. For
instance, if we get a write fault on a non-writeable VMA, we
SIGSEGV.
We try to do the same thing for protection keys. Basically, we
try to make sure that if a user does this:
mprotect(ptr, size, PROT_NONE);
*ptr = foo;
they see the same effects with protection keys when they do this:
mprotect(ptr, size, PROT_READ|PROT_WRITE);
set_pkey(ptr, size, 4);
wrpkru(0xffffff3f); // access disable pkey 4
*ptr = foo;
The state to do that checking is in the VMA, but we also
sometimes have to do it on the page tables only, like when doing
a get_user_pages_fast() where we have no VMA.
We add two functions and expose them to generic code:
arch_pte_access_permitted(pte_flags, write)
arch_vma_access_permitted(vma, write)
These are, of course, backed up in x86 arch code with checks
against the PTE or VMA's protection key.
But, there are also cases where we do not want to respect
protection keys. When we ptrace(), for instance, we do not want
to apply the tracer's PKRU permissions to the PTEs from the
process being traced.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boaz Harrosh <boaz@plexistor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>
Cc: Dominik Vogt <vogt@linux.vnet.ibm.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Shachar Raindel <raindel@mellanox.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/20160212210219.14D5D715@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-13 05:02:19 +08:00
|
|
|
if (bad_area_access_from_pkeys(error_code, vma))
|
2016-02-13 05:02:14 +08:00
|
|
|
__bad_area(regs, error_code, address, vma, SEGV_PKUERR);
|
|
|
|
else
|
|
|
|
__bad_area(regs, error_code, address, vma, SEGV_ACCERR);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static void
|
2009-09-16 17:50:09 +08:00
|
|
|
do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
|
2016-02-13 05:02:11 +08:00
|
|
|
struct vm_area_struct *vma, unsigned int fault)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
2009-09-16 17:50:09 +08:00
|
|
|
int code = BUS_ADRERR;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/* Kernel mode? Handle exceptions or die: */
|
2010-08-14 00:49:20 +08:00
|
|
|
if (!(error_code & PF_USER)) {
|
2011-11-08 08:33:40 +08:00
|
|
|
no_context(regs, error_code, address, SIGBUS, BUS_ADRERR);
|
2010-08-14 00:49:20 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2009-02-21 06:39:02 +08:00
|
|
|
/* User-space => ok to do another page fault: */
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (is_prefetch(regs, error_code, address))
|
|
|
|
return;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
|
|
|
tsk->thread.cr2 = address;
|
|
|
|
tsk->thread.error_code = error_code;
|
2012-03-12 17:25:55 +08:00
|
|
|
tsk->thread.trap_nr = X86_TRAP_PF;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2009-09-16 17:50:09 +08:00
|
|
|
#ifdef CONFIG_MEMORY_FAILURE
|
2010-09-28 04:05:55 +08:00
|
|
|
if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
|
2009-09-16 17:50:09 +08:00
|
|
|
printk(KERN_ERR
|
|
|
|
"MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
|
|
|
|
tsk->comm, tsk->pid, address);
|
|
|
|
code = BUS_MCEERR_AR;
|
|
|
|
}
|
|
|
|
#endif
|
2016-02-13 05:02:11 +08:00
|
|
|
force_sig_info_fault(SIGBUS, code, address, tsk, vma, fault);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 06:13:40 +08:00
|
|
|
static noinline void
|
2009-02-21 02:56:40 +08:00
|
|
|
mm_fault_error(struct pt_regs *regs, unsigned long error_code,
|
2016-02-13 05:02:11 +08:00
|
|
|
unsigned long address, struct vm_area_struct *vma,
|
|
|
|
unsigned int fault)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
2013-09-13 06:13:40 +08:00
|
|
|
if (fatal_signal_pending(current) && !(error_code & PF_USER)) {
|
|
|
|
no_context(regs, error_code, address, 0, 0);
|
|
|
|
return;
|
2011-05-26 16:12:12 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
if (fault & VM_FAULT_OOM) {
|
x86/mm: Handle mm_fault_error() in kernel space
mm_fault_error() should not execute oom-killer, if page fault
occurs in kernel space. E.g. in copy_from_user()/copy_to_user().
This would happen if we find ourselves in OOM on a
copy_to_user(), or a copy_from_user() which faults.
Without this patch, the kernels hangs up in copy_from_user(),
because OOM killer sends SIG_KILL to current process, but it
can't handle a signal while in syscall, then the kernel returns
to copy_from_user(), reexcute current command and provokes
page_fault again.
With this patch the kernel return -EFAULT from copy_from_user().
The code, which checks that page fault occurred in kernel space,
has been copied from do_sigbus().
This situation is handled by the same way on powerpc, xtensa,
tile, ...
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: <stable@kernel.org>
LKML-Reference: <201103092322.p29NMNPH001682@imap1.linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2011-03-10 07:22:23 +08:00
|
|
|
/* Kernel mode? Handle exceptions or die: */
|
|
|
|
if (!(error_code & PF_USER)) {
|
2011-11-08 08:33:40 +08:00
|
|
|
no_context(regs, error_code, address,
|
|
|
|
SIGSEGV, SEGV_MAPERR);
|
2013-09-13 06:13:40 +08:00
|
|
|
return;
|
x86/mm: Handle mm_fault_error() in kernel space
mm_fault_error() should not execute oom-killer, if page fault
occurs in kernel space. E.g. in copy_from_user()/copy_to_user().
This would happen if we find ourselves in OOM on a
copy_to_user(), or a copy_from_user() which faults.
Without this patch, the kernels hangs up in copy_from_user(),
because OOM killer sends SIG_KILL to current process, but it
can't handle a signal while in syscall, then the kernel returns
to copy_from_user(), reexcute current command and provokes
page_fault again.
With this patch the kernel return -EFAULT from copy_from_user().
The code, which checks that page fault occurred in kernel space,
has been copied from do_sigbus().
This situation is handled by the same way on powerpc, xtensa,
tile, ...
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: <stable@kernel.org>
LKML-Reference: <201103092322.p29NMNPH001682@imap1.linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2011-03-10 07:22:23 +08:00
|
|
|
}
|
|
|
|
|
2012-12-13 05:52:10 +08:00
|
|
|
/*
|
|
|
|
* We ran out of memory, call the OOM killer, and return the
|
|
|
|
* userspace (which will retry the fault, or kill us if we got
|
|
|
|
* oom-killed):
|
|
|
|
*/
|
|
|
|
pagefault_out_of_memory();
|
2009-02-21 02:56:40 +08:00
|
|
|
} else {
|
2010-09-28 04:05:55 +08:00
|
|
|
if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|
|
|
|
|
VM_FAULT_HWPOISON_LARGE))
|
2016-02-13 05:02:11 +08:00
|
|
|
do_sigbus(regs, error_code, address, vma, fault);
|
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-30 02:51:32 +08:00
|
|
|
else if (fault & VM_FAULT_SIGSEGV)
|
2016-02-13 05:02:11 +08:00
|
|
|
bad_area_nosemaphore(regs, error_code, address, vma);
|
2009-02-21 02:56:40 +08:00
|
|
|
else
|
|
|
|
BUG();
|
|
|
|
}
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 05:39:43 +08:00
|
|
|
static int spurious_fault_check(unsigned long error_code, pte_t *pte)
|
|
|
|
{
|
|
|
|
if ((error_code & PF_WRITE) && !pte_write(*pte))
|
|
|
|
return 0;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-02-07 05:39:43 +08:00
|
|
|
if ((error_code & PF_INSTR) && !pte_exec(*pte))
|
|
|
|
return 0;
|
2016-02-13 05:02:07 +08:00
|
|
|
/*
|
|
|
|
* Note: We do not do lazy flushing on protection key
|
|
|
|
* changes, so no spurious fault will ever set PF_PK.
|
|
|
|
*/
|
|
|
|
if ((error_code & PF_PK))
|
|
|
|
return 1;
|
2008-02-07 05:39:43 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-30 20:34:11 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Handle a spurious fault caused by a stale TLB entry.
|
|
|
|
*
|
|
|
|
* This allows us to lazily refresh the TLB when increasing the
|
|
|
|
* permissions of a kernel page (RO -> RW or NX -> X). Doing it
|
|
|
|
* eagerly is very expensive since that implies doing a full
|
|
|
|
* cross-processor TLB flush, even if no stale TLB entries exist
|
|
|
|
* on other processors.
|
|
|
|
*
|
2014-04-11 01:46:45 +08:00
|
|
|
* Spurious faults may only occur if the TLB contains an entry with
|
|
|
|
* fewer permission than the page table entry. Non-present (P = 0)
|
|
|
|
* and reserved bit (R = 1) faults are never spurious.
|
|
|
|
*
|
2008-01-30 20:34:11 +08:00
|
|
|
* There are no security implications to leaving a stale TLB when
|
|
|
|
* increasing the permissions on a page.
|
2014-04-11 01:46:45 +08:00
|
|
|
*
|
|
|
|
* Returns non-zero if a spurious fault was handled, zero otherwise.
|
|
|
|
*
|
|
|
|
* See Intel Developer's Manual Vol 3 Section 4.10.4.3, bullet 3
|
|
|
|
* (Optional Invalidation).
|
2008-01-30 20:34:11 +08:00
|
|
|
*/
|
2014-04-17 16:18:14 +08:00
|
|
|
static noinline int
|
2009-02-21 02:56:40 +08:00
|
|
|
spurious_fault(unsigned long error_code, unsigned long address)
|
2008-01-30 20:34:11 +08:00
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
|
|
|
pud_t *pud;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
2009-02-20 00:46:36 +08:00
|
|
|
int ret;
|
2008-01-30 20:34:11 +08:00
|
|
|
|
2014-04-11 01:46:45 +08:00
|
|
|
/*
|
|
|
|
* Only writes to RO or instruction fetches from NX may cause
|
|
|
|
* spurious faults.
|
|
|
|
*
|
|
|
|
* These could be from user or supervisor accesses but the TLB
|
|
|
|
* is only lazily flushed after a kernel mapping protection
|
|
|
|
* change, so user accesses are not expected to cause spurious
|
|
|
|
* faults.
|
|
|
|
*/
|
|
|
|
if (error_code != (PF_WRITE | PF_PROT)
|
|
|
|
&& error_code != (PF_INSTR | PF_PROT))
|
2008-01-30 20:34:11 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pgd = init_mm.pgd + pgd_index(address);
|
|
|
|
if (!pgd_present(*pgd))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pud = pud_offset(pgd, address);
|
|
|
|
if (!pud_present(*pud))
|
|
|
|
return 0;
|
|
|
|
|
2008-02-07 05:39:43 +08:00
|
|
|
if (pud_large(*pud))
|
|
|
|
return spurious_fault_check(error_code, (pte_t *) pud);
|
|
|
|
|
2008-01-30 20:34:11 +08:00
|
|
|
pmd = pmd_offset(pud, address);
|
|
|
|
if (!pmd_present(*pmd))
|
|
|
|
return 0;
|
|
|
|
|
2008-02-07 05:39:43 +08:00
|
|
|
if (pmd_large(*pmd))
|
|
|
|
return spurious_fault_check(error_code, (pte_t *) pmd);
|
|
|
|
|
2008-01-30 20:34:11 +08:00
|
|
|
pte = pte_offset_kernel(pmd, address);
|
2013-02-23 07:11:49 +08:00
|
|
|
if (!pte_present(*pte))
|
2008-01-30 20:34:11 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-02-20 00:46:36 +08:00
|
|
|
ret = spurious_fault_check(error_code, pte);
|
|
|
|
if (!ret)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* Make sure we have permissions in PMD.
|
|
|
|
* If not, then there's a bug in the page tables:
|
2009-02-20 00:46:36 +08:00
|
|
|
*/
|
|
|
|
ret = spurious_fault_check(error_code, (pte_t *) pmd);
|
|
|
|
WARN_ONCE(!ret, "PMD has incorrect permission bits\n");
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2009-02-20 00:46:36 +08:00
|
|
|
return ret;
|
2008-01-30 20:34:11 +08:00
|
|
|
}
|
2014-04-17 16:18:14 +08:00
|
|
|
NOKPROBE_SYMBOL(spurious_fault);
|
2008-01-30 20:34:11 +08:00
|
|
|
|
2007-07-22 17:12:28 +08:00
|
|
|
int show_unhandled_signals = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
static inline int
|
2010-10-27 05:21:58 +08:00
|
|
|
access_error(unsigned long error_code, struct vm_area_struct *vma)
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
{
|
2016-02-13 05:02:22 +08:00
|
|
|
/* This is only called for the current mm, so: */
|
|
|
|
bool foreign = false;
|
2016-07-30 00:30:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read or write was blocked by protection keys. This is
|
|
|
|
* always an unconditional error and can never result in
|
|
|
|
* a follow-up action to resolve the fault, like a COW.
|
|
|
|
*/
|
|
|
|
if (error_code & PF_PK)
|
|
|
|
return 1;
|
|
|
|
|
2016-02-13 05:02:22 +08:00
|
|
|
/*
|
|
|
|
* Make sure to check the VMA so that we do not perform
|
|
|
|
* faults just to hit a PF_PK as soon as we fill in a
|
|
|
|
* page.
|
|
|
|
*/
|
2016-02-13 05:02:24 +08:00
|
|
|
if (!arch_vma_access_permitted(vma, (error_code & PF_WRITE),
|
|
|
|
(error_code & PF_INSTR), foreign))
|
2016-02-13 05:02:22 +08:00
|
|
|
return 1;
|
mm/gup, x86/mm/pkeys: Check VMAs and PTEs for protection keys
Today, for normal faults and page table walks, we check the VMA
and/or PTE to ensure that it is compatible with the action. For
instance, if we get a write fault on a non-writeable VMA, we
SIGSEGV.
We try to do the same thing for protection keys. Basically, we
try to make sure that if a user does this:
mprotect(ptr, size, PROT_NONE);
*ptr = foo;
they see the same effects with protection keys when they do this:
mprotect(ptr, size, PROT_READ|PROT_WRITE);
set_pkey(ptr, size, 4);
wrpkru(0xffffff3f); // access disable pkey 4
*ptr = foo;
The state to do that checking is in the VMA, but we also
sometimes have to do it on the page tables only, like when doing
a get_user_pages_fast() where we have no VMA.
We add two functions and expose them to generic code:
arch_pte_access_permitted(pte_flags, write)
arch_vma_access_permitted(vma, write)
These are, of course, backed up in x86 arch code with checks
against the PTE or VMA's protection key.
But, there are also cases where we do not want to respect
protection keys. When we ptrace(), for instance, we do not want
to apply the tracer's PKRU permissions to the PTEs from the
process being traced.
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boaz Harrosh <boaz@plexistor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: David Hildenbrand <dahi@linux.vnet.ibm.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>
Cc: Dominik Vogt <vogt@linux.vnet.ibm.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Shachar Raindel <raindel@mellanox.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lkml.kernel.org/r/20160212210219.14D5D715@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-02-13 05:02:19 +08:00
|
|
|
|
2010-10-27 05:21:58 +08:00
|
|
|
if (error_code & PF_WRITE) {
|
2009-02-21 02:56:40 +08:00
|
|
|
/* write, present and write, not present: */
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (unlikely(!(vma->vm_flags & VM_WRITE)))
|
|
|
|
return 1;
|
2009-02-21 02:56:40 +08:00
|
|
|
return 0;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/* read, present: */
|
|
|
|
if (unlikely(error_code & PF_PROT))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* read, not present: */
|
|
|
|
if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
|
|
|
|
return 1;
|
|
|
|
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-05 07:24:09 +08:00
|
|
|
static int fault_in_kernel_space(unsigned long address)
|
|
|
|
{
|
2009-02-21 06:32:28 +08:00
|
|
|
return address >= TASK_SIZE_MAX;
|
2009-02-05 07:24:09 +08:00
|
|
|
}
|
|
|
|
|
2012-09-22 03:43:14 +08:00
|
|
|
static inline bool smap_violation(int error_code, struct pt_regs *regs)
|
|
|
|
{
|
2014-02-13 23:46:04 +08:00
|
|
|
if (!IS_ENABLED(CONFIG_X86_SMAP))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!static_cpu_has(X86_FEATURE_SMAP))
|
|
|
|
return false;
|
|
|
|
|
2012-09-22 03:43:14 +08:00
|
|
|
if (error_code & PF_USER)
|
|
|
|
return false;
|
|
|
|
|
2015-03-19 09:33:33 +08:00
|
|
|
if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
|
2012-09-22 03:43:14 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* This routine handles page faults. It determines the address,
|
|
|
|
* and the problem, and then passes it off to one of the appropriate
|
|
|
|
* routines.
|
2014-03-05 21:07:49 +08:00
|
|
|
*
|
|
|
|
* This function must have noinline because both callers
|
|
|
|
* {,trace_}do_page_fault() have notrace on. Having this an actual function
|
|
|
|
* guarantees there's a function trace entry.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2014-04-17 16:18:14 +08:00
|
|
|
static noinline void
|
2014-03-01 00:05:26 +08:00
|
|
|
__do_page_fault(struct pt_regs *regs, unsigned long error_code,
|
|
|
|
unsigned long address)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-02-21 02:56:40 +08:00
|
|
|
struct vm_area_struct *vma;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct task_struct *tsk;
|
|
|
|
struct mm_struct *mm;
|
2014-12-16 07:07:33 +08:00
|
|
|
int fault, major = 0;
|
2013-09-13 06:13:39 +08:00
|
|
|
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-25 23:30:10 +08:00
|
|
|
tsk = current;
|
|
|
|
mm = tsk->mm;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2008-04-04 06:53:23 +08:00
|
|
|
/*
|
|
|
|
* Detect and handle instructions that would cause a page fault for
|
|
|
|
* both a tracked kernel page and a userspace page.
|
|
|
|
*/
|
|
|
|
if (kmemcheck_active(regs))
|
|
|
|
kmemcheck_hide(regs);
|
2009-06-16 16:23:32 +08:00
|
|
|
prefetchw(&mm->mmap_sem);
|
2008-04-04 06:53:23 +08:00
|
|
|
|
x86: mmiotrace full patch, preview 1
kmmio.c handles the list of mmio probes with callbacks, list of traced
pages, and attaching into the page fault handler and die notifier. It
arms, traps and disarms the given pages, this is the core of mmiotrace.
mmio-mod.c is a user interface, hooking into ioremap functions and
registering the mmio probes. It also decodes the required information
from trapped mmio accesses via the pre and post callbacks in each probe.
Currently, hooking into ioremap functions works by redefining the symbols
of the target (binary) kernel module, so that it calls the traced
versions of the functions.
The most notable changes done since the last discussion are:
- kmmio.c is a built-in, not part of the module
- direct call from fault.c to kmmio.c, removing all dynamic hooks
- prepare for unregistering probes at any time
- make kmmio re-initializable and accessible to more than one user
- rewrite kmmio locking to remove all spinlocks from page fault path
Can I abuse call_rcu() like I do in kmmio.c:unregister_kmmio_probe()
or is there a better way?
The function called via call_rcu() itself calls call_rcu() again,
will this work or break? There I need a second grace period for RCU
after the first grace period for page faults.
Mmiotrace itself (mmio-mod.c) is still a module, I am going to attack
that next. At some point I will start looking into how to make mmiotrace
a tracer component of ftrace (thanks for the hint, Ingo). Ftrace should
make the user space part of mmiotracing as simple as
'cat /debug/trace/mmio > dump.txt'.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-13 03:20:57 +08:00
|
|
|
if (unlikely(kmmio_fault(regs, address)))
|
2008-05-13 03:20:56 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We fault-in kernel-space virtual memory on-demand. The
|
|
|
|
* 'reference' page table is init_mm.pgd.
|
|
|
|
*
|
|
|
|
* NOTE! We MUST NOT take any locks for this case. We may
|
|
|
|
* be in an interrupt or a critical region, and should
|
|
|
|
* only copy the information from the master page table,
|
|
|
|
* nothing more.
|
|
|
|
*
|
|
|
|
* This verifies that the fault happens in kernel space
|
|
|
|
* (error_code & 4) == 0, and that the fault was not a
|
2006-01-12 05:42:23 +08:00
|
|
|
* protection error (error_code & 9) == 0.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-02-05 07:24:09 +08:00
|
|
|
if (unlikely(fault_in_kernel_space(address))) {
|
2008-04-04 06:53:23 +08:00
|
|
|
if (!(error_code & (PF_RSVD | PF_USER | PF_PROT))) {
|
|
|
|
if (vmalloc_fault(address) >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (kmemcheck_fault(regs, address, error_code))
|
|
|
|
return;
|
|
|
|
}
|
2008-01-30 20:34:11 +08:00
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/* Can handle a stale RO->RW TLB: */
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (spurious_fault(error_code, address))
|
2008-01-30 20:34:11 +08:00
|
|
|
return;
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/* kprobes don't want to hook the spurious faults: */
|
2013-10-24 18:52:06 +08:00
|
|
|
if (kprobes_fault(regs))
|
2009-02-06 06:12:39 +08:00
|
|
|
return;
|
2008-01-30 20:34:10 +08:00
|
|
|
/*
|
|
|
|
* Don't take the mm semaphore here. If we fixup a prefetch
|
2009-02-21 02:56:40 +08:00
|
|
|
* fault we could otherwise deadlock:
|
2008-01-30 20:34:10 +08:00
|
|
|
*/
|
2016-02-13 05:02:11 +08:00
|
|
|
bad_area_nosemaphore(regs, error_code, address, NULL);
|
2009-02-21 02:56:40 +08:00
|
|
|
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return;
|
2008-01-30 20:34:10 +08:00
|
|
|
}
|
|
|
|
|
2009-02-21 02:56:40 +08:00
|
|
|
/* kprobes don't want to hook the spurious faults: */
|
2013-10-24 18:52:06 +08:00
|
|
|
if (unlikely(kprobes_fault(regs)))
|
2009-02-06 06:12:39 +08:00
|
|
|
return;
|
2006-03-25 23:29:40 +08:00
|
|
|
|
2006-01-12 05:44:09 +08:00
|
|
|
if (unlikely(error_code & PF_RSVD))
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
pgtable_bad(regs, error_code, address);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-02-13 23:46:04 +08:00
|
|
|
if (unlikely(smap_violation(error_code, regs))) {
|
2016-02-13 05:02:11 +08:00
|
|
|
bad_area_nosemaphore(regs, error_code, address, NULL);
|
2014-02-13 23:46:04 +08:00
|
|
|
return;
|
2012-09-22 03:43:14 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* If we're in an interrupt, have no user context or are running
|
2015-05-11 23:52:11 +08:00
|
|
|
* in a region with pagefaults disabled then we must not take the fault
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2015-05-11 23:52:11 +08:00
|
|
|
if (unlikely(faulthandler_disabled() || !mm)) {
|
2016-02-13 05:02:11 +08:00
|
|
|
bad_area_nosemaphore(regs, error_code, address, NULL);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-24 18:52:06 +08:00
|
|
|
/*
|
|
|
|
* It's safe to allow irq's after cr2 has been saved and the
|
|
|
|
* vmalloc fault has been handled.
|
|
|
|
*
|
|
|
|
* User-mode registers count as a user access even for any
|
|
|
|
* potential system fault or CPU buglet:
|
|
|
|
*/
|
2015-03-19 09:33:33 +08:00
|
|
|
if (user_mode(regs)) {
|
2013-10-24 18:52:06 +08:00
|
|
|
local_irq_enable();
|
|
|
|
error_code |= PF_USER;
|
|
|
|
flags |= FAULT_FLAG_USER;
|
|
|
|
} else {
|
|
|
|
if (regs->flags & X86_EFLAGS_IF)
|
|
|
|
local_irq_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
|
|
|
|
|
2013-09-13 06:13:39 +08:00
|
|
|
if (error_code & PF_WRITE)
|
|
|
|
flags |= FAULT_FLAG_WRITE;
|
2016-02-13 05:02:24 +08:00
|
|
|
if (error_code & PF_INSTR)
|
|
|
|
flags |= FAULT_FLAG_INSTRUCTION;
|
2013-09-13 06:13:39 +08:00
|
|
|
|
2008-10-13 23:49:02 +08:00
|
|
|
/*
|
|
|
|
* When running in the kernel we expect faults to occur only to
|
2009-02-21 02:56:40 +08:00
|
|
|
* addresses in user space. All other faults represent errors in
|
|
|
|
* the kernel and should generate an OOPS. Unfortunately, in the
|
|
|
|
* case of an erroneous fault occurring in a code path which already
|
|
|
|
* holds mmap_sem we will deadlock attempting to validate the fault
|
|
|
|
* against the address space. Luckily the kernel only validly
|
|
|
|
* references user space from well defined areas of code, which are
|
|
|
|
* listed in the exceptions table.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* As the vast majority of faults will be valid we will only perform
|
2009-02-21 02:56:40 +08:00
|
|
|
* the source reference check when there is a possibility of a
|
|
|
|
* deadlock. Attempt to lock the address space, if we cannot we then
|
|
|
|
* validate the source. If this is invalid we can skip the address
|
|
|
|
* space check, thus avoiding the deadlock:
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
|
2006-01-12 05:44:09 +08:00
|
|
|
if ((error_code & PF_USER) == 0 &&
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
!search_exception_tables(regs->ip)) {
|
2016-02-13 05:02:11 +08:00
|
|
|
bad_area_nosemaphore(regs, error_code, address, NULL);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-10-27 05:21:57 +08:00
|
|
|
retry:
|
2005-04-17 06:20:36 +08:00
|
|
|
down_read(&mm->mmap_sem);
|
2009-01-29 23:02:12 +08:00
|
|
|
} else {
|
|
|
|
/*
|
2009-02-21 02:56:40 +08:00
|
|
|
* The above down_read_trylock() might have succeeded in
|
|
|
|
* which case we'll have missed the might_sleep() from
|
|
|
|
* down_read():
|
2009-01-29 23:02:12 +08:00
|
|
|
*/
|
|
|
|
might_sleep();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
vma = find_vma(mm, address);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (unlikely(!vma)) {
|
|
|
|
bad_area(regs, error_code, address);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (likely(vma->vm_start <= address))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto good_area;
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) {
|
|
|
|
bad_area(regs, error_code, address);
|
|
|
|
return;
|
|
|
|
}
|
2008-01-30 20:32:19 +08:00
|
|
|
if (error_code & PF_USER) {
|
2008-01-30 20:33:13 +08:00
|
|
|
/*
|
|
|
|
* Accessing the stack below %sp is always a bug.
|
|
|
|
* The large cushion allows instructions like enter
|
2009-02-21 02:56:40 +08:00
|
|
|
* and pusha to work. ("enter $65535, $31" pushes
|
2008-01-30 20:33:13 +08:00
|
|
|
* 32 pointers and then decrements %sp by 65535.)
|
2006-06-26 19:59:50 +08:00
|
|
|
*/
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
|
|
|
|
bad_area(regs, error_code, address);
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
if (unlikely(expand_stack(vma, address))) {
|
|
|
|
bad_area(regs, error_code, address);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, we have a good vm_area for this memory access, so
|
|
|
|
* we can handle it..
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
good_area:
|
2010-10-27 05:21:58 +08:00
|
|
|
if (unlikely(access_error(error_code, vma))) {
|
2016-02-13 05:02:11 +08:00
|
|
|
bad_area_access_error(regs, error_code, address, vma);
|
x86: optimise x86's do_page_fault (C entry point for the page fault path)
Impact: cleanup, restructure code to improve assembly
gcc isn't _all_ that smart about spilling registers to stack or reusing
stack slots, even with branch annotations. do_page_fault contained a lot
of functionality, so split unlikely paths into their own functions, and
mark them as noinline just to be sure. I consider this actually to be
somewhat of a cleanup too: the main function now contains about half
the number of lines so the normal path is easier to read, while the error
cases are also nicely split away.
Also, ensure the order of arguments to functions is always the same: regs,
addr, error_code. This can reduce code size a tiny bit, and just looks neater
too.
And add a couple of branch annotations.
Before:
do_page_fault:
subq $360, %rsp #,
After:
do_page_fault:
subq $56, %rsp #,
bloat-o-meter:
add/remove: 8/0 grow/shrink: 0/1 up/down: 2222/-1680 (542)
function old new delta
__bad_area_nosemaphore - 506 +506
no_context - 474 +474
vmalloc_fault - 424 +424
spurious_fault - 358 +358
mm_fault_error - 272 +272
bad_area_access_error - 89 +89
bad_area - 89 +89
bad_area_nosemaphore - 10 +10
do_page_fault 2464 784 -1680
Yes, the total size increases by 542 bytes, due to the extra function calls.
But these will very rarely be called (except for vmalloc_fault) in a normal
workload. Importantly, do_page_fault is less than 1/3rd it's original size,
and touches far less stack.
Existing gotos and branch hints did move a lot of the infrequently used text
out of the fastpath, but that's even further improved after this patch.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-01-20 11:24:26 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If for any reason at all we couldn't handle the fault,
|
|
|
|
* make sure we exit gracefully rather than endlessly redo
|
2014-08-07 07:07:24 +08:00
|
|
|
* the fault. Since we never set FAULT_FLAG_RETRY_NOWAIT, if
|
|
|
|
* we get VM_FAULT_RETRY back, the mmap_sem has been unlocked.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2016-07-27 06:25:18 +08:00
|
|
|
fault = handle_mm_fault(vma, address, flags);
|
2014-12-16 07:07:33 +08:00
|
|
|
major |= fault & VM_FAULT_MAJOR;
|
2009-02-21 02:56:40 +08:00
|
|
|
|
2013-09-13 06:13:40 +08:00
|
|
|
/*
|
2014-12-16 07:07:33 +08:00
|
|
|
* If we need to retry the mmap_sem has already been released,
|
|
|
|
* and if there is a fatal signal pending there is no guarantee
|
|
|
|
* that we made any progress. Handle this case first.
|
2013-09-13 06:13:40 +08:00
|
|
|
*/
|
2014-12-16 07:07:33 +08:00
|
|
|
if (unlikely(fault & VM_FAULT_RETRY)) {
|
|
|
|
/* Retry at most once */
|
|
|
|
if (flags & FAULT_FLAG_ALLOW_RETRY) {
|
|
|
|
flags &= ~FAULT_FLAG_ALLOW_RETRY;
|
|
|
|
flags |= FAULT_FLAG_TRIED;
|
|
|
|
if (!fatal_signal_pending(tsk))
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User mode? Just return to handle the fatal exception */
|
2014-12-18 03:52:37 +08:00
|
|
|
if (flags & FAULT_FLAG_USER)
|
2014-12-16 07:07:33 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Not returning to user mode? Handle exceptions or die: */
|
|
|
|
no_context(regs, error_code, address, SIGBUS, BUS_ADRERR);
|
2013-09-13 06:13:40 +08:00
|
|
|
return;
|
2014-12-16 07:07:33 +08:00
|
|
|
}
|
2013-09-13 06:13:40 +08:00
|
|
|
|
2014-12-16 07:07:33 +08:00
|
|
|
up_read(&mm->mmap_sem);
|
2013-09-13 06:13:40 +08:00
|
|
|
if (unlikely(fault & VM_FAULT_ERROR)) {
|
2016-02-13 05:02:11 +08:00
|
|
|
mm_fault_error(regs, error_code, address, vma, fault);
|
2013-09-13 06:13:40 +08:00
|
|
|
return;
|
2011-05-25 08:11:30 +08:00
|
|
|
}
|
|
|
|
|
2010-10-27 05:21:57 +08:00
|
|
|
/*
|
2014-12-16 07:07:33 +08:00
|
|
|
* Major/minor page fault accounting. If any of the events
|
|
|
|
* returned VM_FAULT_MAJOR, we account it as a major fault.
|
2010-10-27 05:21:57 +08:00
|
|
|
*/
|
2014-12-16 07:07:33 +08:00
|
|
|
if (major) {
|
|
|
|
tsk->maj_flt++;
|
|
|
|
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, address);
|
|
|
|
} else {
|
|
|
|
tsk->min_flt++;
|
|
|
|
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address);
|
2009-03-13 19:21:34 +08:00
|
|
|
}
|
2008-01-30 20:33:23 +08:00
|
|
|
|
2009-02-21 05:12:18 +08:00
|
|
|
check_v8086_mode(regs, address, tsk);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2014-04-17 16:18:14 +08:00
|
|
|
NOKPROBE_SYMBOL(__do_page_fault);
|
2012-07-12 02:26:35 +08:00
|
|
|
|
2014-04-17 16:18:14 +08:00
|
|
|
dotraplinkage void notrace
|
2012-07-12 02:26:35 +08:00
|
|
|
do_page_fault(struct pt_regs *regs, unsigned long error_code)
|
|
|
|
{
|
2014-03-05 21:07:49 +08:00
|
|
|
unsigned long address = read_cr2(); /* Get the faulting address */
|
2013-02-24 08:19:14 +08:00
|
|
|
enum ctx_state prev_state;
|
2014-03-05 21:07:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We must have this function tagged with __kprobes, notrace and call
|
|
|
|
* read_cr2() before calling anything else. To avoid calling any kind
|
|
|
|
* of tracing machinery before we've observed the CR2 value.
|
|
|
|
*
|
|
|
|
* exception_{enter,exit}() contain all sorts of tracepoints.
|
|
|
|
*/
|
2013-02-24 08:19:14 +08:00
|
|
|
|
|
|
|
prev_state = exception_enter();
|
2014-03-01 00:05:26 +08:00
|
|
|
__do_page_fault(regs, error_code, address);
|
2013-02-24 08:19:14 +08:00
|
|
|
exception_exit(prev_state);
|
2012-07-12 02:26:35 +08:00
|
|
|
}
|
2014-04-17 16:18:14 +08:00
|
|
|
NOKPROBE_SYMBOL(do_page_fault);
|
2013-10-31 04:37:00 +08:00
|
|
|
|
2014-03-05 21:07:49 +08:00
|
|
|
#ifdef CONFIG_TRACING
|
2014-04-17 16:18:14 +08:00
|
|
|
static nokprobe_inline void
|
|
|
|
trace_page_fault_entries(unsigned long address, struct pt_regs *regs,
|
|
|
|
unsigned long error_code)
|
2013-10-31 04:39:03 +08:00
|
|
|
{
|
|
|
|
if (user_mode(regs))
|
2014-03-05 21:07:49 +08:00
|
|
|
trace_page_fault_user(address, regs, error_code);
|
2013-10-31 04:39:03 +08:00
|
|
|
else
|
2014-03-05 21:07:49 +08:00
|
|
|
trace_page_fault_kernel(address, regs, error_code);
|
2013-10-31 04:39:03 +08:00
|
|
|
}
|
|
|
|
|
2014-04-17 16:18:14 +08:00
|
|
|
dotraplinkage void notrace
|
2013-10-31 04:37:00 +08:00
|
|
|
trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
|
|
|
|
{
|
2014-03-01 00:05:26 +08:00
|
|
|
/*
|
|
|
|
* The exception_enter and tracepoint processing could
|
|
|
|
* trigger another page faults (user space callchain
|
|
|
|
* reading) and destroy the original cr2 value, so read
|
|
|
|
* the faulting address now.
|
|
|
|
*/
|
|
|
|
unsigned long address = read_cr2();
|
2014-03-05 21:07:49 +08:00
|
|
|
enum ctx_state prev_state;
|
2013-10-31 04:37:00 +08:00
|
|
|
|
|
|
|
prev_state = exception_enter();
|
2014-03-05 21:07:49 +08:00
|
|
|
trace_page_fault_entries(address, regs, error_code);
|
2014-03-01 00:05:26 +08:00
|
|
|
__do_page_fault(regs, error_code, address);
|
2013-10-31 04:37:00 +08:00
|
|
|
exception_exit(prev_state);
|
|
|
|
}
|
2014-04-17 16:18:14 +08:00
|
|
|
NOKPROBE_SYMBOL(trace_do_page_fault);
|
2014-03-05 21:07:49 +08:00
|
|
|
#endif /* CONFIG_TRACING */
|