From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932696AbXCPLb7 (ORCPT ); Fri, 16 Mar 2007 07:31:59 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932987AbXCPLb7 (ORCPT ); Fri, 16 Mar 2007 07:31:59 -0400 Received: from mx10.go2.pl ([193.17.41.74]:51091 "EHLO poczta.o2.pl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932696AbXCPLb6 (ORCPT ); Fri, 16 Mar 2007 07:31:58 -0400 Date: Fri, 16 Mar 2007 12:36:15 +0100 From: Jarek Poplawski To: Dave Jones , Linux Kernel Cc: Richard Hughes , Philippe Elie , oprofile-list@lists.sourceforge.net Subject: [PATCH] Re: Fwd: oprofile lockdep warning on rc1 Message-ID: <20070316113614.GA5877@ff.dom.local> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070228004641.GC12600@redhat.com> User-Agent: Mutt/1.4.2.2i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On 28-02-2007 01:46, Dave Jones wrote: > This happened on a 2.6.21rc1 kernel. ... > Richard Hughes > Date: > Tue, 27 Feb 2007 21:59:07 +0000 > To: > Development discussions related to Fedora Core > ... > But also I get this (!!!): > > oprofile: using NMI interrupt. > > ================================= > [ INFO: inconsistent lock state ] > 2.6.20-1.2949.fc7 #1 > --------------------------------- > inconsistent {hardirq-on-W} -> {in-hardirq-W} usage. > swapper/0 [HC1[1]:SC0[0]:HE0:SE1] takes: > (oprofilefs_lock){+-..}, at: [] nmi_cpu_setup+0x15/0x4f > [oprofile] > {hardirq-on-W} state was registered at: > [] __lock_acquire+0x448/0xba4 > [] lock_acquire+0x56/0x6f > [] _spin_lock+0x2b/0x38 > [] oprofilefs_ulong_from_user+0x4e/0x74 [oprofile] > [] ulong_write_file+0x2a/0x38 [oprofile] > [] vfs_write+0xaf/0x163 > [] sys_write+0x3d/0x61 > [] syscall_call+0x7/0xb > [] 0xffffffff > irq event stamp: 23424902 > hardirqs last enabled at (23424901): [] > _spin_unlock_irqrestore+0x36/0x3c > hardirqs last disabled at (23424902): [] > call_function_interrupt+0x29/0x38 > softirqs last enabled at (23424892): [] __do_softirq > +0xdc/0xe2 > softirqs last disabled at (23424885): [] do_softirq+0x61/0xd0 > > other info that might help us debug this: > no locks held by swapper/0. > > stack backtrace: > [] show_trace_log_lvl+0x1a/0x2f > [] show_trace+0x12/0x14 > [] dump_stack+0x16/0x18 > [] print_usage_bug+0x141/0x14b > [] mark_lock+0xa2/0x419 > [] __lock_acquire+0x3b9/0xba4 > [] lock_acquire+0x56/0x6f > [] _spin_lock+0x2b/0x38 > [] nmi_cpu_setup+0x15/0x4f [oprofile] > [] smp_call_function_interrupt+0x3f/0x5b > [] call_function_interrupt+0x33/0x38 > [] _spin_unlock+0x16/0x20 > [] clockevents_notify+0x3e/0x42 > [] acpi_state_timer_broadcast+0x2e/0x31 > [] acpi_processor_idle+0x285/0x419 > [] cpu_idle+0xb7/0xdd > [] start_secondary+0x330/0x338 > [<00000000>] 0x0 > ======================= > > Why do the simplest bugs always turn into the most complicated ones ;-) > > Richard. Here is my patch proposal for testing. Regards, Jarek P. lockdep found oprofilefs_lock is taken both in process context (oprofilefs_ulong_from_user()) and from hardirq (nmi_cpu_setup()), so the lockup is possible. Reported-by: Richard Hughes Signed-off-by: Jarek Poplawski --- diff -Nurp linux-2.6.21-rc1-/drivers/oprofile/oprofilefs.c linux-2.6.21-rc1/drivers/oprofile/oprofilefs.c --- linux-2.6.21-rc1-/drivers/oprofile/oprofilefs.c 2007-02-27 10:47:38.000000000 +0100 +++ linux-2.6.21-rc1/drivers/oprofile/oprofilefs.c 2007-03-16 11:36:30.000000000 +0100 @@ -65,6 +65,7 @@ ssize_t oprofilefs_ulong_to_user(unsigne int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) { char tmpbuf[TMPBUFSIZE]; + unsigned long flags; if (!count) return 0; @@ -77,9 +78,9 @@ int oprofilefs_ulong_from_user(unsigned if (copy_from_user(tmpbuf, buf, count)) return -EFAULT; - spin_lock(&oprofilefs_lock); + spin_lock_irqsave(&oprofilefs_lock, flags); *val = simple_strtoul(tmpbuf, NULL, 0); - spin_unlock(&oprofilefs_lock); + spin_unlock_irqrestore(&oprofilefs_lock, flags); return 0; }