Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <lorenzo.stoakes@oracle.com>
Cc: Jann Horn <jannh@google.com>
Cc: kernel test robot <oliver.sang@intel.com>
Cc: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
e8133a77 c4d91e22

+40
+40
tools/testing/vma/vma.c
··· 1522 1522 return true; 1523 1523 } 1524 1524 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 + 1525 1564 int main(void) 1526 1565 { 1527 1566 int num_tests = 0, num_fail = 0; ··· 1592 1553 TEST(vmi_prealloc_fail); 1593 1554 TEST(merge_extend); 1594 1555 TEST(copy_vma); 1556 + TEST(expand_only_mode); 1595 1557 1596 1558 #undef TEST 1597 1559