Re: [PATCH v2 03/13] mm: add mk_vma_flags() bitmap flag macro helper

Lorenzo Stoakes <[email protected]>
Newsgroups org.kernel.vger.linux-sgx,dev.linux.lists.ntfs3,dev.linux.lists.nvdimm,org.freedesktop.lists.dri-devel,org.freedesktop.lists.intel-gfx,org.kernel.vger.keyrings,org.kernel.vger.linux-cxl,org.kernel.vger.linux-ext4,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-security-module,org.kernel.vger.linux-xfs,org.kvack.linux-mm,org.ozlabs.lists.linux-erofs
Message-ID <[email protected]>
On Fri, Feb 06, 2026 at 05:14:10PM +0000, Pedro Falcato wrote:
> On Thu, Jan 22, 2026 at 04:06:12PM +0000, Lorenzo Stoakes wrote:
> > This patch introduces the mk_vma_flags() macro helper to allow easy
> > manipulation of VMA flags utilising the new bitmap representation
> > implemented of VMA flags defined by the vma_flags_t type.
> >
> > It is a variadic macro which provides a bitwise-or'd representation of all
> > of each individual VMA flag specified.
> >
> > Note that, while we maintain VM_xxx flags for backwards compatibility until
> > the conversion is complete, we define VMA flags of type vma_flag_t using
> > VMA_xxx_BIT to avoid confusing the two.
> >
> > This helper macro therefore can be used thusly:
> >
> > vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT);
> >
> > We allow for up to 5 flags to specified at a time which should accommodate
> > all current kernel uses of combined VMA flags.
> >
>
> How do you allow up to 5 flags? I don't see any such limitation in the code?

Yeah oops :) This is from a previous implementation.

Andrew could you drop this paragraph? Thanks!

>
> > Testing has demonstrated that the compiler optimises this code such that it
> > generates the same assembly utilising this macro as it does if the flags
> > were specified manually, for instance:
> >
> > vma_flags_t get_flags(void)
> > {
> > 	return mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT);
> > }
> >
> > Generates the same code as:
> >
> > vma_flags_t get_flags(void)
> > {
> > 	vma_flags_t flags;
> >
> > 	vma_flags_clear_all(&flags);
> > 	vma_flag_set(&flags, VMA_READ_BIT);
> > 	vma_flag_set(&flags, VMA_WRITE_BIT);
> > 	vma_flag_set(&flags, VMA_EXEC_BIT);
> >
> > 	return flags;
> > }
> >
> > And:
> >
> > vma_flags_t get_flags(void)
> > {
> > 	vma_flags_t flags;
> > 	unsigned long *bitmap = ACCESS_PRIVATE(&flags, __vma_flags);
> >
> > 	*bitmap = 1UL << (__force int)VMA_READ_BIT;
> > 	*bitmap |= 1UL << (__force int)VMA_WRITE_BIT;
> > 	*bitmap |= 1UL << (__force int)VMA_EXEC_BIT;
> >
> > 	return flags;
> > }
> >
> > That is:
> >
> > get_flags:
> >         movl    $7, %eax
> >         ret
> >
> > Suggested-by: Jason Gunthorpe <[email protected]>
> > Signed-off-by: Lorenzo Stoakes <[email protected]>
>
> Reviewed-by: Pedro Falcato <[email protected]>

Thanks!

>
> --
> Pedro

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.