12
12
static unsigned long HUGEPAGE_SIZE ;
13
13
14
14
#define MOCK_PAGE_SIZE (PAGE_SIZE / 2)
15
+ #define MOCK_HUGE_PAGE_SIZE (512 * MOCK_PAGE_SIZE)
15
16
16
17
static unsigned long get_huge_page_size (void )
17
18
{
@@ -1716,10 +1717,12 @@ FIXTURE(iommufd_dirty_tracking)
1716
1717
FIXTURE_VARIANT (iommufd_dirty_tracking )
1717
1718
{
1718
1719
unsigned long buffer_size ;
1720
+ bool hugepages ;
1719
1721
};
1720
1722
1721
1723
FIXTURE_SETUP (iommufd_dirty_tracking )
1722
1724
{
1725
+ int mmap_flags ;
1723
1726
void * vrc ;
1724
1727
int rc ;
1725
1728
@@ -1732,9 +1735,17 @@ FIXTURE_SETUP(iommufd_dirty_tracking)
1732
1735
variant -> buffer_size , rc );
1733
1736
}
1734
1737
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
+ }
1735
1746
assert ((uintptr_t )self -> buffer % HUGEPAGE_SIZE == 0 );
1736
1747
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 );
1738
1749
assert (vrc == self -> buffer );
1739
1750
1740
1751
self -> page_size = MOCK_PAGE_SIZE ;
@@ -1749,8 +1760,16 @@ FIXTURE_SETUP(iommufd_dirty_tracking)
1749
1760
assert ((uintptr_t )self -> bitmap % PAGE_SIZE == 0 );
1750
1761
1751
1762
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
+ }
1754
1773
}
1755
1774
1756
1775
FIXTURE_TEARDOWN (iommufd_dirty_tracking )
@@ -1784,12 +1803,26 @@ FIXTURE_VARIANT_ADD(iommufd_dirty_tracking, domain_dirty128M)
1784
1803
.buffer_size = 128UL * 1024UL * 1024UL ,
1785
1804
};
1786
1805
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
+
1787
1813
FIXTURE_VARIANT_ADD (iommufd_dirty_tracking , domain_dirty256M )
1788
1814
{
1789
1815
/* 8K bitmap (256M IOVA range) */
1790
1816
.buffer_size = 256UL * 1024UL * 1024UL ,
1791
1817
};
1792
1818
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
+
1793
1826
TEST_F (iommufd_dirty_tracking , enforce_dirty )
1794
1827
{
1795
1828
uint32_t ioas_id , stddev_id , idev_id ;
@@ -1853,6 +1886,9 @@ TEST_F(iommufd_dirty_tracking, get_dirty_bitmap)
1853
1886
uint32_t hwpt_id ;
1854
1887
uint32_t ioas_id ;
1855
1888
1889
+ if (variant -> hugepages )
1890
+ page_size = MOCK_HUGE_PAGE_SIZE ;
1891
+
1856
1892
test_ioctl_ioas_alloc (& ioas_id );
1857
1893
test_ioctl_ioas_map_fixed_id (ioas_id , self -> buffer ,
1858
1894
variant -> buffer_size , MOCK_APERTURE_START );
@@ -1887,6 +1923,9 @@ TEST_F(iommufd_dirty_tracking, get_dirty_bitmap_no_clear)
1887
1923
uint32_t hwpt_id ;
1888
1924
uint32_t ioas_id ;
1889
1925
1926
+ if (variant -> hugepages )
1927
+ page_size = MOCK_HUGE_PAGE_SIZE ;
1928
+
1890
1929
test_ioctl_ioas_alloc (& ioas_id );
1891
1930
test_ioctl_ioas_map_fixed_id (ioas_id , self -> buffer ,
1892
1931
variant -> buffer_size , MOCK_APERTURE_START );
0 commit comments