linux/arch/mips/kernel
Paul Burton d8550860d9 MIPS: Fix IRQ tracing & lockdep when rescheduling
When the scheduler sets TIF_NEED_RESCHED & we call into the scheduler
from arch/mips/kernel/entry.S we disable interrupts. This is true
regardless of whether we reach work_resched from syscall_exit_work,
resume_userspace or by looping after calling schedule(). Although we
disable interrupts in these paths we don't call trace_hardirqs_off()
before calling into C code which may acquire locks, and we therefore
leave lockdep with an inconsistent view of whether interrupts are
disabled or not when CONFIG_PROVE_LOCKING & CONFIG_DEBUG_LOCKDEP are
both enabled.

Without tracing this interrupt state lockdep will print warnings such
as the following once a task returns from a syscall via
syscall_exit_partial with TIF_NEED_RESCHED set:

[   49.927678] ------------[ cut here ]------------
[   49.934445] WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:3687 check_flags.part.41+0x1dc/0x1e8
[   49.946031] DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled)
[   49.946355] CPU: 0 PID: 1 Comm: init Not tainted 4.10.0-00439-gc9fd5d362289-dirty #197
[   49.963505] Stack : 0000000000000000 ffffffff81bb5d6a 0000000000000006 ffffffff801ce9c4
[   49.974431]         0000000000000000 0000000000000000 0000000000000000 000000000000004a
[   49.985300]         ffffffff80b7e487 ffffffff80a24498 a8000000ff160000 ffffffff80ede8b8
[   49.996194]         0000000000000001 0000000000000000 0000000000000000 0000000077c8030c
[   50.007063]         000000007fd8a510 ffffffff801cd45c 0000000000000000 a8000000ff127c88
[   50.017945]         0000000000000000 ffffffff801cf928 0000000000000001 ffffffff80a24498
[   50.028827]         0000000000000000 0000000000000001 0000000000000000 0000000000000000
[   50.039688]         0000000000000000 a8000000ff127bd0 0000000000000000 ffffffff805509bc
[   50.050575]         00000000140084e0 0000000000000000 0000000000000000 0000000000040a00
[   50.061448]         0000000000000000 ffffffff8010e1b0 0000000000000000 ffffffff805509bc
[   50.072327]         ...
[   50.076087] Call Trace:
[   50.079869] [<ffffffff8010e1b0>] show_stack+0x80/0xa8
[   50.086577] [<ffffffff805509bc>] dump_stack+0x10c/0x190
[   50.093498] [<ffffffff8015dde0>] __warn+0xf0/0x108
[   50.099889] [<ffffffff8015de34>] warn_slowpath_fmt+0x3c/0x48
[   50.107241] [<ffffffff801c15b4>] check_flags.part.41+0x1dc/0x1e8
[   50.114961] [<ffffffff801c239c>] lock_is_held_type+0x8c/0xb0
[   50.122291] [<ffffffff809461b8>] __schedule+0x8c0/0x10f8
[   50.129221] [<ffffffff80946a60>] schedule+0x30/0x98
[   50.135659] [<ffffffff80106278>] work_resched+0x8/0x34
[   50.142397] ---[ end trace 0cb4f6ef5b99fe21 ]---
[   50.148405] possible reason: unannotated irqs-off.
[   50.154600] irq event stamp: 400463
[   50.159566] hardirqs last  enabled at (400463): [<ffffffff8094edc8>] _raw_spin_unlock_irqrestore+0x40/0xa8
[   50.171981] hardirqs last disabled at (400462): [<ffffffff8094eb98>] _raw_spin_lock_irqsave+0x30/0xb0
[   50.183897] softirqs last  enabled at (400450): [<ffffffff8016580c>] __do_softirq+0x4ac/0x6a8
[   50.195015] softirqs last disabled at (400425): [<ffffffff80165e78>] irq_exit+0x110/0x128

Fix this by using the TRACE_IRQS_OFF macro to call trace_hardirqs_off()
when CONFIG_TRACE_IRQFLAGS is enabled. This is done before invoking
schedule() following the work_resched label because:

 1) Interrupts are disabled regardless of the path we take to reach
    work_resched() & schedule().

 2) Performing the tracing here avoids the need to do it in paths which
    disable interrupts but don't call out to C code before hitting a
    path which uses the RESTORE_SOME macro that will call
    trace_hardirqs_on() or trace_hardirqs_off() as appropriate.

We call trace_hardirqs_on() using the TRACE_IRQS_ON macro before calling
syscall_trace_leave() for similar reasons, ensuring that lockdep has a
consistent view of state after we re-enable interrupts.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Cc: linux-mips@linux-mips.org
Cc: stable <stable@vger.kernel.org>
Patchwork: https://patchwork.linux-mips.org/patch/15385/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2017-06-30 04:40:18 +02:00
..
.gitignore
8250-platform.c
asm-offsets.c MIPS: IRQ Stack: Unwind IRQ stack onto task stack 2017-03-22 11:53:57 +01:00
binfmt_elfn32.c fs/binfmt: Convert obsolete cputime type to nsecs 2017-02-01 09:13:51 +01:00
binfmt_elfo32.c fs/binfmt: Convert obsolete cputime type to nsecs 2017-02-01 09:13:51 +01:00
bmips_5xxx_init.S MIPS: BMIPS: Make whitespacely correct. 2016-05-09 12:00:01 +02:00
bmips_vec.S MIPS: BMIPS: Add Whirlwind (BMIPS5200) initialization code 2016-05-09 12:00:01 +02:00
branch.c MIPS: Fix bnezc/jialc return address calculation 2017-06-15 11:47:42 +02:00
cacheinfo.c MIPS: Fix cacheinfo overflow 2017-02-13 18:57:34 +00:00
cevt-bcm1480.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-ds1287.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-gt641xx.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-r4k.c MIPS: cevt-r4k: Fix out-of-bounds array access 2017-04-10 13:31:12 +02:00
cevt-sb1250.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-txx9.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cps-vec-ns16550.S MIPS: CPS: Early debug using an ns16550-compatible UART 2015-11-11 08:34:25 +01:00
cps-vec.S MIPS: smp-cps: Fix retrieval of VPE mask on big endian CPUs 2017-03-21 20:39:40 +01:00
cpu-bugs64.c MIPS: Fix printk continuations in cpu-bugs64.c 2017-01-24 18:30:34 +01:00
cpu-probe.c Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2017-05-12 09:56:30 -07:00
crash.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
crash_dump.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
csrc-bcm1480.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-ioasic.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-r4k.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-sb1250.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
early_printk.c
early_printk_8250.c MIPS: Add 8250/16550 serial early printk driver 2013-10-29 21:24:36 +01:00
elf.c MIPS: Avoid BUG warning in arch_check_elf 2017-04-12 15:22:13 +02:00
entry.S MIPS: Fix IRQ tracing & lockdep when rescheduling 2017-06-30 04:40:18 +02:00
ftrace.c MIPS: ftrace: fix init functions tracing 2017-06-08 14:51:59 +02:00
genex.S MIPS: IRQ Stack: Unwind IRQ stack onto task stack 2017-03-22 11:53:57 +01:00
gpio_txx9.c MIPS: txx9: switch to gpiochip_add_data() 2016-02-19 09:51:44 +01:00
head.S MIPS: head: Reorder instructions missing a delay slot 2017-06-27 23:35:21 +02:00
i8253.c
idle.c MIPS: Loongson: Add Loongson-3A R2 basic support 2016-05-13 14:02:14 +02:00
irq-gt641xx.c
irq-msc01.c MIPS: MSC: Prevent out-of-bounds writes to MIPS SC ioremap'd region 2014-06-26 10:48:23 +01:00
irq-rm7000.c
irq.c MIPS: Introduce irq_stack 2017-01-03 16:34:34 +01:00
irq_txx9.c
jump_label.c jump_label: Rename JUMP_LABEL_{EN,DIS}ABLE to JUMP_LABEL_{JMP,NOP} 2015-08-03 11:34:12 +02:00
kgdb.c MIPS: KGDB: Use kernel context for sleeping threads 2017-04-12 22:29:22 +02:00
kprobes.c MIPS: tracing: disable uprobe/kprobe on compact branch instructions 2016-10-06 17:37:40 +02:00
linux32.c MIPS: Return directly in 32_mmap2() 2017-01-25 02:51:11 +01:00
machine_kexec.c MIPS: kexec: add debug info about the new kexec'ed image 2017-01-03 16:34:46 +01:00
Makefile MIPS: Export {copy, clear}_page functions alongside their definitions 2017-01-03 16:48:39 +01:00
mcount.S MIPS: Export _mcount alongside its definition 2017-01-03 16:34:49 +01:00
mips-cm.c tree-wide: replace config_enabled() with IS_ENABLED() 2016-08-04 08:50:07 -04:00
mips-cpc.c MIPS: CPC: Provide default mips_cpc_default_phys_base to ignore CPC 2016-11-04 00:17:46 +01:00
mips-mt-fpaff.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task.h> 2017-03-02 08:42:35 +01:00
mips-mt.c MIPS: MT: Remove SMTC support 2014-05-24 00:07:01 +02:00
mips-r2-to-r6-emul.c Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2017-05-12 09:56:30 -07:00
mips_machine.c
module-rela.c MIPS: module: fix incorrect IS_ERR_VALUE macro usages 2016-05-13 14:02:11 +02:00
module.c MIPS: Migrate exception table users off module.h and onto extable.h 2016-10-04 16:13:57 +02:00
octeon_switch.S MIPS: Fix octeon FP context switch handling 2015-10-02 19:16:06 +02:00
perf_event.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
perf_event_mipsxx.c MIPS: perf: Remove incorrect odd/even counter handling for I6400 2017-06-08 14:51:58 +02:00
pm-cps.c MIPS: pm-cps: Drop manual cache-line alignment of ready_count 2017-06-30 04:38:55 +02:00
pm.c MIPS: Fix watchpoint restoration 2016-05-09 12:00:02 +02:00
probes-common.h MIPS: tracing: disable uprobe/kprobe on compact branch instructions 2016-10-06 17:37:40 +02:00
proc.c MIPS: Move identification of VP(E) into proc.c from smp-mt.c 2016-10-04 16:13:57 +02:00
process.c kthread: fix boot hang (regression) on MIPS/OpenRISC 2017-05-29 09:40:54 -07:00
prom.c MIPS: Use early_init_fdt_reserve_self to protect DTB location 2017-01-03 16:34:45 +01:00
ptrace.c Merge branch 'regset' (PTRACE_SETREGSET data leakage) 2017-03-29 08:55:25 -07:00
ptrace32.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
r4k_fpu.S MIPS: Use copy_s.fmt rather than copy_u.fmt 2016-05-09 12:00:04 +02:00
r4k_switch.S MIPS: Remove dead define of ST_OFF 2017-04-12 13:52:21 +02:00
r2300_fpu.S MIPS: Correct MIPS I FP sigcontext layout 2016-11-04 01:39:23 +01:00
r2300_switch.S MIPS: Export _save_fp & _save_msa alongside their definitions 2017-01-03 16:34:49 +01:00
r6000_fpu.S MIPS: Fix ISA I/II FP signal context offsets 2016-11-04 01:38:52 +01:00
relocate.c MIPS: KASLR: Add missing header files 2017-04-12 17:02:04 +02:00
relocate_kernel.S MIPS: Replace add and sub instructions in relocate_kernel.S with addiu 2015-08-03 15:26:30 +02:00
reset.c MIPS: Provide fallback reboot/poweroff/halt implementations 2015-04-01 17:21:58 +02:00
rtlx-cmp.c MIPS: APRP: Fix an issue when device_create() fails. 2014-08-01 17:30:35 +02:00
rtlx-mt.c MIPS: APRP: Fix an issue when device_create() fails. 2014-08-01 17:30:35 +02:00
rtlx.c sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
scall32-o32.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
scall64-64.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
scall64-n32.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
scall64-o32.S MIPS: Wire up statx system call 2017-03-08 12:11:13 +01:00
segment.c MIPS: Print segment physical address when EU=1 2016-07-28 11:44:30 +02:00
setup.c MIPS: kexec: Do not reserve invalid crashkernel memory on boot 2017-01-03 16:34:46 +01:00
signal-common.h MIPS: Save MSA extended context around signals 2015-09-03 12:07:59 +02:00
signal.c Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-08-06 09:13:11 -04:00
signal32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal_n32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal_o32.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
smp-bmips.c MIPS: Add missing include files 2017-03-08 10:38:06 +01:00
smp-cmp.c MIPS: Make smp CMP, CPS and MT use the new generic IPI functions 2016-02-25 10:56:58 +01:00
smp-cps.c Merge branch '4.11-fixes' into mips-for-linux-next 2017-04-13 00:48:47 +02:00
smp-mt.c MIPS: smp-mt: Use CPU interrupt controller IPI IRQ domain support 2017-04-12 23:13:13 +02:00
smp-up.c MIPS: SMP: Remove plat_smp_ops cpus_done method. 2014-05-27 11:06:42 +02:00
smp.c MIPS: Stengthen IPI IRQ domain sanity check 2017-04-12 23:13:44 +02:00
spinlock_test.c MIPS: Declare mips_debugfs_dir in a header 2015-10-26 09:49:42 +01:00
spram.c MIPS: Add P6600 cases to CPU switch statements 2016-05-13 14:01:52 +02:00
stacktrace.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
sync-r4k.c MIPS: sync-r4k: Fix KERN_CONT fallout 2017-02-13 18:58:39 +00:00
syscall.c mips: sanitize __access_ok() 2017-04-06 02:08:06 -04:00
sysrq.c MIPS: Refactor dumping of TLB registers for r3k/r4k 2015-09-03 12:07:45 +02:00
time.c KVM: MIPS: Implement VZ support 2017-03-28 14:53:54 +01:00
topology.c
traps.c format-security: move static strings to const 2017-05-08 17:15:14 -07:00
unaligned.c new helper: uaccess_kernel() 2017-03-28 16:43:25 -04:00
uprobes.c MIPS: uprobes: Remove __weak attribute from arch_uprobe_copy_ixol. 2017-01-03 16:34:48 +01:00
vdso.c userfaultfd: non-cooperative: add event for memory unmaps 2017-02-24 17:46:55 -08:00
vmlinux.lds.S debug: Fix __bug_table[] in arch linker scripts 2017-04-03 10:22:40 +02:00
vpe-cmp.c MIPS: APRP: Add VPE loader support for CMP platforms. 2014-01-22 20:19:02 +01:00
vpe-mt.c MIPS: MT: Remove SMTC support 2014-05-24 00:07:01 +02:00
vpe.c module: use a structure to encapsulate layout. 2015-12-04 22:46:25 +01:00
watch.c MIPS: Add and use watch register field definitions 2016-05-13 14:02:13 +02:00