Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756498AbdD1Okk (ORCPT ); Fri, 28 Apr 2017 10:40:40 -0400 Received: from 8bytes.org ([81.169.241.247]:38697 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755816AbdD1Okc (ORCPT ); Fri, 28 Apr 2017 10:40:32 -0400 Date: Fri, 28 Apr 2017 16:40:30 +0200 From: Joerg Roedel To: Gerald Schaefer Cc: Sebastian Ott , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: Re: [PATCH 1/2] iommu/s390: Fix IOMMU groups Message-ID: <20170428144030.GG1332@8bytes.org> References: <1493306905-32334-1-git-send-email-joro@8bytes.org> <1493306905-32334-2-git-send-email-joro@8bytes.org> <20170427201142.18d467a3@thinkpad> <20170427211232.GF1332@8bytes.org> <20170428152017.5e99d67f@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170428152017.5e99d67f@thinkpad> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1278 Lines: 29 On Fri, Apr 28, 2017 at 03:20:17PM +0200, Gerald Schaefer wrote: > On Thu, 27 Apr 2017 23:12:32 +0200 > Joerg Roedel wrote: > > This is the way to free an iommu-group. It was missing before probably > > because it was unclear whether the add_device function allocated a group > > or not. So there was no way to know if it needs to be put again in the > > remove_device function. > > Hmm, for the reference count it should not matter whether a new group was > allocated or an existing group found with iommu_group_get(). Our add_device > callback always gets one reference either from iommu_group_get or _alloc, > and then another one from iommu_group_add_device(), after which the first > reference is put again. So there should always be one reference more after > a successful add_device. Right, my statement above is wrong. The current code is fine, it gets a reference to the group with iommu_group_get/iommu_group_alloc, attaches the device to the group (which takes a reference to the group of its own), and in the end it drops its local reference. When the device->group link is broken up in the remove_device function, that reference is also dropped. So everything is fine. The additional iommu_group_put() in my patch is wrong. Regards, Joerg