vfio iommu: Use shift operation for 64-bit integer division
Subsystems (2)
PATCH 1/2 vfio iommu: Use shift operation for 64-bit integer division
Fixes compilation error with ARCH=i386.
Error fixed by this commit:
ld: drivers/vfio/vfio_iommu_type1.o: in function `vfio_dma_populate_bitmap':
Quoted 1 line
Quoted 1 line
vfio_iommu_type1.c:(.text+0x666): undefined reference to `__udivdi3'
--- drivers/vfio/vfio_iommu_type1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vfio/vfio_iommu_type1.c +2 -1
@@ -227,11 +227,12 @@ static void vfio_dma_bitmap_free(struct vfio_dma *dma)static void vfio_dma_populate_bitmap (struct vfio_dma *dma,size_t pgsize) {struct rb_node *p; +unsigned long pgshift =__ffs (pgsize);for (p =rb_first (&dma->pfn_list); p; p =rb_next (p)) { struct vfio_pfn *vpfn = rb_entry(p, struct vfio_pfn, node); -bitmap_set (dma->bitmap, (vpfn->iova - dma->iova) / pgsize,1 ); +bitmap_set (dma->bitmap, (vpfn->iova - dma->iova) >> pgshift,1 ); } }
Signature · 1 line
2.7.0
PATCH 2/2 vfio iommu: typecast corrections
Fixes sparse warnings by adding '__user' in typecast for copy_[from,to]_user()
--- drivers/vfio/vfio_iommu_type1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/vfio_iommu_type1.c +2 -2
@@ -998,14 +998,14 @@ static int update_user_bitmap(u64 __user *bitmap, struct vfio_iommu *iommu, nbits + shift);if (copy_from_user (&leftover, - (const void *)(bitmap + copy_offset), + (void __user *)(bitmap + copy_offset),sizeof (leftover)))return -EFAULT ;bitmap_or (dma->bitmap, dma->bitmap, &leftover, shift); } -if (copy_to_user ((void *)(bitmap + copy_offset), dma->bitmap, +if (copy_to_user ((void __user *)(bitmap + copy_offset), dma->bitmap,DIRTY_BITMAP_BYTES (nbits + shift)))return -EFAULT ;
Signature · 1 line
2.7.0
Quoted 22 lines · On Wed, 3 Jun 2020 00:12:36 +0530 Kirti Wankhede <[email protected]> wrote:
Fixes compilation error with ARCH=i386.
Error fixed by this commit:
ld:drivers/vfio/vfio_iommu_type1.o: in function `vfio_dma_populate_bitmap':Quoted 1 line
Quoted 1 line
vfio_iommu_type1.c:(.text+0x666): undefined reference to `__udivdi3'
Fixes d6a4c185660c (vfio iommu: Implementation of ioctl for dirty pages tracking)Signed-off-by Kirti Wankhede <[email protected]>Reported-by kbuild test robot <[email protected]>--- drivers/vfio/vfio_iommu_type1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/vfio/vfio_iommu_type1.c +0
-0@@ -227,11 +227,12 @@ static void vfio_dma_bitmap_free(struct vfio_dma *dma)static void vfio_dma_populate_bitmap (struct vfio_dma *dma,size_t pgsize) {struct rb_node *p;
drivers/vfio/vfio_iommu_type1.c static void vfio_dma_bitmap_free(struct vfio_dma *dma) · line 238
Quoted 10 lines
drivers/vfio/vfio_iommu_type1.c +2
-1+unsigned long pgshift =__ffs (pgsize);for (p =rb_first (&dma->pfn_list); p; p =rb_next (p)) { struct vfio_pfn *vpfn = rb_entry(p, struct vfio_pfn, node); -bitmap_set (dma->bitmap, (vpfn->iova - dma->iova) / pgsize,1 ); +bitmap_set (dma->bitmap, (vpfn->iova - dma->iova) >> pgshift,1 ); } }
Applied and pushed both to the vfio next branch. Thanks!
Alex