From owner-freebsd-bugs@FreeBSD.ORG Mon Dec 13 04:45:34 2004 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5FECE16A4CE for ; Mon, 13 Dec 2004 04:45:34 +0000 (GMT) Received: from mailout2.pacific.net.au (mailout2.pacific.net.au [61.8.0.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id BBB6A43D39 for ; Mon, 13 Dec 2004 04:45:33 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87])iBD4j4KP000319; Mon, 13 Dec 2004 15:45:04 +1100 Received: from epsplex.bde.org (katana.zip.com.au [61.8.7.246]) iBD4ix7M010697; Mon, 13 Dec 2004 15:45:01 +1100 Date: Mon, 13 Dec 2004 15:44:59 +1100 (EST) From: Bruce Evans X-X-Sender: bde@epsplex.bde.org To: Julian Elischer In-Reply-To: <41BBCC16.9040909@elischer.org> Message-ID: <20041213131051.W2647@epsplex.bde.org> References: <41BBCC16.9040909@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: cejkar@fit.vutbr.cz cc: danny@cs.huji.ac.il cc: freebsd-bugs@freebsd.org Subject: Re: kern/65769: Call to tcflush(x, TCIFLUSH) stops input on usb-serialforever X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Dec 2004 04:45:34 -0000 On Sat, 11 Dec 2004, Julian Elischer wrote: > I there a patch that I can consider for commit for this? The PR mentions the wrong fix of breaking tty.c back to rev.1.15. This would be wrong because flushing of input must be requested of drivers to flush any downstream software or hardware buffers. t_stop() is overloaded to do this as follows: - t_stop() always flushes downstream i/o according to the setting of its FREAD/FWRITE flags - t_stop() stops downstream output iff the TS_TTSTOP flag is set. Most drivers don't need to anything in t_stop() for this, but sio converts TS_TTSTOP to a driver flag to simplify locking and improve efficiency. - t_stop() is not intended to stop input AFAIK. So pure stopping of downstream output involves setting TS_TTSTOP and calling t_stop() with flags 0, pure stopping of downstream input is not supported, and pure flushing of downstream i/o involves calling t_stop() with the relevant FREAD/FWRITE flags combination without changing TS_TTSTOP. We have the bug because our ucom.c is mostly maintained in NetBSD but out tty.c is mostly maintained in FreeBSD, and NetBSD still doesn't pass input-flushing requests down to drivers. It's interesting that the more common TCSETAF ioctl (== tcsetattr() with TCSAFLUSH) also stops/flushes input but apparently doesn't cause the problem. It apparently works because ucomparam() finishes up by calling ucomstart() which restarts things. Also, ucomparam() calls the the same function as ucomstop() to "stop" the devices, namely ucomstopread(), even in the !TCSAFLUSH case. This can only be right if (as I suspect) ucomstopread() is not overloaded to flush and ucomstop()'s input flushing is complete nonsense. It is reasonable to stop but not to flush input in ucomparam() -- stopping may be required for physical reasons to change the parameters, but flushing should not be done there since upper layers have already done it iff it has been requested (though there is a race here). OTOH, ucomstop() is apparently calling the stop function when only input flushing is requested. Possible fixes: 1. never stop input in ucomstop(), or 2. if ucomstopread() is needed in ucomstop() for a side effect of flushing input in ucomstop(), then call ucomstart() in ucomstop() to restart input, hopefully as in ucomparam(). Also, don't call it in ucomparam() if it flushes input. sio already has the corresponding call to comstart() from comstop() for unrelated reasons (to reduce duplication of code for stopping output). Bruce