[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251007162136.1885546-1-aliceryhl@google.com>
Date: Tue, 7 Oct 2025 16:21:36 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: acsjakub@...zon.de
Cc: akpm@...ux-foundation.org, axelrasmussen@...gle.com,
chengming.zhou@...ux.dev, david@...hat.com, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org, peterx@...hat.com,
xu.xin16@....com.cn, rust-for-linux@...r.kernel.org,
Alice Ryhl <aliceryhl@...gle.com>
Subject: [PATCH] mm: use enum for vm_flags
The bindgen tool is better able to handle BIT(_) declarations when used
in an enum.
Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
---
Hi Jakub,
what do you think about modifying the patch like this to use an enum? It
resolves the issues brought up in
https://lore.kernel.org/all/CAH5fLghTu-Zcm9e3Hy07nNtvB_-hRjojAWDoq-hhBYGE7LPEbQ@mail.gmail.com/
Feel free to squash this patch into your patch.
include/linux/mm.h | 90 +++++++++++++++++----------------
rust/bindings/bindings_helper.h | 1 -
2 files changed, 46 insertions(+), 45 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7916d527f687..69da7ce13e50 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -273,57 +273,58 @@ extern unsigned int kobjsize(const void *objp);
* vm_flags in vm_area_struct, see mm_types.h.
* When changing, update also include/trace/events/mmflags.h
*/
-#define VM_NONE 0
+enum {
+ VM_NONE = 0,
-#define VM_READ BIT(0) /* currently active flags */
-#define VM_WRITE BIT(1)
-#define VM_EXEC BIT(2)
-#define VM_SHARED BIT(3)
+ VM_READ = BIT(0), /* currently active flags */
+ VM_WRITE = BIT(1),
+ VM_EXEC = BIT(2),
+ VM_SHARED = BIT(3),
/* mprotect() hardcodes VM_MAYREAD >> 4 == VM_READ, and so for r/w/x bits. */
-#define VM_MAYREAD BIT(4) /* limits for mprotect() etc */
-#define VM_MAYWRITE BIT(5)
-#define VM_MAYEXEC BIT(6)
-#define VM_MAYSHARE BIT(7)
+ VM_MAYREAD = BIT(4), /* limits for mprotect() etc */
+ VM_MAYWRITE = BIT(5),
+ VM_MAYEXEC = BIT(6),
+ VM_MAYSHARE = BIT(7),
-#define VM_GROWSDOWN BIT(8) /* general info on the segment */
+ VM_GROWSDOWN = BIT(8), /* general info on the segment */
#ifdef CONFIG_MMU
-#define VM_UFFD_MISSING BIT(9) /* missing pages tracking */
+ VM_UFFD_MISSING = BIT(9), /* missing pages tracking */
#else /* CONFIG_MMU */
-#define VM_MAYOVERLAY BIT(9) /* nommu: R/O MAP_PRIVATE mapping that might overlay a file mapping */
+ VM_MAYOVERLAY = BIT(9), /* nommu: R/O MAP_PRIVATE mapping that might overlay a file mapping */
#define VM_UFFD_MISSING 0
#endif /* CONFIG_MMU */
-#define VM_PFNMAP BIT(10) /* Page-ranges managed without "struct page", just pure PFN */
-#define VM_UFFD_WP BIT(12) /* wrprotect pages tracking */
-
-#define VM_LOCKED BIT(13)
-#define VM_IO BIT(14) /* Memory mapped I/O or similar */
-
- /* Used by sys_madvise() */
-#define VM_SEQ_READ BIT(15) /* App will access data sequentially */
-#define VM_RAND_READ BIT(16) /* App will not benefit from clustered reads */
-
-#define VM_DONTCOPY BIT(17) /* Do not copy this vma on fork */
-#define VM_DONTEXPAND BIT(18) /* Cannot expand with mremap() */
-#define VM_LOCKONFAULT BIT(19) /* Lock the pages covered when they are faulted in */
-#define VM_ACCOUNT BIT(20) /* Is a VM accounted object */
-#define VM_NORESERVE BIT(21) /* should the VM suppress accounting */
-#define VM_HUGETLB BIT(22) /* Huge TLB Page VM */
-#define VM_SYNC BIT(23) /* Synchronous page faults */
-#define VM_ARCH_1 BIT(24) /* Architecture-specific flag */
-#define VM_WIPEONFORK BIT(25) /* Wipe VMA contents in child. */
-#define VM_DONTDUMP BIT(26) /* Do not include in the core dump */
+ VM_PFNMAP = BIT(10), /* Page-ranges managed without "struct page", just pure PFN */
+ VM_UFFD_WP = BIT(12), /* wrprotect pages tracking */
+
+ VM_LOCKED = BIT(13),
+ VM_IO = BIT(14), /* Memory mapped I/O or similar */
+
+ /* Used by sys_madvise() */
+ VM_SEQ_READ = BIT(15), /* App will access data sequentially */
+ VM_RAND_READ = BIT(16), /* App will not benefit from clustered reads */
+
+ VM_DONTCOPY = BIT(17), /* Do not copy this vma on fork */
+ VM_DONTEXPAND = BIT(18), /* Cannot expand with mremap() */
+ VM_LOCKONFAULT = BIT(19), /* Lock the pages covered when they are faulted in */
+ VM_ACCOUNT = BIT(20), /* Is a VM accounted object */
+ VM_NORESERVE = BIT(21), /* should the VM suppress accounting */
+ VM_HUGETLB = BIT(22), /* Huge TLB Page VM */
+ VM_SYNC = BIT(23), /* Synchronous page faults */
+ VM_ARCH_1 = BIT(24), /* Architecture-specific flag */
+ VM_WIPEONFORK = BIT(25), /* Wipe VMA contents in child. */
+ VM_DONTDUMP = BIT(26), /* Do not include in the core dump */
#ifdef CONFIG_MEM_SOFT_DIRTY
-# define VM_SOFTDIRTY BIT(27) /* Not soft dirty clean area */
+ VM_SOFTDIRTY = BIT(27), /* Not soft dirty clean area */
#else
# define VM_SOFTDIRTY 0
#endif
-#define VM_MIXEDMAP BIT(28) /* Can contain "struct page" and pure PFN pages */
-#define VM_HUGEPAGE BIT(29) /* MADV_HUGEPAGE marked this vma */
-#define VM_NOHUGEPAGE BIT(30) /* MADV_NOHUGEPAGE marked this vma */
-#define VM_MERGEABLE BIT(31) /* KSM may merge identical pages */
+ VM_MIXEDMAP = BIT(28), /* Can contain "struct page" and pure PFN pages */
+ VM_HUGEPAGE = BIT(29), /* MADV_HUGEPAGE marked this vma */
+ VM_NOHUGEPAGE = BIT(30), /* MADV_NOHUGEPAGE marked this vma */
+ VM_MERGEABLE = BIT(31), /* KSM may merge identical pages */
#ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS
#define VM_HIGH_ARCH_BIT_0 32 /* bit only usable on 64-bit architectures */
@@ -333,14 +334,15 @@ extern unsigned int kobjsize(const void *objp);
#define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */
#define VM_HIGH_ARCH_BIT_6 38 /* bit only usable on 64-bit architectures */
-#define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)
-#define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)
-#define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)
-#define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3)
-#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
-#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5)
-#define VM_HIGH_ARCH_6 BIT(VM_HIGH_ARCH_BIT_6)
+ VM_HIGH_ARCH_0 = BIT(VM_HIGH_ARCH_BIT_0),
+ VM_HIGH_ARCH_1 = BIT(VM_HIGH_ARCH_BIT_1),
+ VM_HIGH_ARCH_2 = BIT(VM_HIGH_ARCH_BIT_2),
+ VM_HIGH_ARCH_3 = BIT(VM_HIGH_ARCH_BIT_3),
+ VM_HIGH_ARCH_4 = BIT(VM_HIGH_ARCH_BIT_4),
+ VM_HIGH_ARCH_5 = BIT(VM_HIGH_ARCH_BIT_5),
+ VM_HIGH_ARCH_6 = BIT(VM_HIGH_ARCH_BIT_6),
#endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */
+};
#ifdef CONFIG_ARCH_HAS_PKEYS
# define VM_PKEY_SHIFT VM_HIGH_ARCH_BIT_0
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 2e43c66635a2..04b75d4d01c3 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -108,7 +108,6 @@ const xa_mark_t RUST_CONST_HELPER_XA_PRESENT = XA_PRESENT;
const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC = XA_FLAGS_ALLOC;
const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC1 = XA_FLAGS_ALLOC1;
-const vm_flags_t RUST_CONST_HELPER_VM_MERGEABLE = VM_MERGEABLE;
#if IS_ENABLED(CONFIG_ANDROID_BINDER_IPC_RUST)
#include "../../drivers/android/binder/rust_binder.h"
--
2.51.0.618.g983fd99d29-goog
Powered by blists - more mailing lists