From owner-freebsd-stable@freebsd.org Fri Aug 12 12:39:58 2016 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B029FBB68C8 for ; Fri, 12 Aug 2016 12:39:58 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0A1AC19A7; Fri, 12 Aug 2016 12:39:57 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u7CCdo2Z037316 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Fri, 12 Aug 2016 15:39:51 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u7CCdo2Z037316 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u7CCdosT037315; Fri, 12 Aug 2016 15:39:50 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 12 Aug 2016 15:39:50 +0300 From: Konstantin Belousov To: Rick Macklem Cc: Harry Schmalzbauer , Mark Johnston , FreeBSD Stable , "kib@FreeBSD.org" Subject: Re: unionfs bugs, a partial patch and some comments [Was: Re: 1-BETA3 Panic: __lockmgr_args: downgrade a recursed lockmgr nfs @ /usr/local/share/deploy-tools/RELENG_11/src/sys/fs/unionfs/union_vnops.c:1905] Message-ID: <20160812123950.GO83214@kib.kiev.ua> References: <57A79E24.8000100@omnilan.de> <57A83C78.1070403@omnilan.de> <20160809060213.GA67664@raichu> <57A9A6C0.9060609@omnilan.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Aug 2016 12:39:58 -0000 On Thu, Aug 11, 2016 at 10:53:03PM +0000, Rick Macklem wrote: > Harry Schmalzbauer wrote: > Bez??glich Mark Johnston's Nachricht vom 09.08.2016 08:02 (localtime): > ??? > >> > >> Just for anybody else needing unionfs: > >> https://people.freebsd.org/~attilio/unionfs_missing_insmntque_lock.patch > >> > >> This patch still applies and I'm successfully using this (unmodified) up > >> to FreeBSD-10.3 and never had any panic in all these years. > > > > Having spent some time looking at unionfs, I'm a bit skeptical that this > > patch will address the panic you reported earlier, though I'd be > > interested to know if it does. > [stuff snipped for brevity] > I took a look at this. (I know nothing about unionfs, but a little w.r.t. the VFS). > I can confirm that this function (unionfs_nodeget()) is weird and appears to > be broken to me. > > The function calls insmntque() before it initializes the vnode, which seems > racey, especially if it isn't LK_EXCLUSIVE locked. > Also, line#s 278-281: > if (uppervp != NULLVP) > vp->v_vnlock = uppervp->v_vnlock; > else > vp->v_vnlock = lowervp->v_vnlock; > so your patch isn't locking the vnode lock that it actually uses. > I think the vp argument to insmntque() is required to be LK_EXCLUSIVE > locked mostly so other threads won't fiddle with the vnode until this > function is done with it, but I am not sure? > > I think a more correct version of this (not saying it would be correct[????], > would call insmntque() later in the function, after it has been initialized. > (This means that the cleanup if it fails is more involved, but...) Yes. > > I've attached a patch (untested) that does this. Maybe you could try it? > > rick > ps: I've cc'd Kostik, in case he has some insight w.r.t. how this should be handled? > insmnque() performs the cleanup on its own, and that default cleanup is not suitable for the situation. I think that insmntque1() would better fit your requirements, your need to move the common code into a helper. It seems that unionfs_ins_cached_vnode() cleanup could reuse it.