Bug 75758 - Hard system hangs on tty code
Summary: Hard system hangs on tty code
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 6.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: Poul-Henning Kamp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-03 18:50 UTC by slw
Modified: 2005-01-25 09:16 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description slw 2005-01-03 18:50:20 UTC
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);

}
Comment 1 Gleb Smirnoff freebsd_committer freebsd_triage 2005-01-13 09:22:08 UTC
Responsible Changed
From-To: freebsd-bugs->phk

Poul-Henning has done major overhaul of tty code in 6-CURRENT.
Comment 2 Gleb Smirnoff freebsd_committer freebsd_triage 2005-01-21 17:10:30 UTC
  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
Comment 3 Gleb Smirnoff freebsd_committer freebsd_triage 2005-01-25 08:05:09 UTC
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
Comment 4 slw 2005-01-25 08:46:46 UTC
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
Comment 5 Poul-Henning Kamp freebsd_committer freebsd_triage 2005-01-25 09:15:44 UTC
State Changed
From-To: open->closed

Fixed! 

Sorry for the delay.