From owner-svn-src-head@freebsd.org Tue Aug 30 10:57:21 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 28D12BC7224; Tue, 30 Aug 2016 10:57:21 +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 D61ECFE2; Tue, 30 Aug 2016 10:57:20 +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 u7UAvKfx025466; Tue, 30 Aug 2016 10:57:20 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7UAvKGK025465; Tue, 30 Aug 2016 10:57:20 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201608301057.u7UAvKGK025465@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Tue, 30 Aug 2016 10:57:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305059 - 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: Tue, 30 Aug 2016 10:57:21 -0000 Author: bde Date: Tue Aug 30 10:57:19 2016 New Revision: 305059 URL: https://svnweb.freebsd.org/changeset/base/305059 Log: 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: head/sys/dev/syscons/syscons.c Modified: head/sys/dev/syscons/syscons.c ============================================================================== --- head/sys/dev/syscons/syscons.c Tue Aug 30 10:21:32 2016 (r305058) +++ head/sys/dev/syscons/syscons.c Tue Aug 30 10:57:19 2016 (r305059) @@ -1648,6 +1648,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); @@ -1824,15 +1825,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 @@ -1841,15 +1855,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);