netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: Cindy Lu <lulu@redhat.com>, <jasowang@redhat.com>,
	<mst@redhat.com>, <jgg@nvidia.com>,
	<linux-kernel@vger.kernel.org>,
	<virtualization@lists.linux-foundation.org>,
	<netdev@vger.kernel.org>
Subject: Re: [RFC v1 6/8] vdpa: change the map/unmap process to support iommufd
Date: Mon, 6 Nov 2023 16:54:53 +0800	[thread overview]
Message-ID: <12ebf6fc-9228-47a1-88dc-a177f7f7d5db@intel.com> (raw)
In-Reply-To: <20231103171641.1703146-7-lulu@redhat.com>

On 2023/11/4 01:16, Cindy Lu wrote:
> 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 | 43 ++++++++++++++++++++++++++++++++++++++-----
>   1 file changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index dfaddd833364..0e2dba59e1ce 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1067,9 +1067,6 @@ static int vhost_vdpa_map(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
>   		/* Legacy iommu domain pathway without IOMMUFD */
>   		r = iommu_map(v->domain, iova, pa, size,
>   			      perm_to_iommu_flags(perm), GFP_KERNEL);
> -	} else {
> -		r = iommu_map(v->domain, iova, pa, size,
> -			      perm_to_iommu_flags(perm), GFP_KERNEL);
>   	}
>   	if (r) {
>   		vhost_iotlb_del_range(iotlb, iova, iova + size - 1);
> @@ -1095,8 +1092,10 @@ 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);
>   	}
> -
>   }
>   
>   static int vhost_vdpa_va_map(struct vhost_vdpa *v,
> @@ -1149,7 +1148,36 @@ static int vhost_vdpa_va_map(struct vhost_vdpa *v,
>   
>   	return ret;
>   }
> +#if 0
> +int vhost_pin_pages(struct vdpa_device *device, dma_addr_t iova, int npage,
> +		    int prot, struct page **pages)
> +{
> +	if (!pages || !npage)
> +		return -EINVAL;
> +	//if (!device->config->dma_unmap)
> +	//return -EINVAL;
> +
> +	if (0) { //device->iommufd_access) {
> +		int ret;
> +
> +		if (iova > ULONG_MAX)
> +			return -EINVAL;
>   
> +		ret = iommufd_access_pin_pages(
> +			device->iommufd_access, iova, npage * PAGE_SIZE, pages,
> +			(prot & IOMMU_WRITE) ? IOMMUFD_ACCESS_RW_WRITE : 0);
> +		if (ret) {
> +
> +			return ret;
> +		}
> +
> +		return npage;
> +	} else {
> +		return pin_user_pages(iova, npage, prot, pages);
> +	}
> +	return -EINVAL;
> +}
> +#endif

Is above code needed or not?

>   static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   			     struct vhost_iotlb *iotlb,
>   			     u64 iova, u64 size, u64 uaddr, u32 perm)
> @@ -1418,9 +1446,13 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v)
>   	struct device *dma_dev = vdpa_get_dma_dev(vdpa);
>   
>   	if (v->domain) {
> -		iommu_detach_device(v->domain, dma_dev);
> +		if (!vdpa->iommufd_ictx) {
> +			iommu_detach_device(v->domain, dma_dev);
> +		}
>   		iommu_domain_free(v->domain);
>   	}
> +	if (vdpa->iommufd_ictx)
> +		vdpa_iommufd_unbind(vdpa);
>   
>   	v->domain = NULL;
>   }
> @@ -1645,6 +1677,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;

-- 
Regards,
Yi Liu

  reply	other threads:[~2023-11-06  8:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 17:16 [RFC v1 0/8] vhost-vdpa: add support for iommufd Cindy Lu
2023-11-03 17:16 ` [RFC v1 1/8] vhost/iommufd: Add the functions support iommufd Cindy Lu
2023-11-03 17:16 ` [RFC v1 2/8] Kconfig: Add the new file vhost/iommufd Cindy Lu
2023-11-06  8:53   ` Yi Liu
2023-11-07  6:15     ` Cindy Lu
2023-11-03 17:16 ` [RFC v1 3/8] vhost: Add 3 new uapi to support iommufd Cindy Lu
2023-11-06  7:27   ` Jason Wang
2023-11-06  7:30   ` Jason Wang
2023-11-07  6:57     ` Cindy Lu
2023-11-08  3:03       ` Jason Wang
2023-11-08  6:38         ` Cindy Lu
2023-11-08  7:09           ` Jason Wang
2023-11-10  2:31             ` Jason Wang
2023-11-10  6:49               ` Cindy Lu
2023-11-03 17:16 ` [RFC v1 4/8] vdpa: Add new vdpa_config_ops " Cindy Lu
2023-11-06  8:52   ` Yi Liu
2023-11-03 17:16 ` [RFC v1 5/8] vdpa_sim :Add support for iommufd Cindy Lu
2023-11-03 17:16 ` [RFC v1 6/8] vdpa: change the map/unmap process to support iommufd Cindy Lu
2023-11-06  8:54   ` Yi Liu [this message]
2023-11-07  6:14     ` Cindy Lu
2023-11-03 17:16 ` [RFC v1 7/8] vp_vdpa::Add support for iommufd Cindy Lu
2023-11-06  7:25   ` Jason Wang
2023-11-03 17:16 ` [RFC v1 8/8] iommu: expose the function iommu_device_use_default_domain Cindy Lu
2023-11-03 17:37   ` Jason Gunthorpe
2023-11-06  7:26   ` Jason Wang
2023-11-07  6:10     ` Cindy Lu
2023-11-08  3:03       ` Jason Wang
2023-11-08  7:05         ` Cindy Lu
2023-11-06  4:11 ` [RFC v1 0/8] vhost-vdpa: add support for iommufd Jason Wang
2023-11-06  8:05   ` Yi Liu
2023-11-07  7:30 ` Michael S. Tsirkin
2023-11-07 12:49   ` Jason Gunthorpe
2023-11-07 13:28     ` Michael S. Tsirkin
2023-11-07 14:12       ` Jason Gunthorpe
2023-11-07 14:30         ` Michael S. Tsirkin
2023-11-07 15:52           ` Jason Gunthorpe
2023-11-09 23:48             ` Michael S. Tsirkin
2023-11-10 14:00               ` Jason Gunthorpe
2023-11-07 17:02       ` Jakub Kicinski
2023-11-07 14:55     ` Michael S. Tsirkin
2023-11-07 15:48       ` Jason Gunthorpe
2023-11-07 16:11         ` Michael S. Tsirkin
2023-11-07 13:23 ` Michael S. Tsirkin
2024-01-10 22:25 ` Michael S. Tsirkin
2024-01-11  9:02   ` 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=12ebf6fc-9228-47a1-88dc-a177f7f7d5db@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lulu@redhat.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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).