linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: acsjakub@amazon.de
Cc: akpm@linux-foundation.org, axelrasmussen@google.com,
	 chengming.zhou@linux.dev, david@redhat.com,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, peterx@redhat.com,  xu.xin16@zte.com.cn,
	rust-for-linux@vger.kernel.org,
	 Alice Ryhl <aliceryhl@google.com>
Subject: [PATCH] mm: use enum for vm_flags
Date: Tue,  7 Oct 2025 16:21:36 +0000	[thread overview]
Message-ID: <20251007162136.1885546-1-aliceryhl@google.com> (raw)
In-Reply-To: <20251002075202.11306-1-acsjakub@amazon.de>

The bindgen tool is better able to handle BIT(_) declarations when used
in an enum.

Signed-off-by: Alice Ryhl <aliceryhl@google.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



  parent reply	other threads:[~2025-10-07 16:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02  7:52 [PATCH v4] mm: redefine VM_* flag constants with BIT() Jakub Acs
2025-10-02  7:54 ` David Hildenbrand
2025-10-02 17:43 ` SeongJae Park
2025-10-07 16:21 ` Alice Ryhl [this message]
2025-10-07 17:01   ` [PATCH] mm: use enum for vm_flags Darrick J. Wong
2025-10-08  2:36   ` John Hubbard
2025-10-08 12:54   ` Jakub Acs
2025-10-08 13:15     ` Alice Ryhl
2025-10-10 15:10       ` Darrick J. Wong
2025-10-08 14:17     ` Steven Rostedt
2025-10-09  2:33     ` John Hubbard
2025-10-11  0:18     ` kernel test robot
2025-10-11  0:39     ` kernel test robot
2025-10-10 16:13   ` kernel test robot
2025-10-11  0:50   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251007162136.1885546-1-aliceryhl@google.com \
    --to=aliceryhl@google.com \
    --cc=acsjakub@amazon.de \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=chengming.zhou@linux.dev \
    --cc=david@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=xu.xin16@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox