mm-introduce-vma-flags-bitmap-type.patch removed from -mm tree
The quilt patch titled
Subject: mm: introduce VMA flags bitmap type
has been removed from the -mm tree. Its filename was
mm-introduce-vma-flags-bitmap-type.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Lorenzo Stoakes <[email protected]>
Subject: mm: introduce VMA flags bitmap type
Date: Tue, 25 Nov 2025 10:01:02 +0000
It is useful to transition to using a bitmap for VMA flags so we can avoid running out of flags, especially for 32-bit kernels which are constrained to 32 flags, necessitating some features to be limited to 64-bit kernels only.
By doing so, we remove any constraint on the number of VMA flags moving forwards no matter the platform and can decide in future to extend beyond 64 if required.
We start by declaring an opaque types, vma_flags_t (which resembles mm_struct flags of type mm_flags_t), setting it to precisely the same size as vm_flags_t, and place it in union with vm_flags in the VMA declaration.
We additionally update struct vm_area_desc equivalently placing the new opaque type in union with vm_flags.
This change therefore does not impact the size of struct vm_area_struct or struct vm_area_desc.
In order for the change to be iterative and to avoid impacting performance, we designate VM_xxx declared bitmap flag values as those which must exist in the first system word of the VMA flags bitmap.
We therefore declare vma_flags_clear_all(), vma_flags_overwrite_word(), vma_flags_overwrite_word(), vma_flags_overwrite_word_once(), vma_flags_set_word() and vma_flags_clear_word() in order to allow us to update the existing vm_flags_*() functions to utilise these helpers.
This is a stepping stone towards converting users to the VMA flags bitmap and behaves precisely as before.
By doing this, we can eliminate the existing private vma->__vm_flags field in the vma->vm_flags union and replace it with the newly introduced opaque type vma_flags, which we call flags so we refer to the new bitmap field as vma->flags.
We update vma_flag_[test, set]_atomic() to account for the change also.
We adapt vm_flags_reset_once() to only clear those bits above the first system word providing write-once semantics to the first system word (which it is presumed the caller requires - and in all current use cases this is so).
As we currently only specify that the VMA flags bitmap size is equal to BITS_PER_LONG number of bits, this is a noop, but is defensive in preparation for a future change that increases this.
We additionally update the VMA userland test declarations to implement the same changes there.
Finally, we update the rust code to reference vma->vm_flags on update rather than vma->__vm_flags which has been removed. This is safe for now, albeit it is implicitly performing a const cast.
Once we introduce flag helpers we can improve this more.
No functional change intended.
---
include/linux/mm.h | 24 +++- include/linux/mm_types.h | 64 +++++++++++- rust/kernel/mm/virt.rs | 2 tools/testing/vma/vma_internal.h | 150 +++++++++++++++++++++++------ 4 files changed, 202 insertions(+), 38 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-introduce-vma-flags-bitmap-type +19 -5
@@ -911,7 +911,8 @@ static inline void vm_flags_init(struct vm_flags_t flags) {VM_WARN_ON_ONCE (!pgtable_supports_soft_dirty () && (flags &VM_SOFTDIRTY )); -ACCESS_PRIVATE (vma, __vm_flags) = flags; +vma_flags_clear_all (&vma->flags); +vma_flags_overwrite_word (&vma->flags, flags); }/*
@@ -931,14 +932,25 @@ static inline void vm_flags_reset_once(s vm_flags_t flags) {vma_assert_write_locked (vma); -WRITE_ONCE (ACCESS_PRIVATE (vma, __vm_flags), flags); +/* +* If VMA flags exist beyond the first system word, also clear these. It +* is assumed the write once behaviour is required only for the first +* system word. +*/ +if (NUM_VMA_FLAG_BITS >BITS_PER_LONG ) { +unsigned long *bitmap =ACCESS_PRIVATE (&vma->flags, __vma_flags); + +bitmap_zero (&bitmap[1 ],NUM_VMA_FLAG_BITS -BITS_PER_LONG ); + } + +vma_flags_overwrite_word_once (&vma->flags, flags); }static inline void vm_flags_set (struct vm_area_struct *vma,vm_flags_t flags) {vma_start_write (vma); -ACCESS_PRIVATE (vma, __vm_flags) |= flags; +vma_flags_set_word (&vma->flags, flags); } static inline void vm_flags_clear(struct vm_area_struct *vma,
@@ -946,7 +958,7 @@ static inline void vm_flags_clear(struct {VM_WARN_ON_ONCE (!pgtable_supports_soft_dirty () && (flags &VM_SOFTDIRTY ));vma_start_write (vma); -ACCESS_PRIVATE (vma, __vm_flags) &= ~flags; +vma_flags_clear_word (&vma->flags, flags); }/*
@@ -989,12 +1001,14 @@ static inline bool __vma_flag_atomic_valstatic inline void vma_flag_set_atomic (struct vm_area_struct *vma,vma_flag_t bit) { +unsigned long *bitmap =ACCESS_PRIVATE (&vma->flags, __vma_flags); +/* mmap read lock/VMA read lock must be held. */ if (!rwsem_is_locked (&vma->vm_mm->mmap_lock))vma_assert_locked (vma);if (__vma_flag_atomic_valid (vma, bit)) -set_bit ((__force int )bit, &ACCESS_PRIVATE (vma, __vm_flags)); +set_bit ((__force int )bit, bitmap); }/*
include/linux/mm_types.h renamed from include/linux/mm_types.h~mm-introduce-vma-flags-bitmap-type +62 -2
91 lines not on this page · raw message
rust/kernel/mm/virt.rs renamed from rust/kernel/mm/virt.rs~mm-introduce-vma-flags-bitmap-type +1 -1
@@ -250,7 +250,7 @@ impl VmaNew {// SAFETY: This is not a data race: the vma is undergoing initial setup, so it's not yet // shared. Additionally, `VmaNew` is `!Sync`, so it cannot be used to write in parallel. // The caller promises that this does not set the flags to an invalid value. -unsafe { (*self.as_ptr ()).__bindgen_anon_2.__vm_flags = flags }; +unsafe { (*self.as_ptr ()).__bindgen_anon_2.vm_flags = flags }; }/// Set the `VM_MIXEDMAP` flag on this vma.
tools/testing/vma/vma_internal.h renamed from tools/testing/vma/vma_internal.h~mm-introduce-vma-flags-bitmap-type +120 -30
190 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are