Skip to content

Commit 62e37c8

Browse files
committed
iommufd/selftest: Cover domain unmap with huge pages and access
Inspired by the syzkaller reproducer check the batch carry path with a simple test. Link: https://lore.kernel.org/r/4-v1-ceab6a4d7d7a+94-iommufd_syz_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 692d42d commit 62e37c8

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tools/testing/selftests/iommu/iommufd.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,40 @@ TEST_F(iommufd_ioas, iova_ranges)
594594
EXPECT_EQ(0, ranges[1].last);
595595
}
596596

597+
TEST_F(iommufd_ioas, access_domain_destory)
598+
{
599+
struct iommu_test_cmd access_cmd = {
600+
.size = sizeof(access_cmd),
601+
.op = IOMMU_TEST_OP_ACCESS_PAGES,
602+
.access_pages = { .iova = self->base_iova + PAGE_SIZE,
603+
.length = PAGE_SIZE},
604+
};
605+
size_t buf_size = 2 * HUGEPAGE_SIZE;
606+
uint8_t *buf;
607+
608+
buf = mmap(0, buf_size, PROT_READ | PROT_WRITE,
609+
MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1,
610+
0);
611+
ASSERT_NE(MAP_FAILED, buf);
612+
test_ioctl_ioas_map_fixed(buf, buf_size, self->base_iova);
613+
614+
test_cmd_create_access(self->ioas_id, &access_cmd.id,
615+
MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES);
616+
access_cmd.access_pages.uptr = (uintptr_t)buf + PAGE_SIZE;
617+
ASSERT_EQ(0,
618+
ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_PAGES),
619+
&access_cmd));
620+
621+
/* Causes a complicated unpin across a huge page boundary */
622+
if (self->stdev_id)
623+
test_ioctl_destroy(self->stdev_id);
624+
625+
test_cmd_destroy_access_pages(
626+
access_cmd.id, access_cmd.access_pages.out_access_pages_id);
627+
test_cmd_destroy_access(access_cmd.id);
628+
ASSERT_EQ(0, munmap(buf, buf_size));
629+
}
630+
597631
TEST_F(iommufd_ioas, access_pin)
598632
{
599633
struct iommu_test_cmd access_cmd = {

0 commit comments

Comments
 (0)