Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Aug 2017 14:47:07 +0000 (UTC)
From:      Ruslan Bukin <br@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r322660 - head/sys/amd64/sgx
Message-ID:  <201708181447.v7IEl7ab072513@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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)) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708181447.v7IEl7ab072513>