kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yan Zhao <yan.y.zhao@intel.com>
To: Kirti Wankhede <kwankhede@nvidia.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"cjia@nvidia.com" <cjia@nvidia.com>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	"Yang, Ziye" <ziye.yang@intel.com>,
	"Liu, Changpeng" <changpeng.liu@intel.com>,
	"Liu, Yi L" <yi.l.liu@intel.com>,
	"mlevitsk@redhat.com" <mlevitsk@redhat.com>,
	"eskultet@redhat.com" <eskultet@redhat.com>,
	"cohuck@redhat.com" <cohuck@redhat.com>,
	"jonathan.davies@nutanix.com" <jonathan.davies@nutanix.com>,
	"eauger@redhat.com" <eauger@redhat.com>,
	"aik@ozlabs.ru" <aik@ozlabs.ru>,
	"pasic@linux.ibm.com" <pasic@linux.ibm.com>,
	"felipe@nutanix.com" <felipe@nutanix.com>,
	"Zhengxiao.zx@Alibaba-inc.com" <Zhengxiao.zx@alibaba-inc.com>,
	"shuangtai.tst@alibaba-inc.com" <shuangtai.tst@alibaba-inc.com>,
	"Ken.Xue@amd.com" <Ken.Xue@amd.com>,
	"Wang, Zhi A" <zhi.a.wang@intel.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH v10 Kernel 4/5] vfio iommu: Implementation of ioctl to for dirty pages tracking.
Date: Thu, 19 Dec 2019 19:58:36 -0500	[thread overview]
Message-ID: <20191220005836.GK21868@joy-OptiPlex-7040> (raw)
In-Reply-To: <75c4f23b-b668-6edb-2f4e-191b253cede9@nvidia.com>

On Fri, Dec 20, 2019 at 12:21:45AM +0800, Kirti Wankhede wrote:
> 
> 
> On 12/19/2019 6:27 AM, Yan Zhao wrote:
> > On Thu, Dec 19, 2019 at 04:05:52AM +0800, Dr. David Alan Gilbert wrote:
> >> * Yan Zhao (yan.y.zhao@intel.com) wrote:
> >>> On Tue, Dec 17, 2019 at 07:47:05PM +0800, Kirti Wankhede wrote:
> >>>>
> >>>>
> >>>> On 12/17/2019 3:21 PM, Yan Zhao wrote:
> >>>>> On Tue, Dec 17, 2019 at 05:24:14PM +0800, Kirti Wankhede wrote:
> >>>>>>>>     
> >>>>>>>>     		return copy_to_user((void __user *)arg, &unmap, minsz) ?
> >>>>>>>>     			-EFAULT : 0;
> >>>>>>>> +	} else if (cmd == VFIO_IOMMU_DIRTY_PAGES) {
> >>>>>>>> +		struct vfio_iommu_type1_dirty_bitmap range;
> >>>>>>>> +		uint32_t mask = VFIO_IOMMU_DIRTY_PAGES_FLAG_START |
> >>>>>>>> +				VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP |
> >>>>>>>> +				VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP;
> >>>>>>>> +		int ret;
> >>>>>>>> +
> >>>>>>>> +		if (!iommu->v2)
> >>>>>>>> +			return -EACCES;
> >>>>>>>> +
> >>>>>>>> +		minsz = offsetofend(struct vfio_iommu_type1_dirty_bitmap,
> >>>>>>>> +				    bitmap);
> >>>>>>>> +
> >>>>>>>> +		if (copy_from_user(&range, (void __user *)arg, minsz))
> >>>>>>>> +			return -EFAULT;
> >>>>>>>> +
> >>>>>>>> +		if (range.argsz < minsz || range.flags & ~mask)
> >>>>>>>> +			return -EINVAL;
> >>>>>>>> +
> >>>>>>>> +		if (range.flags & VFIO_IOMMU_DIRTY_PAGES_FLAG_START) {
> >>>>>>>> +			iommu->dirty_page_tracking = true;
> >>>>>>>> +			return 0;
> >>>>>>>> +		} else if (range.flags & VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP) {
> >>>>>>>> +			iommu->dirty_page_tracking = false;
> >>>>>>>> +
> >>>>>>>> +			mutex_lock(&iommu->lock);
> >>>>>>>> +			vfio_remove_unpinned_from_dma_list(iommu);
> >>>>>>>> +			mutex_unlock(&iommu->lock);
> >>>>>>>> +			return 0;
> >>>>>>>> +
> >>>>>>>> +		} else if (range.flags &
> >>>>>>>> +				 VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP) {
> >>>>>>>> +			uint64_t iommu_pgmask;
> >>>>>>>> +			unsigned long pgshift = __ffs(range.pgsize);
> >>>>>>>> +			unsigned long *bitmap;
> >>>>>>>> +			long bsize;
> >>>>>>>> +
> >>>>>>>> +			iommu_pgmask =
> >>>>>>>> +			 ((uint64_t)1 << __ffs(vfio_pgsize_bitmap(iommu))) - 1;
> >>>>>>>> +
> >>>>>>>> +			if (((range.pgsize - 1) & iommu_pgmask) !=
> >>>>>>>> +			    (range.pgsize - 1))
> >>>>>>>> +				return -EINVAL;
> >>>>>>>> +
> >>>>>>>> +			if (range.iova & iommu_pgmask)
> >>>>>>>> +				return -EINVAL;
> >>>>>>>> +			if (!range.size || range.size > SIZE_MAX)
> >>>>>>>> +				return -EINVAL;
> >>>>>>>> +			if (range.iova + range.size < range.iova)
> >>>>>>>> +				return -EINVAL;
> >>>>>>>> +
> >>>>>>>> +			bsize = verify_bitmap_size(range.size >> pgshift,
> >>>>>>>> +						   range.bitmap_size);
> >>>>>>>> +			if (bsize)
> >>>>>>>> +				return ret;
> >>>>>>>> +
> >>>>>>>> +			bitmap = kmalloc(bsize, GFP_KERNEL);
> >>>>>>>> +			if (!bitmap)
> >>>>>>>> +				return -ENOMEM;
> >>>>>>>> +
> >>>>>>>> +			ret = copy_from_user(bitmap,
> >>>>>>>> +			     (void __user *)range.bitmap, bsize) ? -EFAULT : 0;
> >>>>>>>> +			if (ret)
> >>>>>>>> +				goto bitmap_exit;
> >>>>>>>> +
> >>>>>>>> +			iommu->dirty_page_tracking = false;
> >>>>>>> why iommu->dirty_page_tracking is false here?
> >>>>>>> suppose this ioctl can be called several times.
> >>>>>>>
> >>>>>>
> >>>>>> This ioctl can be called several times, but once this ioctl is called
> >>>>>> that means vCPUs are stopped and VFIO devices are stopped (i.e. in
> >>>>>> stop-and-copy phase) and dirty pages bitmap are being queried by user.
> >>>>>>
> >>>>> can't agree that VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP can only be
> >>>>> called in stop-and-copy phase.
> >>>>> As stated in last version, this will cause QEMU to get a wrong expectation
> >>>>> of VM downtime and this is also the reason for previously pinned pages
> >>>>> before log_sync cannot be treated as dirty. If this get bitmap ioctl can
> >>>>> be called early in save_setup phase, then it's no problem even all ram
> >>>>> is dirty.
> >>>>>
> >>>>
> >>>> Device can also write to pages which are pinned, and then there is no
> >>>> way to know pages dirtied by device during pre-copy phase.
> >>>> If user ask dirty bitmap in per-copy phase, even then user will have to
> >>>> query dirty bitmap in stop-and-copy phase where this will be superset
> >>>> including all pages reported during pre-copy. Then instead of copying
> >>>> all pages twice, its better to do it once during stop-and-copy phase.
> >>>>
> >>> I think the flow should be like this:
> >>> 1. save_setup --> GET_BITMAP ioctl --> return bitmap for currently + previously
> >>> pinned pages and clean all previously pinned pages
> >>>
> >>> 2. save_pending --> GET_BITMAP ioctl  --> return bitmap of (currently
> >>> pinned pages + previously pinned pages since last clean) and clean all
> >>> previously pinned pages
> >>>
> >>> 3. save_complete_precopy --> GET_BITMAP ioctl --> return bitmap of (currently
> >>> pinned pages + previously pinned pages since last clean) and clean all
> >>> previously pinned pages
> >>>
> >>>
> >>> Copying pinned pages multiple times is unavoidable because those pinned pages
> >>> are always treated as dirty. That's per vendor's implementation.
> >>> But if the pinned pages are not reported as dirty before stop-and-copy phase,
> >>> QEMU would think dirty pages has converged
> >>> and enter blackout phase, making downtime_limit severely incorrect.
> >>
> >> I'm not sure it's any worse.
> >> I *think* we do a last sync after we've decided to go to stop-and-copy;
> >> wont that then mark all those pages as dirty again, so it'll have the
> >> same behaviour?
> > No. something will be different.
> > currently, in kirti's implementation, if GET_BITMAP ioctl is called only
> > once in stop-and-copy phase, then before that phase, QEMU does not know those
> > pages are dirty.
> > If we can report those dirty pages earlier before stop-and-copy phase,
> > QEMU can at least copy other pages to reduce dirty pages to below threshold.
> > 
> > Take a example, let's assume those vfio dirty pages is 1Gb, and network speed is
> > also 1Gb. Expected vm downtime is 1s.
> > If before stop-and-copy phase, dirty pages produced by other pages is
> > also 1Gb. To meet the expected vm downtime, QEMU should copy pages to
> > let dirty pages be less than 1Gb, otherwise, it should not complete live
> > migration.
> > If vfio does not report this 1Gb dirty pages, QEMU would think there's
> > only 1Gb and stop the vm. It would then find out there's actually 2Gb and vm
> > downtime is 2s.
> > Though the expected vm downtime is always not exactly the same as the
> > true vm downtime, it should be caused by rapid dirty page rate, which is
> > not predictable.
> > Right?
> > 
> 
> If you report vfio dirty pages 1Gb before stop-and-copy phase (i.e. in 
> pre-copy phase), enter into stop-and-copy phase, how will you know which 
> and how many pages are dirtied by device from the time when pages copied 
> in pre-copy phase to that time where device is stopped? You don't have a 
> way to know which pages are dirtied by device. So ideally device can 
> write to all pages which are pinned. Then we have to mark all those 
> pinned pages dirty in stop-and-copy phase, 1Gb, and copy to destination. 
> Now you had copied same pages twice. Shouldn't we try not to copy pages 
> twice?
>
For mdevs who reply on treating all pinned pages as dirty pages, as above
mentioned condition, repeated page copying can be avoided by
(1) adding an ioctl to get size of dirty pages and report it to QEMU through
vfio_save_pending() interface
(2) in this GET_BITMAP ioctl, empty bitmap is returned until stop-and-copy phase.

But for devices who know fine-grained dirty pages, (e.g. devices have ditry page
tracking in hardware), GET_BITMAP ioctl has to return incremental dirty
bitmaps in each iteration and step (1) should return 0 to avoid 2*size
of dirty page reported.

Thanks
Yan

  reply	other threads:[~2019-12-20  1:06 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-16 20:21 [PATCH v10 Kernel 0/5] KABIs to support migration for VFIO devices Kirti Wankhede
2019-12-16 20:21 ` [PATCH v10 Kernel 1/5] vfio: KABI for migration interface for device state Kirti Wankhede
2019-12-16 22:44   ` Alex Williamson
2019-12-17  6:28     ` Kirti Wankhede
2019-12-17  7:12       ` Yan Zhao
2019-12-17 18:43       ` Alex Williamson
2019-12-19 16:08         ` Kirti Wankhede
2019-12-19 17:27           ` Alex Williamson
2019-12-19 20:10             ` Kirti Wankhede
2019-12-19 21:09               ` Alex Williamson
2020-01-02 18:25                 ` Dr. David Alan Gilbert
2020-01-06 23:18                   ` Alex Williamson
2020-01-07  7:28                     ` Kirti Wankhede
2020-01-07 17:09                       ` Alex Williamson
2020-01-07 17:53                         ` Kirti Wankhede
2020-01-07 18:56                           ` Alex Williamson
2020-01-08 14:59                             ` Cornelia Huck
2020-01-08 18:31                               ` Alex Williamson
2020-01-08 20:41                                 ` Kirti Wankhede
2020-01-08 22:44                                   ` Alex Williamson
2020-01-10 14:21                                     ` Cornelia Huck
2020-01-07  9:57                     ` Dr. David Alan Gilbert
2020-01-07 16:54                       ` Alex Williamson
2020-01-07 17:50                         ` Dr. David Alan Gilbert
2019-12-16 20:21 ` [PATCH v10 Kernel 2/5] vfio iommu: Adds flag to indicate dirty pages tracking capability support Kirti Wankhede
2019-12-16 23:16   ` Alex Williamson
2019-12-17  6:32     ` Kirti Wankhede
2019-12-16 20:21 ` [PATCH v10 Kernel 3/5] vfio iommu: Add ioctl defination for dirty pages tracking Kirti Wankhede
2019-12-16 20:21 ` [PATCH v10 Kernel 4/5] vfio iommu: Implementation of ioctl to " Kirti Wankhede
2019-12-17  5:15   ` Yan Zhao
2019-12-17  9:24     ` Kirti Wankhede
2019-12-17  9:51       ` Yan Zhao
2019-12-17 11:47         ` Kirti Wankhede
2019-12-18  1:04           ` Yan Zhao
2019-12-18 20:05             ` Dr. David Alan Gilbert
2019-12-19  0:57               ` Yan Zhao
2019-12-19 16:21                 ` Kirti Wankhede
2019-12-20  0:58                   ` Yan Zhao [this message]
2020-01-03 19:44                     ` Dr. David Alan Gilbert
2020-01-04  3:53                       ` Yan Zhao
2019-12-18 21:39       ` Alex Williamson
2019-12-19 18:42         ` Kirti Wankhede
2019-12-19 18:56           ` Alex Williamson
2019-12-16 20:21 ` [PATCH v10 Kernel 5/5] vfio iommu: Update UNMAP_DMA ioctl to get dirty bitmap before unmap Kirti Wankhede

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=20191220005836.GK21868@joy-OptiPlex-7040 \
    --to=yan.y.zhao@intel.com \
    --cc=Ken.Xue@amd.com \
    --cc=Zhengxiao.zx@alibaba-inc.com \
    --cc=aik@ozlabs.ru \
    --cc=alex.williamson@redhat.com \
    --cc=changpeng.liu@intel.com \
    --cc=cjia@nvidia.com \
    --cc=cohuck@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eauger@redhat.com \
    --cc=eskultet@redhat.com \
    --cc=felipe@nutanix.com \
    --cc=jonathan.davies@nutanix.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=mlevitsk@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shuangtai.tst@alibaba-inc.com \
    --cc=yi.l.liu@intel.com \
    --cc=zhi.a.wang@intel.com \
    --cc=ziye.yang@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).