qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kirti Wankhede <kwankhede@nvidia.com>
To: Cornelia Huck <cohuck@redhat.com>
Cc: kevin.tian@intel.com, yi.l.liu@intel.com, cjia@nvidia.com,
	kvm@vger.kernel.org, eskultet@redhat.com, ziye.yang@intel.com,
	qemu-devel@nongnu.org, Zhengxiao.zx@Alibaba-inc.com,
	shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com,
	zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com,
	aik@ozlabs.ru, alex.williamson@redhat.com, eauger@redhat.com,
	felipe@nutanix.com, jonathan.davies@nutanix.com,
	yan.y.zhao@intel.com, changpeng.liu@intel.com, Ken.Xue@amd.com
Subject: Re: [PATCH Kernel v18 4/7] vfio iommu: Implementation of ioctl for dirty pages tracking.
Date: Thu, 14 May 2020 01:56:33 +0530	[thread overview]
Message-ID: <b9b97dfb-2c1a-519b-3778-7a546cda9bda@nvidia.com> (raw)
In-Reply-To: <20200506125405.745bb99e.cohuck@redhat.com>



On 5/6/2020 4:24 PM, Cornelia Huck wrote:
> On Mon, 4 May 2020 21:28:56 +0530
> Kirti Wankhede <kwankhede@nvidia.com> wrote:
> 
>> VFIO_IOMMU_DIRTY_PAGES ioctl performs three operations:
>> - Start dirty pages tracking while migration is active
>> - Stop dirty pages tracking.
>> - Get dirty pages bitmap. Its user space application's responsibility to
>>    copy content of dirty pages from source to destination during migration.
>>
>> To prevent DoS attack, memory for bitmap is allocated per vfio_dma
>> structure. Bitmap size is calculated considering smallest supported page
>> size. Bitmap is allocated for all vfio_dmas when dirty logging is enabled
>>
>> Bitmap is populated for already pinned pages when bitmap is allocated for
>> a vfio_dma with the smallest supported page size. Update bitmap from
>> pinning functions when tracking is enabled. When user application queries
>> bitmap, check if requested page size is same as page size used to
>> populated bitmap. If it is equal, copy bitmap, but if not equal, return
>> error.
>>
>> Fixed below error by changing pgsize type from uint64_t to size_t.
>> Reported-by: kbuild test robot <lkp@intel.com>
>>
>> All errors:
>> drivers/vfio/vfio_iommu_type1.c:197: undefined reference to `__udivdi3'
>>
>> drivers/vfio/vfio_iommu_type1.c:225: undefined reference to `__udivdi3'
> 
> Move that below the '---' delimiter so that it does not end up in the
> commit? (Crediting the build bot is fine, but the details are not
> really useful when you look at the code later.)
> 

ok, removing errors.

>>
>> Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
>> Reviewed-by: Neo Jia <cjia@nvidia.com>
>> ---
>>   drivers/vfio/vfio_iommu_type1.c | 266 +++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 260 insertions(+), 6 deletions(-)
> 
>> @@ -2278,6 +2435,93 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
>>   
>>   		return copy_to_user((void __user *)arg, &unmap, minsz) ?
>>   			-EFAULT : 0;
>> +	} else if (cmd == VFIO_IOMMU_DIRTY_PAGES) {
>> +		struct vfio_iommu_type1_dirty_bitmap dirty;
>> +		uint32_t mask = VFIO_IOMMU_DIRTY_PAGES_FLAG_START |
>> +				VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP |
>> +				VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP;
>> +		int ret = 0;
>> +
>> +		if (!iommu->v2)
>> +			return -EACCES;
>> +
>> +		minsz = offsetofend(struct vfio_iommu_type1_dirty_bitmap,
>> +				    flags);
>> +
>> +		if (copy_from_user(&dirty, (void __user *)arg, minsz))
>> +			return -EFAULT;
>> +
>> +		if (dirty.argsz < minsz || dirty.flags & ~mask)
>> +			return -EINVAL;
>> +
>> +		/* only one flag should be set at a time */
>> +		if (__ffs(dirty.flags) != __fls(dirty.flags))
>> +			return -EINVAL;
>> +
> 
> Shouldn't you also check whether the flag that is set is actually
> valid? (maybe dirty.flags & ~VFIO_IOMMU_DIRTY_PAGES_FLAG_MASK and do a
> switch/case over dirty.flags & VFIO_IOMMU_DIRTY_PAGES_FLAG_MASK)
> 

There is a check above this check, dirty.flags & ~mask, which makes sure 
that flag is valid.

Thanks,
Kirti



  reply	other threads:[~2020-05-13 20:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 15:58 [PATCH Kernel v18 0/7] KABIs to support migration for VFIO devices Kirti Wankhede
2020-05-04 15:58 ` [PATCH Kernel v18 1/7] vfio: UAPI for migration interface for device state Kirti Wankhede
2020-05-04 15:58 ` [PATCH Kernel v18 2/7] vfio iommu: Remove atomicity of ref_count of pinned pages Kirti Wankhede
2020-05-04 15:58 ` [PATCH Kernel v18 3/7] vfio iommu: Add ioctl definition for dirty pages tracking Kirti Wankhede
2020-05-04 15:58 ` [PATCH Kernel v18 4/7] vfio iommu: Implementation of ioctl " Kirti Wankhede
2020-05-06  8:15   ` Yan Zhao
2020-05-06 19:42     ` Kirti Wankhede
2020-05-07 18:19       ` Alex Williamson
2020-05-06 10:54   ` Cornelia Huck
2020-05-13 20:26     ` Kirti Wankhede [this message]
2020-05-04 15:58 ` [PATCH Kernel v18 5/7] vfio iommu: Update UNMAP_DMA ioctl to get dirty bitmap before unmap Kirti Wankhede
2020-05-06 22:25   ` Alex Williamson
2020-05-12 20:30     ` Kirti Wankhede
2020-05-12 21:21       ` Alex Williamson
2020-05-04 15:58 ` [PATCH Kernel v18 6/7] vfio iommu: Add migration capability to report supported features Kirti Wankhede
2020-05-06 22:27   ` Alex Williamson
2020-05-07  5:37     ` Kirti Wankhede
2020-05-07 15:17       ` Alex Williamson
2020-05-04 15:58 ` [PATCH Kernel v18 7/7] vfio: Selective dirty page tracking if IOMMU backed device pins pages 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=b9b97dfb-2c1a-519b-3778-7a546cda9bda@nvidia.com \
    --to=kwankhede@nvidia.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=mlevitsk@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shuangtai.tst@alibaba-inc.com \
    --cc=yan.y.zhao@intel.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).