Re: [PATCH v3 1/4] mm: declare VMA flags by bit
From: Pedro Falcato
Date: Tue Nov 25 2025 - 05:42:59 EST
On Tue, Nov 25, 2025 at 10:00:59AM +0000, Lorenzo Stoakes wrote:
> In order to lay the groundwork for VMA flags being a bitmap rather than a
> system word in size, we need to be able to consistently refer to VMA flags
> by bit number rather than value.
>
> Take this opportunity to do so in an enum which we which is additionally
> useful for tooling to extract metadata from.
>
> This additionally makes it very clear which bits are being used for what at
> a glance.
>
> We use the VMA_ prefix for the bit values as it is logical to do so since
> these reference VMAs. We consistently suffix with _BIT to make it clear
> what the values refer to.
>
> We declare bit values even when the flags that use them would not be
> enabled by config options as this is simply clearer and clearly defines
> what bit numbers are used for what, at no additional cost.
>
> We declare a sparse-bitwise type vma_flag_t which ensures that users can't
> pass around invalid VMA flags by accident and prepares for future work
> towards VMA flags being a bitmap where we want to ensure bit values are
> type safe.
>
> To make life easier, we declare some macro helpers - DECLARE_VMA_BIT()
> allows us to avoid duplication in the enum bit number declarations (and
> maintaining the sparse __bitwise attribute), and INIT_VM_FLAG() is used to
> assist with declaration of flags.
>
> Unfortunately we can't declare both in the enum, as we run into issue with
> logic in the kernel requiring that flags are preprocessor definitions, and
> additionally we cannot have a macro which declares another macro so we must
> define each flag macro directly.
>
> Additionally, update the VMA userland testing vma_internal.h header to
> include these changes.
>
> We also have to fix the parameters to the vma_flag_*_atomic() functions
> since VMA_MAYBE_GUARD_BIT is now of type vma_flag_t and sparse will
> complain otherwise.
>
> We have to update some rather silly if-deffery found in mm/task_mmu.c which
> would otherwise break.
>
> Finally, we update the rust binding helper as now it cannot auto-detect the
> flags at all.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> Acked-by: Vlastimil Babka <vbabka@xxxxxxx>
Reviewed-by: Pedro Falcato <pfalcato@xxxxxxx>
Scary but cromulent-looking. Thanks :)
--
Pedro