Thread (55 messages) 55 messages, 9 authors, 2026-02-10

Re: [PATCH v2 05/13] mm: add basic VMA flag operation helper functions

flat view

From: Lorenzo Stoakes <hidden>
Date: 2026-02-09 14:06:08
Also in: dri-devel, intel-gfx, keyrings, linux-cxl, linux-ext4, linux-fsdevel, linux-mm, linux-xfs, lkml, ntfs3, nvdimm

On Fri, Feb 06, 2026 at 05:35:49PM +0000, Pedro Falcato wrote:
On Thu, Jan 22, 2026 at 04:06:14PM +0000, Lorenzo Stoakes wrote:
quoted
Now we have the mk_vma_flags() macro helper which permits easy
specification of any number of VMA flags, add helper functions which
operate with vma_flags_t parameters.

This patch provides vma_flags_test[_mask](), vma_flags_set[_mask]() and
vma_flags_clear[_mask]() respectively testing, setting and clearing flags
with the _mask variants accepting vma_flag_t parameters, and the non-mask
variants implemented as macros which accept a list of flags.

This allows us to trivially test/set/clear aggregate VMA flag values as
necessary, for instance:

	if (vma_flags_test(&flags, VMA_READ_BIT, VMA_WRITE_BIT))
		goto readwrite;
I'm not a huge fan of the _test ambiguity here, but more words makes it uglier :/
I think I can live with it though.
Yeah, as discussed on IRC it's a bit of a trade off here unfortunately.

I don't love having the _BIT stuff there but is necessary for now I feel until
VM_xxx flags are finally fully deprecated.
quoted
	vma_flags_set(&flags, VMA_READ_BIT, VMA_WRITE_BIT);

	vma_flags_clear(&flags, VMA_READ_BIT, VMA_WRITE_BIT);
The variadic-ness here is very nice though.
Thanks!
quoted
We also add a function for testing that ALL flags are set for convenience,
e.g.:

	if (vma_flags_test_all(&flags, VMA_READ_BIT, VMA_MAYREAD_BIT)) {
		/* Both READ and MAYREAD flags set */
		...
	}

The compiler generates optimal assembly for each such that they behave as
if the caller were setting the bitmap flags manually.

This is important for e.g. drivers which manipulate flag values rather than
a VMA's specific flag values.

We also add helpers for testing, setting and clearing flags for VMA's and
VMA descriptors to reduce boilerplate.

Also add the EMPTY_VMA_FLAGS define to aid initialisation of empty flags.

Finally, update the userland VMA tests to add the helpers there so they can
be utilised as part of userland testing.

Signed-off-by: Lorenzo Stoakes <redacted>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Thanks (also for other tags :P)
--
Pedro
Cheers, Lorenzo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help