From owner-freebsd-current@FreeBSD.ORG Fri Jan 18 05:45:49 2013 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 69D1BECC for ; Fri, 18 Jan 2013 05:45:49 +0000 (UTC) (envelope-from okuno.kohji@jp.panasonic.com) Received: from smtp.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by mx1.freebsd.org (Postfix) with ESMTP id E6780E2C for ; Fri, 18 Jan 2013 05:45:48 +0000 (UTC) Received: from mail-gw.jp.panasonic.com ([157.8.1.157]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile13) with ESMTP id r0I5jlOs017896 for ; Fri, 18 Jan 2013 14:45:47 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili11) with ESMTP id r0I5jka16587 for ; Fri, 18 Jan 2013 14:45:46 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi17) id r0I5jkwN024042; Fri, 18 Jan 2013 14:45:46 +0900 Received: from localhost by lomi17.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id r0I5jksA024022; Fri, 18 Jan 2013 14:45:46 +0900 Date: Fri, 18 Jan 2013 14:45:38 +0900 (JST) Message-Id: <20130118.144538.1860198911942517633.okuno.kohji@jp.panasonic.com> To: freebsd-current@FreeBSD.org Subject: deadlock between g_event and a thread on removing a device. From: Kohji Okuno Organization: Panasonic Corporation X-Mailer: Mew version 6.5 on Emacs 23.4 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: okuno.kohji@jp.panasonic.com X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jan 2013 05:45:49 -0000 Hi, When I removed a device (ex. /dev/da0), I have encounterd a dead-lock between ``g_event'' thread and a thread that is opening device file (I call this thread as A). Would you refer the following? When the device is removed between dev_refthread() and g_dev_open(), thread A incremented dev->si_threadcount, but can't acquire topology_lock. On the other hand, g_event is waiting to set dev->si_threadcount to 0 with topology_lock. Regards, Kohji Okuno <<< Thread A >>> ... devfs_open() { ... dsw = dev_refthread(dev, &ref); <= increment dev->si_threadcount ... error = dsw->d_open(...); <= call g_dev_open() ... dev_relthread(dev, ref); <= decrement dev->si_threadcount } g_dev_open() { ... g_topology_lock(); <= Thread A couldn't acquire ... topology_lock. } <<< g_event >>> g_run_events() { ... g_topology_lock(); <= g_event acuired topology_lock here. ... one_event() ... } one_event() g_orphan_register() g_dev_orphan() destroy_dev() destroy_dev() destroy_devl() { ... while (dev->si_threadcount != 0) { <= this count was incremented by Thread A /* Use unique dummy wait ident */ msleep(&csw, &devmtx, PRIBIO, "devdrn", hz / 10); } ... }