> +static bool test_pure_anon_dev_zero(void)
> +{
> +     const vma_flags_t vma_flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
> +                     VMA_MAYREAD_BIT, VMA_MAYWRITE_BIT);
> +     const struct file_operations f_op = {
> +             .mmap_prepare = dummy_mmap_prepare,
> +     };
> +     struct inode inode = {
> +             .i_mode = S_IFCHR,
> +             .i_rdev = MKDEV(MEM_MAJOR, DEVZERO_MINOR),
> +     };
> +     struct file file = {
> +             .f_inode = &inode,
> +             .f_op = &f_op,
> +     };
> +     struct mm_struct mm = {};
> +     struct vm_area_struct *vma;
> +     unsigned long addr;
> +     VMA_ITERATOR(vmi, &mm, 0);
> +

When we go with a zero_vm_ops this gets a bit simpler (see schloppedi-schlop).

> +     current->mm = &mm;
> +
> +     /*
> +      * Map a MAP_PRIVATE-/dev/zero mapping at address 0x300000 with a page
> +      * offset of 0x10, which we expect to be reset to the anonymous page
> +      * offset.
> +      */
> +     addr = __mmap_region(&file, 0x300000, 0x3000, vma_flags, 0x10, NULL);
> +     ASSERT_EQ(addr, 0x300000);
> +
> +     /* Assert that it truly is an anonymous mapping. */
> +     vma = vma_lookup(&mm, addr);
> +     ASSERT_NE(vma, NULL);
> +     ASSERT_TRUE(vma_is_anonymous(vma));
> +     ASSERT_EQ(vma->vm_file, NULL);
> +     ASSERT_EQ(vma->vm_private_data, NULL);
> +     /* Expect anonymous page offsets. */
> +     ASSERT_EQ(vma->vm_pgoff, 0x300);
> +     ASSERT_EQ(vma_start_anon_pgoff(vma), 0x300);

Yes, that looks good to me.

Acked-by: David Hildenbrand (Arm) <[email protected]>

-- 
Cheers,

David

Reply via email to