From 646e29ccacf5e6e1f6df1e3198f47ffa08049b8e Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Fri, 23 Jan 2004 21:07:52 +0000 Subject: [PATCH] Don't grab Giant in crfree(), since prison_free() no longer requires it. The uidinfo code appears to be MPSAFE, and is referenced without Giant elsewhere. While this grab of Giant was only made in fairly rare circumstances (actually GC'ing on refcount==0), grabbing Giant here potentially introduces lock order issues with any locks held by the caller. So this probably won't help performance much unless you change credentials a lot in an application, and leave a lot of file descriptors and cached credentials around. However, it simplifies locking down consumers of the credential interfaces. Bumped into by: sam Appeased: tjr --- sys/kern/kern_prot.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index d6ecb3f971a..1d8f07e0b88 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1746,13 +1746,12 @@ crfree(struct ucred *cr) mtx_lock(mtxp); KASSERT(cr->cr_ref > 0, ("bad ucred refcount: %d", cr->cr_ref)); if (--cr->cr_ref == 0) { + mtx_unlock(mtxp); /* * Some callers of crget(), such as nfs_statfs(), * allocate a temporary credential, but don't * allocate a uidinfo structure. */ - mtx_unlock(mtxp); - mtx_lock(&Giant); if (cr->cr_uidinfo != NULL) uifree(cr->cr_uidinfo); if (cr->cr_ruidinfo != NULL) @@ -1766,7 +1765,6 @@ crfree(struct ucred *cr) mac_destroy_cred(cr); #endif FREE(cr, M_CRED); - mtx_unlock(&Giant); } else { mtx_unlock(mtxp); }