From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1Q0T-0004qO-OK for qemu-devel@nongnu.org; Mon, 31 Oct 2016 23:45:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1Q0O-0001d1-Op for qemu-devel@nongnu.org; Mon, 31 Oct 2016 23:45:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38080) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1Q0O-0001cu-Jz for qemu-devel@nongnu.org; Mon, 31 Oct 2016 23:44:56 -0400 Date: Mon, 31 Oct 2016 21:44:53 -0600 From: Alex Williamson Message-ID: <20161031214453.49da775c@t450s.home> In-Reply-To: <5818071F.3020507@intel.com> References: <1477517366-27871-1-git-send-email-kwankhede@nvidia.com> <1477517366-27871-2-git-send-email-kwankhede@nvidia.com> <5818071F.3020507@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v10 01/19] vfio: Mediated device Core driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jike Song Cc: Kirti Wankhede , pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com, bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org On Tue, 01 Nov 2016 11:08:15 +0800 Jike Song wrote: > On 10/27/2016 05:29 AM, Kirti Wankhede wrote: > > +static int mdev_attach_iommu(struct mdev_device *mdev) > > +{ > > + int ret; > > + struct iommu_group *group; > > + > > + group = iommu_group_alloc(); > > + if (IS_ERR(group)) > > + return PTR_ERR(group); > > Maybe I overthought, but where the iommu_group is released? On successful > return you already have a ref, I didn't find an iommu_group_put after that. ... > > + > > + ret = iommu_group_add_device(group, &mdev->dev); > > + if (ret) > > + goto attach_fail; > > + > > + dev_info(&mdev->dev, "MDEV: group_id = %d\n", > > + iommu_group_id(group)); > > +attach_fail: > > + iommu_group_put(group); > > + return ret; > > +} > > + > > +static void mdev_detach_iommu(struct mdev_device *mdev) > > +{ > > + iommu_group_remove_device(&mdev->dev); Here. Adding a device to the group takes a group reference so we can 'put' the group to release the reference from the alloc as soon as a device is added. When we remove the device, that reference is removed and this should result in a release of the group if all other references are balanced. Thanks, Alex > > + dev_info(&mdev->dev, "MDEV: detaching iommu\n"); > > +} > > + >