From slw@zxy.spb.ru  Mon Jan  3 18:47:16 2005
Return-Path: <slw@zxy.spb.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0E70816A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  3 Jan 2005 18:47:16 +0000 (GMT)
Received: from mail.acropolis.ru (mail.acropolis.ru [81.211.90.2])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E24A043D48
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  3 Jan 2005 18:47:14 +0000 (GMT)
	(envelope-from slw@zxy.spb.ru)
Received: from slw.office.acropolis.ru (slw.office.acropolis.ru [10.200.0.19]) by mail.acropolis.ru (8.13.1/8.13.1) with ESMTP id j03IlD29090883 for <FreeBSD-gnats-submit@freebsd.org>; Mon, 3 Jan 2005 21:47:14 +0300 (MSK) (envelope-from slw@zxy.spb.ru)
Received: from zxy.spb.ru (localhost [127.0.0.1])
	by slw.office.acropolis.ru (8.13.1/8.13.1) with ESMTP id j03IkWPh040400
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 3 Jan 2005 21:46:32 +0300 (MSK)
	(envelope-from slw@zxy.spb.ru)
Received: (from slw@localhost)
	by zxy.spb.ru (8.13.1/8.13.1/Submit) id j03IkWde040399;
	Mon, 3 Jan 2005 21:46:32 +0300 (MSK)
	(envelope-from slw)
Message-Id: <200501031846.j03IkWde040399@zxy.spb.ru>
Date: Mon, 3 Jan 2005 21:46:32 +0300 (MSK)
From: Slawa Olhovchenkov <slw@zxy.spb.ru>
Reply-To: Slawa Olhovchenkov <slwzxy.spb.ru@zxy.spb.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Hard system hangs on tty code
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         75758
>Category:       kern
>Synopsis:       Hard system hangs on tty code
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    phk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 03 18:50:20 GMT 2005
>Closed-Date:    Tue Jan 25 09:16:03 GMT 2005
>Last-Modified:  Tue Jan 25 09:16:03 GMT 2005
>Originator:     Slawa Olhovchenkov
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
no
>Environment:
System: FreeBSD notebook.acropolis.ru 6.0-CURRENT FreeBSD 6.0-CURRENT #5: Mon Jan 3 13:33:38 MSK 2005 root@notebook.acropolis.ru:/usr/obj/usr/src/sys/BOOK i386

	i386, FreeBSD 6.0-CURRENT i386
>Description:

6-current totally hangs by this program, from user, not root.
No responds on keys pressed, Control-Alt-ESC, switching console and etc.

System run in infinite loop in sys/kern/tty.c:ttread()

===
read:
        splx(s);
        /*
         * Input present, check for input mapping and processing.
         */
        first = 1;
        if (ISSET(lflag, ICANON | ISIG))
                goto slowcase;
        for (;;) {
                char ibuf[IBUFSIZ];
                int icc;

                icc = imin(uio->uio_resid, IBUFSIZ);
/* XXX uio_resid==0 => icc=0 */
                icc = q_to_b(qp, ibuf, icc);
/* icc == 0 */
                if (icc <= 0) {
                        if (first)
                                goto loop;

===

>How-To-Repeat:

Run this test program and type any. System immediately hangs.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define cfmakeraw(ptr) (ptr)->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR\
                                         |IGNCR|ICRNL|IXON);\
                       (ptr)->c_oflag &= ~OPOST;\
                       (ptr)->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);\
                       (ptr)->c_cflag &= ~(CSIZE|PARENB);\
                       (ptr)->c_cflag |= CS8


int
main(int argc, char *argv[])
{
        int     fd,
                i;
        char *buf[1024];

        struct termios tcn;
        if ((fd = open("/dev/tty", O_RDWR | O_NONBLOCK)) == -1) {
                return -1;      /* errno already set */
        }

        /* Set the tty to raw and to the correct speed */
        tcgetattr(fd, &tcn);

        tcn.c_oflag     = 0;
        tcn.c_iflag     = IGNBRK | IGNPAR;
        tcn.c_cflag     = CREAD | CLOCAL | CS8;

        tcn.c_lflag = NOFLSH;

        cfmakeraw(&tcn);

        for (i = 0; i < 16; i++)
                tcn.c_cc[i] = 0;

        tcn.c_cc[VMIN]  = 1;
        tcn.c_cc[VTIME] = 0;

        tcsetattr(fd, TCSANOW, &tcn);

        if ((i = fcntl(fd, F_GETFL, 0)) != -1) {
                i &= ~O_NONBLOCK;
                fcntl(fd, F_SETFL, i);
        }
        read(fd, buf, 0);

}                                                                                                                                              

>Fix:

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->phk 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Thu Jan 13 09:22:08 GMT 2005 
Responsible-Changed-Why:  
Poul-Henning has done major overhaul of tty code in 6-CURRENT. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75758 

From: Gleb Smirnoff <glebius@freebsd.org>
To: phk@freebsd.org
Cc: Slawa Olhovchenkov <slw@zxy.spb.ru>,
	freebsd-gnats-submit@freebsd.org
Subject: Re: kern/75758: Hard system hangs on tty code
Date: Fri, 21 Jan 2005 20:10:30 +0300

   Poul-Henning,
 
 Slawa has done a binary search and has found that the problem was
 introduced Nov 15 2004, between 18:00 and 24:00 GMT.
 There was a serie of commits fixing each other, and he can't find
 the exact one. However, I think the time slice of breakage is given
 quite precisely. Hope this information will be useful for you.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Gleb Smirnoff <glebius@freebsd.org>
To: phk@freebsd.org
Cc: freebsd-gnats-submit@freebsd.org,
	Slawa Olhovchenkov <slw@zxy.spb.ru>
Subject: Re: kern/75758: Hard system hangs on tty code
Date: Tue, 25 Jan 2005 11:05:09 +0300

 Mime-Version: 1.0
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 In-Reply-To: <20050124205703.GA1019@mail.acropolis.ru>
 User-Agent: Mutt/1.5.6i
 X-Virus-Scanned: ClamAV version devel-20050119, clamav-milter version 0.80ff on relay.bestcom.ru
 X-Virus-Status: Clean
 
   Poul-Henning,
 
   some more information from Slawa. I'm just Russian-English translator.
 
 [Slawa]
 I've found the commit which makes my test program freeze system.
 
 S> phk         2004-11-15 22:11:09 UTC
 S> 
 S>   FreeBSD src repository
 S> 
 S>   Modified files:
 S>     sys/fs/devfs         devfs_vnops.c
 S>   Log:
 S>   Make vnode bypass the default for devices.
 S> 
 S>   Can be disabled in case of problems with
 S>           vfs.devfs.fops=0
 S>   in loader.conf
 S> 
 S>   Revision  Changes    Path
 S>   1.85      +1 -1      src/sys/fs/devfs/devfs_vnops.c
 
 I suppose that cause of the problem has been in tty.c for a long time,
 and this commit exposes it.
 
 The test were made with program submitted in PR. Sorry, but can't run the
 tests with real hardware, since it is not longer available. Originally the
 problem was found on a dial in server.
 [/Slawa]
 
 Slawa, does CURRENT works for you if you put vfs.devfs.fops=0 in loader.conf?
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Slawa Olhovchenkov <slw@zxy.spb.ru>
To: Gleb Smirnoff <glebius@freebsd.org>
Cc: phk@freebsd.org, freebsd-gnats-submit@freebsd.org
Subject: Re: kern/75758: Hard system hangs on tty code
Date: Tue, 25 Jan 2005 11:46:46 +0300

 On Tue, Jan 25, 2005 at 11:05:09AM +0300, Gleb Smirnoff wrote:
 
 >   some more information from Slawa. I'm just Russian-English translator.
 > 
 > [Slawa]
 > I've found the commit which makes my test program freeze system.
 > 
 > S> phk         2004-11-15 22:11:09 UTC
 > S> 
 > S>   FreeBSD src repository
 > S> 
 > S>   Modified files:
 > S>     sys/fs/devfs         devfs_vnops.c
 > S>   Log:
 > S>   Make vnode bypass the default for devices.
 > S> 
 > S>   Can be disabled in case of problems with
 > S>           vfs.devfs.fops=0
 > S>   in loader.conf
 > S> 
 > S>   Revision  Changes    Path
 > S>   1.85      +1 -1      src/sys/fs/devfs/devfs_vnops.c
 > 
 > I suppose that cause of the problem has been in tty.c for a long time,
 > and this commit exposes it.
 > 
 > The test were made with program submitted in PR. Sorry, but can't run the
 > tests with real hardware, since it is not longer available. Originally the
 > problem was found on a dial in server.
 > [/Slawa]
 > 
 > Slawa, does CURRENT works for you if you put vfs.devfs.fops=0 in loader.conf?
 
 No, if vfs.devfs.fops=0 only test program run OK,
 pilot-xfer alike hangs system.
 
 -- 
 Slawa Olhovchenkov
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Tue Jan 25 09:15:44 GMT 2005 
State-Changed-Why:  
Fixed! 

Sorry for the delay. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=75758 
>Unformatted:
