Skip to content

Commit fe13166

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/selftest: Add mock IO hugepages tests
Leverage previously added MOCK_FLAGS_DEVICE_HUGE_IOVA flag to create an IOMMU domain with more than MOCK_IO_PAGE_SIZE supported. Plumb the hugetlb backing memory for buffer allocation and change the expected page size to MOCK_HUGE_PAGE_SIZE (1M) when hugepage variant test cases are used. These so far are limited to 128M and 256M IOVA range tests cases which is when 1M hugepages can be used. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joao Martins <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 7db521e commit fe13166

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

tools/testing/selftests/iommu/iommufd.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
static unsigned long HUGEPAGE_SIZE;
1313

1414
#define MOCK_PAGE_SIZE (PAGE_SIZE / 2)
15+
#define MOCK_HUGE_PAGE_SIZE (512 * MOCK_PAGE_SIZE)
1516

1617
static unsigned long get_huge_page_size(void)
1718
{
@@ -1716,10 +1717,12 @@ FIXTURE(iommufd_dirty_tracking)
17161717
FIXTURE_VARIANT(iommufd_dirty_tracking)
17171718
{
17181719
unsigned long buffer_size;
1720+
bool hugepages;
17191721
};
17201722

17211723
FIXTURE_SETUP(iommufd_dirty_tracking)
17221724
{
1725+
int mmap_flags;
17231726
void *vrc;
17241727
int rc;
17251728

@@ -1732,9 +1735,17 @@ FIXTURE_SETUP(iommufd_dirty_tracking)
17321735
variant->buffer_size, rc);
17331736
}
17341737

1738+
mmap_flags = MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED;
1739+
if (variant->hugepages) {
1740+
/*
1741+
* MAP_POPULATE will cause the kernel to fail mmap if THPs are
1742+
* not available.
1743+
*/
1744+
mmap_flags |= MAP_HUGETLB | MAP_POPULATE;
1745+
}
17351746
assert((uintptr_t)self->buffer % HUGEPAGE_SIZE == 0);
17361747
vrc = mmap(self->buffer, variant->buffer_size, PROT_READ | PROT_WRITE,
1737-
MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
1748+
mmap_flags, -1, 0);
17381749
assert(vrc == self->buffer);
17391750

17401751
self->page_size = MOCK_PAGE_SIZE;
@@ -1749,8 +1760,16 @@ FIXTURE_SETUP(iommufd_dirty_tracking)
17491760
assert((uintptr_t)self->bitmap % PAGE_SIZE == 0);
17501761

17511762
test_ioctl_ioas_alloc(&self->ioas_id);
1752-
test_cmd_mock_domain(self->ioas_id, &self->stdev_id, &self->hwpt_id,
1753-
&self->idev_id);
1763+
/* Enable 1M mock IOMMU hugepages */
1764+
if (variant->hugepages) {
1765+
test_cmd_mock_domain_flags(self->ioas_id,
1766+
MOCK_FLAGS_DEVICE_HUGE_IOVA,
1767+
&self->stdev_id, &self->hwpt_id,
1768+
&self->idev_id);
1769+
} else {
1770+
test_cmd_mock_domain(self->ioas_id, &self->stdev_id,
1771+
&self->hwpt_id, &self->idev_id);
1772+
}
17541773
}
17551774

17561775
FIXTURE_TEARDOWN(iommufd_dirty_tracking)
@@ -1784,12 +1803,26 @@ FIXTURE_VARIANT_ADD(iommufd_dirty_tracking, domain_dirty128M)
17841803
.buffer_size = 128UL * 1024UL * 1024UL,
17851804
};
17861805

1806+
FIXTURE_VARIANT_ADD(iommufd_dirty_tracking, domain_dirty128M_huge)
1807+
{
1808+
/* 4K bitmap (128M IOVA range) */
1809+
.buffer_size = 128UL * 1024UL * 1024UL,
1810+
.hugepages = true,
1811+
};
1812+
17871813
FIXTURE_VARIANT_ADD(iommufd_dirty_tracking, domain_dirty256M)
17881814
{
17891815
/* 8K bitmap (256M IOVA range) */
17901816
.buffer_size = 256UL * 1024UL * 1024UL,
17911817
};
17921818

1819+
FIXTURE_VARIANT_ADD(iommufd_dirty_tracking, domain_dirty256M_huge)
1820+
{
1821+
/* 8K bitmap (256M IOVA range) */
1822+
.buffer_size = 256UL * 1024UL * 1024UL,
1823+
.hugepages = true,
1824+
};
1825+
17931826
TEST_F(iommufd_dirty_tracking, enforce_dirty)
17941827
{
17951828
uint32_t ioas_id, stddev_id, idev_id;
@@ -1853,6 +1886,9 @@ TEST_F(iommufd_dirty_tracking, get_dirty_bitmap)
18531886
uint32_t hwpt_id;
18541887
uint32_t ioas_id;
18551888

1889+
if (variant->hugepages)
1890+
page_size = MOCK_HUGE_PAGE_SIZE;
1891+
18561892
test_ioctl_ioas_alloc(&ioas_id);
18571893
test_ioctl_ioas_map_fixed_id(ioas_id, self->buffer,
18581894
variant->buffer_size, MOCK_APERTURE_START);
@@ -1887,6 +1923,9 @@ TEST_F(iommufd_dirty_tracking, get_dirty_bitmap_no_clear)
18871923
uint32_t hwpt_id;
18881924
uint32_t ioas_id;
18891925

1926+
if (variant->hugepages)
1927+
page_size = MOCK_HUGE_PAGE_SIZE;
1928+
18901929
test_ioctl_ioas_alloc(&ioas_id);
18911930
test_ioctl_ioas_map_fixed_id(ioas_id, self->buffer,
18921931
variant->buffer_size, MOCK_APERTURE_START);

0 commit comments

Comments
 (0)