From owner-svn-src-stable@freebsd.org Wed Mar 14 07:08:46 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 C8398F5AA91; Wed, 14 Mar 2018 07:08:46 +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 79A6B70E0E; Wed, 14 Mar 2018 07:08:46 +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 747D824BEC; Wed, 14 Mar 2018 07:08:46 +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 w2E78kH3052221; Wed, 14 Mar 2018 07:08:46 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2E78ksI052220; Wed, 14 Mar 2018 07:08:46 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201803140708.w2E78ksI052220@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:46 +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: r330910 - 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: 330910 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:47 -0000 Author: eadler Date: Wed Mar 14 07:08:46 2018 New Revision: 330910 URL: https://svnweb.freebsd.org/changeset/base/330910 Log: MFC r305059: Start adding locking to sc_cngetc(). Restore an splx() lost in r228644. We aren't nearly ready to remove spl's. They give hints about missing locking. This lost one was misplaced. Dropping it early for convenience gave race windows for accesses to the fkey buffer. Giant locking accidentally fixed this for non-console cases. Put the spl's around the whole function. Since there are many returns that would need splx() just before them for a direct fix, split the function into a wrapper that does the spl's and a "locked" function that does the work. Return earlier when no keyboard is attached to match the ordering in a planned version. This breaks the dubious feature of returning keys from the fkey buffer after the keyboard has gone away. Losing the keys wouldn't matter, but we keep them too long now. 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 07:08:02 2018 (r330909) +++ stable/11/sys/dev/syscons/syscons.c Wed Mar 14 07:08:46 2018 (r330910) @@ -1650,6 +1650,7 @@ sc_cnterm(struct consdev *cp) } static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp); +static int sc_cngetc_locked(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); @@ -1826,15 +1827,28 @@ sc_cnputc(struct consdev *cd, int c) static int sc_cngetc(struct consdev *cd) { + int c, s; + + /* assert(sc_console != NULL) */ + s = spltty(); /* block sckbdevent and scrn_timer while we poll */ + if (sc_console->sc->kbd == NULL) { + splx(s); + return -1; + } + c = sc_cngetc_locked(NULL); + splx(s); + return c; +} + +static int +sc_cngetc_locked(struct sc_cnstate *sp) +{ static struct fkeytab fkey; static int fkeycp; scr_stat *scp; const u_char *p; - int s = spltty(); /* block sckbdevent and scrn_timer while we poll */ int c; - /* assert(sc_console != NULL) */ - /* * Stop the screen saver and update the screen if necessary. * What if we have been running in the screen saver code... XXX @@ -1843,15 +1857,8 @@ sc_cngetc(struct consdev *cd) scp = sc_console->sc->cur_scp; /* XXX */ sccnupdate(scp); - if (fkeycp < fkey.len) { - splx(s); + if (fkeycp < fkey.len) return fkey.str[fkeycp++]; - } - - if (scp->sc->kbd == NULL) { - splx(s); - return -1; - } c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK, NULL);