iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>,
	David Woodhouse <dwmw2@infradead.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	Kirti Wankhede <kwankhede@nvidia.com>
Cc: ashok.raj@intel.com, sanjay.k.kumar@intel.com,
	jacob.jun.pan@intel.com, kevin.tian@intel.com,
	yi.l.liu@intel.com, yi.y.sun@intel.com, peterx@redhat.com,
	iommu@lists.linux-foundation.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Lu Baolu <baolu.lu@linux.intel.com>,
	Jacob Pan <jacob.jun.pan@linux.intel.com>
Subject: [RFC PATCH 10/10] vfio/type1: Allocate domain for mediated device
Date: Sun, 22 Jul 2018 14:09:33 +0800	[thread overview]
Message-ID: <1532239773-15325-11-git-send-email-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <1532239773-15325-1-git-send-email-baolu.lu@linux.intel.com>

This allocates a domain for the mediated device if it is able to
be isolated and protected individually by IOMMU.

Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Liu Yi L <yi.l.liu@intel.com>
Signed-off-by: Sanjay Kumar <sanjay.k.kumar@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/vfio/vfio_iommu_type1.c | 43 ++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 3e5b177..496bea6 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1177,6 +1177,22 @@ static int vfio_bus_type(struct device *dev, void *data)
 	return 0;
 }
 
+static int mdev_private_domain(struct device *dev, void *data)
+{
+	enum mdev_domain_type type;
+	enum mdev_domain_type (*fn)(struct device *dev);
+
+	fn = symbol_get(mdev_get_domain_type);
+	if (fn) {
+		type = fn(dev);
+		symbol_put(mdev_get_domain_type);
+
+		return type != DOMAIN_TYPE_PRIVATE;
+	}
+
+	return -EINVAL;
+}
+
 static int vfio_iommu_replay(struct vfio_iommu *iommu,
 			     struct vfio_domain *domain)
 {
@@ -1371,18 +1387,23 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
 	mdev_bus = symbol_get(mdev_bus_type);
 
 	if (mdev_bus) {
-		if ((bus == mdev_bus) && !iommu_present(bus)) {
-			symbol_put(mdev_bus_type);
-			if (!iommu->external_domain) {
-				INIT_LIST_HEAD(&domain->group_list);
-				iommu->external_domain = domain;
-			} else
-				kfree(domain);
+		if (bus == mdev_bus) {
+			ret = iommu_group_for_each_dev(iommu_group, NULL,
+						       mdev_private_domain);
+			if (!iommu_present(bus) || ret) {
+				symbol_put(mdev_bus_type);
+				if (!iommu->external_domain) {
+					INIT_LIST_HEAD(&domain->group_list);
+					iommu->external_domain = domain;
+				} else {
+					kfree(domain);
+				}
 
-			list_add(&group->next,
-				 &iommu->external_domain->group_list);
-			mutex_unlock(&iommu->lock);
-			return 0;
+				list_add(&group->next,
+					 &iommu->external_domain->group_list);
+				mutex_unlock(&iommu->lock);
+				return 0;
+			}
 		}
 		symbol_put(mdev_bus_type);
 	}
-- 
2.7.4

      parent reply	other threads:[~2018-07-22  6:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-22  6:09 [RFC PATCH 00/10] vfio/mdev: IOMMU aware mediated device Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 01/10] iommu/vt-d: Get iommu device for a " Lu Baolu
2018-07-23  4:44   ` Liu, Yi L
     [not found]     ` <A2975661238FB949B60364EF0F2C257439CA141D-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-07-24  2:06       ` Lu Baolu
     [not found]   ` <1532239773-15325-2-git-send-email-baolu.lu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-24 18:50     ` Alex Williamson
     [not found]       ` <20180724125056.4ae477c9-1yVPhWWZRC1BDLzU/O5InQ@public.gmane.org>
2018-07-25  1:18         ` Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 02/10] iommu/vt-d: Alloc domain " Lu Baolu
2018-07-23  4:44   ` Liu, Yi L
     [not found]     ` <A2975661238FB949B60364EF0F2C257439CA1432-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-07-24  2:09       ` Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 03/10] iommu/vt-d: Allocate groups for mediated devices Lu Baolu
     [not found]   ` <1532239773-15325-4-git-send-email-baolu.lu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-23  4:44     ` Liu, Yi L
     [not found]       ` <A2975661238FB949B60364EF0F2C257439CA143E-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-07-24  2:22         ` Lu Baolu
2018-07-24 11:30           ` Jean-Philippe Brucker
2018-07-24 19:51             ` Alex Williamson
2018-07-25  2:06             ` Lu Baolu
     [not found]             ` <ccf6890a-30c6-770b-4299-8cabfdc32f2b-5wv7dgnIgG8@public.gmane.org>
2018-07-25  2:16               ` Tian, Kevin
2018-07-25  2:35             ` Liu, Yi L
     [not found]             ` <AADFC41AFE54684AB9EE6CBC0274A5D19127FB9E@SHSMSX101.ccr.corp.intel.com>
2018-07-25  6:19               ` Tian, Kevin
     [not found]                 ` <AADFC41AFE54684AB9EE6CBC0274A5D19127FF05-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-07-25 19:19                   ` Jean-Philippe Brucker
     [not found]                     ` <a530c220-9bf1-05ec-5698-526ccbea127f-5wv7dgnIgG8@public.gmane.org>
2018-07-26  3:03                       ` Tian, Kevin
     [not found]                         ` <AADFC41AFE54684AB9EE6CBC0274A5D1912826A4-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-07-26 15:09                           ` Jean-Philippe Brucker
     [not found]                     ` <AADFC41AFE54684AB9EE6CBC0274A5D1912826AE@SHSMSX101.ccr.corp.intel.com>
     [not found]                       ` <AADFC41AFE54684AB9EE6CBC0274A5D1912826AE-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2018-07-26  3:28                         ` Tian, Kevin
2018-07-26 15:09                           ` Jean-Philippe Brucker
2018-07-22  6:09 ` [RFC PATCH 04/10] iommu/vt-d: Get pasid table for a mediated device Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 05/10] iommu/vt-d: Setup DMA remapping for mediated devices Lu Baolu
2018-07-23  4:44   ` Liu, Yi L
2018-07-24  2:29     ` Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 06/10] iommu: Add iommu_set_bus API interface Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 07/10] iommu/vt-d: Add set_bus iommu ops Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 08/10] vfio/mdev: Set iommu ops for mdev bus Lu Baolu
2018-07-22  6:09 ` [RFC PATCH 09/10] vfio/mdev: Add mediated device domain type Lu Baolu
2018-07-22  6:09 ` Lu Baolu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1532239773-15325-11-git-send-email-baolu.lu@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@intel.com \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=sanjay.k.kumar@intel.com \
    --cc=yi.l.liu@intel.com \
    --cc=yi.y.sun@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).