netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cindy Lu <lulu@redhat.com>
To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com,
	yi.l.liu@intel.com, jgg@nvidia.com, linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org
Subject: [RFC 4/7] vdpa: change the map/unmap process to support iommufd
Date: Sun, 24 Sep 2023 01:05:37 +0800	[thread overview]
Message-ID: <20230923170540.1447301-5-lulu@redhat.com> (raw)
In-Reply-To: <20230923170540.1447301-1-lulu@redhat.com>

Add the check for iommufd_ictx,If vdpa don't have the iommufd_ictx
then will use the Legacy iommu domain pathway

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 drivers/vhost/vdpa.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 91da012084e9..8d1ad89d4671 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -981,6 +981,10 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
 	} else if (ops->set_map) {
 		if (!v->in_batch)
 			r = ops->set_map(vdpa, asid, iotlb);
+	} else if (!vdpa->iommufd_ictx) {
+		/* Legacy iommu domain pathway without IOMMUFD */
+		r = iommu_map(v->domain, iova, pa, size,
+			      perm_to_iommu_flags(perm));
 	} else {
 		r = iommu_map(v->domain, iova, pa, size,
 			      perm_to_iommu_flags(perm));
@@ -1009,6 +1013,9 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v,
 	if (ops->set_map) {
 		if (!v->in_batch)
 			ops->set_map(vdpa, asid, iotlb);
+	} else if (!vdpa->iommufd_ictx) {
+		/* Legacy iommu domain pathway without IOMMUFD */
+		iommu_unmap(v->domain, iova, size);
 	}
 	/* If we are in the middle of batch processing, delay the free
 	 * of AS until BATCH_END.
@@ -1337,6 +1344,8 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v)
 		iommu_detach_device(v->domain, dma_dev);
 		iommu_domain_free(v->domain);
 	}
+	if (vdpa->iommufd_ictx)
+		vdpa_iommufd_unbind(vdpa);
 
 	v->domain = NULL;
 }
@@ -1560,6 +1569,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 	}
 
 	atomic_set(&v->opened, 0);
+	atomic_set(&vdpa->iommufd_users, 0);
 	v->minor = minor;
 	v->vdpa = vdpa;
 	v->nvqs = vdpa->nvqs;
-- 
2.34.3


  parent reply	other threads:[~2023-09-23 17:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23 17:05 [RFC 0/7] vdpa: Add support for iommufd Cindy Lu
2023-09-23 17:05 ` [RFC 1/7] vhost/iommufd: Add the functions support iommufd Cindy Lu
2023-09-26  2:47   ` Jason Wang
2023-09-23 17:05 ` [RFC 2/7] Kconfig: Add the new file vhost/iommufd Cindy Lu
2023-09-23 17:05 ` [RFC 3/7] vhost: Add 3 new uapi to support iommufd Cindy Lu
2023-09-25 13:49   ` Jason Gunthorpe
2023-09-26  2:47   ` Jason Wang
2023-09-23 17:05 ` Cindy Lu [this message]
2023-09-25 13:45   ` [RFC 4/7] vdpa: change the map/unmap process " Jason Gunthorpe
2023-09-26  8:09     ` Cindy Lu
2023-09-23 17:05 ` [RFC 5/7] vdpa: Add new vdpa_config_ops Cindy Lu
2023-09-26  2:47   ` Jason Wang
2023-09-23 17:05 ` [RFC 6/7] vdpa_sim :Add support for iommufd Cindy Lu
2023-09-25 13:46   ` Jason Gunthorpe
2023-09-23 17:05 ` [RFC 7/7] iommufd: Skip the CACHE_COHERENCY and iommu group check Cindy Lu
2023-09-25 13:50   ` Jason Gunthorpe
2023-09-26  8:02     ` Cindy Lu
2023-09-26  2:46 ` [RFC 0/7] vdpa: Add support for iommufd Jason Wang
2023-10-26  6:42 ` Michael S. Tsirkin
2023-10-26  6:48   ` Cindy Lu
2023-10-26  6:49     ` Michael S. Tsirkin
2023-10-26  7:03       ` Cindy Lu
2023-11-02 10:02     ` Michael S. Tsirkin
2023-11-02 12:09       ` Cindy Lu

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=20230923170540.1447301-5-lulu@redhat.com \
    --to=lulu@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=yi.l.liu@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).