qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kirti Wankhede <kwankhede@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com,
	qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com,
	shuai.ruan@intel.com, jike.song@intel.com, zhiyuan.lv@intel.com
Subject: Re: [Qemu-devel] [RFC PATCH v3 3/3] VFIO Type1 IOMMU change: to support with iommu and without iommu
Date: Thu, 5 May 2016 13:21:31 +0530	[thread overview]
Message-ID: <21b8ed47-de72-f95b-e7cc-ecc45ccc264d@nvidia.com> (raw)
In-Reply-To: <20160503164306.6a699fe3@t450s.home>


On 5/4/2016 4:13 AM, Alex Williamson wrote:
 > On Tue, 3 May 2016 00:10:41 +0530
 > Kirti Wankhede <kwankhede@nvidia.com> wrote:
 >
[..]


 >> +	if (domain->vfio_iommu_api_only)
 >> +		mm = domain->vmm_mm;
 >> +	else
 >> +		mm = current->mm;
 >> +
 >> +	if (!mm)
 >> +		return -ENODEV;
 >> +
 >> +	ret = vaddr_get_pfn(mm, vaddr, prot, pfn_base);
 >
 > We could pass domain->mm unconditionally to vaddr_get_pfn(), let it be
 > NULL in the !api_only case and use it as a cue to vaddr_get_pfn() which
 > gup variant to use.  Of course we need to deal with mmap_sem somewhere
 > too without turning the code into swiss cheese.
 >

Yes, I missed that. Thanks for pointing out. I'll fix it.

 > Correct me if I'm wrong, but I assume the main benefit of interweaving
 > this into type1 vs pulling out common code and making a new vfio iommu
 > backend is the page accounting, ie. not over accounting locked pages.
 > TBH, I don't know if it's worth it.  Any idea what the high water mark
 > of pinned pages for a vgpu might be?
 >

It depends in which VM (Linux/Windows) is running and what workload is 
running. On Windows DMA pages are managed by WDDM model. On Linux each 
user space application can DMA to pages and there are not restrictions.


 > The only reason I can come up with for why we'd want to integrate an
 > api-only domain into the existing type1 code would be to avoid page
 > accounting issues where we count locked pages once for a normal
 > assigned device and again for a vgpu, but that's not what we're doing
 > here.  We're not only locking the pages again regardless of them
 > already being locked, we're counting every time we lock them through
 > this new interface.  So there's really no point at all to making type1
 > become this unsupportable.  In that case we should be pulling out the
 > common code that we want to share from type1 and making a new type1
 > compatible vfio iommu backend rather than conditionalizing everything
 > here.
 >

I tried to add pfn tracking logic and use already locked pages, but that 
didn't worked somehow, I'll revisit it again.
With this there will be additional pfn tracking logic for the case where 
device is directly assigned and vGPU device is not present.



 >> +		// verify if pfn exist in pfn_list
 >> +		if (!(p = vfio_find_vgpu_pfn(domain_vgpu, *(pfn + i)))) {
 >> +			continue;
 >
 > How does the caller deal with this, the function returns number of
 > pages unpinned which will not match the requested number of pages to
 > unpin if there are any missing.  Also, no setting variables within a
 > test when easily avoidable please, separate to a set then test.
 >

Here we are following the current code logic. Do you have any suggestion 
how to deal with that?


 >> +	(iommu, &domain, &domain_vgpu);
 >> +
 >> +	if (!domain)
 >> +		return;
 >> +
 >> +	d = domain;
 >>  	list_for_each_entry_continue(d, &iommu->domain_list, next) {
 >> -		iommu_unmap(d->domain, dma->iova, dma->size);
 >> -		cond_resched();
 >> +		if (!d->vfio_iommu_api_only) {
 >> +			iommu_unmap(d->domain, dma->iova, dma->size);
 >> +			cond_resched();
 >> +		}get_first_domains
 >>  	}
 >>
 >>  	while (iova < end) {
 >
 > How do api-only domain not blowup on the iommu API code in this next
 > code block?  Are you just getting lucky that the api-only domain is
 > first in the list and the real domain is last?
 >

Control will not come here if there is no domain with IOMMU due to below 
change:

 >> +	if (!domain)
 >> +		return;

get_first_domains() returns the first domain with IOMMU and first domain 
with api_only.


 >> +		if (d->vfio_iommu_api_only)
 >> +			continue;
 >> +
 >
 > Really disliking all these switches everywhere, too many different code
 > paths.
 >

I'll move such APIs to inline functions such that this check would be 
within inline functions and code would look much cleaner.


 >> +	// Skip pin and map only if domain without IOMMU is present
 >> +	if (!domain_with_iommu_present) {
 >> +		dma->size = size;
 >> +		goto map_done;
 >> +	}
 >> +
 >
 > Yet more special cases, the code is getting unsupportable.

 From vfio_dma_do_map(), if there is no devices pass-throughed then we 
don't want to pin all pages upfront. and that is the reason of this check.

 >
 > I'm really not convinced that pushing this into the type1 code is the
 > right approach vs pulling out shareable code chunks where it makes
 > sense and creating a separate iommu backend.  We're not getting
 > anything but code complexity out of this approach it seems.

I find pulling out shared code is also not simple. I would like to 
revisit this again and sort out the concerns you raised rather than 
making separate module.

Thanks,
Kirti.

  parent reply	other threads:[~2016-05-05  7:52 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-02 18:40 [Qemu-devel] [RFC PATCH v3 0/3] Add vGPU support Kirti Wankhede
2016-05-02 18:40 ` [Qemu-devel] [RFC PATCH v3 1/3] vGPU Core driver Kirti Wankhede
2016-05-03 22:43   ` Alex Williamson
2016-05-04  2:45     ` Tian, Kevin
2016-05-04 16:57       ` Alex Williamson
2016-05-05  8:58         ` Tian, Kevin
2016-05-04  2:58     ` Tian, Kevin
2016-05-12  8:22       ` Tian, Kevin
2016-05-04 13:31     ` Kirti Wankhede
2016-05-05  9:06       ` Tian, Kevin
2016-05-05 10:44         ` Kirti Wankhede
2016-05-05 12:07           ` Tian, Kevin
2016-05-05 12:57             ` Kirti Wankhede
2016-05-11  6:37               ` Tian, Kevin
2016-05-06 12:14         ` Jike Song
2016-05-06 16:16           ` Kirti Wankhede
2016-05-09 12:12             ` Jike Song
2016-05-02 18:40 ` [Qemu-devel] [RFC PATCH v3 2/3] VFIO driver for vGPU device Kirti Wankhede
2016-05-03 22:43   ` Alex Williamson
2016-05-04  3:23     ` Tian, Kevin
2016-05-04 17:06       ` Alex Williamson
2016-05-04 21:14         ` Neo Jia
2016-05-05  4:42           ` Kirti Wankhede
2016-05-05  9:24         ` Tian, Kevin
2016-05-05 20:27           ` Neo Jia
2016-05-11  6:45         ` Tian, Kevin
2016-05-11 20:10           ` Alex Williamson
2016-05-12  0:59             ` Tian, Kevin
2016-05-04 16:25     ` Kirti Wankhede
2016-05-02 18:40 ` [Qemu-devel] [RFC PATCH v3 3/3] VFIO Type1 IOMMU change: to support with iommu and without iommu Kirti Wankhede
2016-05-03 10:40   ` Jike Song
2016-05-03 22:43   ` Alex Williamson
2016-05-04  3:39     ` Tian, Kevin
2016-05-05  6:55     ` Jike Song
2016-05-05  9:27       ` Tian, Kevin
2016-05-10  7:52         ` Jike Song
2016-05-10 16:02           ` Neo Jia
2016-05-11  9:15             ` Jike Song
2016-05-11 22:06               ` Alex Williamson
2016-05-12  4:11                 ` Jike Song
2016-05-12 19:49                   ` Neo Jia
2016-05-13  2:41                     ` Tian, Kevin
2016-05-13  6:22                       ` Jike Song
2016-05-13  6:43                         ` Neo Jia
2016-05-13  7:30                           ` Jike Song
2016-05-13  7:42                             ` Neo Jia
2016-05-13  7:45                               ` Tian, Kevin
2016-05-13  8:31                                 ` Neo Jia
2016-05-13  9:23                                   ` Jike Song
2016-05-13 15:50                                     ` Neo Jia
2016-05-16  6:57                                       ` Jike Song
2016-05-13  6:08                     ` Jike Song
2016-05-13  6:41                       ` Neo Jia
2016-05-13  7:13                         ` Tian, Kevin
2016-05-13  7:38                           ` Neo Jia
2016-05-13  8:02                             ` Tian, Kevin
2016-05-13  8:41                               ` Neo Jia
2016-05-12  8:00                 ` Tian, Kevin
2016-05-12 19:05                   ` Alex Williamson
2016-05-12 20:12                     ` Neo Jia
2016-05-13  9:46                       ` Jike Song
2016-05-13 15:48                         ` Neo Jia
2016-05-16  2:27                           ` Jike Song
2016-05-13  3:55                     ` Tian, Kevin
2016-05-13 16:16                       ` Alex Williamson
2016-05-13  7:10                     ` Dong Jia
2016-05-13  7:24                       ` Neo Jia
2016-05-13  8:39                         ` Dong Jia
2016-05-13  9:05                           ` Neo Jia
2016-05-19  7:28                             ` Dong Jia
2016-05-20  3:21                               ` Tian, Kevin
2016-06-06  6:59                                 ` Dong Jia
2016-06-07  2:47                                   ` Tian, Kevin
2016-06-07  7:04                                     ` Dong Jia
2016-05-05  7:51     ` Kirti Wankhede [this message]
2016-05-04  1:05 ` [Qemu-devel] [RFC PATCH v3 0/3] Add vGPU support Tian, Kevin
2016-05-04  6:17   ` Neo Jia
2016-05-04 17:07     ` Alex Williamson

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=21b8ed47-de72-f95b-e7cc-ecc45ccc264d@nvidia.com \
    --to=kwankhede@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=cjia@nvidia.com \
    --cc=jike.song@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shuai.ruan@intel.com \
    --cc=zhiyuan.lv@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).