Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Mar 2018 07:08:02 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r330909 - stable/11/sys/dev/syscons
Message-ID:  <201803140708.w2E782ej052156@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Mar 14 07:08:02 2018
New Revision: 330909
URL: https://svnweb.freebsd.org/changeset/base/330909

Log:
  MFC r305010:
  
  Add screen locking calls to sc cn grab and ungrab.  The locking functions
  just use the same mutex locking as sc cn putc so they have the same
  defects.
  
  The locking calls to acquire the lock are actually in sc cn open and close.
  Ungrab has to unlock, although this opens a race window.
  
  Change the direct mutex lock calls in sc cn putc to the new locking
  functions via the open and close functions.  Putc also has to unlock, but
  doesn't keep the screen open like grab.  Screen open and close reduce to
  locking, except screen open for grab also attempts to switch the screen.
  
  Keyboard locking is more difficult and still null, even when keyboard
  input calls screen functions, except some of the functions have locks
  too deep to work right.
  
  This organization gives a single place to fix some of the locking.

Modified:
  stable/11/sys/dev/syscons/syscons.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/syscons/syscons.c
==============================================================================
--- stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 04:00:00 2018	(r330908)
+++ stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 07:08:02 2018	(r330909)
@@ -1651,8 +1651,22 @@ sc_cnterm(struct consdev *cp)
 
 static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
 static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
+static void sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp);
+static void sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp);
 
 static void
+sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp)
+{
+    SC_VIDEO_LOCK(sc);
+}
+
+static void
+sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp)
+{
+    SC_VIDEO_UNLOCK(sc);
+}
+
+static void
 sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags)
 {
     int kbd_mode;
@@ -1682,6 +1696,7 @@ sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int fl
 over_keyboard: ;
 
     /* The screen is opened iff locking it succeeds. */
+    sccnscrlock(sc, sp);
     sp->scr_opened = TRUE;
 
     /* The screen switch is optional. */
@@ -1700,6 +1715,7 @@ static void
 sccnclose(sc_softc_t *sc, struct sc_cnstate *sp)
 {
     sp->scr_opened = FALSE;
+    sccnscrunlock(sc, sp);
 
     if (!sp->kbd_opened)
 	return;
@@ -1733,8 +1749,10 @@ sc_cngrab(struct consdev *cp)
 
     sc = sc_console->sc;
     lev = atomic_fetchadd_int(&sc->grab_level, 1);
-    if (lev >= 0 && lev < 2)
+    if (lev >= 0 && lev < 2) {
 	sccnopen(sc, &sc->grab_state[lev], 1 | 2);
+	sccnscrunlock(sc, &sc->grab_state[lev]);
+    }
 }
 
 static void
@@ -1745,14 +1763,17 @@ sc_cnungrab(struct consdev *cp)
 
     sc = sc_console->sc;
     lev = atomic_load_acq_int(&sc->grab_level) - 1;
-    if (lev >= 0 && lev < 2)
+    if (lev >= 0 && lev < 2) {
+	sccnscrlock(sc, &sc->grab_state[lev]);
 	sccnclose(sc, &sc->grab_state[lev]);
+    }
     atomic_add_int(&sc->grab_level, -1);
 }
 
 static void
 sc_cnputc(struct consdev *cd, int c)
 {
+    struct sc_cnstate st;
     u_char buf[1];
     scr_stat *scp = sc_console;
 #ifndef SC_NO_HISTORY
@@ -1764,7 +1785,7 @@ sc_cnputc(struct consdev *cd, int c)
 
     /* assert(sc_console != NULL) */
 
-    SC_VIDEO_LOCK(scp->sc);
+    sccnopen(scp->sc, &st, 0);
 
 #ifndef SC_NO_HISTORY
     if (scp == scp->sc->cur_scp && scp->status & SLKED) {
@@ -1799,7 +1820,7 @@ sc_cnputc(struct consdev *cd, int c)
     s = spltty();	/* block sckbdevent and scrn_timer */
     sccnupdate(scp);
     splx(s);
-    SC_VIDEO_UNLOCK(scp->sc);
+    sccnclose(scp->sc, &st);
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803140708.w2E782ej052156>