From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755568AbcJXKf1 (ORCPT ); Mon, 24 Oct 2016 06:35:27 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:1386 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752075AbcJXKf0 (ORCPT ); Mon, 24 Oct 2016 06:35:26 -0400 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 24 Oct 2016 03:35:23 -0700 Subject: Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices To: Alex Williamson , Jike Song References: <1476739332-4911-1-git-send-email-kwankhede@nvidia.com> <1476739332-4911-5-git-send-email-kwankhede@nvidia.com> <5809C873.1040703@intel.com> <20161021083602.2b05ecac@t450s.home> CC: , , , , , , , X-Nvconfidentiality: public From: Kirti Wankhede Message-ID: <3c640913-c51f-873d-952f-cc279b8f4869@nvidia.com> Date: Mon, 24 Oct 2016 16:05:13 +0530 MIME-Version: 1.0 In-Reply-To: <20161021083602.2b05ecac@t450s.home> X-Originating-IP: [10.24.216.210] X-ClientProxiedBy: BGMAIL104.nvidia.com (10.25.59.13) To bgmail102.nvidia.com (10.25.59.11) Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/21/2016 8:06 PM, Alex Williamson wrote: > On Fri, 21 Oct 2016 15:49:07 +0800 > Jike Song wrote: > >> On 10/18/2016 05:22 AM, Kirti Wankhede wrote: >>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c >>> index 2ba19424e4a1..5d67058a611d 100644 >>> --- a/drivers/vfio/vfio_iommu_type1.c >>> +++ b/drivers/vfio/vfio_iommu_type1.c >> [snip] >>> static int vfio_iommu_type1_attach_group(void *iommu_data, >>> struct iommu_group *iommu_group) >>> { >>> struct vfio_iommu *iommu = iommu_data; >>> - struct vfio_group *group, *g; >>> + struct vfio_group *group; >>> struct vfio_domain *domain, *d; >>> struct bus_type *bus = NULL; >>> int ret; >>> @@ -746,10 +1136,14 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, >>> mutex_lock(&iommu->lock); >>> >>> list_for_each_entry(d, &iommu->domain_list, next) { >>> - list_for_each_entry(g, &d->group_list, next) { >>> - if (g->iommu_group != iommu_group) >>> - continue; >>> + if (find_iommu_group(d, iommu_group)) { >>> + mutex_unlock(&iommu->lock); >>> + return -EINVAL; >>> + } >>> + } >>> >>> + if (iommu->local_domain) { >>> + if (find_iommu_group(iommu->local_domain, iommu_group)) { >>> mutex_unlock(&iommu->lock); >>> return -EINVAL; >>> } >>> @@ -769,6 +1163,30 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, >>> if (ret) >>> goto out_free; >>> >>> + if (IS_ENABLED(CONFIG_VFIO_MDEV) && !iommu_present(bus) && >>> + (bus == &mdev_bus_type)) { >> >> Hi Kirti, >> >> By refering mdev_bus_type directly you are making vfio_iommu_type1.ko depends >> on mdev.ko, but in Kconfig doesn't guarantee the dependency. For example, >> if CONFIG_VFIO_IOMMU_TYPE1=y and CONFIG_VFIO_MDEV=m, the building will fail. > > Good point, Jike. I don't think we want to make existing vfio modules > dependent on mdev modules. I wonder if we can lookup the mdev_bus_type > symbol w/o triggering the module load. Thanks, > Ok. Modifying the check as below works in above case: mdev_bus = symbol_get(mdev_bus_type); if (mdev_bus && (bus == mdev_bus) && !iommu_present(bus) ) { symbol_put(mdev_bus_type); ... } Kirti