Commit e8bff74afbdb4ad72bf6135c84289c47cf557892

Authored by Ingo Molnar
1 parent e760e716d4

x86: fix "BUG: sleeping function called from invalid context" in print_vma_addr()

Jiri Kosina reported the following deadlock scenario with
show_unhandled_signals enabled:

 [   68.379022] gnome-settings-[2941] trap int3 ip:3d2c840f34
 sp:7fff36f5d100 error:0<3>BUG: sleeping function called from invalid
 context at kernel/rwsem.c:21
 [   68.379039] in_atomic():1, irqs_disabled():0
 [   68.379044] no locks held by gnome-settings-/2941.
 [   68.379050] Pid: 2941, comm: gnome-settings- Not tainted 2.6.25-rc1 #30
 [   68.379054]
 [   68.379056] Call Trace:
 [   68.379061]  <#DB>  [<ffffffff81064883>] ? __debug_show_held_locks+0x13/0x30
 [   68.379109]  [<ffffffff81036765>] __might_sleep+0xe5/0x110
 [   68.379123]  [<ffffffff812f2240>] down_read+0x20/0x70
 [   68.379137]  [<ffffffff8109cdca>] print_vma_addr+0x3a/0x110
 [   68.379152]  [<ffffffff8100f435>] do_trap+0xf5/0x170
 [   68.379168]  [<ffffffff8100f52b>] do_int3+0x7b/0xe0
 [   68.379180]  [<ffffffff812f4a6f>] int3+0x9f/0xd0
 [   68.379203]  <<EOE>>
 [   68.379229]  in libglib-2.0.so.0.1505.0[3d2c800000+dc000]

and tracked it down to:

  commit 03252919b79891063cf99145612360efbdf9500b
  Author: Andi Kleen <ak@suse.de>
  Date:   Wed Jan 30 13:33:18 2008 +0100

      x86: print which shared library/executable faulted in segfault etc. messages

the problem is that we call down_read() from an atomic context.

Solve this by returning from print_vma_addr() if the preempt count is
elevated. Update preempt_conditional_sti / preempt_conditional_cli to
unconditionally lift the preempt count even on !CONFIG_PREEMPT.

Reported-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 2 changed files with 9 additions and 2 deletions Side-by-side Diff

arch/x86/kernel/traps_64.c
... ... @@ -84,7 +84,7 @@
84 84  
85 85 static inline void preempt_conditional_sti(struct pt_regs *regs)
86 86 {
87   - preempt_disable();
  87 + inc_preempt_count();
88 88 if (regs->flags & X86_EFLAGS_IF)
89 89 local_irq_enable();
90 90 }
... ... @@ -95,7 +95,7 @@
95 95 local_irq_disable();
96 96 /* Make sure to not schedule here because we could be running
97 97 on an exception stack. */
98   - preempt_enable_no_resched();
  98 + dec_preempt_count();
99 99 }
100 100  
101 101 int kstack_depth_to_print = 12;
... ... @@ -2711,6 +2711,13 @@
2711 2711 struct mm_struct *mm = current->mm;
2712 2712 struct vm_area_struct *vma;
2713 2713  
  2714 + /*
  2715 + * Do not print if we are in atomic
  2716 + * contexts (in exception stacks, etc.):
  2717 + */
  2718 + if (preempt_count())
  2719 + return;
  2720 +
2714 2721 down_read(&mm->mmap_sem);
2715 2722 vma = find_vma(mm, ip);
2716 2723 if (vma && vma->vm_file) {