From owner-svn-src-head@freebsd.org Mon Aug 29 18:41:07 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A213FBC30F8; Mon, 29 Aug 2016 18:41:07 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7D67B2535; Mon, 29 Aug 2016 18:41:07 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7TIf6PQ053343; Mon, 29 Aug 2016 18:41:06 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7TIf6mu053342; Mon, 29 Aug 2016 18:41:06 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201608291841.u7TIf6mu053342@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Mon, 29 Aug 2016 18:41:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305010 - head/sys/dev/syscons X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Aug 2016 18:41:07 -0000 Author: bde Date: Mon Aug 29 18:41:06 2016 New Revision: 305010 URL: https://svnweb.freebsd.org/changeset/base/305010 Log: 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: head/sys/dev/syscons/syscons.c Modified: head/sys/dev/syscons/syscons.c ============================================================================== --- head/sys/dev/syscons/syscons.c Mon Aug 29 18:31:34 2016 (r305009) +++ head/sys/dev/syscons/syscons.c Mon Aug 29 18:41:06 2016 (r305010) @@ -1649,6 +1649,20 @@ 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) @@ -1680,6 +1694,7 @@ sccnopen(sc_softc_t *sc, struct sc_cnsta over_keyboard: ; /* The screen is opened iff locking it succeeds. */ + sccnscrlock(sc, sp); sp->scr_opened = TRUE; /* The screen switch is optional. */ @@ -1698,6 +1713,7 @@ static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp) { sp->scr_opened = FALSE; + sccnscrunlock(sc, sp); if (!sp->kbd_opened) return; @@ -1731,8 +1747,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 @@ -1743,14 +1761,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 @@ -1762,7 +1783,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) { @@ -1797,7 +1818,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