From: Markus Armbruster Subject: Re: [PATCH 1/3] xenoprof fixes: sleep with interrupts disabled Date: Mon, 15 May 2006 19:33:51 +0200 Message-ID: <87ejyv19c0.fsf@pike.pond.sub.org> References: <87hd3r2qst.fsf@pike.pond.sub.org> <87d5ef2qrk.fsf@pike.pond.sub.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: In-Reply-To: <87d5ef2qrk.fsf@pike.pond.sub.org> (Markus Armbruster's message of "Mon, 15 May 2006 18:31:59 +0200") List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Ill-advised use of on_each_cpu() can lead to sleep with interrupts disabled. This is best explained with a backtrace: BUG: sleeping function called from invalid context at /home/armbru/linux-2.6.tip-xen-quintela.hg/mm/slab.c:2783 in_atomic():0, irqs_disabled():1 [] show_trace+0x13/0x15 [] dump_stack+0x18/0x1c [] __might_sleep+0x9f/0xa7 [] __kmalloc+0x65/0x110 [] proc_create+0x8d/0xe2 [] proc_mkdir_mode+0x1a/0x4d [] proc_mkdir+0x13/0x15 [] register_handler_proc+0x90/0x9e [] setup_irq+0xdf/0xf5 [] request_irq+0x6a/0x8a [] bind_virq_to_irqhandler+0xe3/0x101 [] bind_virq_cpu+0x28/0x62 [oprofile] [] on_each_cpu+0x36/0x5d [] xenoprof_setup+0x22/0x14a [oprofile] [] oprofile_setup+0x45/0x8b [oprofile] [] event_buffer_open+0x3e/0x62 [oprofile] [] __dentry_open+0xc7/0x1b0 [] nameidata_to_filp+0x20/0x34 [] do_filp_open+0x30/0x39 [] do_sys_open+0x40/0xb0 [] sys_open+0x13/0x15 [] syscall_call+0x7/0xb on_each_cpu() disables interrupts. proc_create() calls passes GFP_KERNEL to kmalloc(). The patch converts from on_each_cpu() to for_each_cpu(), and then simplifies things. Signed-off-by: Markus Armbruster diff -rup linux-2.6.16.13-xen/arch/i386/oprofile/xenoprof.c linux-2.6.16.13-xen.patched-1/arch/i386/oprofile/xenoprof.c --- linux-2.6.16.13-xen/arch/i386/oprofile/xenoprof.c 2006-05-15 10:32:22.000000000 +0200 +++ linux-2.6.16.13-xen.patched-1/arch/i386/oprofile/xenoprof.c 2006-05-15 10:30:49.000000000 +0200 @@ -141,56 +141,40 @@ xenoprof_ovf_interrupt(int irq, void * d } -static void unbind_virq_cpu(void * info) -{ - int cpu = smp_processor_id(); - if (ovf_irq[cpu] >= 0) { - unbind_from_irqhandler(ovf_irq[cpu], NULL); - ovf_irq[cpu] = -1; - } -} - - static void unbind_virq(void) { - on_each_cpu(unbind_virq_cpu, NULL, 0, 1); -} - - -int bind_virq_error; - -static void bind_virq_cpu(void * info) -{ - int result; - int cpu = smp_processor_id(); + int i; - result = bind_virq_to_irqhandler(VIRQ_XENOPROF, - cpu, - xenoprof_ovf_interrupt, - SA_INTERRUPT, - "xenoprof", - NULL); - - if (result<0) { - bind_virq_error = result; - printk("xenoprof.c: binding VIRQ_XENOPROF to IRQ failed on CPU " - "%d\n", cpu); - } else { - ovf_irq[cpu] = result; + for_each_cpu(i) { + if (ovf_irq[i] >= 0) { + unbind_from_irqhandler(ovf_irq[i], NULL); + ovf_irq[i] = -1; + } } } static int bind_virq(void) { - bind_virq_error = 0; - on_each_cpu(bind_virq_cpu, NULL, 0, 1); - if (bind_virq_error) { - unbind_virq(); - return bind_virq_error; - } else { - return 0; + int i, result; + + for_each_cpu(i) { + result = bind_virq_to_irqhandler(VIRQ_XENOPROF, + i, + xenoprof_ovf_interrupt, + SA_INTERRUPT, + "xenoprof", + NULL); + + if (result < 0) { + unbind_virq(); + return result; + } + + ovf_irq[i] = result; } + + return 0; }