Subject: Re: ppp/tty panic
To: Andrew Doran <ad@netbsd.org>
From: Iain Hibbert <plunky@rya-online.net>
List: current-users
Date: 11/10/2007 22:13:10
On Sat, 10 Nov 2007, Andrew Doran wrote:

> On Sat, Nov 10, 2007 at 11:48:43AM +0000, Iain Hibbert wrote:
>
> > with a -current kernel from this morning (userland about a month old), I
> > get the following panic when trying to connect with ppp
> >
> > panic: kernel diagnostic assertion "mutex_owned(&tty_lock)" failed: file "/home/plunky/src/sys/kern/tty.c", line 1396
> > Stopped in pid 478.1 (pppd) at	netbsd:breakpoint+0x1:	ret
> > db> bt
> > breakpoint(c048cd70,c042fde1,c0451cdf,c0451da4,574) at netbsd:breakpoint+0x1
> > __kernassert(c042fde1,c0451da4,574,c0451cdf,c0bfd800) at netbsd:__kernassert+0x39
> > ttyflush(cb724abc,3,4,c0290429,cb724abc) at netbsd:ttyflush+0x119
> > pppopen(506,cb724abc,0,c02714f7,7) at netbsd:pppopen+0x188
> > ttioctl(cb724abc,8004741b,cb752b90,3,cb569000) at netbsd:ttioctl+0x3e6
> > ptyioctl(506,8004741b,cb752b90,3,cb569000) at netbsd:ptyioctl+0x2a4
> > spec_ioctl(cb752a70,c0ca449c,ffffffff,c03f8300,caffaca4) at netbsd:spec_ioctl+0xbd
> > VOP_IOCTL(caffaca4,8004741b,cb752b90,3,c9dc3300) at netbsd:VOP_IOCTL+0x3d
> > vn_ioctl(cb72bd88,8004741b,cb752b90,cb569000,cb72bf38) at netbsd:vn_ioctl+0x71
> > sys_ioctl(cb569000,cb752c48,cb752c68,8075e40,8075000) at netbsd:sys_ioctl+0x1b4
> > syscall_plain() at netbsd:syscall_plain+0x15a
> > --- syscall (number 54) ---
> > 0xbbb5d527:
> >
> > any ideas?
>
> The locking around the tty code is kind of gross... I just checked in a fix,
> I think it should work now.

Well, I'm not sure 'kind of gross' covers it adequately, but I got
slightly further this time:

panic: kernel diagnostic assertion "mutex_owned(&tty_lock)" failed: file "/home/plunky/src/sys/kern/tty.c", line 2204
Stopped in pid 756.1 (rfcomm_sppd) at	netbsd:breakpoint+0x1:	ret
db>
breakpoint(c048cf6c,c0430041,c0451eef,c0451fb4,89c) at netbsd:breakpoint+0x1
__kernassert(c0430041,c0451fb4,89c,c0451eef,3) at netbsd:__kernassert+0x39
ttwakeup(cb74bdcc,cb74be04,c0a61d5d,c0a61d00,c0c8ce54) at netbsd:ttwakeup+0x8b
pppasyncctlp(c0c8cc00,0,25,c0a61d38,0) at netbsd:pppasyncctlp+0x3e
pppintr(c0c8cc00,330,3,0,c010100f) at netbsd:pppintr+0x287
softintr_dispatch(1,cb722a00,0,uvm_fault(0xc04b1ac0, 0xca5bd000, 1) -> 0xe

I'm slightly afraid to touch this but following your lead I tried:

 static void
 pppasyncctlp(struct ppp_softc *sc)
 {
     struct tty *tp;
     int s;

     /* Put a placeholder byte in canq for ttselect()/ttnread(). */
     s = spltty();
     tp = (struct tty *) sc->sc_devp;
     putc(0, &tp->t_canq);
+    mutex_spin_enter(&tty_lock);
     ttwakeup(tp);
+    mutex_spin_exit(&tty_lock);
     splx(s);
 }

and that workedr; is it right?

iain