From owner-p4-projects@FreeBSD.ORG Thu Jul 8 21:46:56 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EEA9916A4D0; Thu, 8 Jul 2004 21:46:55 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC75C16A4CE for ; Thu, 8 Jul 2004 21:46:55 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A2F7F43D2D for ; Thu, 8 Jul 2004 21:46:55 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i68LkttT028565 for ; Thu, 8 Jul 2004 21:46:55 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i68LktDM028562 for perforce@freebsd.org; Thu, 8 Jul 2004 21:46:55 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Thu, 8 Jul 2004 21:46:55 GMT Message-Id: <200407082146.i68LktDM028562@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Subject: PERFORCE change 56811 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Jul 2004 21:46:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=56811 Change 56811 by rwatson@rwatson_tislabs on 2004/07/08 21:46:17 Remove module refcount; maybe removed a little too much and will have to re-add it. Affected files ... .. //depot/projects/trustedbsd/mac/sys/kern/sysv_shm.c#20 edit Differences ... ==== //depot/projects/trustedbsd/mac/sys/kern/sysv_shm.c#20 (text+ko) ==== @@ -94,8 +94,6 @@ static int shm_last_free, shm_nused, shm_committed, shmalloced; static struct shmid_kernel *shmsegs; -static int refcount; /* to ensure consistency during and after shmunload */ -static struct mtx refcnt_mtx; /* global mutex for refcount. */ struct shm_handle { /* vm_offset_t kva; */ @@ -283,18 +281,6 @@ if (!jail_sysvipc_allowed && jailed(td->td_ucred)) return (ENOSYS); - /* - * Prevent thread from going any further if module is (being) - * unloaded. - */ - mtx_lock(&refcnt_mtx); - if (refcount < 0 ) { - mtx_unlock(&refcnt_mtx); - return (ENOSYS); - } - refcount++; /* Indicate that thread is active in the code-path */ - mtx_unlock(&refcnt_mtx); - mtx_lock(&Giant); shmmap_s = p->p_vmspace->vm_shm; if (shmmap_s == NULL) { @@ -327,9 +313,6 @@ error = shm_delete_mapping(p->p_vmspace, shmmap_s); done2: mtx_unlock(&Giant); - mtx_lock(&refcnt_mtx); - refcount--; /* Indicate that thread no longer active in the code-path */ - mtx_unlock(&refcnt_mtx); return (error); } @@ -365,18 +348,6 @@ if (!jail_sysvipc_allowed && jailed(td->td_ucred)) return (ENOSYS); - /* - * Prevent thread from going any further if module is (being) - * unloaded. - */ - mtx_lock(&refcnt_mtx); - if (refcount < 0 ) { - mtx_unlock(&refcnt_mtx); - return (ENOSYS); - } - refcount++; /* Indicate that thread is active in the code-path */ - mtx_unlock(&refcnt_mtx); - mtx_lock(&Giant); shmmap_s = p->p_vmspace->vm_shm; if (shmmap_s == NULL) { @@ -459,9 +430,6 @@ td->td_retval[0] = attach_va; done2: mtx_unlock(&Giant); - mtx_lock(&refcnt_mtx); - refcount--; /* Indicate that thread no longer active in the code-path */ - mtx_unlock(&refcnt_mtx); return (error); } @@ -507,18 +475,6 @@ if (!jail_sysvipc_allowed && jailed(td->td_ucred)) return (ENOSYS); - /* - * Prevent thread from going any further if module is (being) - * unloaded. - */ - mtx_lock(&refcnt_mtx); - if (refcount < 0 ) { - mtx_unlock(&refcnt_mtx); - return (ENOSYS); - } - refcount++; /* Indicate that thread is active in the code-path */ - mtx_unlock(&refcnt_mtx); - mtx_lock(&Giant); shmseg = shm_find_segment_by_shmid(uap->shmid); if (shmseg == NULL) { @@ -557,9 +513,6 @@ } done2: mtx_unlock(&Giant); - mtx_lock(&refcnt_mtx); - refcount--; /* Indicate that thread no longer active in the code-path */ - mtx_unlock(&refcnt_mtx); return (error); #else return (EINVAL); @@ -591,18 +544,6 @@ if (!jail_sysvipc_allowed && jailed(td->td_ucred)) return (ENOSYS); - /* - * Prevent thread from going any further if module is (being) - * unloaded - */ - mtx_lock(&refcnt_mtx); - if (refcount < 0 ) { - mtx_unlock(&refcnt_mtx); - return (ENOSYS); - } - refcount++; /* Indicate that thread is active in the code-path */ - mtx_unlock(&refcnt_mtx); - mtx_lock(&Giant); switch (cmd) { case IPC_INFO: @@ -689,9 +630,6 @@ } done2: mtx_unlock(&Giant); - mtx_lock(&refcnt_mtx); - refcount--; /* Indicate that thread no longer active in the code-path */ - mtx_unlock(&refcnt_mtx); return (error); } @@ -882,18 +820,6 @@ if (!jail_sysvipc_allowed && jailed(td->td_ucred)) return (ENOSYS); - /* - * Prevent thread from going any further if module is (being) - * unloaded. - */ - mtx_lock(&refcnt_mtx); - if (refcount < 0 ) { - mtx_unlock(&refcnt_mtx); - return (ENOSYS); - } - refcount++; /* Indicate that thread is active in the code-path */ - mtx_unlock(&refcnt_mtx); - mtx_lock(&Giant); mode = uap->shmflg & ACCESSPERMS; if (uap->key != IPC_PRIVATE) { @@ -913,9 +839,6 @@ error = shmget_allocate_segment(td, uap, mode); done2: mtx_unlock(&Giant); - mtx_lock(&refcnt_mtx); - refcount--; /* Indicate that thread no longer active in the code-path */ - mtx_unlock(&refcnt_mtx); return (error); } @@ -1043,39 +966,14 @@ shm_committed = 0; shmexit_hook = &shmexit_myhook; shmfork_hook = &shmfork_myhook; - refcount = 0; - /* - * It is not permissible to pass the same mutex to mtx_init() - * multiple times without intervening calls to mtx_destroy(). Since - * we cannot destroy the refcnt_mtx during shmunload, we check if - * the mtx_init has ever been called. If so, we dont need to do - * mtx_init as the mutex is already initialized. - */ - if (mtx_initialized(&refcnt_mtx) == 0) - mtx_init(&refcnt_mtx, "shmrefcnt", NULL, MTX_DEF); } static int shmunload() { - - /* - * Make sure that the shmunload maintains the consistency of the - * shmsegs data structure. This assures that the unload doesn't - * take place if any thread is in any of the code-paths (tinkering - * with the data structures), and also that no thread can enter - * the code-paths once the module is unloaded. - */ - mtx_lock(&refcnt_mtx); - if ((refcount > 0) || (shm_nused > 0)) { - mtx_unlock(&refcnt_mtx); - return (EBUSY); - } - refcount= -1; /* Mark the module as being unloaded */ - mtx_unlock(&refcnt_mtx); - #ifdef MAC int i; + for (i = 0; i < shmalloced; i++) mac_destroy_ipc_shm(&shmsegs[i]); #endif