Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165444AbdD1NUi (ORCPT ); Fri, 28 Apr 2017 09:20:38 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38859 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968635AbdD1NUc (ORCPT ); Fri, 28 Apr 2017 09:20:32 -0400 Date: Fri, 28 Apr 2017 15:20:17 +0200 From: Gerald Schaefer To: Joerg Roedel 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 In-Reply-To: <20170427211232.GF1332@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> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17042813-0012-0000-0000-0000051B40BB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042813-0013-0000-0000-000018412D47 Message-Id: <20170428152017.5e99d67f@thinkpad> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-28_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704280193 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1488 Lines: 34 On Thu, 27 Apr 2017 23:12:32 +0200 Joerg Roedel wrote: > On Thu, Apr 27, 2017 at 08:11:42PM +0200, Gerald Schaefer wrote: > > > +void zpci_destroy_iommu(struct zpci_dev *zdev) > > > +{ > > > + iommu_group_put(zdev->group); > > > + zdev->group = NULL; > > > +} > > > > While the rest of this patch doesn't seem to make much of a difference to > > the current behavior, I'm wondering where this extra iommu_group_put() > > comes from. It either was erroneously missing before this patch, or it > > is erroneously introduced by this patch. > > 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. Now I'm wondering where this one reference is put again, and I thought that happened in the remove_device callback, where we call iommu_group_remove_device(). Is this not correct? Just want to make sure that we don't have a refcount issue in the current code. Regards, Gerald