From owner-freebsd-current@FreeBSD.ORG Wed Aug 1 20:46:59 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 047A5106564A for ; Wed, 1 Aug 2012 20:46:59 +0000 (UTC) (envelope-from edschouten@gmail.com) Received: from mail-gh0-f182.google.com (mail-gh0-f182.google.com [209.85.160.182]) by mx1.freebsd.org (Postfix) with ESMTP id B29008FC15 for ; Wed, 1 Aug 2012 20:46:58 +0000 (UTC) Received: by ghbz22 with SMTP id z22so9095435ghb.13 for ; Wed, 01 Aug 2012 13:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=CvgeXVdC3ONQfLB7sOco4SOH1br2eL0r4oAi2oa0Bw4=; b=RFwDgT4N5brWNq31q004IKOmojPnUIRABiyLnqln6tSMcD7wrFHglINwbsGok7DSX1 6/2F4RU+OxxaHU8lL2og9wg3JAYWQOY7gcFak80fpg0mEncCRUMJzRZtIL+LlIMHmr0K DZLNu0LbQ61DDw/KMI4urFdEc4OYCGLrhGBtmno0Y41Tm3F0dQbPDzTvomlb/06pDOBt FxfpSIG3XJeV0W8S1+EDnB7lj01Y9FLpkVzHkqlmGyfuIEd1aj9IkQcojmtu030MYHHn Sl3Ef6pjtw6ViZnjLLYgNBjsiurEhgkFrR/KU4dkbdIMAVMtEqdtR/5yUBwfCiq+2dQY fyfw== MIME-Version: 1.0 Received: by 10.60.29.161 with SMTP id l1mr31612089oeh.43.1343854018064; Wed, 01 Aug 2012 13:46:58 -0700 (PDT) Sender: edschouten@gmail.com Received: by 10.76.153.195 with HTTP; Wed, 1 Aug 2012 13:46:58 -0700 (PDT) In-Reply-To: <20120801160323.GN2676@deviant.kiev.zoral.com.ua> References: <20120801160323.GN2676@deviant.kiev.zoral.com.ua> Date: Wed, 1 Aug 2012 22:46:58 +0200 X-Google-Sender-Auth: 9i2_6e-4M9vq4gu4gbxklded3SA Message-ID: From: Ed Schouten To: Konstantin Belousov Content-Type: text/plain; charset=UTF-8 Cc: current@freebsd.org Subject: Re: ttydev_cdevsw has no d_purge X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 01 Aug 2012 20:46:59 -0000 Hi Kostik, 2012/8/1 Konstantin Belousov : > I would blame tty subsystem rather then USB subsystem. The d_purge > method of the ttydev_cdevsw is not implemented, but it is the only > measure that can break the deadlocks like the one I described. The > d_purge shall wake up threads sleeping inside devsw methods, which was > specifically added to notify driver about device gone events. I guess d_purge was added quite recently, right? In the current design, the USB code must call into tty_gone() to report that the TTY is no longer associated with an actual device. This shall result in all threads blocking on a TTY to be woken up. Also, it will prevent any further calls into the USB code by the TTY layer. Still, if the processes are not actually interacting with the TTY (e.g. sleep 100000, just waiting for nanosleep() to return), then there is no way the TTY code can actually garbage collect the TTY. It must stay there. Removing the actual TTY would introduce a whole bunch of races and unwanted behaviour. Applications may cache the pathname to the TTY. If the pathname were to be reused by another device, apps would start writing to random TTYs. So that's why TTYs may still stick around in devfs, even though the device underneath went missing. The driver simply calls tty_gone() and leaves the TTY alone. It will die eventually, but you shouldn't wait for it to happen. Still, I seem to remember the USB code does something weird. I think the USB serial driver tries to block until the TTY is actually destroyed. This is a bug, which I've discussed with hselasky@ numerous times. It simply must not do that. -- Ed Schouten