Skip to content

Commit 75ec946

Browse files
Sayali Patilgregkh
authored andcommitted
selftests/mm: allow PUD-level entries in compound testcase of hmm tests
[ Upstream commit 224ed0e ] Patch series "selftests/mm: assorted fixes for hmm-tests", v3. This series fixes a few issues in hmm-tests that show up when page-size and huge-page configuration differ from the hardcoded assumptions the tests were written for (PMD/THP sizing, default hugepage size, and related cases). It also includes a fix to exclusive_cow: the test ignored the return value of fork(), so both parent and child ran the same teardown path. This patch (of 3): The HMM compound testcase currently assumes only PMD-level mappings and fails on systems where default_hugepagesz=1G is set, because the region is then reported by the device at PUD level. Determine the mapping level (PMD or PUD) the device reports for the first page of the range and require every page to match that level exactly via ASSERT_EQ(). This accepts PUD-level mappings while preserving the expected/observed protection values printed on failure, and rejects a fragmented mapping that mixes PMD- and PUD-level entries within the same range (which a per-page OR check would have let pass). Link: https://lore.kernel.org/20260611034102.1030738-1-aboorvad@linux.ibm.com Link: https://lore.kernel.org/20260611034102.1030738-2-aboorvad@linux.ibm.com Fixes: e478425 ("mm/hmm: add tests for hmm_pfn_to_map_order()") Signed-off-by: Sayali Patil <sayalip@linux.ibm.com> Co-developed-by: Aboorva Devarajan <aboorvad@linux.ibm.com> Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com> Cc: Alex Sierra <alex.sierra@amd.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Balbir Singh <balbirs@nvidia.com> Cc: David Hildenbrand <david@kernel.org> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Matthew Brost <matthew.brost@intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Ralph Campbell <rcampbell@nvidia.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 04dfc21 commit 75ec946

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

tools/testing/selftests/mm/hmm-tests.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,8 @@ TEST_F(hmm2, snapshot)
16121612
}
16131613

16141614
/*
1615-
* Test the hmm_range_fault() HMM_PFN_PMD flag for large pages that
1616-
* should be mapped by a large page table entry.
1615+
* Test the hmm_range_fault() handling of large pages (PMD or PUD)
1616+
* that should be mapped by a large page table entry.
16171617
*/
16181618
TEST_F(hmm, compound)
16191619
{
@@ -1623,6 +1623,7 @@ TEST_F(hmm, compound)
16231623
unsigned long default_hsize;
16241624
int *ptr;
16251625
unsigned char *m;
1626+
unsigned char prot;
16261627
int ret;
16271628
unsigned long i;
16281629

@@ -1661,11 +1662,20 @@ TEST_F(hmm, compound)
16611662
ASSERT_EQ(ret, 0);
16621663
ASSERT_EQ(buffer->cpages, npages);
16631664

1664-
/* Check what the device saw. */
1665+
/*
1666+
* Check what the device saw. The region is backed by a single huge
1667+
* page that the device reports either at PMD or at PUD level depending
1668+
* on the configured default hugepage size. Determine that level from
1669+
* the first page and require every page in the range to match it
1670+
* exactly, so that a fragmented mapping mixing levels (or a missing
1671+
* large-page bit) is still caught and reported with its actual value.
1672+
*/
16651673
m = buffer->mirror;
1674+
prot = HMM_DMIRROR_PROT_WRITE |
1675+
((m[0] & HMM_DMIRROR_PROT_PUD) ? HMM_DMIRROR_PROT_PUD :
1676+
HMM_DMIRROR_PROT_PMD);
16661677
for (i = 0; i < npages; ++i)
1667-
ASSERT_EQ(m[i], HMM_DMIRROR_PROT_WRITE |
1668-
HMM_DMIRROR_PROT_PMD);
1678+
ASSERT_EQ(m[i], prot);
16691679

16701680
/* Make the region read-only. */
16711681
ret = mprotect(buffer->ptr, size, PROT_READ);
@@ -1676,11 +1686,17 @@ TEST_F(hmm, compound)
16761686
ASSERT_EQ(ret, 0);
16771687
ASSERT_EQ(buffer->cpages, npages);
16781688

1679-
/* Check what the device saw. */
1689+
/*
1690+
* Check what the device saw after mprotect(PROT_READ). Same
1691+
* approach as above: determine the mapping level from the first
1692+
* page and require every page to match it exactly.
1693+
*/
16801694
m = buffer->mirror;
1695+
prot = HMM_DMIRROR_PROT_READ |
1696+
((m[0] & HMM_DMIRROR_PROT_PUD) ? HMM_DMIRROR_PROT_PUD :
1697+
HMM_DMIRROR_PROT_PMD);
16811698
for (i = 0; i < npages; ++i)
1682-
ASSERT_EQ(m[i], HMM_DMIRROR_PROT_READ |
1683-
HMM_DMIRROR_PROT_PMD);
1699+
ASSERT_EQ(m[i], prot);
16841700

16851701
munmap(buffer->ptr, buffer->size);
16861702
buffer->ptr = NULL;

0 commit comments

Comments
 (0)