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

-- 
Pedro

Reply via email to