From owner-svn-src-stable@freebsd.org Wed Mar 14 07:08:02 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BF4D7F5A9E2; Wed, 14 Mar 2018 07:08:02 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 74C4C70CB4; Wed, 14 Mar 2018 07:08:02 +0000 (UTC) (envelope-from eadler@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6F35924BEB; Wed, 14 Mar 2018 07:08:02 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2E782cB052157; Wed, 14 Mar 2018 07:08:02 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2E782ej052156; Wed, 14 Mar 2018 07:08:02 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201803140708.w2E782ej052156@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Wed, 14 Mar 2018 07:08:02 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: stable/11/sys/dev/syscons X-SVN-Commit-Revision: 330909 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Mar 2018 07:08:03 -0000 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