From owner-svn-src-head@freebsd.org Fri Aug 18 14:47:08 2017 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 5DB7ADE5F67; Fri, 18 Aug 2017 14:47:08 +0000 (UTC) (envelope-from br@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 287B26647E; Fri, 18 Aug 2017 14:47:08 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7IEl7uM072514; Fri, 18 Aug 2017 14:47:07 GMT (envelope-from br@FreeBSD.org) Received: (from br@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7IEl7ab072513; Fri, 18 Aug 2017 14:47:07 GMT (envelope-from br@FreeBSD.org) Message-Id: <201708181447.v7IEl7ab072513@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: br set sender to br@FreeBSD.org using -f From: Ruslan Bukin Date: Fri, 18 Aug 2017 14:47:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322660 - head/sys/amd64/sgx X-SVN-Group: head X-SVN-Commit-Author: br X-SVN-Commit-Paths: head/sys/amd64/sgx X-SVN-Commit-Revision: 322660 X-SVN-Commit-Repository: base 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.23 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: Fri, 18 Aug 2017 14:47:08 -0000 Author: br Date: Fri Aug 18 14:47:06 2017 New Revision: 322660 URL: https://svnweb.freebsd.org/changeset/base/322660 Log: Fix module unload when SGX support is not present in CPU. Sponsored by: DARPA, AFRL Modified: head/sys/amd64/sgx/sgx.c Modified: head/sys/amd64/sgx/sgx.c ============================================================================== --- head/sys/amd64/sgx/sgx.c Fri Aug 18 14:30:12 2017 (r322659) +++ head/sys/amd64/sgx/sgx.c Fri Aug 18 14:47:06 2017 (r322660) @@ -1132,9 +1132,6 @@ sgx_load(void) if ((cpu_stdext_feature & CPUID_STDEXT_SGX) == 0) return (ENXIO); - mtx_init(&sc->mtx_encls, "SGX ENCLS", NULL, MTX_DEF); - mtx_init(&sc->mtx, "SGX driver", NULL, MTX_DEF); - error = sgx_get_epc_area(sc); if (error) { printf("%s: Failed to get Processor Reserved Memory area.\n", @@ -1142,6 +1139,9 @@ sgx_load(void) return (ENXIO); } + mtx_init(&sc->mtx_encls, "SGX ENCLS", NULL, MTX_DEF); + mtx_init(&sc->mtx, "SGX driver", NULL, MTX_DEF); + TAILQ_INIT(&sc->enclaves); sc->sgx_cdev = make_dev(&sgx_cdevsw, 0, UID_ROOT, GID_WHEEL, @@ -1161,6 +1161,9 @@ sgx_unload(void) struct sgx_softc *sc; sc = &sgx_sc; + + if ((sc->state & SGX_STATE_RUNNING) == 0) + return (0); mtx_lock(&sc->mtx); if (!TAILQ_EMPTY(&sc->enclaves)) {