Re: [PATCH v4 19/20] tools/testing/vma: add test to assert MAP_PRIVATE-/dev/zero is anon

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups org.kernel.vger.linux-s390,org.freedesktop.lists.amd-gfx,org.freedesktop.lists.dri-devel,org.freedesktop.lists.intel-xe,org.kernel.vger.kvm,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.kernel.vger.linux-perf-users,org.kernel.vger.linux-trace-kernel,org.kvack.linux-mm
Message-ID <any2O0nZdz7R3V-G@lucifer>
On Wed, Aug 12, 2026 at 07:17:39PM +0200, David Hildenbrand (Arm) wrote:
> > +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).

Obviously will have to replace this with something else that just sets anon in
an mmap_prepare callback once I drop 17/20.

>
> > +	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]>

Thanks

>
> --
> Cheers,
>
> David

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.