From owner-p4-projects@FreeBSD.ORG Mon Oct 22 13:16:17 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6426D16A474; Mon, 22 Oct 2007 13:16:17 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 099A216A418 for ; Mon, 22 Oct 2007 13:16:17 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E5ED613C4BC for ; Mon, 22 Oct 2007 13:16:16 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l9MDGGew010819 for ; Mon, 22 Oct 2007 13:16:16 GMT (envelope-from zec@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l9MDGGvV010816 for perforce@freebsd.org; Mon, 22 Oct 2007 13:16:16 GMT (envelope-from zec@FreeBSD.org) Date: Mon, 22 Oct 2007 13:16:16 GMT Message-Id: <200710221316.l9MDGGvV010816@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@FreeBSD.org using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 127921 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Oct 2007 13:16:17 -0000 http://perforce.freebsd.org/chv.cgi?CH=127921 Change 127921 by zec@zec_tpx32 on 2007/10/22 13:15:44 Refcount ucred -> vimage bindings in struct vimage. Obviously, we shouldn't release a vimage if other objects point to it. NB it is still not completely clear to me whether this additional refcounting would need additional protection / locking... Affected files ... .. //depot/projects/vimage/src/sys/kern/init_main.c#14 edit .. //depot/projects/vimage/src/sys/kern/kern_prot.c#7 edit .. //depot/projects/vimage/src/sys/kern/kern_vimage.c#49 edit .. //depot/projects/vimage/src/sys/sys/vimage.h#47 edit Differences ... ==== //depot/projects/vimage/src/sys/kern/init_main.c#14 (text+ko) ==== @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -447,9 +448,9 @@ p->p_ucred->cr_ruidinfo = uifind(0); p->p_ucred->cr_prison = NULL; /* Don't jail it. */ #ifdef VIMAGE - p->p_ucred->cr_vimage = LIST_FIRST(&vimage_head); - p->p_ucred->cr_rvimage = p->p_ucred->cr_vimage; - LIST_FIRST(&vprocg_head)->nprocs = 1; + P_TO_VIMAGE(p) = LIST_FIRST(&vimage_head); + refcount_acquire(&P_TO_VIMAGE(p)->vi_ucredrefc); + LIST_FIRST(&vprocg_head)->nprocs++; #endif #ifdef AUDIT audit_cred_kproc0(p->p_ucred); ==== //depot/projects/vimage/src/sys/kern/kern_prot.c#7 (text+ko) ==== @@ -1794,6 +1794,10 @@ */ if (jailed(cr)) prison_free(cr->cr_prison); +#ifdef VIMAGE + if (cr->cr_vimage != NULL) + refcount_release(&cr->cr_vimage->vi_ucredrefc); +#endif #ifdef AUDIT audit_cred_destroy(cr); #endif @@ -1829,6 +1833,10 @@ uihold(dest->cr_ruidinfo); if (jailed(dest)) prison_hold(dest->cr_prison); +#ifdef VIMAGE + KASSERT(src->cr_vimage != NULL, ("cr_vimage == NULL")); + refcount_acquire(&dest->cr_vimage->vi_ucredrefc); +#endif #ifdef AUDIT audit_cred_copy(src, dest); #endif ==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#49 (text+ko) ==== @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -527,12 +528,14 @@ oldcred = p->p_ucred; setsugid(p); crcopy(newcred, oldcred); + refcount_release(&newcred->cr_vimage->vi_ucredrefc); newcred->cr_vimage = vip_r; - newcred->cr_rvimage = vip_r; /* XXX */ + refcount_acquire(&newcred->cr_vimage->vi_ucredrefc); p->p_ucred = newcred; PROC_UNLOCK(p); sx_xlock(&allproc_lock); oldcred->cr_vimage->v_procg->nprocs--; + refcount_release(&oldcred->cr_vimage->vi_ucredrefc); P_TO_VPROCG(p)->nprocs++; sched_load_reassign(oldcred->cr_vimage->v_procg, newcred->cr_vimage->v_procg); @@ -682,6 +685,10 @@ if (vnet->sockcnt != 0) return (EBUSY); + if (vip->vi_ucredrefc != 0) + printf("vi_destroy: %s ucredrefc %d\n", + vip->vi_name, vip->vi_ucredrefc); + VNET_LIST_LOCK(); LIST_REMOVE(vnet, vnet_le); VNET_LIST_UNLOCK(); ==== //depot/projects/vimage/src/sys/sys/vimage.h#47 (text+ko) ==== @@ -383,6 +383,7 @@ LIST_HEAD(, vimage) vi_child_head; /* direct offspring list */ struct vimage *vi_parent; /* ptr to parent vimage */ u_int vi_id; /* ID num */ + u_int vi_ucredrefc; /* refc of ucreds pointing to us */ char vi_name[MAXHOSTNAMELEN]; /* assigned by parent */