linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Yi L <yi.l.liu@intel.com>
To: alex.williamson@redhat.com, kwankhede@nvidia.com
Cc: kevin.tian@intel.com, baolu.lu@linux.intel.com,
	yi.l.liu@intel.com, yi.y.sun@intel.com, joro@8bytes.org,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	yan.y.zhao@intel.com, shaopeng.he@intel.com,
	chenbo.xia@intel.com, jun.j.tian@intel.com
Subject: [PATCH v2 12/13] vfio/type1: use iommu_attach_group() for wrapping PF/VF as mdev
Date: Thu,  5 Sep 2019 15:59:29 +0800	[thread overview]
Message-ID: <1567670370-4484-13-git-send-email-yi.l.liu@intel.com> (raw)
In-Reply-To: <1567670370-4484-1-git-send-email-yi.l.liu@intel.com>

This patch uses iommu_attach_group() to do group attach when it is
for the case of wrapping a PF/VF as a mdev. iommu_attach_device()
doesn't support non-singleton iommu group attach. With this change,
wrapping PF/VF as mdev can work on non-singleton iommu groups.

Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
---
 drivers/vfio/vfio_iommu_type1.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 054391f..317430d 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1312,13 +1312,20 @@ static int vfio_mdev_attach_domain(struct device *dev, void *data)
 {
 	struct iommu_domain *domain = data;
 	struct device *iommu_device;
+	struct iommu_group *group;
 
 	iommu_device = vfio_mdev_get_iommu_device(dev);
 	if (iommu_device) {
 		if (iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX))
 			return iommu_aux_attach_device(domain, iommu_device);
-		else
-			return iommu_attach_device(domain, iommu_device);
+		else {
+			group = iommu_group_get(iommu_device);
+			if (!group) {
+				WARN_ON(1);
+				return -EINVAL;
+			}
+			return iommu_attach_group(domain, group);
+		}
 	}
 
 	return -EINVAL;
@@ -1328,13 +1335,20 @@ static int vfio_mdev_detach_domain(struct device *dev, void *data)
 {
 	struct iommu_domain *domain = data;
 	struct device *iommu_device;
+	struct iommu_group *group;
 
 	iommu_device = vfio_mdev_get_iommu_device(dev);
 	if (iommu_device) {
 		if (iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX))
 			iommu_aux_detach_device(domain, iommu_device);
-		else
-			iommu_detach_device(domain, iommu_device);
+		else {
+			group = iommu_group_get(iommu_device);
+			if (!group) {
+				WARN_ON(1);
+				return -EINVAL;
+			}
+			iommu_detach_group(domain, group);
+		}
 	}
 
 	return 0;
-- 
2.7.4


  parent reply	other threads:[~2019-09-06  8:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05  7:59 [PATCH v2 00/13] vfio_pci: wrap pci device as a mediated device Liu Yi L
2019-09-05  7:59 ` [PATCH v2 01/13] vfio_pci: move vfio_pci_is_vga/vfio_vga_disabled to header Liu Yi L
2019-09-05  7:59 ` [PATCH v2 02/13] vfio_pci: refine user config reference in vfio-pci module Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:38     ` Liu, Yi L
2019-09-05  7:59 ` [PATCH v2 03/13] vfio_pci: refine vfio_pci_driver reference in vfio_pci.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 04/13] vfio_pci: make common functions be extern Liu Yi L
2019-09-05  7:59 ` [PATCH v2 05/13] vfio_pci: duplicate vfio_pci.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 06/13] vfio_pci: shrink vfio_pci_common.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 07/13] vfio_pci: shrink vfio_pci.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 08/13] vfio/pci: protect cap/ecap_perm bits alloc/free with atomic op Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:38     ` Liu, Yi L
2019-09-05  7:59 ` [PATCH v2 09/13] samples: add vfio-mdev-pci driver Liu Yi L
2019-09-05  7:59 ` [PATCH v2 10/13] samples: refine " Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:39     ` Liu, Yi L
2019-09-05  7:59 ` [PATCH v2 11/13] samples/vfio-mdev-pci: call vfio_add_group_dev() Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:40     ` Liu, Yi L
2019-09-05  7:59 ` Liu Yi L [this message]
2019-09-26  2:37   ` [PATCH v2 12/13] vfio/type1: use iommu_attach_group() for wrapping PF/VF as mdev Alex Williamson
2019-09-05  7:59 ` [PATCH v2 13/13] vfio/type1: track iommu backed group attach Liu Yi L
2019-09-25  9:13 ` [PATCH v2 00/13] vfio_pci: wrap pci device as a mediated device Liu, Yi L
2019-09-30 12:40 [PATCH v2 12/13] vfio/type1: use iommu_attach_group() for wrapping PF/VF as mdev Liu, Yi L

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=1567670370-4484-13-git-send-email-yi.l.liu@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=joro@8bytes.org \
    --cc=jun.j.tian@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shaopeng.he@intel.com \
    --cc=yan.y.zhao@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).