From owner-p4-projects@FreeBSD.ORG Mon Feb 6 21:41:34 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E6DFC16A423; Mon, 6 Feb 2006 21:41:33 +0000 (GMT) X-Original-To: perforce@freebsd.org 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 C08CD16A420 for ; Mon, 6 Feb 2006 21:41:33 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id D55B243D76 for ; Mon, 6 Feb 2006 21:41:29 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k16LfTiB097442 for ; Mon, 6 Feb 2006 21:41:29 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k16LfT07097439 for perforce@freebsd.org; Mon, 6 Feb 2006 21:41:29 GMT (envelope-from jhb@freebsd.org) Date: Mon, 6 Feb 2006 21:41:29 GMT Message-Id: <200602062141.k16LfT07097439@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 91261 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, 06 Feb 2006 21:41:35 -0000 http://perforce.freebsd.org/chv.cgi?CH=91261 Change 91261 by jhb@jhb_slimer on 2006/02/06 21:40:31 Save this fix for a race condition here until Kris can test it to verify that it works. Reviewed by: alc Affected files ... .. //depot/projects/smpng/sys/vm/vm_object.c#77 edit Differences ... ==== //depot/projects/smpng/sys/vm/vm_object.c#77 (text+ko) ==== @@ -438,23 +438,37 @@ while (object != NULL) { int vfslocked; - /* - * In general, the object should be locked when working with - * its type. In this case, in order to maintain proper lock - * ordering, an exception is possible because a vnode-backed - * object never changes its type. - */ + vfslocked = 0; + restart: + VM_OBJECT_LOCK(object); if (object->type == OBJT_VNODE) { struct vnode *vp = (struct vnode *) object->handle; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); - } - VM_OBJECT_LOCK(object); - if (object->type == OBJT_VNODE) { + + /* + * Conditionally acquire Giant for a vnode-backed + * object. We have to be careful since the type of + * a vnode object can change while the object is + * unlocked. + */ + if (VFS_NEEDSGIANT(vp->v_mount) && !vfslocked) { + vfslocked = 1; + if (!mtx_trylock(&Giant)) { + VM_OBJECT_UNLOCK(object); + mtx_lock(&Giant); + goto restart; + } + } vm_object_vndeallocate(object); VFS_UNLOCK_GIANT(vfslocked); return; - } + } else + /* + * This is to handle the case that the object + * changed type while we dropped its lock to + * obtain Giant. + */ + VFS_UNLOCK_GIANT(vfslocked); KASSERT(object->ref_count != 0, ("vm_object_deallocate: object deallocated too many times: %d", object->type));