2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
2008-07-02 07:29:44 +08:00
|
|
|
* Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Pentium III FXSR, SSE support
|
|
|
|
* Gareth Hughes <gareth@valinux.com>, May 2000
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-10-04 05:17:11 +08:00
|
|
|
* Handle hardware traps and faults.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/kprobes.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/utsname.h>
|
|
|
|
#include <linux/kdebug.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/kernel.h>
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ptrace.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/string.h>
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <linux/delay.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/errno.h>
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <linux/kexec.h>
|
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/init.h>
|
2006-12-08 18:36:21 +08:00
|
|
|
#include <linux/bug.h>
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <linux/nmi.h>
|
|
|
|
#include <linux/mm.h>
|
2008-10-04 05:17:11 +08:00
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_EISA
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/eisa.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_MCA
|
|
|
|
#include <linux/mca.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-19 16:49:46 +08:00
|
|
|
#if defined(CONFIG_EDAC)
|
|
|
|
#include <linux/edac.h>
|
|
|
|
#endif
|
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <asm/stacktrace.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/debugreg.h>
|
2008-02-26 18:15:50 +08:00
|
|
|
#include <asm/atomic.h>
|
|
|
|
#include <asm/system.h>
|
2008-10-04 05:17:11 +08:00
|
|
|
#include <asm/traps.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/i387.h>
|
2008-10-04 05:17:11 +08:00
|
|
|
|
|
|
|
#include <mach_traps.h>
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/pda.h>
|
|
|
|
#else
|
2008-10-04 05:17:11 +08:00
|
|
|
#include <asm/processor-flags.h>
|
|
|
|
#include <asm/arch_hooks.h>
|
2008-07-15 23:39:13 +08:00
|
|
|
#include <asm/traps.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-10 03:56:11 +08:00
|
|
|
#include "cpu/mcheck/mce.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
asmlinkage int system_call(void);
|
|
|
|
|
|
|
|
/* Do we ignore FPU interrupts ? */
|
2008-02-26 18:15:50 +08:00
|
|
|
char ignore_fpu_irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The IDT has to be page-aligned to simplify the Pentium
|
|
|
|
* F0 0F bug workaround.. We have a special link segment
|
|
|
|
* for this.
|
|
|
|
*/
|
2008-01-30 20:31:12 +08:00
|
|
|
gate_desc idt_table[256]
|
2008-01-30 20:31:11 +08:00
|
|
|
__attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-20 07:23:44 +08:00
|
|
|
DECLARE_BITMAP(used_vectors, NR_VECTORS);
|
|
|
|
EXPORT_SYMBOL_GPL(used_vectors);
|
|
|
|
|
2008-07-02 07:30:30 +08:00
|
|
|
static int ignore_nmis;
|
[PATCH] Notifier chain update: API changes
The kernel's implementation of notifier chains is unsafe. There is no
protection against entries being added to or removed from a chain while the
chain is in use. The issues were discussed in this thread:
http://marc.theaimsgroup.com/?l=linux-kernel&m=113018709002036&w=2
We noticed that notifier chains in the kernel fall into two basic usage
classes:
"Blocking" chains are always called from a process context
and the callout routines are allowed to sleep;
"Atomic" chains can be called from an atomic context and
the callout routines are not allowed to sleep.
We decided to codify this distinction and make it part of the API. Therefore
this set of patches introduces three new, parallel APIs: one for blocking
notifiers, one for atomic notifiers, and one for "raw" notifiers (which is
really just the old API under a new name). New kinds of data structures are
used for the heads of the chains, and new routines are defined for
registration, unregistration, and calling a chain. The three APIs are
explained in include/linux/notifier.h and their implementation is in
kernel/sys.c.
With atomic and blocking chains, the implementation guarantees that the chain
links will not be corrupted and that chain callers will not get messed up by
entries being added or removed. For raw chains the implementation provides no
guarantees at all; users of this API must provide their own protections. (The
idea was that situations may come up where the assumptions of the atomic and
blocking APIs are not appropriate, so it should be possible for users to
handle these things in their own way.)
There are some limitations, which should not be too hard to live with. For
atomic/blocking chains, registration and unregistration must always be done in
a process context since the chain is protected by a mutex/rwsem. Also, a
callout routine for a non-raw chain must not try to register or unregister
entries on its own chain. (This did happen in a couple of places and the code
had to be changed to avoid it.)
Since atomic chains may be called from within an NMI handler, they cannot use
spinlocks for synchronization. Instead we use RCU. The overhead falls almost
entirely in the unregister routine, which is okay since unregistration is much
less frequent that calling a chain.
Here is the list of chains that we adjusted and their classifications. None
of them use the raw API, so for the moment it is only a placeholder.
ATOMIC CHAINS
-------------
arch/i386/kernel/traps.c: i386die_chain
arch/ia64/kernel/traps.c: ia64die_chain
arch/powerpc/kernel/traps.c: powerpc_die_chain
arch/sparc64/kernel/traps.c: sparc64die_chain
arch/x86_64/kernel/traps.c: die_chain
drivers/char/ipmi/ipmi_si_intf.c: xaction_notifier_list
kernel/panic.c: panic_notifier_list
kernel/profile.c: task_free_notifier
net/bluetooth/hci_core.c: hci_notifier
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_chain
net/ipv4/netfilter/ip_conntrack_core.c: ip_conntrack_expect_chain
net/ipv6/addrconf.c: inet6addr_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_chain
net/netfilter/nf_conntrack_core.c: nf_conntrack_expect_chain
net/netlink/af_netlink.c: netlink_chain
BLOCKING CHAINS
---------------
arch/powerpc/platforms/pseries/reconfig.c: pSeries_reconfig_chain
arch/s390/kernel/process.c: idle_chain
arch/x86_64/kernel/process.c idle_notifier
drivers/base/memory.c: memory_chain
drivers/cpufreq/cpufreq.c cpufreq_policy_notifier_list
drivers/cpufreq/cpufreq.c cpufreq_transition_notifier_list
drivers/macintosh/adb.c: adb_client_list
drivers/macintosh/via-pmu.c sleep_notifier_list
drivers/macintosh/via-pmu68k.c sleep_notifier_list
drivers/macintosh/windfarm_core.c wf_client_list
drivers/usb/core/notify.c usb_notifier_list
drivers/video/fbmem.c fb_notifier_list
kernel/cpu.c cpu_chain
kernel/module.c module_notify_list
kernel/profile.c munmap_notifier
kernel/profile.c task_exit_notifier
kernel/sys.c reboot_notifier_list
net/core/dev.c netdev_chain
net/decnet/dn_dev.c: dnaddr_chain
net/ipv4/devinet.c: inetaddr_chain
It's possible that some of these classifications are wrong. If they are,
please let us know or submit a patch to fix them. Note that any chain that
gets called very frequently should be atomic, because the rwsem read-locking
used for blocking chains is very likely to incur cache misses on SMP systems.
(However, if the chain's callout routines may sleep then the chain cannot be
atomic.)
The patch set was written by Alan Stern and Chandra Seetharaman, incorporating
material written by Keith Owens and suggestions from Paul McKenney and Andrew
Morton.
[jes@sgi.com: restructure the notifier chain initialization macros]
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-03-27 17:16:30 +08:00
|
|
|
|
2008-09-10 03:55:55 +08:00
|
|
|
static inline void conditional_sti(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (regs->flags & X86_EFLAGS_IF)
|
|
|
|
local_irq_enable();
|
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:37 +08:00
|
|
|
static inline void preempt_conditional_sti(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
inc_preempt_count();
|
|
|
|
if (regs->flags & X86_EFLAGS_IF)
|
|
|
|
local_irq_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void preempt_conditional_cli(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (regs->flags & X86_EFLAGS_IF)
|
|
|
|
local_irq_disable();
|
|
|
|
dec_preempt_count();
|
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-02-26 18:15:50 +08:00
|
|
|
static inline void
|
|
|
|
die_if_kernel(const char *str, struct pt_regs *regs, long err)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-23 15:08:45 +08:00
|
|
|
if (!user_mode_vm(regs))
|
2005-04-17 06:20:36 +08:00
|
|
|
die(str, regs, err);
|
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:35 +08:00
|
|
|
/*
|
|
|
|
* Perform the lazy TSS's I/O bitmap copy. If the TSS has an
|
|
|
|
* invalid offset set (the LAZY one) and the faulting thread has
|
|
|
|
* a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS,
|
|
|
|
* we set the offset field correctly and return 1.
|
|
|
|
*/
|
|
|
|
static int lazy_iobitmap_copy(void)
|
|
|
|
{
|
|
|
|
struct thread_struct *thread;
|
|
|
|
struct tss_struct *tss;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
cpu = get_cpu();
|
|
|
|
tss = &per_cpu(init_tss, cpu);
|
|
|
|
thread = ¤t->thread;
|
|
|
|
|
|
|
|
if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
|
|
|
|
thread->io_bitmap_ptr) {
|
|
|
|
memcpy(tss->io_bitmap, thread->io_bitmap_ptr,
|
|
|
|
thread->io_bitmap_max);
|
|
|
|
/*
|
|
|
|
* If the previously set map was extending to higher ports
|
|
|
|
* than the current one, pad extra space with 0xff (no access).
|
|
|
|
*/
|
|
|
|
if (thread->io_bitmap_max < tss->io_bitmap_max) {
|
|
|
|
memset((char *) tss->io_bitmap +
|
|
|
|
thread->io_bitmap_max, 0xff,
|
|
|
|
tss->io_bitmap_max - thread->io_bitmap_max);
|
|
|
|
}
|
|
|
|
tss->io_bitmap_max = thread->io_bitmap_max;
|
|
|
|
tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET;
|
|
|
|
tss->io_bitmap_owner = thread;
|
|
|
|
put_cpu();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
put_cpu();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2008-10-01 00:41:35 +08:00
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
static void __kprobes
|
2008-09-26 20:03:08 +08:00
|
|
|
do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
|
2008-02-26 18:15:50 +08:00
|
|
|
long error_code, siginfo_t *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-06-26 05:58:27 +08:00
|
|
|
struct task_struct *tsk = current;
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-03-28 22:56:57 +08:00
|
|
|
if (regs->flags & X86_VM_MASK) {
|
2008-09-26 20:03:08 +08:00
|
|
|
/*
|
|
|
|
* traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
|
|
|
|
* On nmi (interrupt 2), do_trap should not be called.
|
|
|
|
*/
|
|
|
|
if (trapnr < 6)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto vm86_trap;
|
|
|
|
goto trap_signal;
|
|
|
|
}
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-23 15:08:45 +08:00
|
|
|
if (!user_mode(regs))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto kernel_trap;
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-02-26 18:15:50 +08:00
|
|
|
trap_signal:
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2008-02-26 18:15:50 +08:00
|
|
|
/*
|
|
|
|
* We want error_code and trap_no set for userspace faults and
|
|
|
|
* kernelspace faults which result in die(), but not
|
|
|
|
* kernelspace faults which are fixed up. die() gives the
|
|
|
|
* process no chance to handle the signal and notice the
|
|
|
|
* kernel fault information, so that won't result in polluting
|
|
|
|
* the information about previously queued, but not yet
|
|
|
|
* delivered, faults. See also do_general_protection below.
|
|
|
|
*/
|
|
|
|
tsk->thread.error_code = error_code;
|
|
|
|
tsk->thread.trap_no = trapnr;
|
2007-05-03 01:27:05 +08:00
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
|
|
|
|
printk_ratelimit()) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"%s[%d] trap %s ip:%lx sp:%lx error:%lx",
|
|
|
|
tsk->comm, tsk->pid, str,
|
|
|
|
regs->ip, regs->sp, error_code);
|
|
|
|
print_vma_addr(" in ", regs->ip);
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
if (info)
|
|
|
|
force_sig_info(signr, info, tsk);
|
|
|
|
else
|
|
|
|
force_sig(signr, tsk);
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
kernel_trap:
|
|
|
|
if (!fixup_exception(regs)) {
|
|
|
|
tsk->thread.error_code = error_code;
|
|
|
|
tsk->thread.trap_no = trapnr;
|
|
|
|
die(str, regs, error_code);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-02-26 18:15:50 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-02-26 18:15:50 +08:00
|
|
|
vm86_trap:
|
|
|
|
if (handle_vm86_trap((struct kernel_vm86_regs *) regs,
|
|
|
|
error_code, trapnr))
|
|
|
|
goto trap_signal;
|
|
|
|
return;
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
#define DO_ERROR(trapnr, signr, str, name) \
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
|
2008-02-26 18:15:50 +08:00
|
|
|
{ \
|
|
|
|
if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
|
2008-07-02 07:29:44 +08:00
|
|
|
== NOTIFY_STOP) \
|
2008-02-26 18:15:50 +08:00
|
|
|
return; \
|
2008-09-10 03:55:56 +08:00
|
|
|
conditional_sti(regs); \
|
2008-09-26 20:03:08 +08:00
|
|
|
do_trap(trapnr, signr, str, regs, error_code, NULL); \
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 20:03:08 +08:00
|
|
|
#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
|
2008-02-26 18:15:50 +08:00
|
|
|
{ \
|
|
|
|
siginfo_t info; \
|
|
|
|
info.si_signo = signr; \
|
|
|
|
info.si_errno = 0; \
|
|
|
|
info.si_code = sicode; \
|
|
|
|
info.si_addr = (void __user *)siaddr; \
|
|
|
|
if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
|
2008-07-02 07:29:44 +08:00
|
|
|
== NOTIFY_STOP) \
|
2008-02-26 18:15:50 +08:00
|
|
|
return; \
|
2008-09-10 03:55:56 +08:00
|
|
|
conditional_sti(regs); \
|
2008-09-26 20:03:08 +08:00
|
|
|
do_trap(trapnr, signr, str, regs, error_code, &info); \
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-26 20:03:08 +08:00
|
|
|
DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
|
|
|
|
DO_ERROR(4, SIGSEGV, "overflow", overflow)
|
|
|
|
DO_ERROR(5, SIGSEGV, "bounds", bounds)
|
|
|
|
DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
|
2008-09-10 03:56:03 +08:00
|
|
|
DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
|
2008-09-10 03:56:04 +08:00
|
|
|
DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
|
2008-09-10 03:56:05 +08:00
|
|
|
DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-09-10 03:56:06 +08:00
|
|
|
DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2008-09-26 20:03:08 +08:00
|
|
|
DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/* Runs on IST stack */
|
|
|
|
dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)
|
|
|
|
{
|
|
|
|
if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
|
|
|
|
12, SIGBUS) == NOTIFY_STOP)
|
|
|
|
return;
|
|
|
|
preempt_conditional_sti(regs);
|
|
|
|
do_trap(12, SIGBUS, "stack segment", regs, error_code, NULL);
|
|
|
|
preempt_conditional_cli(regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
|
|
|
|
{
|
|
|
|
static const char str[] = "double fault";
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
|
|
|
|
/* Return not checked because double check cannot be ignored */
|
|
|
|
notify_die(DIE_TRAP, str, regs, error_code, 8, SIGSEGV);
|
|
|
|
|
|
|
|
tsk->thread.error_code = error_code;
|
|
|
|
tsk->thread.trap_no = 8;
|
|
|
|
|
2008-12-26 16:20:22 +08:00
|
|
|
/*
|
|
|
|
* This is always a kernel trap and never fixable (and thus must
|
|
|
|
* never return).
|
|
|
|
*/
|
2008-10-04 04:00:39 +08:00
|
|
|
for (;;)
|
|
|
|
die(str, regs, error_code);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void __kprobes
|
2008-07-02 07:32:04 +08:00
|
|
|
do_general_protection(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-07-02 07:32:04 +08:00
|
|
|
struct task_struct *tsk;
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2008-09-10 03:56:07 +08:00
|
|
|
conditional_sti(regs);
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-10-01 00:41:35 +08:00
|
|
|
if (lazy_iobitmap_copy()) {
|
|
|
|
/* restart the faulting instruction */
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-28 22:56:57 +08:00
|
|
|
if (regs->flags & X86_VM_MASK)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto gp_in_vm86;
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-02 07:32:04 +08:00
|
|
|
tsk = current;
|
2005-06-23 15:08:45 +08:00
|
|
|
if (!user_mode(regs))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto gp_in_kernel;
|
|
|
|
|
2008-07-02 07:32:04 +08:00
|
|
|
tsk->thread.error_code = error_code;
|
|
|
|
tsk->thread.trap_no = 13;
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2008-07-02 07:32:04 +08:00
|
|
|
if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
|
|
|
|
printk_ratelimit()) {
|
2007-07-22 17:12:28 +08:00
|
|
|
printk(KERN_INFO
|
2008-07-02 07:32:04 +08:00
|
|
|
"%s[%d] general protection ip:%lx sp:%lx error:%lx",
|
|
|
|
tsk->comm, task_pid_nr(tsk),
|
|
|
|
regs->ip, regs->sp, error_code);
|
2008-01-30 20:33:18 +08:00
|
|
|
print_vma_addr(" in ", regs->ip);
|
|
|
|
printk("\n");
|
|
|
|
}
|
2007-07-22 17:12:28 +08:00
|
|
|
|
2008-07-02 07:32:04 +08:00
|
|
|
force_sig(SIGSEGV, tsk);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
gp_in_vm86:
|
|
|
|
local_irq_enable();
|
|
|
|
handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
|
|
|
|
return;
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
gp_in_kernel:
|
2008-07-02 07:32:04 +08:00
|
|
|
if (fixup_exception(regs))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tsk->thread.error_code = error_code;
|
|
|
|
tsk->thread.trap_no = 13;
|
|
|
|
if (notify_die(DIE_GPF, "general protection fault", regs,
|
2005-04-17 06:20:36 +08:00
|
|
|
error_code, 13, SIGSEGV) == NOTIFY_STOP)
|
2008-07-02 07:32:04 +08:00
|
|
|
return;
|
|
|
|
die("general protection fault", regs, error_code);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:19:55 +08:00
|
|
|
static notrace __kprobes void
|
2008-02-26 18:15:50 +08:00
|
|
|
mem_parity_error(unsigned char reason, struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-26 18:15:50 +08:00
|
|
|
printk(KERN_EMERG
|
|
|
|
"Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
|
|
|
|
reason, smp_processor_id());
|
|
|
|
|
|
|
|
printk(KERN_EMERG
|
|
|
|
"You have some hardware problem, likely on the PCI bus.\n");
|
2007-07-19 16:49:46 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_EDAC)
|
2008-02-26 18:15:50 +08:00
|
|
|
if (edac_handler_set()) {
|
2007-07-19 16:49:46 +08:00
|
|
|
edac_atomic_assert_error();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-26 16:52:27 +08:00
|
|
|
if (panic_on_unrecovered_nmi)
|
2008-02-26 18:15:50 +08:00
|
|
|
panic("NMI: Not continuing");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-26 16:52:27 +08:00
|
|
|
printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Clear and disable the memory parity error line. */
|
2008-10-04 04:00:36 +08:00
|
|
|
reason = (reason & 0xf) | 4;
|
|
|
|
outb(reason, 0x61);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:19:55 +08:00
|
|
|
static notrace __kprobes void
|
2008-02-26 18:15:50 +08:00
|
|
|
io_check_error(unsigned char reason, struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
|
2006-01-10 12:51:32 +08:00
|
|
|
printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
show_registers(regs);
|
|
|
|
|
|
|
|
/* Re-enable the IOCK line, wait for a few seconds */
|
|
|
|
reason = (reason & 0xf) | 8;
|
|
|
|
outb(reason, 0x61);
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
i = 2000;
|
2008-02-26 18:15:50 +08:00
|
|
|
while (--i)
|
|
|
|
udelay(1000);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
reason &= ~8;
|
|
|
|
outb(reason, 0x61);
|
|
|
|
}
|
|
|
|
|
2008-04-20 01:19:55 +08:00
|
|
|
static notrace __kprobes void
|
2008-02-26 18:15:50 +08:00
|
|
|
unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-10-04 05:17:11 +08:00
|
|
|
if (notify_die(DIE_NMIUNKNOWN, "nmi", regs, reason, 2, SIGINT) ==
|
|
|
|
NOTIFY_STOP)
|
2008-02-16 04:55:53 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_MCA
|
2008-02-26 18:15:50 +08:00
|
|
|
/*
|
|
|
|
* Might actually be able to figure out what the guilty party
|
|
|
|
* is:
|
|
|
|
*/
|
|
|
|
if (MCA_bus) {
|
2005-04-17 06:20:36 +08:00
|
|
|
mca_handle_nmi();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-26 18:15:50 +08:00
|
|
|
printk(KERN_EMERG
|
|
|
|
"Uhhuh. NMI received for unknown reason %02x on CPU %d.\n",
|
|
|
|
reason, smp_processor_id());
|
|
|
|
|
2006-09-26 16:52:27 +08:00
|
|
|
printk(KERN_EMERG "Do you have a strange power saving mode enabled?\n");
|
2006-09-26 16:52:27 +08:00
|
|
|
if (panic_on_unrecovered_nmi)
|
2008-02-26 18:15:50 +08:00
|
|
|
panic("NMI: Not continuing");
|
2006-09-26 16:52:27 +08:00
|
|
|
|
2006-09-26 16:52:27 +08:00
|
|
|
printk(KERN_EMERG "Dazed and confused, but trying to continue\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-20 01:19:55 +08:00
|
|
|
static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char reason = 0;
|
2008-07-03 00:39:01 +08:00
|
|
|
int cpu;
|
|
|
|
|
|
|
|
cpu = smp_processor_id();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-03 00:39:01 +08:00
|
|
|
/* Only the BSP gets external NMIs from the system. */
|
|
|
|
if (!cpu)
|
2005-04-17 06:20:36 +08:00
|
|
|
reason = get_nmi_reason();
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(reason & 0xc0)) {
|
2006-03-26 17:37:01 +08:00
|
|
|
if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
|
2008-07-02 07:29:44 +08:00
|
|
|
== NOTIFY_STOP)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
|
|
|
/*
|
|
|
|
* Ok, so this is none of the documented NMI sources,
|
|
|
|
* so it must be the NMI watchdog.
|
|
|
|
*/
|
2006-09-26 16:52:26 +08:00
|
|
|
if (nmi_watchdog_tick(regs, reason))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2008-07-03 00:39:01 +08:00
|
|
|
if (!do_nmi_callback(regs, cpu))
|
2006-09-26 16:52:26 +08:00
|
|
|
unknown_nmi_error(reason, regs);
|
2008-02-26 18:15:50 +08:00
|
|
|
#else
|
|
|
|
unknown_nmi_error(reason, regs);
|
|
|
|
#endif
|
2006-09-26 16:52:27 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2006-03-26 17:37:01 +08:00
|
|
|
if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2008-07-02 07:29:44 +08:00
|
|
|
|
|
|
|
/* AK: following checks seem to be broken on modern chipsets. FIXME */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (reason & 0x80)
|
|
|
|
mem_parity_error(reason, regs);
|
|
|
|
if (reason & 0x40)
|
|
|
|
io_check_error(reason, regs);
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Reassert NMI in case it became active meanwhile
|
2008-02-26 18:15:50 +08:00
|
|
|
* as it's edge-triggered:
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
reassert_nmi();
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage notrace __kprobes void
|
|
|
|
do_nmi(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
nmi_enter();
|
|
|
|
|
2008-12-09 11:19:26 +08:00
|
|
|
inc_irq_stat(__nmi_count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-22 17:12:32 +08:00
|
|
|
if (!ignore_nmis)
|
|
|
|
default_do_nmi(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
nmi_exit();
|
|
|
|
}
|
|
|
|
|
2007-07-22 17:12:32 +08:00
|
|
|
void stop_nmi(void)
|
|
|
|
{
|
|
|
|
acpi_nmi_disable();
|
|
|
|
ignore_nmis++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void restart_nmi(void)
|
|
|
|
{
|
|
|
|
ignore_nmis--;
|
|
|
|
acpi_nmi_enable();
|
|
|
|
}
|
|
|
|
|
2008-10-04 05:17:11 +08:00
|
|
|
/* May run on IST stack. */
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-10 03:55:58 +08:00
|
|
|
#ifdef CONFIG_KPROBES
|
2005-04-17 06:20:36 +08:00
|
|
|
if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
|
|
|
|
== NOTIFY_STOP)
|
2005-05-01 23:58:49 +08:00
|
|
|
return;
|
2008-09-10 03:55:58 +08:00
|
|
|
#else
|
|
|
|
if (notify_die(DIE_TRAP, "int3", regs, error_code, 3, SIGTRAP)
|
|
|
|
== NOTIFY_STOP)
|
|
|
|
return;
|
|
|
|
#endif
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2008-10-04 04:00:34 +08:00
|
|
|
preempt_conditional_sti(regs);
|
2008-09-26 20:03:08 +08:00
|
|
|
do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
|
2008-10-04 04:00:34 +08:00
|
|
|
preempt_conditional_cli(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
2008-12-26 16:20:22 +08:00
|
|
|
/*
|
|
|
|
* Help handler running on IST stack to switch back to user stack
|
|
|
|
* for scheduling or signal handling. The actual stack switch is done in
|
|
|
|
* entry.S
|
|
|
|
*/
|
2008-10-04 04:00:39 +08:00
|
|
|
asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
|
|
|
|
{
|
|
|
|
struct pt_regs *regs = eregs;
|
|
|
|
/* Did already sync */
|
|
|
|
if (eregs == (struct pt_regs *)eregs->sp)
|
|
|
|
;
|
|
|
|
/* Exception from user space */
|
|
|
|
else if (user_mode(eregs))
|
|
|
|
regs = task_pt_regs(current);
|
2008-12-26 16:20:22 +08:00
|
|
|
/*
|
|
|
|
* Exception from kernel and interrupts are enabled. Move to
|
|
|
|
* kernel process stack.
|
|
|
|
*/
|
2008-10-04 04:00:39 +08:00
|
|
|
else if (eregs->flags & X86_EFLAGS_IF)
|
|
|
|
regs = (struct pt_regs *)(eregs->sp -= sizeof(struct pt_regs));
|
|
|
|
if (eregs != regs)
|
|
|
|
*regs = *eregs;
|
|
|
|
return regs;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Our handling of the processor debug registers is non-trivial.
|
|
|
|
* We do not clear them on entry and exit from the kernel. Therefore
|
|
|
|
* it is possible to get a watchpoint trap here from inside the kernel.
|
|
|
|
* However, the code in ./ptrace.c has ensured that the user can
|
|
|
|
* only set watchpoints on userspace addresses. Therefore the in-kernel
|
|
|
|
* watchpoint trap can only occur in code which is reading/writing
|
|
|
|
* from user space. Such code must not hold kernel locks (since it
|
|
|
|
* can equally take a page fault), therefore it is safe to call
|
|
|
|
* force_sig_info even though that claims and releases locks.
|
2008-02-26 18:15:50 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Code in ./signal.c ensures that the debug control register
|
|
|
|
* is restored before we deliver any signal, and therefore that
|
|
|
|
* user code runs with the correct debug control register even though
|
|
|
|
* we clear it here.
|
|
|
|
*
|
|
|
|
* Being careful here means that we don't have to be as careful in a
|
|
|
|
* lot of more complicated places (task switching can be a bit lazy
|
|
|
|
* about restoring all the debug state, and ptrace doesn't have to
|
|
|
|
* find every occurrence of the TF bit that could be saved away even
|
|
|
|
* by user code)
|
2008-10-04 05:17:11 +08:00
|
|
|
*
|
|
|
|
* May run on IST stack.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
2008-10-01 00:41:37 +08:00
|
|
|
unsigned long condition;
|
2008-09-23 17:53:52 +08:00
|
|
|
int si_code;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-23 15:08:43 +08:00
|
|
|
get_debugreg(condition, 6);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:30:54 +08:00
|
|
|
/*
|
|
|
|
* The processor cleared BTF, so don't mark that we need it set.
|
|
|
|
*/
|
|
|
|
clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
|
|
|
|
tsk->thread.debugctlmsr = 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
|
2008-07-02 07:29:44 +08:00
|
|
|
SIGTRAP) == NOTIFY_STOP)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2008-10-01 00:41:37 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* It's safe to allow irq's after DR6 has been saved */
|
2008-10-01 00:41:37 +08:00
|
|
|
preempt_conditional_sti(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Mask out spurious debug traps due to lazy DR7 setting */
|
|
|
|
if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
|
2008-01-30 20:30:59 +08:00
|
|
|
if (!tsk->thread.debugreg7)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto clear_dr7;
|
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-03-28 22:56:57 +08:00
|
|
|
if (regs->flags & X86_VM_MASK)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto debug_vm86;
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Save debug status register where ptrace can see it */
|
2008-01-30 20:30:59 +08:00
|
|
|
tsk->thread.debugreg6 = condition;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Single-stepping through TF: make sure we ignore any events in
|
|
|
|
* kernel space (but re-enable TF when returning to user mode).
|
|
|
|
*/
|
|
|
|
if (condition & DR_STEP) {
|
2005-06-23 15:08:45 +08:00
|
|
|
if (!user_mode(regs))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto clear_TF_reenable;
|
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:37 +08:00
|
|
|
si_code = get_si_code(condition);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Ok, finally something we can handle */
|
2008-09-23 17:53:52 +08:00
|
|
|
send_sigtrap(tsk, regs, error_code, si_code);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
/*
|
|
|
|
* Disable additional traps. They'll be re-enabled when
|
2005-04-17 06:20:36 +08:00
|
|
|
* the signal is delivered.
|
|
|
|
*/
|
|
|
|
clear_dr7:
|
2005-06-23 15:08:43 +08:00
|
|
|
set_debugreg(0, 7);
|
2008-10-01 00:41:37 +08:00
|
|
|
preempt_conditional_cli(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
debug_vm86:
|
|
|
|
handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
|
2008-10-01 00:41:37 +08:00
|
|
|
preempt_conditional_cli(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
clear_TF_reenable:
|
|
|
|
set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
|
2008-03-30 17:45:23 +08:00
|
|
|
regs->flags &= ~X86_EFLAGS_TF;
|
2008-10-01 00:41:37 +08:00
|
|
|
preempt_conditional_cli(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
|
|
|
|
{
|
|
|
|
if (fixup_exception(regs))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
|
|
|
|
/* Illegal floating point operation in the kernel */
|
|
|
|
current->thread.trap_no = trapnr;
|
|
|
|
die(str, regs, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Note that we play around with the 'TS' bit in an attempt to get
|
|
|
|
* the correct behaviour even in the presence of the asynchronous
|
|
|
|
* IRQ13 behaviour
|
|
|
|
*/
|
2008-01-30 20:30:56 +08:00
|
|
|
void math_error(void __user *ip)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-26 18:15:50 +08:00
|
|
|
struct task_struct *task;
|
2005-04-17 06:20:36 +08:00
|
|
|
siginfo_t info;
|
2008-12-23 09:56:05 +08:00
|
|
|
unsigned short cwd, swd, err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the info for the exception handler and clear the error.
|
|
|
|
*/
|
|
|
|
task = current;
|
|
|
|
save_init_fpu(task);
|
|
|
|
task->thread.trap_no = 16;
|
|
|
|
task->thread.error_code = 0;
|
|
|
|
info.si_signo = SIGFPE;
|
|
|
|
info.si_errno = 0;
|
2008-01-30 20:30:56 +08:00
|
|
|
info.si_addr = ip;
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* (~cwd & swd) will mask out exceptions that are not set to unmasked
|
|
|
|
* status. 0x3f is the exception bits in these regs, 0x200 is the
|
|
|
|
* C1 reg you need in case of a stack fault, 0x040 is the stack
|
|
|
|
* fault bit. We should only be taking one exception at a time,
|
|
|
|
* so if this combination doesn't produce any single exception,
|
2008-07-02 07:29:44 +08:00
|
|
|
* then we have a bad program that isn't synchronizing its FPU usage
|
2005-04-17 06:20:36 +08:00
|
|
|
* and it will suffer the consequences since we won't be able to
|
|
|
|
* fully reproduce the context of the exception
|
|
|
|
*/
|
|
|
|
cwd = get_fpu_cwd(task);
|
|
|
|
swd = get_fpu_swd(task);
|
2008-12-23 09:56:05 +08:00
|
|
|
|
2008-12-26 02:39:01 +08:00
|
|
|
err = swd & ~cwd;
|
2008-12-23 09:56:05 +08:00
|
|
|
|
|
|
|
if (err & 0x001) { /* Invalid op */
|
2008-02-26 18:15:50 +08:00
|
|
|
/*
|
|
|
|
* swd & 0x240 == 0x040: Stack Underflow
|
|
|
|
* swd & 0x240 == 0x240: Stack Overflow
|
|
|
|
* User must clear the SF bit (0x40) if set
|
|
|
|
*/
|
|
|
|
info.si_code = FPE_FLTINV;
|
2008-12-23 09:56:05 +08:00
|
|
|
} else if (err & 0x004) { /* Divide by Zero */
|
2008-02-26 18:15:50 +08:00
|
|
|
info.si_code = FPE_FLTDIV;
|
2008-12-23 09:56:05 +08:00
|
|
|
} else if (err & 0x008) { /* Overflow */
|
2008-02-26 18:15:50 +08:00
|
|
|
info.si_code = FPE_FLTOVF;
|
2008-12-23 09:56:05 +08:00
|
|
|
} else if (err & 0x012) { /* Denormal, Underflow */
|
|
|
|
info.si_code = FPE_FLTUND;
|
|
|
|
} else if (err & 0x020) { /* Precision */
|
2008-02-26 18:15:50 +08:00
|
|
|
info.si_code = FPE_FLTRES;
|
2008-12-23 09:56:05 +08:00
|
|
|
} else {
|
2008-12-26 16:20:22 +08:00
|
|
|
/*
|
|
|
|
* If we're using IRQ 13, or supposedly even some trap 16
|
|
|
|
* implementations, it's possible we get a spurious trap...
|
|
|
|
*/
|
2008-12-26 02:39:01 +08:00
|
|
|
return; /* Spurious trap, no error */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
force_sig_info(SIGFPE, &info, task);
|
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-10 03:56:09 +08:00
|
|
|
conditional_sti(regs);
|
2008-10-04 04:00:39 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
ignore_fpu_irq = 1;
|
2008-10-04 04:00:39 +08:00
|
|
|
#else
|
|
|
|
if (!user_mode(regs) &&
|
|
|
|
kernel_math_error(regs, "kernel x87 math error", 16))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2008-01-30 20:30:56 +08:00
|
|
|
math_error((void __user *)regs->ip);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 20:30:56 +08:00
|
|
|
static void simd_math_error(void __user *ip)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-26 18:15:50 +08:00
|
|
|
struct task_struct *task;
|
|
|
|
siginfo_t info;
|
2008-07-02 07:33:14 +08:00
|
|
|
unsigned short mxcsr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the info for the exception handler and clear the error.
|
|
|
|
*/
|
|
|
|
task = current;
|
|
|
|
save_init_fpu(task);
|
|
|
|
task->thread.trap_no = 19;
|
|
|
|
task->thread.error_code = 0;
|
|
|
|
info.si_signo = SIGFPE;
|
|
|
|
info.si_errno = 0;
|
|
|
|
info.si_code = __SI_FAULT;
|
2008-01-30 20:30:56 +08:00
|
|
|
info.si_addr = ip;
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* The SIMD FPU exceptions are handled a little differently, as there
|
|
|
|
* is only a single status/control register. Thus, to determine which
|
|
|
|
* unmasked exception was caught we must mask the exception mask bits
|
|
|
|
* at 0x1f80, and then use these to mask the exception bits at 0x3f.
|
|
|
|
*/
|
|
|
|
mxcsr = get_fpu_mxcsr(task);
|
|
|
|
switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
|
2008-02-26 18:15:50 +08:00
|
|
|
case 0x000:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case 0x001: /* Invalid Op */
|
|
|
|
info.si_code = FPE_FLTINV;
|
|
|
|
break;
|
|
|
|
case 0x002: /* Denormalize */
|
|
|
|
case 0x010: /* Underflow */
|
|
|
|
info.si_code = FPE_FLTUND;
|
|
|
|
break;
|
|
|
|
case 0x004: /* Zero Divide */
|
|
|
|
info.si_code = FPE_FLTDIV;
|
|
|
|
break;
|
|
|
|
case 0x008: /* Overflow */
|
|
|
|
info.si_code = FPE_FLTOVF;
|
|
|
|
break;
|
|
|
|
case 0x020: /* Precision */
|
|
|
|
info.si_code = FPE_FLTRES;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
force_sig_info(SIGFPE, &info, task);
|
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void
|
|
|
|
do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-10 03:56:12 +08:00
|
|
|
conditional_sti(regs);
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cpu_has_xmm) {
|
|
|
|
/* Handle SIMD FPU exceptions on PIII+ processors. */
|
|
|
|
ignore_fpu_irq = 1;
|
2008-01-30 20:30:56 +08:00
|
|
|
simd_math_error((void __user *)regs->ip);
|
2008-02-26 18:15:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Handle strange cache flush from user space exception
|
|
|
|
* in all other cases. This is undocumented behaviour.
|
|
|
|
*/
|
2008-03-28 22:56:57 +08:00
|
|
|
if (regs->flags & X86_VM_MASK) {
|
2008-02-26 18:15:50 +08:00
|
|
|
handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-02-26 18:15:50 +08:00
|
|
|
current->thread.trap_no = 19;
|
|
|
|
current->thread.error_code = error_code;
|
|
|
|
die_if_kernel("cache flush denied", regs, error_code);
|
|
|
|
force_sig(SIGSEGV, current);
|
2008-10-04 04:00:39 +08:00
|
|
|
#else
|
|
|
|
if (!user_mode(regs) &&
|
|
|
|
kernel_math_error(regs, "kernel simd math error", 19))
|
|
|
|
return;
|
|
|
|
simd_math_error((void __user *)regs->ip);
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void
|
|
|
|
do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-10 03:56:08 +08:00
|
|
|
conditional_sti(regs);
|
2005-04-17 06:20:36 +08:00
|
|
|
#if 0
|
|
|
|
/* No need to warn about this any longer. */
|
2008-02-26 18:15:50 +08:00
|
|
|
printk(KERN_INFO "Ignoring P6 Local APIC Spurious Interrupt Bug...\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-02-26 18:15:50 +08:00
|
|
|
unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-05-28 11:14:51 +08:00
|
|
|
struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
|
2006-12-07 09:14:01 +08:00
|
|
|
unsigned long base = (kesp - uesp) & -THREAD_SIZE;
|
|
|
|
unsigned long new_kesp = kesp - base;
|
|
|
|
unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
|
|
|
|
__u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2006-12-07 09:14:01 +08:00
|
|
|
/* Set up base for espfix segment */
|
2008-02-26 18:15:50 +08:00
|
|
|
desc &= 0x00f0ff0000000000ULL;
|
|
|
|
desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
|
2006-12-07 09:14:01 +08:00
|
|
|
((((__u64)base) << 32) & 0xff00000000000000ULL) |
|
|
|
|
((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
|
|
|
|
(lim_pages & 0xffff);
|
|
|
|
*(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2006-12-07 09:14:01 +08:00
|
|
|
return new_kesp;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-10-04 04:00:39 +08:00
|
|
|
#else
|
|
|
|
asmlinkage void __attribute__((weak)) smp_thermal_interrupt(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2008-02-26 18:15:50 +08:00
|
|
|
* 'math_state_restore()' saves the current math information in the
|
2005-04-17 06:20:36 +08:00
|
|
|
* old math state array, and gets the new ones from the current task
|
|
|
|
*
|
|
|
|
* Careful.. There are problems with IBM-designed IRQ13 behaviour.
|
|
|
|
* Don't touch unless you *really* know how it works.
|
|
|
|
*
|
|
|
|
* Must be called with kernel preemption disabled (in this case,
|
|
|
|
* local interrupts are disabled at the call-site in entry.S).
|
|
|
|
*/
|
2006-12-07 09:14:01 +08:00
|
|
|
asmlinkage void math_state_restore(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct thread_info *thread = current_thread_info();
|
|
|
|
struct task_struct *tsk = thread->task;
|
|
|
|
|
2008-03-11 06:28:05 +08:00
|
|
|
if (!tsk_used_math(tsk)) {
|
|
|
|
local_irq_enable();
|
|
|
|
/*
|
|
|
|
* does a slab alloc which can sleep
|
|
|
|
*/
|
|
|
|
if (init_fpu(tsk)) {
|
|
|
|
/*
|
|
|
|
* ran out of memory!
|
|
|
|
*/
|
|
|
|
do_group_exit(SIGKILL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
local_irq_disable();
|
|
|
|
}
|
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
clts(); /* Allow maths ops (or we recurse) */
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
restore_fpu(tsk);
|
2008-10-04 04:00:39 +08:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Paranoid restore. send a SIGSEGV if we fail to restore the state.
|
|
|
|
*/
|
|
|
|
if (unlikely(restore_fpu_checking(tsk))) {
|
|
|
|
stts();
|
|
|
|
force_sig(SIGSEGV, tsk);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
thread->status |= TS_USEDFPU; /* So we fnsave on switch_to() */
|
2006-12-07 09:14:01 +08:00
|
|
|
tsk->fpu_counter++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-07-19 16:49:21 +08:00
|
|
|
EXPORT_SYMBOL_GPL(math_state_restore);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifndef CONFIG_MATH_EMULATION
|
|
|
|
asmlinkage void math_emulate(long arg)
|
|
|
|
{
|
2008-02-26 18:15:50 +08:00
|
|
|
printk(KERN_EMERG
|
|
|
|
"math-emulation not enabled and no coprocessor found.\n");
|
|
|
|
printk(KERN_EMERG "killing %s.\n", current->comm);
|
|
|
|
force_sig(SIGFPE, current);
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule();
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MATH_EMULATION */
|
|
|
|
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void __kprobes
|
|
|
|
do_device_not_available(struct pt_regs *regs, long error)
|
2008-09-10 03:56:02 +08:00
|
|
|
{
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-09-10 03:56:02 +08:00
|
|
|
if (read_cr0() & X86_CR0_EM) {
|
|
|
|
conditional_sti(regs);
|
|
|
|
math_emulate(0);
|
|
|
|
} else {
|
|
|
|
math_state_restore(); /* interrupts still off */
|
|
|
|
conditional_sti(regs);
|
|
|
|
}
|
2008-10-04 04:00:39 +08:00
|
|
|
#else
|
|
|
|
math_state_restore();
|
|
|
|
#endif
|
2008-09-10 03:56:02 +08:00
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-10-01 00:41:36 +08:00
|
|
|
dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code)
|
2008-09-10 03:56:13 +08:00
|
|
|
{
|
|
|
|
siginfo_t info;
|
|
|
|
local_irq_enable();
|
|
|
|
|
|
|
|
info.si_signo = SIGILL;
|
|
|
|
info.si_errno = 0;
|
|
|
|
info.si_code = ILL_BADSTK;
|
|
|
|
info.si_addr = 0;
|
|
|
|
if (notify_die(DIE_TRAP, "iret exception",
|
|
|
|
regs, error_code, 32, SIGILL) == NOTIFY_STOP)
|
|
|
|
return;
|
2008-09-26 20:03:08 +08:00
|
|
|
do_trap(32, SIGILL, "iret exception", regs, error_code, &info);
|
2008-09-10 03:56:13 +08:00
|
|
|
}
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2008-09-10 03:56:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void __init trap_init(void)
|
|
|
|
{
|
2007-10-20 02:35:03 +08:00
|
|
|
int i;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_EISA
|
2008-01-30 20:33:49 +08:00
|
|
|
void __iomem *p = early_ioremap(0x0FFFD9, 4);
|
2008-02-26 18:15:50 +08:00
|
|
|
|
|
|
|
if (readl(p) == 'E' + ('I'<<8) + ('S'<<16) + ('A'<<24))
|
2005-04-17 06:20:36 +08:00
|
|
|
EISA_bus = 1;
|
2008-01-30 20:33:49 +08:00
|
|
|
early_iounmap(p, 4);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2008-09-10 03:55:57 +08:00
|
|
|
set_intr_gate(0, ÷_error);
|
2008-10-04 04:00:32 +08:00
|
|
|
set_intr_gate_ist(1, &debug, DEBUG_STACK);
|
|
|
|
set_intr_gate_ist(2, &nmi, NMI_STACK);
|
|
|
|
/* int3 can be called from all */
|
|
|
|
set_system_intr_gate_ist(3, &int3, DEBUG_STACK);
|
|
|
|
/* int4 can be called from all */
|
|
|
|
set_system_intr_gate(4, &overflow);
|
2008-09-10 03:56:00 +08:00
|
|
|
set_intr_gate(5, &bounds);
|
2008-09-10 03:56:01 +08:00
|
|
|
set_intr_gate(6, &invalid_op);
|
2008-09-10 03:56:02 +08:00
|
|
|
set_intr_gate(7, &device_not_available);
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-07-02 07:29:44 +08:00
|
|
|
set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
|
2008-10-04 04:00:39 +08:00
|
|
|
#else
|
|
|
|
set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
|
|
|
|
#endif
|
2008-09-10 03:56:03 +08:00
|
|
|
set_intr_gate(9, &coprocessor_segment_overrun);
|
2008-09-10 03:56:04 +08:00
|
|
|
set_intr_gate(10, &invalid_TSS);
|
2008-09-10 03:56:05 +08:00
|
|
|
set_intr_gate(11, &segment_not_present);
|
2008-10-04 04:00:32 +08:00
|
|
|
set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
|
2008-09-10 03:56:07 +08:00
|
|
|
set_intr_gate(13, &general_protection);
|
2008-02-26 18:15:50 +08:00
|
|
|
set_intr_gate(14, &page_fault);
|
2008-09-10 03:56:08 +08:00
|
|
|
set_intr_gate(15, &spurious_interrupt_bug);
|
2008-09-10 03:56:09 +08:00
|
|
|
set_intr_gate(16, &coprocessor_error);
|
2008-09-10 03:56:10 +08:00
|
|
|
set_intr_gate(17, &alignment_check);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_X86_MCE
|
2008-10-04 04:00:32 +08:00
|
|
|
set_intr_gate_ist(18, &machine_check, MCE_STACK);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2008-09-10 03:56:12 +08:00
|
|
|
set_intr_gate(19, &simd_coprocessor_error);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
|
|
|
set_system_intr_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
2006-01-06 16:11:49 +08:00
|
|
|
if (cpu_has_fxsr) {
|
|
|
|
printk(KERN_INFO "Enabling fast FPU save and restore... ");
|
|
|
|
set_in_cr4(X86_CR4_OSFXSR);
|
|
|
|
printk("done.\n");
|
|
|
|
}
|
|
|
|
if (cpu_has_xmm) {
|
2008-02-26 18:15:50 +08:00
|
|
|
printk(KERN_INFO
|
|
|
|
"Enabling unmasked SIMD FPU exception support... ");
|
2006-01-06 16:11:49 +08:00
|
|
|
set_in_cr4(X86_CR4_OSXMMEXCPT);
|
|
|
|
printk("done.\n");
|
|
|
|
}
|
|
|
|
|
2008-10-04 04:00:32 +08:00
|
|
|
set_system_trap_gate(SYSCALL_VECTOR, &system_call);
|
2008-12-20 07:23:44 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-26 18:15:50 +08:00
|
|
|
/* Reserve all the builtin and the syscall vector: */
|
2007-10-20 02:35:03 +08:00
|
|
|
for (i = 0; i < FIRST_EXTERNAL_VECTOR; i++)
|
|
|
|
set_bit(i, used_vectors);
|
2008-02-26 18:15:50 +08:00
|
|
|
|
2008-12-20 07:23:44 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
set_bit(IA32_SYSCALL_VECTOR, used_vectors);
|
|
|
|
#else
|
2007-10-20 02:35:03 +08:00
|
|
|
set_bit(SYSCALL_VECTOR, used_vectors);
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2008-02-26 18:15:50 +08:00
|
|
|
* Should be a barrier for any external CPU state:
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
cpu_init();
|
|
|
|
|
2008-10-04 04:00:39 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2005-04-17 06:20:36 +08:00
|
|
|
trap_init_hook();
|
2008-10-04 04:00:39 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|