Skip to content

Commit a2e33fb

Browse files
committed
Merge tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd
Pull iommufd fixes from Jason Gunthorpe: - Syzkaller found a case where maths overflows can cause divide by 0 - Typo in a compiler bug warning fix in the selftests broke the selftests - type1 compatability had a mismatch when unmapping an already unmapped range, it should succeed * tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd: iommufd: Make vfio_compat's unmap succeed if the range is already empty iommufd/selftest: Fix ioctl return value in _test_cmd_trigger_vevents() iommufd: Don't overflow during division for dirty tracking
2 parents da32d15 + afb4776 commit a2e33fb

5 files changed

Lines changed: 13 additions & 14 deletions

File tree

drivers/iommu/iommufd/io_pagetable.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ static int iopt_unmap_iova_range(struct io_pagetable *iopt, unsigned long start,
707707
struct iopt_area *area;
708708
unsigned long unmapped_bytes = 0;
709709
unsigned int tries = 0;
710-
int rc = -ENOENT;
710+
/* If there are no mapped entries then success */
711+
int rc = 0;
711712

712713
/*
713714
* The domains_rwsem must be held in read mode any time any area->pages
@@ -777,8 +778,6 @@ static int iopt_unmap_iova_range(struct io_pagetable *iopt, unsigned long start,
777778

778779
down_write(&iopt->iova_rwsem);
779780
}
780-
if (unmapped_bytes)
781-
rc = 0;
782781

783782
out_unlock_iova:
784783
up_write(&iopt->iova_rwsem);
@@ -815,13 +814,8 @@ int iopt_unmap_iova(struct io_pagetable *iopt, unsigned long iova,
815814

816815
int iopt_unmap_all(struct io_pagetable *iopt, unsigned long *unmapped)
817816
{
818-
int rc;
819-
820-
rc = iopt_unmap_iova_range(iopt, 0, ULONG_MAX, unmapped);
821817
/* If the IOVAs are empty then unmap all succeeds */
822-
if (rc == -ENOENT)
823-
return 0;
824-
return rc;
818+
return iopt_unmap_iova_range(iopt, 0, ULONG_MAX, unmapped);
825819
}
826820

827821
/* The caller must always free all the nodes in the allowed_iova rb_root. */

drivers/iommu/iommufd/ioas.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ int iommufd_ioas_unmap(struct iommufd_ucmd *ucmd)
367367
&unmapped);
368368
if (rc)
369369
goto out_put;
370+
if (!unmapped) {
371+
rc = -ENOENT;
372+
goto out_put;
373+
}
370374
}
371375

372376
cmd->length = unmapped;

drivers/iommu/iommufd/iova_bitmap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ struct iova_bitmap {
130130
static unsigned long iova_bitmap_offset_to_index(struct iova_bitmap *bitmap,
131131
unsigned long iova)
132132
{
133-
unsigned long pgsize = 1UL << bitmap->mapped.pgshift;
134-
135-
return iova / (BITS_PER_TYPE(*bitmap->bitmap) * pgsize);
133+
return (iova >> bitmap->mapped.pgshift) /
134+
BITS_PER_TYPE(*bitmap->bitmap);
136135
}
137136

138137
/*

tools/testing/selftests/iommu/iommufd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,8 @@ TEST_F(vfio_compat_mock_domain, map)
26382638
ASSERT_EQ(0, ioctl(self->fd, VFIO_IOMMU_MAP_DMA, &map_cmd));
26392639
ASSERT_EQ(0, ioctl(self->fd, VFIO_IOMMU_UNMAP_DMA, &unmap_cmd));
26402640
ASSERT_EQ(BUFFER_SIZE, unmap_cmd.size);
2641+
/* Unmap of empty is success */
2642+
ASSERT_EQ(0, ioctl(self->fd, VFIO_IOMMU_UNMAP_DMA, &unmap_cmd));
26412643

26422644
/* UNMAP_FLAG_ALL requires 0 iova/size */
26432645
ASSERT_EQ(0, ioctl(self->fd, VFIO_IOMMU_MAP_DMA, &map_cmd));

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,8 @@ static int _test_cmd_trigger_vevents(int fd, __u32 dev_id, __u32 nvevents)
10441044
};
10451045

10461046
while (nvevents--) {
1047-
if (!ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VEVENT),
1048-
&trigger_vevent_cmd))
1047+
if (ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_VEVENT),
1048+
&trigger_vevent_cmd))
10491049
return -1;
10501050
}
10511051
return 0;

0 commit comments

Comments
 (0)