Skip to content

Commit e8133a7

Browse files
lorenzo-stoakesakpm00
authored andcommitted
tools: testing: add expand-only mode VMA test
Add a test to assert that VMG_FLAG_JUST_EXPAND functions as expected - that is, when the VMA iterator is positioned at the previous VMA and no VMAs proceed it, we observe an expansion with all state as expected. Explicitly place a prior VMA that would otherwise fail this test if the mode were not enabled (as it would traverse to the previous-previous VMA). Link: https://lkml.kernel.org/r/d2f88330254a6448092412bf7dfe077a579ab0dc.1729174352.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <[email protected]> Cc: Jann Horn <[email protected]> Cc: kernel test robot <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c4d91e2 commit e8133a7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tools/testing/vma/vma.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,45 @@ static bool test_copy_vma(void)
15221522
return true;
15231523
}
15241524

1525+
static bool test_expand_only_mode(void)
1526+
{
1527+
unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE;
1528+
struct mm_struct mm = {};
1529+
VMA_ITERATOR(vmi, &mm, 0);
1530+
struct vm_area_struct *vma_prev, *vma;
1531+
VMG_STATE(vmg, &mm, &vmi, 0x5000, 0x9000, flags, 5);
1532+
1533+
/*
1534+
* Place a VMA prior to the one we're expanding so we assert that we do
1535+
* not erroneously try to traverse to the previous VMA even though we
1536+
* have, through the use of VMG_FLAG_JUST_EXPAND, indicated we do not
1537+
* need to do so.
1538+
*/
1539+
alloc_and_link_vma(&mm, 0, 0x2000, 0, flags);
1540+
1541+
/*
1542+
* We will be positioned at the prev VMA, but looking to expand to
1543+
* 0x9000.
1544+
*/
1545+
vma_iter_set(&vmi, 0x3000);
1546+
vma_prev = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags);
1547+
vmg.prev = vma_prev;
1548+
vmg.merge_flags = VMG_FLAG_JUST_EXPAND;
1549+
1550+
vma = vma_merge_new_range(&vmg);
1551+
ASSERT_NE(vma, NULL);
1552+
ASSERT_EQ(vma, vma_prev);
1553+
ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS);
1554+
ASSERT_EQ(vma->vm_start, 0x3000);
1555+
ASSERT_EQ(vma->vm_end, 0x9000);
1556+
ASSERT_EQ(vma->vm_pgoff, 3);
1557+
ASSERT_TRUE(vma_write_started(vma));
1558+
ASSERT_EQ(vma_iter_addr(&vmi), 0x3000);
1559+
1560+
cleanup_mm(&mm, &vmi);
1561+
return true;
1562+
}
1563+
15251564
int main(void)
15261565
{
15271566
int num_tests = 0, num_fail = 0;
@@ -1553,6 +1592,7 @@ int main(void)
15531592
TEST(vmi_prealloc_fail);
15541593
TEST(merge_extend);
15551594
TEST(copy_vma);
1595+
TEST(expand_only_mode);
15561596

15571597
#undef TEST
15581598

0 commit comments

Comments
 (0)