From owner-freebsd-xen@freebsd.org Mon Jul 30 09:32:05 2018 Return-Path: Delivered-To: freebsd-xen@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 947B110507D8 for ; Mon, 30 Jul 2018 09:32:05 +0000 (UTC) (envelope-from royger@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BE079045B; Mon, 30 Jul 2018 09:32:05 +0000 (UTC) (envelope-from royger@freebsd.org) Received: from localhost (95.red-88-3-119.dynamicip.rima-tde.net [88.3.119.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: royger) by smtp.freebsd.org (Postfix) with ESMTPSA id AA9269292; Mon, 30 Jul 2018 09:32:04 +0000 (UTC) (envelope-from royger@freebsd.org) Date: Mon, 30 Jul 2018 11:31:55 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Pratyush Yadav Cc: FreeBSD-Xen , Akshay Jaggi , Edward Napierala Subject: Re: Recursion in non-recursive mutex when using the grant table free callbacks Message-ID: <20180730093155.c6ihgafia5ducw65@mac.bytemobile.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-BeenThere: freebsd-xen@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Discussion of the freebsd port to xen - implementation and usage List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2018 09:32:05 -0000 On Sun, Jul 29, 2018 at 06:08:56PM +0530, Pratyush Yadav wrote: > Hi, > > Currently, the grant table free callbacks can not work. This is > because of a recursion on a non-recursive mutex that causes a kernel > panic. The cause of the recursion is: check_free_callbacks() is always > called with the lock gnttab_list_lock held. So, the callback function > is called with the lock held. So, when the client uses any of the > grant reference allocation methods get_free_entries() is called, which > tries to acquire gnttab_list_lock(grant_table.c:77 [0]), causing a > recursion on the lock. > > I'm not sure what the correct fix would be though. One way I can think > of is that check_free_callback() should be called without the lock > held. But with this fix, it is possible for the callback to be called > even though the grant references it needs are not available. This > would happen when another thread takes those references while the > current thread has completed the check if(gnttab_free_count >= > callback->count) but has not yet called the callback > (grant_table,c:105 [1]). > > I think a better way to fix this would be to have a check in > get_free_entries() whether the current thread holds the lock, so it > does not try to acquire the lock if the current thread already holds > it. I agree in the analysis, however I think the proper solution is to use a recursive lock. Roger.