virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Xie Yongji <xieyongji@bytedance.com>,
	mst@redhat.com, stefanha@redhat.com, sgarzare@redhat.com,
	parav@nvidia.com, bob.liu@oracle.com, hch@infradead.org,
	rdunlap@infradead.org, willy@infradead.org,
	viro@zeniv.linux.org.uk, axboe@kernel.dk, bcrl@kvack.org,
	corbet@lwn.net, mika.penttila@nextfour.com,
	dan.carpenter@oracle.com
Cc: linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v5 06/11] vdpa: factor out vhost_vdpa_pa_map()
Date: Tue, 23 Mar 2021 11:09:20 +0800	[thread overview]
Message-ID: <45a307b5-85a4-0cbc-0bbc-7e8edbbac9ca@redhat.com> (raw)
In-Reply-To: <20210315053721.189-7-xieyongji@bytedance.com>


在 2021/3/15 下午1:37, Xie Yongji 写道:
> The upcoming patch is going to support VA mapping. So let's
> factor out the logic of PA mapping firstly to make the code
> more readable.
>
> Suggested-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Xie Yongji <xieyongji@bytedance.com>


Acked-by: Jason Wang <jasowang@redhat.com>

While at it, I think it's better to factor out the unmap() part? Since 
the unpin and page dirty is not needed for va device.

Thanks


> ---
>   drivers/vhost/vdpa.c | 46 ++++++++++++++++++++++++++++------------------
>   1 file changed, 28 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index b24ec69a374b..7c83fbf3edac 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -579,37 +579,28 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, u64 iova, u64 size)
>   	}
>   }
>   
> -static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> -					   struct vhost_iotlb_msg *msg)
> +static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
> +			     u64 iova, u64 size, u64 uaddr, u32 perm)
>   {
>   	struct vhost_dev *dev = &v->vdev;
> -	struct vhost_iotlb *iotlb = dev->iotlb;
>   	struct page **page_list;
>   	unsigned long list_size = PAGE_SIZE / sizeof(struct page *);
>   	unsigned int gup_flags = FOLL_LONGTERM;
>   	unsigned long npages, cur_base, map_pfn, last_pfn = 0;
>   	unsigned long lock_limit, sz2pin, nchunks, i;
> -	u64 iova = msg->iova;
> +	u64 start = iova;
>   	long pinned;
>   	int ret = 0;
>   
> -	if (msg->iova < v->range.first ||
> -	    msg->iova + msg->size - 1 > v->range.last)
> -		return -EINVAL;
> -
> -	if (vhost_iotlb_itree_first(iotlb, msg->iova,
> -				    msg->iova + msg->size - 1))
> -		return -EEXIST;
> -
>   	/* Limit the use of memory for bookkeeping */
>   	page_list = (struct page **) __get_free_page(GFP_KERNEL);
>   	if (!page_list)
>   		return -ENOMEM;
>   
> -	if (msg->perm & VHOST_ACCESS_WO)
> +	if (perm & VHOST_ACCESS_WO)
>   		gup_flags |= FOLL_WRITE;
>   
> -	npages = PAGE_ALIGN(msg->size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT;
> +	npages = PAGE_ALIGN(size + (iova & ~PAGE_MASK)) >> PAGE_SHIFT;
>   	if (!npages) {
>   		ret = -EINVAL;
>   		goto free;
> @@ -623,7 +614,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
>   		goto unlock;
>   	}
>   
> -	cur_base = msg->uaddr & PAGE_MASK;
> +	cur_base = uaddr & PAGE_MASK;
>   	iova &= PAGE_MASK;
>   	nchunks = 0;
>   
> @@ -654,7 +645,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
>   				csize = (last_pfn - map_pfn + 1) << PAGE_SHIFT;
>   				ret = vhost_vdpa_map(v, iova, csize,
>   						     map_pfn << PAGE_SHIFT,
> -						     msg->perm);
> +						     perm);
>   				if (ret) {
>   					/*
>   					 * Unpin the pages that are left unmapped
> @@ -683,7 +674,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
>   
>   	/* Pin the rest chunk */
>   	ret = vhost_vdpa_map(v, iova, (last_pfn - map_pfn + 1) << PAGE_SHIFT,
> -			     map_pfn << PAGE_SHIFT, msg->perm);
> +			     map_pfn << PAGE_SHIFT, perm);
>   out:
>   	if (ret) {
>   		if (nchunks) {
> @@ -702,13 +693,32 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
>   			for (pfn = map_pfn; pfn <= last_pfn; pfn++)
>   				unpin_user_page(pfn_to_page(pfn));
>   		}
> -		vhost_vdpa_unmap(v, msg->iova, msg->size);
> +		vhost_vdpa_unmap(v, start, size);
>   	}
>   unlock:
>   	mmap_read_unlock(dev->mm);
>   free:
>   	free_page((unsigned long)page_list);
>   	return ret;
> +
> +}
> +
> +static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
> +					   struct vhost_iotlb_msg *msg)
> +{
> +	struct vhost_dev *dev = &v->vdev;
> +	struct vhost_iotlb *iotlb = dev->iotlb;
> +
> +	if (msg->iova < v->range.first ||
> +	    msg->iova + msg->size - 1 > v->range.last)
> +		return -EINVAL;
> +
> +	if (vhost_iotlb_itree_first(iotlb, msg->iova,
> +				    msg->iova + msg->size - 1))
> +		return -EEXIST;
> +
> +	return vhost_vdpa_pa_map(v, msg->iova, msg->size, msg->uaddr,
> +				 msg->perm);
>   }
>   
>   static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev,

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2021-03-23  3:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210315053721.189-1-xieyongji@bytedance.com>
     [not found] ` <20210315053721.189-2-xieyongji@bytedance.com>
2021-03-15  9:08   ` [PATCH v5 01/11] file: Export __receive_fd() to modules Christoph Hellwig
     [not found]     ` <CACycT3vrHOExXj6v8ULvUzdLcRkdzS5=TNK6=g4+RWEdN-nOJw@mail.gmail.com>
2021-03-25  8:23       ` Christoph Hellwig
     [not found] ` <20210315053721.189-7-xieyongji@bytedance.com>
2021-03-23  3:09   ` Jason Wang [this message]
     [not found] ` <20210315053721.189-8-xieyongji@bytedance.com>
2021-03-23  3:13   ` [PATCH v5 07/11] vdpa: Support transferring virtual addressing during DMA mapping Jason Wang
     [not found] ` <20210315053721.189-9-xieyongji@bytedance.com>
2021-03-24  3:54   ` [PATCH v5 08/11] vduse: Implement an MMU-based IOMMU driver Jason Wang
     [not found]     ` <CACycT3v_-G6ju-poofXEzYt8QPKWNFHwsS7t=KTLgs-=g+iPQQ@mail.gmail.com>
2021-03-25  4:52       ` Jason Wang
     [not found]         ` <CACycT3uS870yy04rw7KBk==sioi+VNunxVz6BQH-Lmxk6m-VSg@mail.gmail.com>
2021-03-26  4:26           ` Jason Wang
     [not found]             ` <CACycT3v6Lj61fafztOuzBNFLs2TbKeqrNLXkzv5RK6-h-iTnvA@mail.gmail.com>
2021-03-26  6:16               ` Jason Wang
     [not found]                 ` <CACycT3t+2MC9rQ7iWdWQ4=O3ojCXHvHZ-M7y7AjXoXYZUiAOzQ@mail.gmail.com>
2021-03-26  7:36                   ` Jason Wang
     [not found] ` <20210315053721.189-10-xieyongji@bytedance.com>
2021-03-24  4:43   ` [PATCH v5 09/11] vduse: Introduce VDUSE - vDPA Device in Userspace Jason Wang
     [not found]     ` <CACycT3u5hEO8=JVkbHmKXYMManiZ1VedyS6O+7M8Rzbk1ftC7A@mail.gmail.com>
2021-03-25  6:30       ` Jason Wang
     [not found] ` <20210315053721.189-11-xieyongji@bytedance.com>
2021-03-24  4:45   ` [PATCH v5 10/11] vduse: Add config interrupt support Jason Wang
     [not found] ` <20210315053721.189-4-xieyongji@bytedance.com>
2021-03-23  3:02   ` [PATCH v5 03/11] vhost-vdpa: protect concurrent access to vhost device iotlb Jason Wang
2021-03-25 11:08   ` Stefano Garzarella

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=45a307b5-85a4-0cbc-0bbc-7e8edbbac9ca@redhat.com \
    --to=jasowang@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bcrl@kvack.org \
    --cc=bob.liu@oracle.com \
    --cc=corbet@lwn.net \
    --cc=dan.carpenter@oracle.com \
    --cc=hch@infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mika.penttila@nextfour.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=parav@nvidia.com \
    --cc=rdunlap@infradead.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=willy@infradead.org \
    --cc=xieyongji@bytedance.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).