Re: [PATCH] mm: use enum for vm_flags

From: Alice Ryhl
Date: Wed Oct 08 2025 - 09:15:24 EST


On Wed, Oct 08, 2025 at 12:54:27PM +0000, Jakub Acs wrote:
> redefine VM_* flag constants with BIT()
>
> Make VM_* flag constant definitions consistent - unify all to use BIT()
> macro and define them within an enum.
>
> The bindgen tool is better able to handle BIT(_) declarations when used
> in an enum.
>
> Also add enum definitions for tracepoints.
>
> We have previously changed VM_MERGEABLE in a separate bugfix. This is a
> follow-up to make all the VM_* flag constant definitions consistent, as
> suggested by David in [1].
>
> [1]: https://lore.kernel.org/all/85f852f9-8577-4230-adc7-c52e7f479454@xxxxxxxxxx/
>
> Signed-off-by: Jakub Acs <acsjakub@xxxxxxxxx>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: David Hildenbrand <david@xxxxxxxxxx>
> Cc: Xu Xin <xu.xin16@xxxxxxxxxx>
> Cc: Chengming Zhou <chengming.zhou@xxxxxxxxx>
> Cc: Peter Xu <peterx@xxxxxxxxxx>
> Cc: Axel Rasmussen <axelrasmussen@xxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> ---
>
> Hi Alice,
>
> thanks for the patch, I squashed it in (should I add your signed-off-by
> too?) and added the TRACE_DEFINE_ENUM calls pointed out by Derrick.

You could add this if you go with the enum approach:

Co-Developed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

> I have the following points to still address, though:
>
> - can the fact that we're not controlling the type of the values if
> using enum be a problem? (likely the indirect control we have through
> the highest value is good enough, but I'm not sure)

The compiler should pick the right integer type in this case.

> - where do TRACE_DEFINE_ENUM calls belong?
> I see them placed e.g. in include/trace/misc/nfs.h for nfs or
> arch/x86/kvm/mmu/mmutrace.h, but I don't see a corresponding file for
> mm.h - does this warrant creating a separate file for these
> definitions?
>
> - with the need for TRACE_DEFINE_ENUM calls, do we still deem this
> to be a good trade-off? - isn't fixing all of these in
> rust/bindings/bindings_helper.h better?
>
> @Derrick, can you point me to how to test for the issue you pointed out?

I'm not familiar with the TRACE_DEFINE_ENUM unfortunately.

> +#ifndef CONFIG_MMU
> +TRACE_DEFINE_ENUM(VM_MAYOVERLAY);
> +#endif /* CONFIG_MMU */

Here I think you want:

#ifdef CONFIG_MMU
TRACE_DEFINE_ENUM(VM_UFFD_MISSING);
#else
TRACE_DEFINE_ENUM(VM_MAYOVERLAY);
#endif /* CONFIG_MMU */

> +TRACE_DEFINE_ENUM(VM_SOFTDIRTY);

Here I think you want:

#ifdef CONFIG_MEM_SOFT_DIRTY
TRACE_DEFINE_ENUM(VM_SOFTDIRTY);
#endif

Alice