From owner-freebsd-xen@freebsd.org Mon Jun 18 13:03:06 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 46A501005EE3 for ; Mon, 18 Jun 2018 13:03:06 +0000 (UTC) (envelope-from royger@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 EC97B7DD1E; Mon, 18 Jun 2018 13:03:05 +0000 (UTC) (envelope-from royger@freebsd.org) Received: from localhost (80.red-88-8-240.dynamicip.rima-tde.net [88.8.240.80]) (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 614E813569; Mon, 18 Jun 2018 13:03:05 +0000 (UTC) (envelope-from royger@freebsd.org) Date: Mon, 18 Jun 2018 15:02:55 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Pratyush Yadav Cc: FreeBSD-Xen Subject: Re: gnttab_end_foreign_access_ref() leaking grant entries? Message-ID: <20180618130255.3eflhi62m7wv7jpv@mac.bytemobile.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180512 X-BeenThere: freebsd-xen@freebsd.org X-Mailman-Version: 2.1.26 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, 18 Jun 2018 13:03:06 -0000 On Mon, Jun 18, 2018 at 06:11:00PM +0530, Pratyush Yadav wrote: > Hi everyone, > > I was looking at gnttab_end_foreign_access_ref() and I notice that > while gnttab_end_foreign_access_ref() ends the foreign access, it does > not free the grant reference. > > gnttab_end_foreign_access() free the reference by calling put_free_entry(ref). > > gnttab_end_foreign_access_references() also frees the grant entries. > > Shouldn't gnttab_end_foreign_access_ref() also free the grant entry? > It is an inconsistency at best and a bug at worst. I think the point of using gnttab_end_foreign_access_ref is that it doesn't free the reference. The naming convention of grant reference related functions is just horrible, but I think this one is actually clear, it just removes the foreign access permissions of this reference, but it doesn't free it. I think I would rather rename gnttab_end_foreign_access to gnttab_end_foreign_access_and_free (and the same with the rest of the end_foreign_ family of functions). This is more descriptive. In any case, this is not a bug. Current netfront code makes use of this function in order to keep a pool of grant references, so by changing gnttab_end_foreign_access_ref to free the references you will break netfront. And now I realize this is something that you will have to take into account for the busdma grant reference project. You will have to introduce a flag that allows creating a dmamap with pre-allocated references that are not freed until the map is destroyed. But let's focus on that after the initial implementation is done. Roger.