From patchwork Fri May 17 12:56:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Sverdlin X-Patchwork-Id: 244639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 58B832C00B2 for ; Fri, 17 May 2013 22:57:59 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754695Ab3EQM56 (ORCPT ); Fri, 17 May 2013 08:57:58 -0400 Received: from demumfd001.nsn-inter.net ([93.183.12.32]:12765 "EHLO demumfd001.nsn-inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753671Ab3EQM56 (ORCPT ); Fri, 17 May 2013 08:57:58 -0400 Received: from demuprx017.emea.nsn-intra.net ([10.150.129.56]) by demumfd001.nsn-inter.net (8.12.11.20060308/8.12.11) with ESMTP id r4HCuaZC001110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 17 May 2013 14:56:36 +0200 Received: from [10.151.24.91] ([10.151.24.91]) by demuprx017.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id r4HCuZvr013562; Fri, 17 May 2013 14:56:35 +0200 Message-ID: <51962903.9050901@nsn.com> Date: Fri, 17 May 2013 14:56:35 +0200 From: Alexander Sverdlin User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: linux-i2c@vger.kernel.org CC: "Eric W. Biederman" , Tejun Heo , Alan Stern , Peter Zijlstra , Greg Kroah-Hartman Subject: [PATCH] i2c: suppress lockdep warning on delete_device X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 3960 X-purgate-ID: 151667::1368795398-000027C8-E5BE30C9/0-0/0-0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org i2c: suppress lockdep warning on delete_device Since commit 846f99749ab68bbc7f75c74fec305de675b1a1bf the following lockdep warning is thrown in case i2c device is removed (via delete_device sysfs attribute) which contains subdevices (e.g. i2c multiplexer): --- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ============================================= [ INFO: possible recursive locking detected ] 3.8.7-0-sampleversion-fct #8 Tainted: G O --------------------------------------------- bash/3743 is trying to acquire lock: (s_active#110){++++.+}, at: [] sysfs_hash_and_remove+0x58/0xc8 but task is already holding lock: (s_active#110){++++.+}, at: [] sysfs_write_file+0xc8/0x208 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(s_active#110); lock(s_active#110); *** DEADLOCK *** May be due to missing lock nesting notation 4 locks held by bash/3743: #0: (&buffer->mutex){+.+.+.}, at: [] sysfs_write_file+0x4c/0x208 #1: (s_active#110){++++.+}, at: [] sysfs_write_file+0xc8/0x208 #2: (&adap->userspace_clients_lock/1){+.+.+.}, at: [] i2c_sysfs_delete_device+0x90/0x238 #3: (&__lockdep_no_validate__){......}, at: [] device_release_driver+0x24/0x48 stack backtrace: Call Trace: [] dump_stack+0x8/0x34 [] __lock_acquire+0x161c/0x2110 [] lock_acquire+0x4c/0x70 [] sysfs_addrm_finish+0x19c/0x1e0 [] sysfs_hash_and_remove+0x58/0xc8 [] sysfs_remove_group+0x64/0x148 [] device_remove_attrs+0x9c/0x1a8 [] device_del+0x104/0x1d8 [] device_unregister+0x28/0x70 [] i2c_del_adapter+0x1cc/0x328 [] i2c_del_mux_adapter+0x14/0x38 [] pca954x_remove+0x90/0xe0 [pca954x] [] i2c_device_remove+0x80/0xe8 [] __device_release_driver+0x74/0xf8 [] device_release_driver+0x2c/0x48 [] bus_remove_device+0x13c/0x1d8 [] device_del+0x10c/0x1d8 [] device_unregister+0x28/0x70 [] i2c_sysfs_delete_device+0x180/0x238 [] sysfs_write_file+0xe4/0x208 [] vfs_write+0xbc/0x160 [] SyS_write+0x54/0xd8 [] handle_sys64+0x44/0x64 The problem is already known for USB and PCI subsystems. The reason is that delete_device attribute is defined statically in i2c-core.c and used for all devices in i2c subsystem. Discussion of original USB problem: http://lkml.indiana.edu/hypermail/linux/kernel/1204.3/01160.html Commit 356c05d58af05d582e634b54b40050c73609617b introduced new macro to suppress lockdep warnings for this special case and included workaround for USB code. LKML discussion of the workaround: http://lkml.indiana.edu/hypermail/linux/kernel/1205.1/03634.html As i2c case is in principle the same, the same workaround could be used here. Signed-off-by: Alexander Sverdlin Cc: Eric W. Biederman Cc: Tejun Heo Cc: Alan Stern Cc: Peter Zijlstra Cc: Greg Kroah-Hartman --- --- linux-next.orig/drivers/i2c/i2c-core.c +++ linux-next/drivers/i2c/i2c-core.c @@ -892,7 +892,8 @@ i2c_sysfs_delete_device(struct device *d } static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device); -static DEVICE_ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device); +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL, + i2c_sysfs_delete_device); static struct attribute *i2c_adapter_attrs[] = { &dev_attr_name.attr,