Re: page fault panic in scioctl and console-kit-daemon

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Joe Marcus Clarke <marcus@...>
Cc: FreeBSD Current <freebsd-current@...>
Date: Wednesday, January 23, 2008 - 5:11 pm

On Wed, Jan 23, 2008 at 02:55:59PM -0500, Joe Marcus Clarke wrote:
ng=20
boot=20
her=20
an=20
s:146
cture
 not
tch ?
sp.
=20
=20

=46rom my reading of the code, scp would be non-NULL after the first open
of the corresponding /dev/ttyvX. sc_attach_unit() creates the scp for
the console and the consolectl devices.

VT_WAITACTIVE ioctl is performed on arbitrary syscons /dev node, and
can wait for any other screens, in particular, the screens that are
not opened at the moment (the reason for the reported panic).

The patch I posted may be improved by making the VT_WAITACTIVE ioctl
to wait for the scp being allocated, and only then for the screen to be
switched too. Please, test.


diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c
index e0c9725..3127ae6 100644
--- a/sys/dev/syscons/syscons.c
+++ b/sys/dev/syscons/syscons.c
@@ -178,6 +178,7 @@ static int scparam(struct tty *tp, struct termios *t);
 static void scstart(struct tty *tp);
 static void scinit(int unit, int flags);
 static scr_stat *sc_get_stat(struct cdev *devptr);
+static void sc_set_stat(struct cdev *devptr, scr_stat *st);
 static void scterm(int unit, int flags);
 static void scshutdown(void *arg, int howto);
 static u_int scgetc(sc_softc_t *sc, u_int flags);
@@ -421,7 +422,7 @@ sc_attach_unit(int unit, int flags)
 		    UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
 	    	sc_alloc_tty(sc->dev[vc]);
 		if (vc =3D=3D 0 && sc->dev =3D=3D main_devs)
-			SC_STAT(sc->dev[0]) =3D &main_console;
+			sc_set_stat(sc->dev[0], &main_console);
 	}
 	/*
 	 * The first vty already has struct tty and scr_stat initialized
@@ -434,7 +435,7 @@ sc_attach_unit(int unit, int flags)
 		   UID_ROOT, GID_WHEEL, 0600, "consolectl");
     sc_console_tty =3D sc_alloc_tty(dev);
     ttyconsolemode(sc_console_tty, 0);
-    SC_STAT(dev) =3D sc_console;
+    sc_set_stat(dev, sc_console);
=20
     return 0;
 }
@@ -525,7 +526,8 @@ scopen(struct cdev *dev, int flag, int mode, struct thr=
ead *td)
=20
     scp =3D sc_get_stat(dev);
     if (scp =3D=3D NULL) {
-	scp =3D SC_STAT(dev) =3D alloc_scp(sc, SC_VTY(dev));
+	scp =3D alloc_scp(sc, SC_VTY(dev));
+	sc_set_stat(dev, scp);
 	if (ISGRAPHSC(scp))
 	    sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
     }
@@ -1063,6 +1065,7 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, i=
nt flag, struct thread *td)
 #endif
     case VT_WAITACTIVE: 	/* wait for switch to occur */
 	i =3D (*(int *)data =3D=3D 0) ? scp->index : (*(int *)data - 1);
+    wait_active:
 	if ((i < sc->first_vty) || (i >=3D sc->first_vty + sc->vtys))
 	    return EINVAL;
 	s =3D spltty();
@@ -1071,6 +1074,12 @@ scioctl(struct cdev *dev, u_long cmd, caddr_t data, =
int flag, struct thread *td)
 	if (error)
 	    return error;
 	scp =3D sc_get_stat(SC_DEV(sc, i));
+	if (scp =3D=3D NULL) {
+		error =3D tsleep(&(dev)->si_drv1, PZERO | PCATCH, "waitvt0", 0);
+		if (error)
+			return (error);
+		goto wait_active;
+	}
 	if (scp =3D=3D scp->sc->cur_scp)
 	    return 0;
 	error =3D tsleep(&scp->smode, PZERO | PCATCH, "waitvt", 0);
@@ -2769,7 +2778,7 @@ scinit(int unit, int flags)
 	        UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS);
 	    sc_alloc_tty(sc->dev[0]);
 	    scp =3D alloc_scp(sc, sc->first_vty);
-	    SC_STAT(sc->dev[0]) =3D scp;
+	    sc_set_stat(sc->dev[0], scp);
 	}
 	sc->cur_scp =3D scp;
=20
@@ -3662,6 +3671,14 @@ sc_get_stat(struct cdev *devptr)
 	return (SC_STAT(devptr));
 }
=20
+static void
+sc_set_stat(struct cdev *devptr, scr_stat *st)
+{
+
+	SC_STAT(devptr) =3D st;
+	wakeup(&devptr->si_drv1);
+}
+
 /*
  * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
  * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: page fault panic in scioctl and console-kit-daemon, Pawel Worach, (Tue Jan 22, 2:26 pm)
Re: page fault panic in scioctl and console-kit-daemon, Kostik Belousov, (Wed Jan 23, 1:16 am)
Re: page fault panic in scioctl and console-kit-daemon, Pawel Worach, (Wed Jan 23, 3:34 pm)
Re: page fault panic in scioctl and console-kit-daemon, Joe Marcus Clarke, (Wed Jan 23, 3:55 pm)
Re: page fault panic in scioctl and console-kit-daemon, Kostik Belousov, (Wed Jan 23, 5:11 pm)
Re: page fault panic in scioctl and console-kit-daemon, Pawel Worach, (Wed Jan 23, 5:35 pm)
Re: page fault panic in scioctl and console-kit-daemon, Joe Marcus Clarke, (Wed Jan 23, 5:32 pm)
Re: page fault panic in scioctl and console-kit-daemon, Kostik Belousov, (Thu Jan 24, 8:42 am)
Re: page fault panic in scioctl and console-kit-daemon, Alexander Nedotsukov, (Wed Feb 20, 8:26 pm)
Re: page fault panic in scioctl and console-kit-daemon, Kostik Belousov, (Thu Feb 21, 11:47 am)
Re: page fault panic in scioctl and console-kit-daemon, Alexander Nedotsukov, (Fri Feb 22, 12:01 pm)
Re: page fault panic in scioctl and console-kit-daemon, Kostik Belousov, (Fri Feb 22, 1:29 pm)
Re: page fault panic in scioctl and console-kit-daemon, Alexander Nedotsukov, (Mon Mar 17, 9:02 am)
Re: page fault panic in scioctl and console-kit-daemon, Kostik Belousov, (Mon Mar 17, 9:18 am)
Re: page fault panic in scioctl and console-kit-daemon, Joe Marcus Clarke, (Thu Jan 24, 11:21 am)