Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S642277AbdD1SG1 (ORCPT ); Fri, 28 Apr 2017 14:06:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42984 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S642245AbdD1SGV (ORCPT ); Fri, 28 Apr 2017 14:06:21 -0400 Date: Fri, 28 Apr 2017 20:06:12 +0200 From: Gerald Schaefer To: Joerg Roedel Cc: Sebastian Ott , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 0/2] iommu/s390: Fix iommu-groups and add sysfs support In-Reply-To: <20170428145513.GH1332@8bytes.org> References: <1493306905-32334-1-git-send-email-joro@8bytes.org> <20170427201018.70c8be5a@thinkpad> <20170427210325.GE1332@8bytes.org> <20170428144634.7950c8cf@thinkpad> <20170428145513.GH1332@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: 17042818-0040-0000-0000-0000037955E0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042818-0041-0000-0000-000025292A2F Message-Id: <20170428200612.42b4f3d2@thinkpad> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-28_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704280231 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2810 Lines: 57 On Fri, 28 Apr 2017 16:55:13 +0200 Joerg Roedel wrote: > > I am however a bit confused now, about how we would have allowed group > > sharing with the current s390 IOMMU code, or IOW in which scenario would > > iommu_group_get() in the add_device callback find a shareable iommu-group? > > The usual way to do this is to use the iommu_group_get_for_dev() > function, which invokes the iommu_ops->device_group call-back of the > driver to find a matching group or allocating a new one. > > There are ready-to-use functions for this call-back already: > > 1) generic_device_group() - which just allocates a new group for > the device. This is usually used outside of PCI > > 2) pci_device_group() - Which walks the PCI hierarchy to find > devices that are not isolated and uses the matching group for > its isolation domain. > > A few drivers have their own versions of this call-back, but those are > IOMMU drivers supporting multiple bus-types and need to find the right > way to determine the group first. > > > So, I guess we may have an issue with not sharing iommu-groups when > > it could make sense to do so. But your patch would not fix this, as > > we still would allocate separate iommu-groups for all functions. > > Yes, but the above approach won't help when each function ends up on a > seperate bus because the code looks for different functions that are > enumerated as such. Anyway, some more insight into how this enumeration > works on s390 would be great :) Since Sebastian confirmed this, it looks like we do not really have any enumeration when there is a separate bus for each function. Also, IIRC, add_device will get called before attach_dev. Currently we allow to attach more than one device (apparently from different buses) to one domain (one shared DMA table) in attach_dev. But then it would be too late to also add all devices to the same iommu-group. That would have had to be done earlier in add_device, but there we don't know yet if a shared DMA table would be set up later in attach_dev. So, it looks to me that we cannot provide correct iommu-group sharing on s390, even though we allow iommu-domain sharing, which sounds odd. Since this "shared domain / DMA table" option in attach_dev was only added because at that time I thought that was a hard requirement for any arch- specific IOMMU API implementation, maybe there was some misunderstanding. It would make the code easier (and more consistent with the s390 hardware) if I would just remove that option from attach_dev, and allow only one device/function per iommu-domain. What do you think, could this be removed for s390, or is there any common code requirement for providing that option (and is it OK that we have separate iommu-groups in this case)? Regards, Gerald