Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4509294img; Tue, 26 Mar 2019 10:44:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqymhuBDtuQX04Ka2ijG01vAPysxCp4lvQKWXjUkagg7kmjV3dQCu50ORzrR/Qw1CENOHRlJ X-Received: by 2002:a65:6559:: with SMTP id a25mr27424845pgw.99.1553622297434; Tue, 26 Mar 2019 10:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553622297; cv=none; d=google.com; s=arc-20160816; b=N0wrFIzCwnkbD4rBClrlQM1G+KCAhbjoy2ColpXYgduFGuTBwv17tDXcJHabryH1JC VzETLUDpHbgsDAyQIV7wh9W/YRb2v8/RhmWWdOemjmGdkm6yOBCgowqefPQbwy/2lMHn I/m1rCPCjI2obOPHg3kPbVSg5w3T6P+kerJZK5fpXkQRItg/CI46gR07Rs6tJk5i/QWr ZUohaAlOkR4clIu12AEklh4mtFy1Bi97nw3z5oBi0AHGVhf8Z5Ku6muFDewqc8Em0MhO M7E1aIC/dPg6blaYDsxjjo6ulUdJ7aBOmnhIDxUCokh2rhN756iP3UZ1QacgPn40zx2t Y9eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=OaKOlki/yalBeezYnDX29NMW0UhOobM7wmSCU6xvJN4=; b=FuB1ot/sjI7q2iT/UBoH03hUeBepoxyjhwn9LhCQb1NJx/fEPID4shjSU6V4jWco4k IqdbTOWEmBxo1ZPPM4akCGcAAtIvHTQgGI97qiWibYIEcR2Bcp52jj1gmK6BeuxhVBTR 5MZ+9jVzJivlCdCWkT4GsBrvoWNo+Jhcn+NN5pXhcsT/XvmGdNg7lqqHXrVUa1SzLcOg h8JiYvlDeYBZY1EyeYDVZiXpapOpZJMAPMJtSxwf4xPRu80tmNE8Y0wL3UsjPcDCdElQ VAYnvwB/KaskjFQq3zdo4xpoImdxeT3RSFOt3rkoEq3M0Qy19Yt1aOBkTv3acnk11dB+ imjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si17834250plj.345.2019.03.26.10.44.42; Tue, 26 Mar 2019 10:44:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732293AbfCZRmk (ORCPT + 99 others); Tue, 26 Mar 2019 13:42:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48898 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729440AbfCZRmj (ORCPT ); Tue, 26 Mar 2019 13:42:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C962E307F5FE; Tue, 26 Mar 2019 17:42:38 +0000 (UTC) Received: from x1.home (ovpn-116-99.phx2.redhat.com [10.3.116.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD16617992; Tue, 26 Mar 2019 17:42:37 +0000 (UTC) Date: Tue, 26 Mar 2019 11:42:37 -0600 From: Alex Williamson To: Lu Baolu Cc: Joerg Roedel , David Woodhouse , Kirti Wankhede , ashok.raj@intel.com, sanjay.k.kumar@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, Jean-Philippe Brucker , yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com, tiwei.bie@intel.com, xin.zeng@intel.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jacob Pan Subject: Re: [PATCH v8 9/9] vfio/type1: Handle different mdev isolation type Message-ID: <20190326114237.6be15e47@x1.home> In-Reply-To: <20190325013036.18400-10-baolu.lu@linux.intel.com> References: <20190325013036.18400-1-baolu.lu@linux.intel.com> <20190325013036.18400-10-baolu.lu@linux.intel.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 26 Mar 2019 17:42:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Mar 2019 09:30:36 +0800 Lu Baolu wrote: > This adds the support to determine the isolation type > of a mediated device group by checking whether it has > an iommu device. If an iommu device exists, an iommu > domain will be allocated and then attached to the iommu > device. Otherwise, keep the same behavior as it is. > > Cc: Ashok Raj > Cc: Jacob Pan > Cc: Kevin Tian > Signed-off-by: Sanjay Kumar > Signed-off-by: Liu Yi L > Signed-off-by: Lu Baolu > Reviewed-by: Jean-Philippe Brucker > --- > drivers/vfio/vfio_iommu_type1.c | 55 +++++++++++++++++++++++++-------- > 1 file changed, 42 insertions(+), 13 deletions(-) Acked-by: Alex Williamson > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index ccc4165474aa..b91cafcd5181 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -559,7 +559,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, > mutex_lock(&iommu->lock); > > /* Fail if notifier list is empty */ > - if ((!iommu->external_domain) || (!iommu->notifier.head)) { > + if (!iommu->notifier.head) { > ret = -EINVAL; > goto pin_done; > } > @@ -641,11 +641,6 @@ static int vfio_iommu_type1_unpin_pages(void *iommu_data, > > mutex_lock(&iommu->lock); > > - if (!iommu->external_domain) { > - mutex_unlock(&iommu->lock); > - return -EINVAL; > - } > - > do_accounting = !IS_IOMMU_CAP_DOMAIN_IN_CONTAINER(iommu); > for (i = 0; i < npage; i++) { > struct vfio_dma *dma; > @@ -1368,13 +1363,40 @@ static void vfio_iommu_detach_group(struct vfio_domain *domain, > iommu_detach_group(domain->domain, group->iommu_group); > } > > +static bool vfio_bus_is_mdev(struct bus_type *bus) > +{ > + struct bus_type *mdev_bus; > + bool ret = false; > + > + mdev_bus = symbol_get(mdev_bus_type); > + if (mdev_bus) { > + ret = (bus == mdev_bus); > + symbol_put(mdev_bus_type); > + } > + > + return ret; > +} > + > +static int vfio_mdev_iommu_device(struct device *dev, void *data) > +{ > + struct device **old = data, *new; > + > + new = vfio_mdev_get_iommu_device(dev); > + if (!new || (*old && *old != new)) > + return -EINVAL; > + > + *old = new; > + > + return 0; > +} > + > 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; > struct vfio_domain *domain, *d; > - struct bus_type *bus = NULL, *mdev_bus; > + struct bus_type *bus = NULL; > int ret; > bool resv_msi, msi_remap; > phys_addr_t resv_msi_base; > @@ -1409,23 +1431,30 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, > if (ret) > goto out_free; > > - mdev_bus = symbol_get(mdev_bus_type); > + if (vfio_bus_is_mdev(bus)) { > + struct device *iommu_device = NULL; > > - if (mdev_bus) { > - if ((bus == mdev_bus) && !iommu_present(bus)) { > - symbol_put(mdev_bus_type); > + group->mdev_group = true; > + > + /* Determine the isolation type */ > + ret = iommu_group_for_each_dev(iommu_group, &iommu_device, > + vfio_mdev_iommu_device); > + if (ret || !iommu_device) { > if (!iommu->external_domain) { > INIT_LIST_HEAD(&domain->group_list); > iommu->external_domain = domain; > - } else > + } else { > kfree(domain); > + } > > list_add(&group->next, > &iommu->external_domain->group_list); > mutex_unlock(&iommu->lock); > + > return 0; > } > - symbol_put(mdev_bus_type); > + > + bus = iommu_device->bus; > } > > domain->domain = iommu_domain_alloc(bus);