mm: continue vma_flags_t conversion
Subsystems (32)
Lorenzo Stoakes (ARM)
maintainercover mm: continue vma_flags_t conversion
Continue the conversion of legacy vm_flags_t flags to the new vma_flags_t bitmap type.
Do some more core mm conversion (we really should be the first to completely move to the new scheme :), but also update some mm-adjacent and otherwise straightforward cases - /proc/$pid/maps and friends, the coredump VMA dump size logic, uprobes, perf and LSM mmap/mprotect hooks.
This series only makes strictly mechanical changes to keep things gentle during this very busy cycle.
No functional change intended.
Build tested on x86-64 (allmodconfig, each patch individually), i386, arm64, riscv nommu and ppc64le.
---
Lorenzo Stoakes (ARM) (13):
mm/gup: convert GUP code to use vma_flags_t mm/filemap: convert fault and readahead logic to use vma_flags_t mm/rmap: convert remaining VMA flag tests to use vma_flags_t mm/migrate: convert VMA flag tests to use vma_flags_t
mm: convert THP VMA flag tests to use vma_flags_t mm/ksm: convert VMA flag tests to use vma_flags_t mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
mm: convert miscellaneous VMA flag tests to use vma_flags_t fs/proc/task_mmu: convert VMA flag tests to use vma_flags_t fs/coredump: convert vma_dump_size() to use vma_flags_t
uprobes: convert VMA flag tests to use vma_flags_t
perf: convert VMA flag tests to use vma_flags_t
security: convert VMA flag tests to use vma_flags_t
arch/powerpc/kvm/book3s_hv_uvmem.c | 10 ++++---- fs/coredump.c | 16 ++++++------- fs/proc/task_mmu.c | 43 +++++++++++++++++----------------- include/linux/huge_mm.h | 4 ++-- include/linux/ksm.h | 4 ++-- include/linux/mm_inline.h | 2 +- kernel/events/core.c | 26 +++++++++++---------- kernel/events/uprobes.c | 12 ++++++---- lib/test_hmm.c | 4 ++-- mm/damon/vaddr.c | 2 +- mm/filemap.c | 24 ++++++++++--------- mm/gup.c | 45 +++++++++++++++++++----------------- mm/hmm.c | 6 ++--- mm/huge_memory.c | 32 +++++++++++++------------- mm/internal.h | 2 +- mm/khugepaged.c | 18 ++++++++------- mm/ksm.c | 22 ++++++++++-------- mm/madvise.c | 47 ++++++++++++++++++++------------------ mm/mempolicy.c | 4 ++-- mm/migrate.c | 5 ++-- mm/migrate_device.c | 8 +++---- mm/mmap_lock.c | 4 ++-- mm/mremap.c | 2 +- mm/msync.c | 4 ++-- mm/oom_kill.c | 4 ++-- mm/pagewalk.c | 2 +- mm/rmap.c | 8 ++++--- mm/vma.h | 4 ++-- security/apparmor/lsm.c | 2 +- security/integrity/ima/ima_main.c | 2 +- security/ipe/hooks.c | 2 +- security/selinux/hooks.c | 14 ++++++------ 32 files changed, 202 insertions(+), 182 deletions(-)
---
base-commit: b61fa14ce6bcbba2cb9a96feea31b760226d6b43
change-id: 20261101-late-2026-vma-flags-461731a636c3
Cheers,
Signature · 1 line
Lorenzo Stoakes (ARM) <[email protected]>
Lorenzo Stoakes (ARM)
maintainerPATCH 1/13 mm/gup: convert GUP code to use vma_flags_t
Replace use of the legacy vm_flags_t flags with vma_flags_t values throughout the GUP logic, both for the MMU and nommu variants.
No functional change intended.
--- mm/gup.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
mm/gup.c +24 -21
@@ -590,15 +590,15 @@ static inline bool can_follow_write_common(struct page *page,return false;/* But FOLL_FORCE has no effect on shared mappings */ -if (vma->vm_flags & (VM_MAYSHARE |VM_SHARED )) +if (vma_test_any (vma,VMA_MAYSHARE_BIT ,VMA_SHARED_BIT ))return false;/* ... or read-only private ones */ -if (!(vma->vm_flags &VM_MAYWRITE )) +if (!vma_test (vma,VMA_MAYWRITE_BIT ))return false;/* ... or already writable ones that just need to take a write fault */ -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT ))return false;/*
@@ -1199,12 +1199,11 @@ static bool writable_file_mapping_allowed(struct vm_area_struct *vma,static int check_vma_flags (struct vm_area_struct *vma,unsigned long gup_flags) { -vm_flags_t vm_flags = vma->vm_flags;int write = (gup_flags &FOLL_WRITE );int foreign = (gup_flags &FOLL_REMOTE );bool vma_anon =vma_is_anonymous (vma); -if (vm_flags & (VM_IO |VM_PFNMAP )) +if (vma_test_any (vma,VMA_IO_BIT ,VMA_PFNMAP_BIT ))return -EFAULT ;if ((gup_flags &FOLL_ANON ) && !vma_anon)
@@ -1224,7 +1223,8 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) !writable_file_mapping_allowed(vma, gup_flags))return -EFAULT ; -if (!(vm_flags &VM_WRITE ) || (vm_flags &VM_SHADOW_STACK )) { +if (!vma_test (vma,VMA_WRITE_BIT ) || +vma_test_single_mask (vma,VMA_SHADOW_STACK )) {if (!(gup_flags &FOLL_FORCE ))return -EFAULT ;/*
@@ -1239,14 +1239,14 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags)if (!vma_is_cow_mapping (vma))return -EFAULT ; } - }else if (!(vm_flags &VM_READ )) { + }else if (!vma_test (vma,VMA_READ_BIT )) {if (!(gup_flags &FOLL_FORCE ))return -EFAULT ;/* * Is there actually any vma we can reach here which does not * have VM_MAYREAD set? */ -if (!(vm_flags &VM_MAYREAD )) +if (!vma_test (vma,VMA_MAYREAD_BIT ))return -EFAULT ; }/*
@@ -1277,7 +1277,7 @@ static struct vm_area_struct *gup_vma_lookup(struct mm_struct *mm,return vma;/* Only warn for half-way relevant accesses */ -if (!(vma->vm_flags &VM_GROWSDOWN )) +if (!vma_test (vma,VMA_GROWSDOWN_BIT ))return NULL ;if (vma->vm_start - addr >65536 )return NULL ;
@@ -1514,9 +1514,8 @@ static bool vma_permits_fault(struct vm_area_struct *vma, {bool write = !!(fault_flags &FAULT_FLAG_WRITE );bool foreign = !!(fault_flags &FAULT_FLAG_REMOTE ); -vm_flags_t vm_flags = write ?VM_WRITE :VM_READ ; -if (!(vm_flags & vma->vm_flags)) +if (!vma_test (vma, write ?VMA_WRITE_BIT :VMA_READ_BIT ))return false;/*
@@ -1829,7 +1828,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,* Rightly or wrongly, the VM_LOCKONFAULT case has never used * faultin_page() to break COW, so it has no work to do here. */ -if (vma->vm_flags &VM_LOCKONFAULT ) +if (vma_test (vma,VMA_LOCKONFAULT_BIT ))return nr_pages;/* ... similarly, we've never faulted in PROT_NONE pages */
@@ -1849,7 +1848,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,* Otherwise, do a read fault, and use FOLL_FORCE in case it's not * readable (ie write-only or executable). */ -if ((vma->vm_flags & (VM_WRITE |VM_SHARED )) ==VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT ) && !vma_test (vma,VMA_SHARED_BIT )) gup_flags |=FOLL_WRITE ;else gup_flags |=FOLL_FORCE ;
@@ -1955,7 +1954,7 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)* range with the first VMA. Also, skip undesirable VMA types. */ nend =min (end, vma->vm_end); -if (vma->vm_flags & (VM_IO |VM_PFNMAP )) +if (vma_test_any (vma,VMA_IO_BIT ,VMA_PFNMAP_BIT ))continue ;if (nstart < vma->vm_start) nstart = vma->vm_start;
@@ -1986,7 +1985,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, {struct vm_area_struct *vma;bool must_unlock = false; -vm_flags_t vm_flags; +vma_flags_t vma_flags;int ret, err = -EFAULT ;long i;
@@ -2011,10 +2010,14 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,/* calculate required read or write permissions. * If FOLL_FORCE is set, we only require the "MAY" flags. */ - vm_flags = (foll_flags &FOLL_WRITE ) ? - (VM_WRITE |VM_MAYWRITE ) : (VM_READ |VM_MAYREAD ); - vm_flags &= (foll_flags &FOLL_FORCE ) ? - (VM_MAYREAD |VM_MAYWRITE ) : (VM_READ |VM_WRITE ); +if (foll_flags &FOLL_WRITE ) + vma_flags =mk_vma_flags (VMA_WRITE_BIT ,VMA_MAYWRITE_BIT ); +else + vma_flags =mk_vma_flags (VMA_READ_BIT ,VMA_MAYREAD_BIT ); +if (foll_flags &FOLL_FORCE ) +vma_flags_clear (&vma_flags,VMA_READ_BIT ,VMA_WRITE_BIT ); +else +vma_flags_clear (&vma_flags,VMA_MAYREAD_BIT ,VMA_MAYWRITE_BIT );for (i =0 ; i < nr_pages; i++) { vma =find_vma (mm, start);
@@ -2022,8 +2025,8 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,break ;/* protect what we can, including chardevs */ -if ((vma->vm_flags & (VM_IO |VM_PFNMAP )) || - !(vm_flags & vma->vm_flags)) +if (vma_test_any (vma,VMA_IO_BIT ,VMA_PFNMAP_BIT ) || + !vma_test_any_mask (vma, vma_flags))break ;if (pages) {
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 01/13] mm/gup: convert GUP code to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the GUP logic, both for the MMU and nommu variants.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 01/13] mm/gup: convert GUP code to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the GUP logic, both for the MMU and nommu variants.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Quoted 6 lines
--- mm/gup.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
mm/gup.c static bool vma_permits_fault(struct vm_area_struct *vma, · line 1519
Quoted 8 lines
mm/gup.c +1
-2@@ -1514,9 +1514,8 @@ static bool vma_permits_fault(struct vm_area_struct *vma, {bool write = !!(fault_flags &FAULT_FLAG_WRITE );bool foreign = !!(fault_flags &FAULT_FLAG_REMOTE ); -vm_flags_t vm_flags = write ?VM_WRITE :VM_READ ; -if (!(vm_flags & vma->vm_flags)) +if (!vma_test (vma, write ?VMA_WRITE_BIT :VMA_READ_BIT ))return false;
This also improves readability. Thanks!
Quoted 1 line
Re: [PATCH 01/13] mm/gup: convert GUP code to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the GUP logic, both for the MMU and nommu variants.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Nice work1
Re: [PATCH 01/13] mm/gup: convert GUP code to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 4 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the GUP logic, both for the MMU and nommu variants.No functional change intended.
Applied, thanks!
tree: mm/core.git
branch: gup-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[01/13] mm/gup: convert GUP code to use vma_flags_t
https://git.kernel.org/mm/core/c/87127ea3
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerPATCH 2/13 mm/filemap: convert fault and readahead logic to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values in the file fault and mmap readahead logic.
No functional change intended.
--- mm/filemap.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
mm/filemap.c +13 -11
@@ -3351,13 +3351,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)struct address_space *mapping = file->f_mapping;DEFINE_READAHEAD (ractl, file, ra, mapping, vmf->pgoff);struct file *fpin =NULL ; -vm_flags_t vm_flags = vmf->vma->vm_flags; +struct vm_area_struct *vma = vmf->vma;bool force_thp_readahead = false;unsigned int thp_order =0 ;unsigned short mmap_miss;/* Use the readahead code, even if readahead is disabled */ -if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && (vm_flags &VM_HUGEPAGE )) { +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && +vma_test (vma,VMA_HUGEPAGE_BIT )) {/* * Cap max THP order at 2MB: this is the common PMD-sized * hugepage size, and it avoids memory pressure from very
@@ -3377,20 +3378,21 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)* If we don't want any read-ahead, don't bother. * VM_EXEC case below is already intended for random access. */ -if ((vm_flags & (VM_RAND_READ |VM_EXEC )) ==VM_RAND_READ ) +if (vma_test (vma,VMA_RAND_READ_BIT ) && + !vma_test (vma,VMA_EXEC_BIT ))return fpin;if (!ra->ra_pages)return fpin; -if (vm_flags &VM_SEQ_READ ) { +if (vma_test (vma,VMA_SEQ_READ_BIT )) { fpin =maybe_unlock_mmap_for_io (vmf, fpin);page_cache_sync_ra (&ractl, ra->ra_pages);return fpin; } } -if (!(vm_flags & (VM_SEQ_READ |VM_EXEC ))) { +if (!vma_test_any (vma,VMA_SEQ_READ_BIT ,VMA_EXEC_BIT )) {/* Avoid banging the cache line if not needed */ mmap_miss =READ_ONCE (ra->mmap_miss);if (mmap_miss <MMAP_LOTSAMISS *10 )
@@ -3414,7 +3416,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)* Fetch two folios so we get the chance to actually * readahead, unless we've been told not to. */ -if (!(vm_flags &VM_RAND_READ )) +if (!vma_test (vma,VMA_RAND_READ_BIT )) ra->size *=2 ; ra->async_size = folio_nr_pages; ra->order = thp_order;
@@ -3422,7 +3424,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)return fpin; } -if (vm_flags &VM_EXEC ) { +if (vma_test (vma,VMA_EXEC_BIT )) {/* * Allow arch to request a preferred minimum folio order for * executable memory. This can often be beneficial to
@@ -3477,7 +3479,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf,unsigned short mmap_miss;/* If we don't want any read-ahead, don't bother */ -if (vmf->vma->vm_flags &VM_RAND_READ || !ra->ra_pages) +if (vma_test (vmf->vma,VMA_RAND_READ_BIT ) || !ra->ra_pages)return fpin;/*
@@ -3491,7 +3493,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf,* keep the counter symmetric. */ if (likely (!folio_test_locked (folio)) && - !(vmf->vma->vm_flags & (VM_SEQ_READ |VM_EXEC ))) { + !vma_test_any (vmf->vma,VMA_SEQ_READ_BIT ,VMA_EXEC_BIT )) { mmap_miss =READ_ONCE (ra->mmap_miss);if (mmap_miss)WRITE_ONCE (ra->mmap_miss, --mmap_miss);
@@ -3524,7 +3526,7 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf)* scenarios. Recheck the PTE without PT lock firstly, thereby reducing * the number of times we hold PT lock. */ -if (!(vma->vm_flags &VM_LOCKED )) +if (!vma_test (vma,VMA_LOCKED_BIT ))return 0 ;if (!(vmf->flags &FAULT_FLAG_ORIG_PTE_VALID ))
@@ -4000,7 +4002,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf,if ((map_ret &VM_FAULT_NOPAGE ) && !(vmf->flags &FAULT_FLAG_TRIED ) && !folio_test_workingset (folio) && - !(vma->vm_flags & (VM_SEQ_READ |VM_EXEC ))) { + !vma_test_any (vma,VMA_SEQ_READ_BIT ,VMA_EXEC_BIT )) {unsigned short mmap_miss; mmap_miss =READ_ONCE (file->f_ra.mmap_miss);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 02/13] mm/filemap: convert fault and readahead logic to use vma_flags_t
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] mm/filemap: use-after-free on vma in do_sync_mmap_readahead() - [Low] mm/filemap: inner vma…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm/filemap: use-after-free on vma in do_sync_mmap_readahead()
- [Low] mm/filemap: inner vma declaration shadows outer vma in do_sync_mmap_readahead() --
commit f5f0f8e634a6a2e2b76ad818de67e83f30cb7dea
Author: Lorenzo Stoakes (ARM) <[email protected]>
mm/filemap: convert fault and readahead logic to use vma_flags_t
This commit replaces direct checks of vm_flags_t values with vma_flags_t helpers in the filemap fault and mmap readahead paths.
Quoted 13 lines
mm/filemap.c +1
-1@@ -3351,13 +3351,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)struct address_space *mapping = file->f_mapping;DEFINE_READAHEAD (ractl, file, ra, mapping, vmf->pgoff);struct file *fpin =NULL ; -vm_flags_t vm_flags = vmf->vma->vm_flags; +struct vm_area_struct *vma = vmf->vma;bool force_thp_readahead = false;unsigned int thp_order =0 ;unsigned short mmap_miss;
[ ... ]
mm/filemap.c static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) · line 3422
Quoted 9 lines
mm/filemap.c +1
-1@@ -3414,7 +3416,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)* Fetch two folios so we get the chance to actually * readahead, unless we've been told not to. */ -if (!(vm_flags &VM_RAND_READ )) +if (!vma_test (vma,VMA_RAND_READ_BIT )) ra->size *=2 ; ra->async_size = folio_nr_pages; ra->order = thp_order;
[Severity: High]
Can this trigger a use-after-free on vma?
Previously, do_sync_mmap_readahead() cached vmf->vma->vm_flags by value in a local variable at entry while the fault lock was held, as introduced by commit dcfa24ba6899 ("filemap: Cache the value of vm_flags").
In the force_thp_readahead block, maybe_unlock_mmap_for_io() is called before this check:
if (force_thp_readahead) {
unsigned long folio_nr_pages = 1UL << thp_order;
fpin = maybe_unlock_mmap_for_io(vmf, fpin);
ractl._index &= ~(folio_nr_pages - 1);
ra->size = folio_nr_pages;
/*
* Fetch two folios so we get the chance to actually
* readahead, unless we've been told not to.
*/
if (!vma_test(vma, VMA_RAND_READ_BIT))
ra->size *= 2;Since maybe_unlock_mmap_for_io() only pins vmf->vma->vm_file and calls release_fault_lock(vmf) to drop mmap_lock or the per-VMA lock, isn't vma unprotected against concurrent modification or freeing when vma_test(vma, VMA_RAND_READ_BIT) dereferences vma->flags?
mm/filemap.c static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) · line 3430
Quoted 9 lines
mm/filemap.c +1
-1@@ -3422,7 +3424,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)return fpin; } -if (vm_flags &VM_EXEC ) { +if (vma_test (vma,VMA_EXEC_BIT )) {/* * Allow arch to request a preferred minimum folio order for * executable memory. This can often be beneficial to
[Severity: Low]
Does the newly added outer vma declaration in do_sync_mmap_readahead() cause the existing inner declaration in this VMA_EXEC_BIT block to shadow it?
if (vma_test(vma, VMA_EXEC_BIT)) {
...
struct vm_area_struct *vma = vmf->vma;
const unsigned long start = vma_start_pgoff(vma);
const unsigned long end = vma_end_pgoff(vma);Should the inner vma variable be removed now that vma is declared at function scope?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 02/13] mm/filemap: convert fault and readahead logic to use vma_flags_t
Quoted 87 lines · On Thu, Nov 05, 2026 at 09:41:34PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm/filemap: use-after-free on vma indo_sync_mmap_readahead()
- [Low] mm/filemap: inner vma declaration shadows outer vma indo_sync_mmap_readahead()--commit
f5f0f8e634a6a2e2b76ad818de67e83f30cb7dea
Author: Lorenzo Stoakes (ARM) <[email protected]>mm/filemap: convert fault and readahead logic to use
vma_flags_tThis commit replaces direct checks of
vm_flags_tvalues withvma_flags_thelpers in the filemap fault and mmap readahead paths.Quoted 13 lines
mm/filemap.c +1
-1@@ -3351,13 +3351,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)struct address_space *mapping = file->f_mapping;DEFINE_READAHEAD (ractl, file, ra, mapping, vmf->pgoff);struct file *fpin =NULL ; -vm_flags_t vm_flags = vmf->vma->vm_flags; +struct vm_area_struct *vma = vmf->vma;bool force_thp_readahead = false;unsigned int thp_order =0 ;unsigned short mmap_miss;[ ... ]
mm/filemap.c static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) · line 3422
Quoted 9 lines
mm/filemap.c +1
-1@@ -3414,7 +3416,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)* Fetch two folios so we get the chance to actually * readahead, unless we've been told not to. */ -if (!(vm_flags &VM_RAND_READ )) +if (!vma_test (vma,VMA_RAND_READ_BIT )) ra->size *=2 ; ra->async_size = folio_nr_pages; ra->order = thp_order;[Severity: High]
Can this trigger a use-after-free on vma?Previously,
do_sync_mmap_readahead()cachedvmf->vma->vm_flagsby value in a local variable at entry while the fault lock was held, as introduced by commitdcfa24ba6899("filemap: Cache the value ofvm_flags").In the
force_thp_readaheadblock,maybe_unlock_mmap_for_io()is called before this check:if (force_thp_readahead) { unsigned long folio_nr_pages = 1UL << thp_order; fpin = maybe_unlock_mmap_for_io(vmf, fpin); ractl._index &= ~(folio_nr_pages - 1); ra->size = folio_nr_pages; /* * Fetch two folios so we get the chance to actually * readahead, unless we've been told not to. */ if (!vma_test(vma, VMA_RAND_READ_BIT)) ra->size *= 2;Since
maybe_unlock_mmap_for_io()only pinsvmf->vma->vm_fileand callsrelease_fault_lock(vmf)to dropmmap_lockor the per-VMA lock, isn't vma unprotected against concurrent modification or freeing whenvma_test(vma, VMA_RAND_READ_BIT)dereferencesvma->flags?mm/filemap.c static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) · line 3430
Quoted 9 lines
mm/filemap.c +1
-1@@ -3422,7 +3424,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)return fpin; } -if (vm_flags &VM_EXEC ) { +if (vma_test (vma,VMA_EXEC_BIT )) {/* * Allow arch to request a preferred minimum folio order for * executable memory. This can often be beneficial to [Severity: Low]
Does the newly added outer vma declaration indo_sync_mmap_readahead()cause the existing inner declaration in thisVMA_EXEC_BITblock to shadow it?if (vma_test(vma, VMA_EXEC_BIT)) { ... struct vm_area_struct *vma = vmf->vma; const unsigned long start = vma_start_pgoff(vma); const unsigned long end = vma_end_pgoff(vma);
Quoted 5 lines
Should the inner vma variable be removed now that vma is declared at function scope?
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
It seems these are valid, oops!
Andrew suggested a fix off-list, and I agreed to this as an in-place fixup to avoid respin.
I have also updated the series locally to reflect this change:
----8<----
mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/filemap.c renamed from mm/filemap.c~mm-filemap-convert-fault-and-readahead-logic-to-use-vma_flags_t-fix +0 -0
@@ -3410,6 +3410,7 @@ static struct file *do_sync_mmap_readahe
if (force_thp_readahead) {
unsigned long folio_nr_pages = 1UL << thp_order;+ const bool random_read = vma_test(vma, VMA_RAND_READ_BIT);
fpin = maybe_unlock_mmap_for_io(vmf, fpin); ractl._index &= ~(folio_nr_pages - 1);
@@ -3418,7 +3419,7 @@ static struct file *do_sync_mmap_readahe
* Fetch two folios so we get the chance to actually
* readahead, unless we've been told not to. */
- if (!vma_test(vma, VMA_RAND_READ_BIT))
+ if (!random_read)
ra->size *= 2; ra->async_size = folio_nr_pages; ra->order = thp_order;
@@ -3438,7 +3439,6 @@ static struct file *do_sync_mmap_readahe
* pad that might exist between sections, which would be a waste
* of memory.
*/
- struct vm_area_struct *vma = vmf->vma; const unsigned long start = vma_start_pgoff(vma); const unsigned long end = vma_end_pgoff(vma); unsigned long ra_end;
_
--
Cheers, Lorenzo
Re: [PATCH 02/13] mm/filemap: convert fault and readahead logic to use vma_flags_t
On Fri, Nov 6, 2026 at 7:53 PM Lorenzo Stoakes (ARM) <[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2It seems these are valid, oops!
Andrew suggested a fix off-list, and I agreed to this as an in-place fixup to avoid respin.
I have also updated the series locally to reflect this change:
Seems like a reasonable fix. maybe_unlock_mmap_for_io() could have released mmap_lock, leaving the VMA unprotected. but ra->size *= 2 is still going there no matter if the vma has disappeared
For the original patch combined with the fix,
Quoted 32 lines
----8<----
mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/filemap.c renamed from mm/filemap.c~mm-filemap-convert-fault-and-readahead-logic-to-use-vma_flags_t-fix +2
-2@@ -3410,6 +3410,7 @@ static struct file *do_sync_mmap_readaheif (force_thp_readahead) {unsigned long folio_nr_pages =1UL << thp_order; +const bool random_read =vma_test (vma,VMA_RAND_READ_BIT ); fpin =maybe_unlock_mmap_for_io (vmf, fpin); ractl._index &= ~(folio_nr_pages -1 );@@ -3418,7 +3419,7 @@ static struct file *do_sync_mmap_readahe* Fetch two folios so we get the chance to actually * readahead, unless we've been told not to. */ -if (!vma_test (vma,VMA_RAND_READ_BIT )) +if (!random_read) ra->size *=2 ; ra->async_size = folio_nr_pages; ra->order = thp_order;@@ -3438,7 +3439,6 @@ static struct file *do_sync_mmap_readahe* pad that might exist between sections, which would be a waste * of memory. */ -struct vm_area_struct *vma = vmf->vma;const unsigned long start =vma_start_pgoff (vma);const unsigned long end =vma_end_pgoff (vma);unsigned long ra_end;
Quoted 2 lines
_
Thanks,
Barry
Barry Song
reviewerRe: [PATCH 02/13] mm/filemap: convert fault and readahead logic to use vma_flags_t
Quoted 13 lines · Barry Song
On Fri, Nov 6, 2026 at 7:53 PM Lorenzo Stoakes (ARM) <[email protected]> wrote:
[...]Quoted 9 lines
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2It seems these are valid, oops!
Andrew suggested a fix off-list, and I agreed to this as an in-place fixup to avoid respin.
I have also updated the series locally to reflect this change:
Quoted 9 lines
Seems like a reasonable fix.
maybe_unlock_mmap_for_io()could have releasedmmap_lock, leaving the VMA unprotected. butra->size*= 2 is still going there no matter if the vma has disappearedFor the original patch combined with the fix,
Reviewed-by Barry Song <[email protected]>
BTW, one question is whether mmap-based readahead is still worthwhile if the VMA is actually gone after we release mmap_lock (or the VMA lock). Perhaps we don't need to continue readahead in that case.
However, we don't have a reliable way to know whether the VMA is really gone until the page fault is retried. We release the lock to perform readahead, so in this racy case, readahead might be happening for a VMA that is being removed.
I'm not challenging this patch, just leaving a note to think about later :-)
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 02/13] mm/filemap: convert fault and readahead logic to use vma_flags_t
Quoted 29 lines · Barry Song
Quoted 13 lines · Barry Song
On Fri, Nov 6, 2026 at 7:53 PM Lorenzo Stoakes (ARM) <[email protected]> wrote:
[...]Quoted 9 lines
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2It seems these are valid, oops!
Andrew suggested a fix off-list, and I agreed to this as an in-place fixup to avoid respin.
I have also updated the series locally to reflect this change:
Quoted 9 lines
Seems like a reasonable fix.
maybe_unlock_mmap_for_io()could have releasedmmap_lock, leaving the VMA unprotected. butra->size*= 2 is still going there no matter if the vma has disappearedFor the original patch combined with the fix,
Reviewed-by Barry Song <[email protected]>BTW, one question is whether mmap-based readahead is still worthwhile if the VMA is actually gone after we release
mmap_lock(or the VMA lock). Perhaps we don't need to continue readahead in that case.
Quoted 8 lines
However, we don't have a reliable way to know whether the VMA is really gone until the page fault is retried. We release the lock to perform readahead, so in this racy case, readahead might be happening for a VMA that is being removed.
I'm not challenging this patch, just leaving a note to think about later :-)
I suspect it's one of those 'not worth checking' situations, VMAs can come and go at will at any time and theoretically you can do useless work, as long as that's mostly not the case I think we're OK.
And in general I think these code paths need significant rework before we revisit stuff like this, we always pay a tax for code complexity!
--
Cheers, Lorenzo
Lorenzo Stoakes (ARM)
maintainerPATCH 3/13 mm/rmap: convert remaining VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace the remaining uses of the legacy vm_flags_t flags in the rmap logic with vma_flags_t values.
No functional change intended.
--- mm/rmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
mm/rmap.c +5 -3
@@ -1196,7 +1196,7 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,static bool invalid_mkclean_vma (struct vm_area_struct *vma,void *arg) { -if (vma->vm_flags &VM_SHARED ) +if (vma_test (vma,VMA_SHARED_BIT ))return false;return true;
@@ -1660,7 +1660,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,* VM_DROPPABLE mappings don't swap; instead they're just dropped when * under memory pressure. */ -if (!folio_test_swapbacked (folio) && !(vma->vm_flags &VM_DROPPABLE )) +if (!folio_test_swapbacked (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE ))__folio_set_swapbacked (folio);__folio_set_anon (folio, vma, address, exclusive);
@@ -2094,7 +2095,8 @@ static bool ttu_anon_lazyfree_folio(struct vm_area_struct *vma,*/ smp_rmb (); -if (folio_test_dirty (folio) && !(vma->vm_flags &VM_DROPPABLE )) { +if (folio_test_dirty (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE )) {/* * redirtied either using the page table or a previously * obtained GUP reference.
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Replace the remaining uses of the legacy
vm_flags_tflags in the rmap logic withvma_flags_tvalues.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace the remaining uses of the legacy
vm_flags_tflags in the rmap logic withvma_flags_tvalues.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM.
Re: [PATCH 03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 8 lines · Lorenzo Stoakes (ARM)
Replace the remaining uses of the legacy
vm_flags_tflags in the rmap logic withvma_flags_tvalues.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM,
Quoted 17 lines
mm/rmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)mm/rmap.c +1
-1@@ -1196,7 +1196,7 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,static bool invalid_mkclean_vma (struct vm_area_struct *vma,void *arg) { -if (vma->vm_flags &VM_SHARED ) +if (vma_test (vma,VMA_SHARED_BIT ))return false;return true;
mm/rmap.c void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, · line 1664
Quoted 6 lines
mm/rmap.c +2
-1@@ -1660,7 +1660,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,* VM_DROPPABLE mappings don't swap; instead they're just dropped when * under memory pressure. */ -if (!folio_test_swapbacked (folio) && !(vma->vm_flags &VM_DROPPABLE )) +if (!folio_test_swapbacked (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE ))
Right, VMA_DROPPABLE_BIT is not available on
32-bit architectures, so vma_test() cannot be
used here.
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
Quoted 29 lines · Barry Song
Quoted 8 lines · Lorenzo Stoakes (ARM)
Replace the remaining uses of the legacy
vm_flags_tflags in the rmap logic withvma_flags_tvalues.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM,
Reviewed-by Barry Song <[email protected]>Quoted 15 lines
mm/rmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)mm/rmap.c +1
-1@@ -1196,7 +1196,7 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,static bool invalid_mkclean_vma (struct vm_area_struct *vma,void *arg) { -if (vma->vm_flags &VM_SHARED ) +if (vma_test (vma,VMA_SHARED_BIT ))return false;
Quoted 12 lines
mm/rmap.c void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, · line 1664
Quoted 8 lines
mm/rmap.c +2
-1return true;@@ -1660,7 +1660,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,* VM_DROPPABLE mappings don't swap; instead they're just dropped when * under memory pressure. */ -if (!folio_test_swapbacked (folio) && !(vma->vm_flags &VM_DROPPABLE )) +if (!folio_test_swapbacked (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE ))Right,
VMA_DROPPABLE_BITis not available on
32-bit architectures, sovma_test()cannot be
used here.
Yeah, it's an annoying wrinkle having to differentiate, but is necessary.
Eventually we will have 32-bit kernels move to the same size vma_flags_t as 64-bit, e.g. something like:
- #define NUM_VMA_FLAG_BITS BITS_PER_LONG
+ #define NUM_VMA_FLAG_BITS 8
But that's down the road :)
Which will solve the 'not in 32-bit-kernels' stuff.
But also this form is also used for stuff that's not defined under certain configurations, in which case you get something like:
#ifdef CONFIG_FOOBAR
#define VMA_BLAH mk_vma_flags(VMA_BLAH_BIT)
#else
#define VMA_BLAH EMPTY_VMA_FLAGS
#endif
And then vma_test_single_mask() is necessary too.
An unfortunate outcome of defining per-bit (so no bit value means 'nothing'), and any kind of invalid bit value solution has worse drawbacks.
In the end all this stuff will be useful as it allows us to no longer be constrained by either 32-bit vs 64-bit or in only having 64 possible flags. :)
--
Cheers, Lorenzo
Re: [PATCH 03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace the remaining uses of the legacy
vm_flags_tflags in the rmap logic withvma_flags_tvalues.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Re: [PATCH 03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 4 lines · Lorenzo Stoakes (ARM)
Replace the remaining uses of the legacy
vm_flags_tflags in the rmap logic withvma_flags_tvalues.No functional change intended.
Applied, thanks!
tree: mm/core.git
branch: rmap-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[03/13] mm/rmap: convert remaining VMA flag tests to use vma_flags_t
https://git.kernel.org/mm/core/c/1c78523f
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerPATCH 4/13 mm/migrate: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values in the migration logic.
We retain the READ_ONCE() of vma->vm_flags in remove_migration_pte(), as there is no vma_flags_t equivalent, and arch_make_huge_pte() continues to take legacy flags for the time being.
No functional change intended.
--- mm/migrate.c | 5 +++-- mm/migrate_device.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
mm/migrate.c +3 -2
@@ -310,7 +310,7 @@ static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw,VM_BUG_ON_PAGE (pte_present (old_pte), page);VM_WARN_ON_ONCE_FOLIO (folio_is_device_private (folio), folio); -if (folio_test_mlocked (folio) || (pvmw->vma->vm_flags &VM_LOCKED ) || +if (folio_test_mlocked (folio) ||vma_test (pvmw->vma,VMA_LOCKED_BIT ) ||mm_forbids_zeropage (pvmw->vma->vm_mm))return false;
@@ -2711,7 +2711,8 @@ int migrate_misplaced_folio_prepare(struct folio *folio,* See folio_maybe_mapped_shared() on possible imprecision * when we cannot easily detect if a folio is shared. */ -if ((vma->vm_flags &VM_EXEC ) &&folio_maybe_mapped_shared (folio)) +if (vma_test (vma,VMA_EXEC_BIT ) && +folio_maybe_mapped_shared (folio))return -EACCES ;/*
mm/migrate_device.c +4 -4
@@ -842,7 +842,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,if (folio_is_device_private (folio)) {swp_entry_t swp_entry; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) swp_entry =make_writable_device_private_entry (page_to_pfn (page));else
@@ -855,7 +855,7 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate, goto free_abort; } entry =folio_mk_pmd (folio, vma->vm_page_prot); -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) entry =pmd_mkwrite (pmd_mkdirty (entry), vma); }
@@ -1043,7 +1043,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate,if (folio_is_device_private (folio)) {swp_entry_t swp_entry; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) swp_entry =make_writable_device_private_entry (page_to_pfn (page));else
@@ -1057,7 +1057,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, goto abort; } entry =mk_pte (page, vma->vm_page_prot); -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) entry =pte_mkwrite (pte_mkdirty (entry), vma); }
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 04/13] mm/migrate: convert VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the migration logic.We retain the
READ_ONCE()ofvma->vm_flagsinremove_migration_pte(), as there is novma_flags_tequivalent, andarch_make_huge_pte()continues to take legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH 04/13] mm/migrate: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 11 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the migration logic.We retain the
READ_ONCE()ofvma->vm_flagsinremove_migration_pte(), as there is novma_flags_tequivalent, andarch_make_huge_pte()continues to take legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM.
Re: [PATCH 04/13] mm/migrate: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 4 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the migration logic.
Quoted 8 lines
We retain the
READ_ONCE()ofvma->vm_flagsinremove_migration_pte(), as there is novma_flags_tequivalent, andarch_make_huge_pte()continues to take legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM,
Re: [PATCH 04/13] mm/migrate: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 11 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the migration logic.We retain the
READ_ONCE()ofvma->vm_flagsinremove_migration_pte(), as there is novma_flags_tequivalent, andarch_make_huge_pte()continues to take legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Re: [PATCH 04/13] mm/migrate: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 8 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the migration logic.We retain the
READ_ONCE()ofvma->vm_flagsinremove_migration_pte(), as there is novma_flags_tequivalent, andarch_make_huge_pte()continues to take legacy flags for the time being.[...]
Applied, thanks!
tree: mm/core.git
branch: migrate-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[04/13] mm/migrate: convert VMA flag tests to use vma_flags_t
https://git.kernel.org/mm/core/c/ec215c56
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerPATCH 5/13 mm: convert THP VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values where VMA flags are tested directly in the THP and khugepaged logic.
The thp_vma_allowable_orders() family of functions, hugepage_madvise() and khugepaged_enter_vma() continue to take legacy flags for the time being.
Also update BUG_ON()'s to VM_WARN_ON_ONCE() while here.
No functional change intended.
--- mm/huge_memory.c | 32 ++++++++++++++++---------------- mm/khugepaged.c | 8 +++++--- 2 files changed, 21 insertions(+), 19 deletions(-)
mm/huge_memory.c +16 -16
@@ -1257,7 +1257,7 @@ __setup("thp_anon=", setup_thp_anon);pmd_t maybe_pmd_mkwrite (pmd_t pmd,struct vm_area_struct *vma) { -if (likely (vma->vm_flags &VM_WRITE )) +if (likely (vma_test (vma,VMA_WRITE_BIT ))) pmd =pmd_mkwrite (pmd, vma);return pmd; }
@@ -1517,7 +1517,7 @@ vm_fault_t do_huge_pmd_device_private(struct vm_fault *vmf)*/ gfp_t vma_thp_gfp_mask (struct vm_area_struct *vma) { -const bool vma_madvised = vma && (vma->vm_flags &VM_HUGEPAGE ); +const bool vma_madvised = vma &&vma_test (vma,VMA_HUGEPAGE_BIT );/* Always do synchronous compaction */ if (test_bit (TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG , &transparent_hugepage_flags))
@@ -1716,10 +1716,9 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn,* but we need to be consistent with PTEs and architectures that * can't support a 'special' bit. */ -BUG_ON (!(vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP ))); -BUG_ON ((vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP )) == - (VM_PFNMAP |VM_MIXEDMAP )); -BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma)); +VM_WARN_ON_ONCE (!vma_test_any (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test_all (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test (vma,VMA_PFNMAP_BIT ) &&vma_is_cow_mapping (vma));if (unlikely (is_huge_zero_pfn (pfn)))return VM_FAULT_SIGBUS ;
@@ -1750,7 +1749,7 @@ EXPORT_SYMBOL_GPL(vmf_insert_folio_pmd);#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static pud_t maybe_pud_mkwrite (pud_t pud,struct vm_area_struct *vma) { -if (likely (vma->vm_flags &VM_WRITE )) +if (likely (vma_test (vma,VMA_WRITE_BIT ))) pud =pud_mkwrite (pud);return pud; }
@@ -1827,10 +1826,9 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, unsigned long pfn,* but we need to be consistent with PTEs and architectures that * can't support a 'special' bit. */ -BUG_ON (!(vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP ))); -BUG_ON ((vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP )) == - (VM_PFNMAP |VM_MIXEDMAP )); -BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma)); +VM_WARN_ON_ONCE (!vma_test_any (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test_all (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test (vma,VMA_PFNMAP_BIT ) &&vma_is_cow_mapping (vma));pfnmap_setup_cachemode_pfn (pfn, &pgprot);
@@ -2262,7 +2260,7 @@ static inline bool can_change_pmd_writable(struct vm_area_struct *vma, {struct page *page; -if (WARN_ON_ONCE (!(vma->vm_flags &VM_WRITE ))) +if (WARN_ON_ONCE (!vma_test (vma,VMA_WRITE_BIT )))return false;/* Don't touch entries that are not even readable (NUMA hinting). */
@@ -2277,7 +2275,7 @@ static inline bool can_change_pmd_writable(struct vm_area_struct *vma,if (userfaultfd_huge_pmd_wp (vma, pmd))return false; -if (!(vma->vm_flags &VM_SHARED )) { +if (!vma_test (vma,VMA_SHARED_BIT )) {/* See can_change_pte_writable(). */ page =vm_normal_page_pmd (vma, addr, pmd);return page &&PageAnon (page) &&PageAnonExclusive (page);
@@ -3568,7 +3566,8 @@ static bool __discard_anon_folio_pmd_locked(struct vm_area_struct *vma,if (pmd_dirty (orig_pmd))folio_set_dirty (folio); -if (folio_test_dirty (folio) && !(vma->vm_flags &VM_DROPPABLE )) { +if (folio_test_dirty (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE )) {folio_set_swapbacked (folio);return false; }
@@ -3600,7 +3599,8 @@ static bool __discard_anon_folio_pmd_locked(struct vm_area_struct *vma,*/ if (pmd_dirty (orig_pmd))folio_set_dirty (folio); -if (folio_test_dirty (folio) && !(vma->vm_flags &VM_DROPPABLE )) { +if (folio_test_dirty (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE )) {folio_set_swapbacked (folio);set_pmd_at (mm, addr, pmdp, orig_pmd);return false;
@@ -3614,7 +3614,7 @@ static bool __discard_anon_folio_pmd_locked(struct vm_area_struct *vma,folio_remove_rmap_pmd (folio,pmd_page (orig_pmd), vma);zap_deposited_table (mm, pmdp);add_mm_counter (mm,MM_ANONPAGES , -HPAGE_PMD_NR ); -if (vma->vm_flags &VM_LOCKED ) +if (vma_test (vma,VMA_LOCKED_BIT ))mlock_drain_local ();folio_put (folio);
mm/khugepaged.c +5 -3
@@ -640,7 +640,8 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma,* If the vma has the VM_DROPPABLE flag, the collapse will * preserve the lazyfree property without needing to skip. */ -if (cc->policy.anon_skip_lazyfree && !(vma->vm_flags &VM_DROPPABLE ) && +if (cc->policy.anon_skip_lazyfree && + !vma_test_single_mask (vma,VMA_DROPPABLE ) &&folio_test_lazyfree (folio) && !pte_dirty (pteval)) { result =SCAN_PAGE_LAZYFREE ; goto out;
@@ -1683,7 +1684,8 @@ static enum scan_result collapse_scan_anon(struct vm_area_struct *vma,* If the vma has the VM_DROPPABLE flag, the collapse will * preserve the lazyfree property without needing to skip. */ -if (cc->policy.anon_skip_lazyfree && !(vma->vm_flags &VM_DROPPABLE ) && +if (cc->policy.anon_skip_lazyfree && + !vma_test_single_mask (vma,VMA_DROPPABLE ) &&folio_test_lazyfree (folio) && !pte_dirty (pteval)) { result =SCAN_PAGE_LAZYFREE ; failed_pfn =folio_pfn (folio);
@@ -1948,7 +1950,7 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign* So page lock of folio does not protect from it, so we must not drop * ptl before pgt_pmd is removed, so uffd private needs pml taken now. */ -if (userfaultfd_armed (vma) && !(vma->vm_flags &VM_SHARED )) +if (userfaultfd_armed (vma) && !vma_test (vma,VMA_SHARED_BIT )) pml =pmd_lock (mm, pmd); start_pte =pte_offset_map_rw_nolock (mm, pmd, haddr, &pgt_pmd, &ptl);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in the THP and khugepaged logic.The
thp_vma_allowable_orders()family of functions,hugepage_madvise()andkhugepaged_enter_vma()continue to take legacy flags for the time being.Also update BUG_ON()'s to
VM_WARN_ON_ONCE()while here.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in the THP and khugepaged logic.The
thp_vma_allowable_orders()family of functions,hugepage_madvise()andkhugepaged_enter_vma()continue to take legacy flags for the time being.
Quoted 6 lines
Also update BUG_ON()'s to
VM_WARN_ON_ONCE()while here.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM.
Re: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in the THP and khugepaged logic.The
thp_vma_allowable_orders()family of functions,hugepage_madvise()andkhugepaged_enter_vma()continue to take legacy flags for the time being.
Quoted 6 lines
Also update BUG_ON()'s to
VM_WARN_ON_ONCE()while here.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
LGTM,
Re: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in the THP and khugepaged logic.The
thp_vma_allowable_orders()family of functions,hugepage_madvise()andkhugepaged_enter_vma()continue to take legacy flags for the time being.
Quoted 6 lines
Also update BUG_ON()'s to
VM_WARN_ON_ONCE()while here.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
David Hildenbrand (Arm)
maintainerRe: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 147 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in the THP and khugepaged logic.The
thp_vma_allowable_orders()family of functions,hugepage_madvise()andkhugepaged_enter_vma()continue to take legacy flags for the time being.Also update BUG_ON()'s to
VM_WARN_ON_ONCE()while here.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- mm/huge_memory.c | 32 ++++++++++++++++---------------- mm/khugepaged.c | 8 +++++--- 2 files changed, 21 insertions(+), 19 deletions(-)mm/huge_memory.c +16
-16@@ -1257,7 +1257,7 @@ __setup("thp_anon=", setup_thp_anon);pmd_t maybe_pmd_mkwrite (pmd_t pmd,struct vm_area_struct *vma) { -if (likely (vma->vm_flags &VM_WRITE )) +if (likely (vma_test (vma,VMA_WRITE_BIT ))) pmd =pmd_mkwrite (pmd, vma);return pmd; }@@ -1517,7 +1517,7 @@ vm_fault_t do_huge_pmd_device_private(struct vm_fault *vmf)*/ gfp_t vma_thp_gfp_mask (struct vm_area_struct *vma) { -const bool vma_madvised = vma && (vma->vm_flags &VM_HUGEPAGE ); +const bool vma_madvised = vma &&vma_test (vma,VMA_HUGEPAGE_BIT );/* Always do synchronous compaction */ if (test_bit (TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG , &transparent_hugepage_flags))@@ -1716,10 +1716,9 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn,* but we need to be consistent with PTEs and architectures that * can't support a 'special' bit. */ -BUG_ON (!(vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP ))); -BUG_ON ((vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP )) == - (VM_PFNMAP |VM_MIXEDMAP )); -BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma)); +VM_WARN_ON_ONCE (!vma_test_any (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test_all (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test (vma,VMA_PFNMAP_BIT ) &&vma_is_cow_mapping (vma));if (unlikely (is_huge_zero_pfn (pfn)))return VM_FAULT_SIGBUS ;@@ -1750,7 +1749,7 @@ EXPORT_SYMBOL_GPL(vmf_insert_folio_pmd);#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static pud_t maybe_pud_mkwrite (pud_t pud,struct vm_area_struct *vma) { -if (likely (vma->vm_flags &VM_WRITE )) +if (likely (vma_test (vma,VMA_WRITE_BIT ))) pud =pud_mkwrite (pud);return pud; }@@ -1827,10 +1826,9 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, unsigned long pfn,* but we need to be consistent with PTEs and architectures that * can't support a 'special' bit. */ -BUG_ON (!(vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP ))); -BUG_ON ((vma->vm_flags & (VM_PFNMAP |VM_MIXEDMAP )) == - (VM_PFNMAP |VM_MIXEDMAP )); -BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma)); +VM_WARN_ON_ONCE (!vma_test_any (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test_all (vma,VMA_PFNMAP_BIT ,VMA_MIXEDMAP_BIT )); +VM_WARN_ON_ONCE (vma_test (vma,VMA_PFNMAP_BIT ) &&vma_is_cow_mapping (vma));pfnmap_setup_cachemode_pfn (pfn, &pgprot);@@ -2262,7 +2260,7 @@ static inline bool can_change_pmd_writable(struct vm_area_struct *vma, {struct page *page; -if (WARN_ON_ONCE (!(vma->vm_flags &VM_WRITE ))) +if (WARN_ON_ONCE (!vma_test (vma,VMA_WRITE_BIT )))return false;/* Don't touch entries that are not even readable (NUMA hinting). */ @@ -2277,7 +2275,7 @@ static inline bool can_change_pmd_writable(struct vm_area_struct *vma,if (userfaultfd_huge_pmd_wp (vma, pmd))return false; -if (!(vma->vm_flags &VM_SHARED )) { +if (!vma_test (vma,VMA_SHARED_BIT )) {/* See can_change_pte_writable(). */ page =vm_normal_page_pmd (vma, addr, pmd);return page &&PageAnon (page) &&PageAnonExclusive (page);@@ -3568,7 +3566,8 @@ static bool __discard_anon_folio_pmd_locked(struct vm_area_struct *vma,if (pmd_dirty (orig_pmd))folio_set_dirty (folio); -if (folio_test_dirty (folio) && !(vma->vm_flags &VM_DROPPABLE )) { +if (folio_test_dirty (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE )) {folio_set_swapbacked (folio);return false; }@@ -3600,7 +3599,8 @@ static bool __discard_anon_folio_pmd_locked(struct vm_area_struct *vma,*/ if (pmd_dirty (orig_pmd))folio_set_dirty (folio); -if (folio_test_dirty (folio) && !(vma->vm_flags &VM_DROPPABLE )) { +if (folio_test_dirty (folio) && + !vma_test_single_mask (vma,VMA_DROPPABLE )) {folio_set_swapbacked (folio);set_pmd_at (mm, addr, pmdp, orig_pmd);return false;@@ -3614,7 +3614,7 @@ static bool __discard_anon_folio_pmd_locked(struct vm_area_struct *vma,folio_remove_rmap_pmd (folio,pmd_page (orig_pmd), vma);zap_deposited_table (mm, pmdp);add_mm_counter (mm,MM_ANONPAGES , -HPAGE_PMD_NR ); -if (vma->vm_flags &VM_LOCKED ) +if (vma_test (vma,VMA_LOCKED_BIT ))mlock_drain_local ();folio_put (folio);mm/khugepaged.c +4
-2@@ -640,7 +640,8 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma,* If the vma has the VM_DROPPABLE flag, the collapse will * preserve the lazyfree property without needing to skip. */ -if (cc->policy.anon_skip_lazyfree && !(vma->vm_flags &VM_DROPPABLE ) && +if (cc->policy.anon_skip_lazyfree && + !vma_test_single_mask (vma,VMA_DROPPABLE ) &&folio_test_lazyfree (folio) && !pte_dirty (pteval)) { result =SCAN_PAGE_LAZYFREE ; goto out;@@ -1683,7 +1684,8 @@ static enum scan_result collapse_scan_anon(struct vm_area_struct *vma,* If the vma has the VM_DROPPABLE flag, the collapse will * preserve the lazyfree property without needing to skip. */ -if (cc->policy.anon_skip_lazyfree && !(vma->vm_flags &VM_DROPPABLE ) && +if (cc->policy.anon_skip_lazyfree && + !vma_test_single_mask (vma,VMA_DROPPABLE ) &&folio_test_lazyfree (folio) && !pte_dirty (pteval)) { result =SCAN_PAGE_LAZYFREE ; failed_pfn =folio_pfn (folio);
mm/khugepaged.c static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign · line 1954
Quoted 6 lines
mm/khugepaged.c +1
-1@@ -1948,7 +1950,7 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign* So page lock of folio does not protect from it, so we must not drop * ptl before pgt_pmd is removed, so uffd private needs pml taken now. */ -if (userfaultfd_armed (vma) && !(vma->vm_flags &VM_SHARED )) +if (userfaultfd_armed (vma) && !vma_test (vma,VMA_SHARED_BIT )) pml =pmd_lock (mm, pmd);
A patch in mm/core.git will remove that entirely.
Right now it results in a conflict between mm-new and mm/core.git.
Beat to drop this here entirely. (I can also drop it when applying)
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
Quoted 34 lines · David Hildenbrand (Arm)
Quoted 25 lines
mm/khugepaged.c +4
-2@@ -640,7 +640,8 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma,* If the vma has the VM_DROPPABLE flag, the collapse will * preserve the lazyfree property without needing to skip. */ -if (cc->policy.anon_skip_lazyfree && !(vma->vm_flags &VM_DROPPABLE ) && +if (cc->policy.anon_skip_lazyfree && + !vma_test_single_mask (vma,VMA_DROPPABLE ) &&folio_test_lazyfree (folio) && !pte_dirty (pteval)) { result =SCAN_PAGE_LAZYFREE ; goto out;@@ -1683,7 +1684,8 @@ static enum scan_result collapse_scan_anon(struct vm_area_struct *vma,* If the vma has the VM_DROPPABLE flag, the collapse will * preserve the lazyfree property without needing to skip. */ -if (cc->policy.anon_skip_lazyfree && !(vma->vm_flags &VM_DROPPABLE ) && +if (cc->policy.anon_skip_lazyfree && + !vma_test_single_mask (vma,VMA_DROPPABLE ) &&folio_test_lazyfree (folio) && !pte_dirty (pteval)) { result =SCAN_PAGE_LAZYFREE ; failed_pfn =folio_pfn (folio);mm/khugepaged.c static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign · line 1954
Quoted 6 lines
mm/khugepaged.c +1
-1@@ -1948,7 +1950,7 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign* So page lock of folio does not protect from it, so we must not drop * ptl before pgt_pmd is removed, so uffd private needs pml taken now. */ -if (userfaultfd_armed (vma) && !(vma->vm_flags &VM_SHARED )) +if (userfaultfd_armed (vma) && !vma_test (vma,VMA_SHARED_BIT )) pml =pmd_lock (mm, pmd);A patch in
mm/core.gitwill remove that entirely.
Quoted 3 lines
Right now it results in a conflict between mm-new and
mm/core.git.Beat to drop this here entirely. (I can also drop it when applying)
Sorry I missed this, feel free to apply with this bit removed!
--
Cheers, Lorenzo
Re: [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 9 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in the THP and khugepaged logic.The
thp_vma_allowable_orders()family of functions,hugepage_madvise()andkhugepaged_enter_vma()continue to take legacy flags for the time being.Also update BUG_ON()'s to
VM_WARN_ON_ONCE()while here.[...]
Applied, thanks!
tree: mm/core.git
branch: thp-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[05/13] mm: convert THP VMA flag tests to use vma_flags_t
https://git.kernel.org/mm/core/c/cb15e2fc
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerPATCH 6/13 mm/ksm: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values where KSM tests VMA flags directly.
The ksm_madvise() interface continues to take legacy flags for the time being.
No functional change intended.
--- mm/ksm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
mm/ksm.c +7 -6
@@ -779,7 +779,7 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,if (ksm_test_exit (mm))return NULL ; vma =vma_lookup (mm, addr); -if (!vma || !(vma->vm_flags &VM_MERGEABLE ) || !vma_has_anon_rmap (vma)) +if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || !vma_has_anon_rmap (vma))return NULL ;return vma; }
@@ -1243,7 +1243,8 @@ static int unmerge_and_remove_all_rmap_items(void) goto mm_exiting;for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_MERGEABLE ) || !vma_has_anon_rmap (vma)) +if (!vma_test (vma,VMA_MERGEABLE_BIT ) || + !vma_has_anon_rmap (vma))continue ; err =break_ksm (vma, vma->vm_start, vma->vm_end, false);if (err)
@@ -2698,7 +2699,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) goto no_vmas;for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_MERGEABLE )) +if (!vma_test (vma,VMA_MERGEABLE_BIT ))continue ;if (ksm_scan.address < vma->vm_start) ksm_scan.address = vma->vm_start;
@@ -2890,7 +2891,7 @@ static int __ksm_del_vma(struct vm_area_struct *vma) {int err; -if (!(vma->vm_flags &VM_MERGEABLE )) +if (!vma_test (vma,VMA_MERGEABLE_BIT ))return 0 ;if (vma_has_anon_rmap (vma)) {
@@ -3027,7 +3028,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,switch (advice) {case MADV_MERGEABLE : -if (vma->vm_flags &VM_MERGEABLE ) +if (vma_test (vma,VMA_MERGEABLE_BIT ))return 0 ;if (!vma_ksm_compatible (vma))return 0 ;
@@ -3484,7 +3485,7 @@ bool ksm_process_mergeable(struct mm_struct *mm)mmap_assert_locked (mm);VMA_ITERATOR (vmi, mm,0 );for_each_vma (vmi, vma) -if (vma->vm_flags &VM_MERGEABLE ) +if (vma_test (vma,VMA_MERGEABLE_BIT ))return true;return false;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 06/13] mm/ksm: convert VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where KSM tests VMA flags directly.The
ksm_madvise()interface continues to take legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH 06/13] mm/ksm: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 10 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where KSM tests VMA flags directly.The
ksm_madvise()interface continues to take legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Re: [PATCH 06/13] mm/ksm: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where KSM tests VMA flags directly.The
ksm_madvise()interface continues to take legacy flags for the time being.
Quoted 6 lines
No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- mm/ksm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
LGTM! Thanks!
Quoted 64 lines
mm/ksm.c +7
-6@@ -779,7 +779,7 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,if (ksm_test_exit (mm))return NULL ; vma =vma_lookup (mm, addr); -if (!vma || !(vma->vm_flags &VM_MERGEABLE ) || !vma_has_anon_rmap (vma)) +if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || !vma_has_anon_rmap (vma))return NULL ;return vma; }@@ -1243,7 +1243,8 @@ static int unmerge_and_remove_all_rmap_items(void) goto mm_exiting;for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_MERGEABLE ) || !vma_has_anon_rmap (vma)) +if (!vma_test (vma,VMA_MERGEABLE_BIT ) || + !vma_has_anon_rmap (vma))continue ; err =break_ksm (vma, vma->vm_start, vma->vm_end, false);if (err)@@ -2698,7 +2699,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) goto no_vmas;for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_MERGEABLE )) +if (!vma_test (vma,VMA_MERGEABLE_BIT ))continue ;if (ksm_scan.address < vma->vm_start) ksm_scan.address = vma->vm_start;@@ -2890,7 +2891,7 @@ static int __ksm_del_vma(struct vm_area_struct *vma) {int err; -if (!(vma->vm_flags &VM_MERGEABLE )) +if (!vma_test (vma,VMA_MERGEABLE_BIT ))return 0 ;if (vma_has_anon_rmap (vma)) {@@ -3027,7 +3028,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,switch (advice) {case MADV_MERGEABLE : -if (vma->vm_flags &VM_MERGEABLE ) +if (vma_test (vma,VMA_MERGEABLE_BIT ))return 0 ;if (!vma_ksm_compatible (vma))return 0 ;@@ -3484,7 +3485,7 @@ bool ksm_process_mergeable(struct mm_struct *mm)mmap_assert_locked (mm);VMA_ITERATOR (vmi, mm,0 );for_each_vma (vmi, vma) -if (vma->vm_flags &VM_MERGEABLE ) +if (vma_test (vma,VMA_MERGEABLE_BIT ))return true;return false;Signature · 2 lines
-- 2.56.0
Re: [PATCH 06/13] mm/ksm: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 9 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where KSM tests VMA flags directly.The
ksm_madvise()interface continues to take legacy flags for the time being.No functional change intended.
[...]
Applied, thanks!
tree: mm/core.git
branch: ksm-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even though the patches have already been applied. If possible, patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. Further, this is not a guarantee that the patches will go upstream. If in doubt, please check the listed branch.
[06/13] mm/ksm: convert VMA flag tests to use vma_flags_t
https://git.kernel.org/mm/core/c/4ec4530e
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerPATCH 7/13 mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values throughout the madvise logic.
In order to do so, update ksm_madvise() and hugepage_madvise() to take a vma_flags_t pointer, and update their other callers in mremap and the powerpc KVM ultravisor code accordingly.
In the latter case we replace vm_flags_reset() with vma_overwrite_flags(). The VMA is write locked at this point, so the atomic flags preserved by vma_overwrite_flags() cannot differ from those copied, and the behaviour is unchanged.
No functional change intended.
--- arch/powerpc/kvm/book3s_hv_uvmem.c | 10 ++++---- include/linux/huge_mm.h | 4 ++-- include/linux/ksm.h | 4 ++-- mm/khugepaged.c | 10 ++++---- mm/ksm.c | 11 +++++---- mm/madvise.c | 47 ++++++++++++++++++++------------------ mm/mremap.c | 2 +- 7 files changed, 46 insertions(+), 42 deletions(-)
arch/powerpc/kvm/book3s_hv_uvmem.c +5 -5
@@ -393,7 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm, {unsigned long gfn = memslot->base_gfn;unsigned long end, start =gfn_to_hva (kvm, gfn); -vm_flags_t vm_flags; +vma_flags_t vma_flags;int ret =0 ;struct vm_area_struct *vma;int merge_flag = (merge) ?MADV_MERGEABLE :MADV_UNMERGEABLE ;
@@ -411,15 +411,15 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,break ; }vma_start_write (vma); -/* Copy vm_flags to avoid partial modifications in ksm_madvise */ - vm_flags = vma->vm_flags; +/* Copy flags to avoid partial modifications in ksm_madvise */ + vma_flags = vma->flags; ret =ksm_madvise (vma, vma->vm_start, vma->vm_end, - merge_flag, &vm_flags); + merge_flag, &vma_flags);if (ret) { ret =H_STATE ;break ; } -vm_flags_reset (vma, vm_flags); +vma_overwrite_flags (vma, vma_flags); start = vma->vm_end; }while (end > vma->vm_end);
include/linux/huge_mm.h +2 -2
@@ -508,7 +508,7 @@ change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma,__split_huge_pud (__vma, __pud, __address); \ }while (0 ) -int hugepage_madvise(struct vm_area_struct *vma, vm_flags_t *vm_flags, +int hugepage_madvise(struct vm_area_struct *vma, vma_flags_t *vma_flags, int advice);int madvise_collapse (struct vm_area_struct *vma,unsigned long start,unsigned long end,bool *lock_dropped);
@@ -710,7 +710,7 @@ static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma, do { } while (0)static inline int hugepage_madvise (struct vm_area_struct *vma, -vm_flags_t *vm_flags,int advice) +vma_flags_t *vma_flags,int advice) {return -EINVAL ; }
include/linux/ksm.h +2 -2
@@ -16,7 +16,7 @@#ifdef CONFIG_KSM int ksm_madvise (struct vm_area_struct *vma,unsigned long start, -unsigned long end,int advice,vm_flags_t *vm_flags); +unsigned long end,int advice,vma_flags_t *vma_flags);vma_flags_t ksm_vma_flags (struct mm_struct *mm,const struct file *file,vma_flags_t vma_flags);int ksm_enable_merge_any (struct mm_struct *mm);
@@ -139,7 +139,7 @@ static inline void collect_procs_ksm(const struct folio *folio,#ifdef CONFIG_MMU static inline int ksm_madvise (struct vm_area_struct *vma,unsigned long start, -unsigned long end,int advice,vm_flags_t *vm_flags) +unsigned long end,int advice,vma_flags_t *vma_flags) {return 0 ; }
mm/khugepaged.c +5 -5
@@ -363,16 +363,16 @@ static unsigned int collapse_max_ptes_swap(struct collapse_control *cc, }int hugepage_madvise (struct vm_area_struct *vma, -vm_flags_t *vm_flags,int advice) +vma_flags_t *vma_flags,int advice) {switch (advice) {case MADV_HUGEPAGE : - *vm_flags &= ~VM_NOHUGEPAGE ; - *vm_flags |=VM_HUGEPAGE ; +vma_flags_clear (vma_flags,VMA_NOHUGEPAGE_BIT ); +vma_flags_set (vma_flags,VMA_HUGEPAGE_BIT );break ;case MADV_NOHUGEPAGE : - *vm_flags &= ~VM_HUGEPAGE ; - *vm_flags |=VM_NOHUGEPAGE ; +vma_flags_clear (vma_flags,VMA_HUGEPAGE_BIT ); +vma_flags_set (vma_flags,VMA_NOHUGEPAGE_BIT );/* * Setting VM_NOHUGEPAGE will prevent khugepaged from scanning * this vma even if we leave the mm registered in khugepaged if
mm/ksm.c +6 -5
@@ -779,7 +779,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,if (ksm_test_exit (mm))return NULL ; vma =vma_lookup (mm, addr); -if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || !vma_has_anon_rmap (vma)) +if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || + !vma_has_anon_rmap (vma))return NULL ;return vma; }
@@ -3021,7 +3022,7 @@ int ksm_disable(struct mm_struct *mm) }int ksm_madvise (struct vm_area_struct *vma,unsigned long start, -unsigned long end,int advice,vm_flags_t *vm_flags) +unsigned long end,int advice,vma_flags_t *vma_flags) {struct mm_struct *mm = vma->vm_mm;int err;
@@ -3039,11 +3040,11 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,return err; } - *vm_flags |=VM_MERGEABLE ; +vma_flags_set (vma_flags,VMA_MERGEABLE_BIT );break ;case MADV_UNMERGEABLE : -if (!(*vm_flags &VM_MERGEABLE )) +if (!vma_flags_test (vma_flags,VMA_MERGEABLE_BIT ))return 0 ;/* just ignore the advice */ if (vma_has_anon_rmap (vma)) {
@@ -3052,7 +3053,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,return err; } - *vm_flags &= ~VM_MERGEABLE ; +vma_flags_clear (vma_flags,VMA_MERGEABLE_BIT );break ; }
mm/madvise.c +25 -22
127 lines not on this page · raw message
mm/mremap.c +1 -1
@@ -1133,7 +1133,7 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)struct vm_area_struct *vma = vrm->vma;unsigned long old_addr = vrm->addr;unsigned long old_len = vrm->old_len; -vm_flags_t dummy = vma->vm_flags; +vma_flags_t dummy = vma->flags;const bool split_before = vma->vm_start != old_addr;const bool split_after = vma->vm_end != old_addr + old_len;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 07/13] mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the madvise logic.In order to do so, update
ksm_madvise()andhugepage_madvise()to take avma_flags_tpointer, and update their other callers in mremap and the powerpc KVM ultravisor code accordingly.
Quoted 8 lines
In the latter case we replace
vm_flags_reset()withvma_overwrite_flags(). The VMA is write locked at this point, so the atomic flags preserved byvma_overwrite_flags()cannot differ from those copied, and the behaviour is unchanged.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH 07/13] mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 12 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the madvise logic.In order to do so, update
ksm_madvise()andhugepage_madvise()to take avma_flags_tpointer, and update their other callers in mremap and the powerpc KVM ultravisor code accordingly.In the latter case we replace
vm_flags_reset()withvma_overwrite_flags(). The VMA is write locked at this point, so the atomic flags preserved byvma_overwrite_flags()cannot differ from those copied, and the behaviour is unchanged.
Quoted 4 lines
No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Re: [PATCH 07/13] mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 39 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues throughout the madvise logic.In order to do so, update
ksm_madvise()andhugepage_madvise()to take avma_flags_tpointer, and update their other callers in mremap and the powerpc KVM ultravisor code accordingly.In the latter case we replace
vm_flags_reset()withvma_overwrite_flags(). The VMA is write locked at this point, so the atomic flags preserved byvma_overwrite_flags()cannot differ from those copied, and the behaviour is unchanged.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- arch/powerpc/kvm/book3s_hv_uvmem.c | 10 ++++---- include/linux/huge_mm.h | 4 ++-- include/linux/ksm.h | 4 ++-- mm/khugepaged.c | 10 ++++---- mm/ksm.c | 11 +++++---- mm/madvise.c | 47 ++++++++++++++++++++------------------ mm/mremap.c | 2 +- 7 files changed, 46 insertions(+), 42 deletions(-)arch/powerpc/kvm/book3s_hv_uvmem.c +1
-1@@ -393,7 +393,7 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm, {unsigned long gfn = memslot->base_gfn;unsigned long end, start =gfn_to_hva (kvm, gfn); -vm_flags_t vm_flags; +vma_flags_t vma_flags;int ret =0 ;struct vm_area_struct *vma;int merge_flag = (merge) ?MADV_MERGEABLE :MADV_UNMERGEABLE ;
arch/powerpc/kvm/book3s_hv_uvmem.c static int kvmppc_memslot_page_merge(struct kvm *kvm, · line 417
Quoted 10 lines
arch/powerpc/kvm/book3s_hv_uvmem.c +3
-3@@ -411,15 +411,15 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,break ; }vma_start_write (vma); -/* Copy vm_flags to avoid partial modifications in ksm_madvise */ - vm_flags = vma->vm_flags; +/* Copy flags to avoid partial modifications in ksm_madvise */ + vma_flags = vma->flags; ret =ksm_madvise (vma, vma->vm_start, vma->vm_end, - merge_flag, &vm_flags); + merge_flag, &vma_flags);
Unusual indentation (before your change).
Quoted 23 lines
arch/powerpc/kvm/book3s_hv_uvmem.c +1
-1if (ret) { ret =H_STATE ;break ; } -vm_flags_reset (vma, vm_flags); +vma_overwrite_flags (vma, vma_flags); start = vma->vm_end; }while (end > vma->vm_end);include/linux/huge_mm.h +1
-1@@ -508,7 +508,7 @@ change_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma,__split_huge_pud (__vma, __pud, __address); \ }while (0 ) -int hugepage_madvise(struct vm_area_struct *vma, vm_flags_t *vm_flags, +int hugepage_madvise(struct vm_area_struct *vma, vma_flags_t *vma_flags, int advice);int madvise_collapse (struct vm_area_struct *vma,unsigned long start,unsigned long end,bool *lock_dropped);
include/linux/huge_mm.h static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma, · line 713
Quoted 5 lines
include/linux/huge_mm.h +1
-1@@ -710,7 +710,7 @@ static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma, do { } while (0)static inline int hugepage_madvise (struct vm_area_struct *vma, -vm_flags_t *vm_flags,int advice) +vma_flags_t *vma_flags,int advice)
Could do two tabs while at it.
Quoted 125 lines
include/linux/huge_mm.h +0
-0{return -EINVAL ; }include/linux/ksm.h +2
-2@@ -16,7 +16,7 @@#ifdef CONFIG_KSM int ksm_madvise (struct vm_area_struct *vma,unsigned long start, -unsigned long end,int advice,vm_flags_t *vm_flags); +unsigned long end,int advice,vma_flags_t *vma_flags);vma_flags_t ksm_vma_flags (struct mm_struct *mm,const struct file *file,vma_flags_t vma_flags);int ksm_enable_merge_any (struct mm_struct *mm);@@ -139,7 +139,7 @@ static inline void collect_procs_ksm(const struct folio *folio,#ifdef CONFIG_MMU static inline int ksm_madvise (struct vm_area_struct *vma,unsigned long start, -unsigned long end,int advice,vm_flags_t *vm_flags) +unsigned long end,int advice,vma_flags_t *vma_flags) {return 0 ; }mm/khugepaged.c +5
-5@@ -363,16 +363,16 @@ static unsigned int collapse_max_ptes_swap(struct collapse_control *cc, }int hugepage_madvise (struct vm_area_struct *vma, -vm_flags_t *vm_flags,int advice) +vma_flags_t *vma_flags,int advice) {switch (advice) {case MADV_HUGEPAGE : - *vm_flags &= ~VM_NOHUGEPAGE ; - *vm_flags |=VM_HUGEPAGE ; +vma_flags_clear (vma_flags,VMA_NOHUGEPAGE_BIT ); +vma_flags_set (vma_flags,VMA_HUGEPAGE_BIT );break ;case MADV_NOHUGEPAGE : - *vm_flags &= ~VM_HUGEPAGE ; - *vm_flags |=VM_NOHUGEPAGE ; +vma_flags_clear (vma_flags,VMA_HUGEPAGE_BIT ); +vma_flags_set (vma_flags,VMA_NOHUGEPAGE_BIT );/* * Setting VM_NOHUGEPAGE will prevent khugepaged from scanning * this vma even if we leave the mm registered in khugepaged if mm/ksm.c +6
-5@@ -779,7 +779,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,if (ksm_test_exit (mm))return NULL ; vma =vma_lookup (mm, addr); -if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || !vma_has_anon_rmap (vma)) +if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || + !vma_has_anon_rmap (vma))return NULL ;return vma; }@@ -3021,7 +3022,7 @@ int ksm_disable(struct mm_struct *mm) }int ksm_madvise (struct vm_area_struct *vma,unsigned long start, -unsigned long end,int advice,vm_flags_t *vm_flags) +unsigned long end,int advice,vma_flags_t *vma_flags) {struct mm_struct *mm = vma->vm_mm;int err;@@ -3039,11 +3040,11 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,return err; } - *vm_flags |=VM_MERGEABLE ; +vma_flags_set (vma_flags,VMA_MERGEABLE_BIT );break ;case MADV_UNMERGEABLE : -if (!(*vm_flags &VM_MERGEABLE )) +if (!vma_flags_test (vma_flags,VMA_MERGEABLE_BIT ))return 0 ;/* just ignore the advice */ if (vma_has_anon_rmap (vma)) {@@ -3052,7 +3053,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,return err; } - *vm_flags &= ~VM_MERGEABLE ; +vma_flags_clear (vma_flags,VMA_MERGEABLE_BIT );break ; }mm/madvise.c +3
-3@@ -148,11 +148,10 @@ static int replace_anon_vma_name(struct vm_area_struct *vma,* Update the vm_flags or anon_name on region of a vma, splitting it or merging * it as necessary. Must be called with mmap_lock held for writing. */ -static int madvise_update_vma (vm_flags_t new_flags, +static int madvise_update_vma (vma_flags_t new_vma_flags,struct madvise_behavior *madv_behavior) {struct vm_area_struct *vma = madv_behavior->vma; -vma_flags_t new_vma_flags =legacy_to_vma_flags (new_flags);struct madvise_behavior_range *range = &madv_behavior->range;struct anon_vma_name *anon_name = madv_behavior->anon_name;bool set_new_anon_name = madv_behavior->behavior == __MADV_SET_ANON_VMA_NAME;@@ -601,7 +600,8 @@ static void madvise_cold_page_range(struct mmu_gather *tlb,static inline bool can_madv_lru_vma (struct vm_area_struct *vma) { -return !(vma->vm_flags & (VM_LOCKED |VM_PFNMAP |VM_HUGETLB )); +return !vma_test_any (vma,VMA_LOCKED_BIT ,VMA_PFNMAP_BIT , +VMA_HUGETLB_BIT ); }static long madvise_cold (struct madvise_behavior *madv_behavior)
mm/madvise.c static long madvise_pageout(struct madvise_behavior *madv_behavior) · line 653
Quoted 5 lines
mm/madvise.c +1
-1@@ -650,7 +650,7 @@ static long madvise_pageout(struct madvise_behavior *madv_behavior)* further to pageout dirty anon pages. */ if (!vma_is_anonymous (vma) && (!can_do_file_pageout (vma) && - (vma->vm_flags &VM_MAYSHARE ))) +vma_test (vma,VMA_MAYSHARE_BIT )))
Another weird indentation. Likely because the spare set of () that are not necessary?
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerRe: [PATCH 07/13] mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)mm/ksm.c static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm, · line 783
Quoted 9 lines
mm/ksm.c +2
-1@@ -779,7 +779,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,if (ksm_test_exit (mm))return NULL ; vma =vma_lookup (mm, addr); -if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || !vma_has_anon_rmap (vma)) +if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || + !vma_has_anon_rmap (vma))
This change should be dropped form this patch IIUC.
It would have to go into the previous one (that I applied) but it's not actually required.
Unless I am missing something :)
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 07/13] mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
Quoted 12 lines · David Hildenbrand (Arm)
mm/ksm.c static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm, · line 783
Quoted 9 lines
mm/ksm.c +2
-1@@ -779,7 +779,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,if (ksm_test_exit (mm))return NULL ; vma =vma_lookup (mm, addr); -if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || !vma_has_anon_rmap (vma)) +if (!vma || !vma_test (vma,VMA_MERGEABLE_BIT ) || + !vma_has_anon_rmap (vma))This change should be dropped form this patch IIUC.
Quoted 4 lines
It would have to go into the previous one (that I applied) but it's not actually required.
Unless I am missing something :)
Yup I'm not bothered by whitespace-only changes :P Feel free to drop this bit!
--
Cheers, Lorenzo
Lorenzo Stoakes (ARM)
maintainerPATCH 8/13 mm: convert miscellaneous VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values in the remaining straightforward VMA flag tests scattered throughout core mm, HMM (and its test module), DAMON and the OOM reaper.
No functional change intended.
--- include/linux/mm_inline.h | 2 +- lib/test_hmm.c | 4 ++-- mm/damon/vaddr.c | 2 +- mm/hmm.c | 6 +++--- mm/internal.h | 2 +- mm/mempolicy.c | 4 ++-- mm/mmap_lock.c | 4 ++-- mm/msync.c | 4 ++-- mm/oom_kill.c | 4 ++-- mm/pagewalk.c | 2 +- mm/vma.h | 4 ++-- 11 files changed, 19 insertions(+), 19 deletions(-)
include/linux/mm_inline.h +1 -1
@@ -657,7 +657,7 @@ static inline pte_marker copy_pte_marker(static inline bool vma_has_recency (const struct vm_area_struct *vma) { -if (vma->vm_flags & (VM_SEQ_READ |VM_RAND_READ )) +if (vma_test_any (vma,VMA_SEQ_READ_BIT ,VMA_RAND_READ_BIT ))return false;if (vma->vm_file && (vma->vm_file->f_mode &FMODE_NOREUSE ))
lib/test_hmm.c +2 -2
@@ -1248,7 +1248,7 @@ static int dmirror_migrate_to_system(struct dmirror *dmirror,mmap_read_lock (mm);for (addr = start; addr < end; addr = next) { vma =vma_lookup (mm, addr); -if (!vma || !(vma->vm_flags &VM_READ )) { +if (!vma || !vma_test (vma,VMA_READ_BIT )) { ret = -EINVAL ; goto out; }
@@ -1320,7 +1320,7 @@ static int dmirror_migrate_to_device(struct dmirror *dmirror,mmap_read_lock (mm);for (addr = start; addr < end; addr = next) { vma =vma_lookup (mm, addr); -if (!vma || !(vma->vm_flags &VM_READ )) { +if (!vma || !vma_test (vma,VMA_READ_BIT )) { ret = -EINVAL ; goto out; }
mm/damon/vaddr.c +1 -1
@@ -240,7 +240,7 @@ static void damon_va_walk_page_range(struct mm_struct *mm, unsigned long start, goto lock_mmap; } -if (!(vma->vm_flags &VM_PFNMAP )) { +if (!vma_test (vma,VMA_PFNMAP_BIT )) { ops->walk_lock =PGWALK_VMA_RDLOCK_VERIFY ;walk_page_range_vma (vma, start, end, ops, private); }
mm/hmm.c +3 -3
@@ -595,8 +595,8 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,struct hmm_range *range = hmm_vma_walk->range;struct vm_area_struct *vma = walk->vma; -if (!(vma->vm_flags & (VM_IO |VM_PFNMAP )) && - vma->vm_flags &VM_READ ) +if (!vma_test_any (vma,VMA_IO_BIT ,VMA_PFNMAP_BIT ) && +vma_test (vma,VMA_READ_BIT ))return 0 ;/*
@@ -659,7 +659,7 @@ static int hmm_do_fault(struct mm_struct *mm,return -EFAULT ;if (required_fault &HMM_NEED_WRITE_FAULT ) { -if (!(vma->vm_flags &VM_WRITE )) +if (!vma_test (vma,VMA_WRITE_BIT ))return -EPERM ; fault_flags |=FAULT_FLAG_WRITE ; }
mm/internal.h +1 -1
@@ -1249,7 +1249,7 @@ size_t splice_folio_into_pipe(struct pipe_inode_info *pipe,static inline bool vma_is_single_threaded_private (struct vm_area_struct *vma) { -if (vma->vm_flags &VM_SHARED ) +if (vma_test (vma,VMA_SHARED_BIT ))return false;return atomic_read (&vma->vm_mm->mm_users) ==1 ;
mm/mempolicy.c +2 -2
@@ -2015,7 +2015,7 @@ SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,bool vma_migratable (struct vm_area_struct *vma) { -if (vma->vm_flags & (VM_IO |VM_PFNMAP )) +if (vma_test_any (vma,VMA_IO_BIT ,VMA_PFNMAP_BIT ))return false;/*
@@ -2565,7 +2565,7 @@ struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order, struct vm_area_structpgoff_t ilx;struct folio *folio; -if (vma->vm_flags &VM_DROPPABLE ) +if (vma_test_single_mask (vma,VMA_DROPPABLE )) gfp |= __GFP_NOWARN; pol =get_vma_policy (vma, addr, order, &ilx);
mm/mmap_lock.c +2 -2
@@ -636,7 +636,7 @@ struct vm_area_struct *lock_mm_and_find_vma(struct mm_struct *mm,* Well, dang. We might still be successful, but only * if we can extend a vma to do so. */ -if (!vma || !(vma->vm_flags &VM_GROWSDOWN )) { +if (!vma || !vma_test (vma,VMA_GROWSDOWN_BIT )) {mmap_read_unlock (mm);return NULL ; }
@@ -659,7 +659,7 @@ struct vm_area_struct *lock_mm_and_find_vma(struct mm_struct *mm, goto fail;if (vma->vm_start <= addr) goto success; -if (!(vma->vm_flags &VM_GROWSDOWN )) +if (!vma_test (vma,VMA_GROWSDOWN_BIT )) goto fail; }
mm/msync.c +2 -2
@@ -81,7 +81,7 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) }/* Here vma->vm_start <= start < vma->vm_end. */ if ((flags &MS_INVALIDATE ) && - (vma->vm_flags &VM_LOCKED )) { +vma_test (vma,VMA_LOCKED_BIT )) { error = -EBUSY ; goto out_unlock; }
@@ -90,7 +90,7 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) fend = fstart + (min (end, vma->vm_end) - start) -1 ; start = vma->vm_end;if ((flags &MS_SYNC ) && file && - (vma->vm_flags &VM_SHARED )) { +vma_test (vma,VMA_SHARED_BIT )) {get_file (file);mmap_read_unlock (mm); error =vfs_fsync_range (file, fstart, fend,1 );
mm/oom_kill.c +2 -2
@@ -524,7 +524,7 @@ static bool __oom_reap_task_mm(struct mm_struct *mm)* of the address space. */ mas_for_each_rev (&mas, vma,0 ) { -if (vma->vm_flags & (VM_HUGETLB |VM_PFNMAP )) +if (vma_test_any (vma,VMA_HUGETLB_BIT ,VMA_PFNMAP_BIT ))continue ;/*
@@ -537,7 +537,7 @@ static bool __oom_reap_task_mm(struct mm_struct *mm)* we do not want to block exit_mmap by keeping mm ref * count elevated without a good reason. */ -if (vma_is_anonymous (vma) || !(vma->vm_flags &VM_SHARED )) { +if (vma_is_anonymous (vma) || !vma_test (vma,VMA_SHARED_BIT )) {if (zap_vma_for_reaping (vma)) ret = false; }
mm/pagewalk.c +1 -1
@@ -393,7 +393,7 @@ static int walk_page_test(unsigned long start, unsigned long end,* define their ->pte_hole() callbacks, so let's delegate them to handle * vma(VM_PFNMAP). */ -if (vma->vm_flags &VM_PFNMAP ) { +if (vma_test (vma,VMA_PFNMAP_BIT )) {int err =1 ;if (ops->pte_hole) err = ops->pte_hole (start, end,-1 , walk);
mm/vma.h +2 -2
@@ -597,9 +597,9 @@ static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma* private mappings, that's always the case when we have write * permissions as we properly have to handle COW. */ -if (vma->vm_flags &VM_SHARED ) +if (vma_test (vma,VMA_SHARED_BIT ))return vma_wants_writenotify (vma, vma->vm_page_prot); -return !!(vma->vm_flags &VM_WRITE ); +return vma_test (vma,VMA_WRITE_BIT ); }#ifdef CONFIG_MMU
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 08/13] mm: convert miscellaneous VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the remaining straightforward VMA flag tests scattered throughout core mm, HMM (and its test module), DAMON and the OOM reaper.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH 08/13] mm: convert miscellaneous VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 5 lines · On Thu, 05 Nov 2026 21:30:59 +0000 "Lorenzo Stoakes (ARM)" <[email protected]>…
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the remaining straightforward VMA flag tests scattered throughout core mm, HMM (and its test module), DAMON and the OOM reaper.No functional change intended.
Thank you for this nice cleanup!
Quoted 2 lines
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
[...]
mm/damon/vaddr.c static void damon_va_walk_page_range(struct mm_struct *mm, unsigned long start, · line 246
Quoted 11 lines
mm/damon/vaddr.c +1
-1@@ -240,7 +240,7 @@ static void damon_va_walk_page_range(struct mm_struct *mm, unsigned long start, goto lock_mmap; } -if (!(vma->vm_flags &VM_PFNMAP )) { +if (!vma_test (vma,VMA_PFNMAP_BIT )) { ops->walk_lock =PGWALK_VMA_RDLOCK_VERIFY ;walk_page_range_vma (vma, start, end, ops, private); }
For DAMON part,
Thanks,
SJ
[...]
Re: [PATCH 08/13] mm: convert miscellaneous VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 8 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the remaining straightforward VMA flag tests scattered throughout core mm, HMM (and its test module), DAMON and the OOM reaper.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Re: [PATCH 08/13] mm: convert miscellaneous VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 8 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the remaining straightforward VMA flag tests scattered throughout core mm, HMM (and its test module), DAMON and the OOM reaper.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerPATCH 9/13 fs/proc/task_mmu: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values where VMA flags are tested directly in /proc/$pid/[s]maps, pagemap, clear_refs and PROCMAP_QUERY.
In replacing vm_flags_clear() (which takes the VMA write lock) with vma_clear_flags() (which does not) in clear_refs_write(), we explicitly write lock the VMA. The mmap write lock is already held at this point.
The show_vma_header_prefix() and show_smap_vma_flags() output functions and the thp_vma_allowable_orders() call continue to use legacy flags for the time being.
No functional change intended.
--- fs/proc/task_mmu.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-)
fs/proc/task_mmu.c +22 -21
@@ -569,18 +569,18 @@ static struct vm_area_struct *query_matching_vma(struct proc_maps_locking_ctx *l/* VMA permissions should satisfy query flags */ if (flags &PROCMAP_QUERY_VMA_FLAGS ) { -u32 perm =0 ; +vma_flags_t perm =EMPTY_VMA_FLAGS ;if (flags &PROCMAP_QUERY_VMA_READABLE ) - perm |=VM_READ ; +vma_flags_set (&perm,VMA_READ_BIT );if (flags &PROCMAP_QUERY_VMA_WRITABLE ) - perm |=VM_WRITE ; +vma_flags_set (&perm,VMA_WRITE_BIT );if (flags &PROCMAP_QUERY_VMA_EXECUTABLE ) - perm |=VM_EXEC ; +vma_flags_set (&perm,VMA_EXEC_BIT );if (flags &PROCMAP_QUERY_VMA_SHARED ) - perm |=VM_MAYSHARE ; +vma_flags_set (&perm,VMA_MAYSHARE_BIT ); -if ((vma->vm_flags & perm) != perm) +if (!vma_test_all_mask (vma, perm)) goto skip_vma; }
@@ -647,13 +647,13 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg) karg.vma_end = vma->vm_end; karg.vma_flags =0 ; -if (vma->vm_flags &VM_READ ) +if (vma_test (vma,VMA_READ_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_READABLE ; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_WRITABLE ; -if (vma->vm_flags &VM_EXEC ) +if (vma_test (vma,VMA_EXEC_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_EXECUTABLE ; -if (vma->vm_flags &VM_MAYSHARE ) +if (vma_test (vma,VMA_MAYSHARE_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_SHARED ; karg.vma_page_size =vma_kernel_pagesize (vma);
@@ -970,7 +970,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, {struct mem_size_stats *mss = walk->private;struct vm_area_struct *vma = walk->vma; -bool locked = !!(vma->vm_flags &VM_LOCKED ); +bool locked =vma_test (vma,VMA_LOCKED_BIT );struct page *page =NULL ;bool present = false, young = false, dirty = false;pte_t ptent =ptep_get (pte);
@@ -1017,7 +1017,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, {struct mem_size_stats *mss = walk->private;struct vm_area_struct *vma = walk->vma; -bool locked = !!(vma->vm_flags &VM_LOCKED ); +bool locked =vma_test (vma,VMA_LOCKED_BIT );struct page *page =NULL ;bool present = false;struct folio *folio;
@@ -1728,7 +1728,7 @@ static int clear_refs_test_walk(unsigned long start, unsigned long end,struct clear_refs_private *cp = walk->private;struct vm_area_struct *vma = walk->vma; -if (vma->vm_flags &VM_PFNMAP ) +if (vma_test (vma,VMA_PFNMAP_BIT ))return 1 ;/*
@@ -1798,9 +1798,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,if (type ==CLEAR_REFS_SOFT_DIRTY ) {for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_SOFTDIRTY )) +if (!vma_test (vma,VMA_SOFTDIRTY_BIT ))continue ; -vm_flags_clear (vma,VM_SOFTDIRTY ); +vma_start_write (vma); +vma_clear_flags (vma,VMA_SOFTDIRTY_BIT );vma_set_page_prot (vma); }
@@ -1904,7 +1905,7 @@ static int pagemap_pte_hole(unsigned long start, unsigned long end,break ;/* Addresses in the VMA. */ -if (vma->vm_flags &VM_SOFTDIRTY ) +if (vma_test (vma,VMA_SOFTDIRTY_BIT )) pme =make_pme (0 ,PM_SOFT_DIRTY );for (; addr <min (end, vma->vm_end); addr +=PAGE_SIZE ) { err =add_to_pagemap (&pme, pm);
@@ -1976,7 +1977,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, } out: -if (vma->vm_flags &VM_SOFTDIRTY ) +if (vma_test (vma,VMA_SOFTDIRTY_BIT )) flags |=PM_SOFT_DIRTY ;return make_pme (frame, flags);
@@ -1994,7 +1995,7 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr,struct folio *folio =NULL ;int err =0 ; -if (vma->vm_flags &VM_SOFTDIRTY ) +if (vma_test (vma,VMA_SOFTDIRTY_BIT )) flags |=PM_SOFT_DIRTY ;if (pmd_none (pmd))
@@ -2116,7 +2117,7 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,int err =0 ;pte_t pte; -if (vma->vm_flags &VM_SOFTDIRTY ) +if (vma_test (vma,VMA_SOFTDIRTY_BIT )) flags |=PM_SOFT_DIRTY ; ptl =huge_pte_lock (hstate_vma (vma), walk->mm, ptep);
@@ -2625,13 +2626,13 @@ static int pagemap_scan_test_walk(unsigned long start, unsigned long end,*/ } -if (vma->vm_flags &VM_PFNMAP ) +if (vma_test (vma,VMA_PFNMAP_BIT ))return 1 ;if (wp_allowed) vma_category |=PAGE_IS_WPALLOWED ; -if (vma->vm_flags &VM_SOFTDIRTY ) +if (vma_test (vma,VMA_SOFTDIRTY_BIT )) vma_category |=PAGE_IS_SOFT_DIRTY ;if (!pagemap_scan_is_interesting_vma (vma_category, p))
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 09/13] fs/proc/task_mmu: convert VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in /proc/$pid/[s]maps, pagemap,clear_refsandPROCMAP_QUERY.In replacing
vm_flags_clear()(which takes the VMA write lock) withvma_clear_flags()(which does not) inclear_refs_write(), we explicitly write lock the VMA. The mmap write lock is already held at this point.
Quoted 7 lines
The
show_vma_header_prefix()andshow_smap_vma_flags()output functions and thethp_vma_allowable_orders()call continue to use legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH 09/13] fs/proc/task_mmu: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 94 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in /proc/$pid/[s]maps, pagemap,clear_refsandPROCMAP_QUERY.In replacing
vm_flags_clear()(which takes the VMA write lock) withvma_clear_flags()(which does not) inclear_refs_write(), we explicitly write lock the VMA. The mmap write lock is already held at this point.The
show_vma_header_prefix()andshow_smap_vma_flags()output functions and thethp_vma_allowable_orders()call continue to use legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
fs/proc/task_mmu.c| 43 ++++++++++++++++++++++---------------------1 file changed, 22 insertions(+), 21 deletions(-)fs/proc/task_mmu.c +13
-13@@ -569,18 +569,18 @@ static struct vm_area_struct *query_matching_vma(struct proc_maps_locking_ctx *l/* VMA permissions should satisfy query flags */ if (flags &PROCMAP_QUERY_VMA_FLAGS ) { -u32 perm =0 ; +vma_flags_t perm =EMPTY_VMA_FLAGS ;if (flags &PROCMAP_QUERY_VMA_READABLE ) - perm |=VM_READ ; +vma_flags_set (&perm,VMA_READ_BIT );if (flags &PROCMAP_QUERY_VMA_WRITABLE ) - perm |=VM_WRITE ; +vma_flags_set (&perm,VMA_WRITE_BIT );if (flags &PROCMAP_QUERY_VMA_EXECUTABLE ) - perm |=VM_EXEC ; +vma_flags_set (&perm,VMA_EXEC_BIT );if (flags &PROCMAP_QUERY_VMA_SHARED ) - perm |=VM_MAYSHARE ; +vma_flags_set (&perm,VMA_MAYSHARE_BIT ); -if ((vma->vm_flags & perm) != perm) +if (!vma_test_all_mask (vma, perm)) goto skip_vma; }@@ -647,13 +647,13 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg) karg.vma_end = vma->vm_end; karg.vma_flags =0 ; -if (vma->vm_flags &VM_READ ) +if (vma_test (vma,VMA_READ_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_READABLE ; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_WRITABLE ; -if (vma->vm_flags &VM_EXEC ) +if (vma_test (vma,VMA_EXEC_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_EXECUTABLE ; -if (vma->vm_flags &VM_MAYSHARE ) +if (vma_test (vma,VMA_MAYSHARE_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_SHARED ; karg.vma_page_size =vma_kernel_pagesize (vma);@@ -970,7 +970,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, {struct mem_size_stats *mss = walk->private;struct vm_area_struct *vma = walk->vma; -bool locked = !!(vma->vm_flags &VM_LOCKED ); +bool locked =vma_test (vma,VMA_LOCKED_BIT );struct page *page =NULL ;bool present = false, young = false, dirty = false;pte_t ptent =ptep_get (pte);@@ -1017,7 +1017,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, {struct mem_size_stats *mss = walk->private;struct vm_area_struct *vma = walk->vma; -bool locked = !!(vma->vm_flags &VM_LOCKED ); +bool locked =vma_test (vma,VMA_LOCKED_BIT );struct page *page =NULL ;bool present = false;struct folio *folio;@@ -1728,7 +1728,7 @@ static int clear_refs_test_walk(unsigned long start, unsigned long end,struct clear_refs_private *cp = walk->private;struct vm_area_struct *vma = walk->vma; -if (vma->vm_flags &VM_PFNMAP ) +if (vma_test (vma,VMA_PFNMAP_BIT ))return 1 ;/*
fs/proc/task_mmu.c static ssize_t clear_refs_write(struct file *file, const char __user *buf, · line 1803
Quoted 7 lines
fs/proc/task_mmu.c +1
-2@@ -1798,9 +1798,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,if (type ==CLEAR_REFS_SOFT_DIRTY ) {for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_SOFTDIRTY )) +if (!vma_test (vma,VMA_SOFTDIRTY_BIT ))continue ; -vm_flags_clear (vma,VM_SOFTDIRTY );
vm_flags_clear() still warns on VM_SOFTDIRTY when pgtable_supports_soft_dirty() is false. Did you mean to drop that?
(Vaguely recall you weren't too keen on that warn, though I could be wrong.)
Otherwise, LGTM!
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 09/13] fs/proc/task_mmu: convert VMA flag tests to use vma_flags_t
Quoted 97 lines · Lance Yang
Quoted 95 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues where VMA flags are tested directly in /proc/$pid/[s]maps, pagemap,clear_refsandPROCMAP_QUERY.In replacing
vm_flags_clear()(which takes the VMA write lock) withvma_clear_flags()(which does not) inclear_refs_write(), we explicitly write lock the VMA. The mmap write lock is already held at this point.The
show_vma_header_prefix()andshow_smap_vma_flags()output functions and thethp_vma_allowable_orders()call continue to use legacy flags for the time being.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
fs/proc/task_mmu.c| 43 ++++++++++++++++++++++---------------------1 file changed, 22 insertions(+), 21 deletions(-)fs/proc/task_mmu.c +13
-13@@ -569,18 +569,18 @@ static struct vm_area_struct *query_matching_vma(struct proc_maps_locking_ctx *l/* VMA permissions should satisfy query flags */ if (flags &PROCMAP_QUERY_VMA_FLAGS ) { -u32 perm =0 ; +vma_flags_t perm =EMPTY_VMA_FLAGS ;if (flags &PROCMAP_QUERY_VMA_READABLE ) - perm |=VM_READ ; +vma_flags_set (&perm,VMA_READ_BIT );if (flags &PROCMAP_QUERY_VMA_WRITABLE ) - perm |=VM_WRITE ; +vma_flags_set (&perm,VMA_WRITE_BIT );if (flags &PROCMAP_QUERY_VMA_EXECUTABLE ) - perm |=VM_EXEC ; +vma_flags_set (&perm,VMA_EXEC_BIT );if (flags &PROCMAP_QUERY_VMA_SHARED ) - perm |=VM_MAYSHARE ; +vma_flags_set (&perm,VMA_MAYSHARE_BIT ); -if ((vma->vm_flags & perm) != perm) +if (!vma_test_all_mask (vma, perm)) goto skip_vma; }@@ -647,13 +647,13 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg) karg.vma_end = vma->vm_end; karg.vma_flags =0 ; -if (vma->vm_flags &VM_READ ) +if (vma_test (vma,VMA_READ_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_READABLE ; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_WRITABLE ; -if (vma->vm_flags &VM_EXEC ) +if (vma_test (vma,VMA_EXEC_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_EXECUTABLE ; -if (vma->vm_flags &VM_MAYSHARE ) +if (vma_test (vma,VMA_MAYSHARE_BIT )) karg.vma_flags |=PROCMAP_QUERY_VMA_SHARED ; karg.vma_page_size =vma_kernel_pagesize (vma);@@ -970,7 +970,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, {struct mem_size_stats *mss = walk->private;struct vm_area_struct *vma = walk->vma; -bool locked = !!(vma->vm_flags &VM_LOCKED ); +bool locked =vma_test (vma,VMA_LOCKED_BIT );struct page *page =NULL ;bool present = false, young = false, dirty = false;pte_t ptent =ptep_get (pte);@@ -1017,7 +1017,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, {struct mem_size_stats *mss = walk->private;struct vm_area_struct *vma = walk->vma; -bool locked = !!(vma->vm_flags &VM_LOCKED ); +bool locked =vma_test (vma,VMA_LOCKED_BIT );struct page *page =NULL ;bool present = false;struct folio *folio;@@ -1728,7 +1728,7 @@ static int clear_refs_test_walk(unsigned long start, unsigned long end,struct clear_refs_private *cp = walk->private;struct vm_area_struct *vma = walk->vma; -if (vma->vm_flags &VM_PFNMAP ) +if (vma_test (vma,VMA_PFNMAP_BIT ))return 1 ;/* @@ -1798,9 +1798,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
Quoted 9 lines
fs/proc/task_mmu.c static ssize_t clear_refs_write(struct file *file, const char __user *buf, · line 1803
Quoted 6 lines
fs/proc/task_mmu.c +1
-2if (type ==CLEAR_REFS_SOFT_DIRTY ) {for_each_vma (vmi, vma) { -if (!(vma->vm_flags &VM_SOFTDIRTY )) +if (!vma_test (vma,VMA_SOFTDIRTY_BIT ))continue ; -vm_flags_clear (vma,VM_SOFTDIRTY );
vm_flags_clear()still warns onVM_SOFTDIRTYwhenpgtable_supports_soft_dirty()is false. Did you mean to drop that?
Yep it's silly. Checking every single operation with VMA_SOFTDIRTY_BIT for whether CONFIG_MEM_SOFT_DIRTY is enabled, which is not done for literally any other VMA flag, is ludicrous frankly :)
Quoted 6 lines
(Vaguely recall you weren't too keen on that warn, though I could be wrong.)
Otherwise, LGTM!
Reviewed-by Lance Yang <[email protected]>
Thanks!
--
Cheers, Lorenzo
Lorenzo Stoakes (ARM)
maintainerPATCH 10/13 fs/coredump: convert vma_dump_size() to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values when determining how much of a VMA to dump.
The flags copied into struct core_vma_metadata remain legacy flags as they are consumed by the binfmt handlers.
No functional change intended.
--- fs/coredump.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/coredump.c +8 -8
@@ -1835,15 +1835,15 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,if (always_dump_vma (vma)) goto whole; -if (vma->vm_flags &VM_DONTDUMP ) +if (vma_test (vma,VMA_DONTDUMP_BIT ))return 0 ;/* support for DAX */ if (vma_is_dax (vma)) { -if ((vma->vm_flags &VM_SHARED ) && +if (vma_test (vma,VMA_SHARED_BIT ) &&COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,DAX_SHARED )) goto whole; -if (!(vma->vm_flags &VM_SHARED ) && +if (!vma_test (vma,VMA_SHARED_BIT ) &&COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,DAX_PRIVATE )) goto whole;return 0 ;
@@ -1851,21 +1851,21 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,/* Hugetlb memory check */ if (vma_is_hugetlb (vma)) { -if ((vma->vm_flags &VM_SHARED ) && +if (vma_test (vma,VMA_SHARED_BIT ) &&COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,HUGETLB_SHARED )) goto whole; -if (!(vma->vm_flags &VM_SHARED ) && +if (!vma_test (vma,VMA_SHARED_BIT ) &&COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,HUGETLB_PRIVATE )) goto whole;return 0 ; }/* Do not dump I/O mapped devices or special mappings */ -if (vma->vm_flags &VM_IO ) +if (vma_test (vma,VMA_IO_BIT ))return 0 ;/* By default, dump shared memory if mapped from an anonymous file. */ -if (vma->vm_flags &VM_SHARED ) { +if (vma_test (vma,VMA_SHARED_BIT )) {if (file_inode (vma->vm_file)->i_nlink ==0 ?COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,ANON_SHARED ) :COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,FILE_SHARED ))
@@ -1888,7 +1888,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,* dump the first page to aid in determining what was mapped here. */ if (COREDUMP_MEMORY_TYPE_INCLUDE (memory_types,ELF_HEADERS ) && - vma->vm_pgoff ==0 && (vma->vm_flags &VM_READ )) { + vma->vm_pgoff ==0 &&vma_test (vma,VMA_READ_BIT )) {if ((READ_ONCE (file_inode (vma->vm_file)->i_mode) &0111 ) !=0 )return PAGE_SIZE ;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 10/13] fs/coredump: convert vma_dump_size() to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues when determining how much of a VMA to dump.The flags copied into struct
core_vma_metadataremain legacy flags as they are consumed by the binfmt handlers.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH 10/13] fs/coredump: convert vma_dump_size() to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 10 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues when determining how much of a VMA to dump.The flags copied into struct
core_vma_metadataremain legacy flags as they are consumed by the binfmt handlers.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Nothing jumped out at me, so:
Lorenzo Stoakes (ARM)
maintainerPATCH 11/13 uprobes: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values in the uprobes VMA validity checks.
No functional change intended.
--- kernel/events/uprobes.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
kernel/events/uprobes.c +7 -5
@@ -134,12 +134,14 @@ static void uprobe_warn(struct task_struct *t, const char *msg)*/ static bool valid_vma (struct vm_area_struct *vma,bool is_register) { -vm_flags_t flags =VM_HUGETLB |VM_MAYEXEC |VM_MAYSHARE ; +vma_flags_t forbidden =mk_vma_flags (VMA_HUGETLB_BIT , +VMA_MAYSHARE_BIT );if (is_register) - flags |=VM_WRITE ; +vma_flags_set (&forbidden,VMA_WRITE_BIT ); -return vma->vm_file && (vma->vm_flags & flags) ==VM_MAYEXEC ; +return vma->vm_file &&vma_test (vma,VMA_MAYEXEC_BIT ) && + !vma_test_any_mask (vma, forbidden); }static unsigned long offset_to_vaddr (struct vm_area_struct *vma,loff_t offset)
@@ -286,7 +288,7 @@ static bool valid_ref_ctr_vma(struct uprobe *uprobe,return uprobe->ref_ctr_offset && vma->vm_file &&file_inode (vma->vm_file) == uprobe->inode && - (vma->vm_flags & (VM_WRITE |VM_SHARED )) ==VM_WRITE && +vma_test (vma,VMA_WRITE_BIT ) && !vma_test (vma,VMA_SHARED_BIT ) && vma->vm_start <= vaddr && vma->vm_end > vaddr; }
@@ -1607,7 +1609,7 @@ int uprobe_mmap(struct vm_area_struct *vma)return 0 ;if (vma->vm_file && - (vma->vm_flags & (VM_WRITE |VM_SHARED )) ==VM_WRITE && +vma_test (vma,VMA_WRITE_BIT ) && !vma_test (vma,VMA_SHARED_BIT ) &&mm_flags_test (MMF_HAS_UPROBES , vma->vm_mm))delayed_ref_ctr_inc (vma);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 11/13] uprobes: convert VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the uprobes VMA validity checks.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Re: [PATCH 11/13] uprobes: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the uprobes VMA validity checks.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Lorenzo Stoakes (ARM)
maintainerPATCH 12/13 perf: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values in the perf mmap and mmap event logic.
No functional change intended.
--- kernel/events/core.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
kernel/events/core.c +14 -12
@@ -7224,6 +7224,7 @@ static int map_range(struct perf_buffer *rb, struct vm_area_struct *vma)unsigned long va = vma->vm_start +PAGE_SIZE * pagenum;struct page *page =perf_mmap_to_page (rb,vma_start_pgoff (vma) + pagenum); +vma_flags_t vma_flags = vma->flags;if (page ==NULL ) { err = -EINVAL ;
@@ -7231,8 +7232,9 @@ static int map_range(struct perf_buffer *rb, struct vm_area_struct *vma) }/* Map readonly, perf_mmap_pfn_mkwrite() called on write fault. */ +vma_flags_clear (&vma_flags,VMA_SHARED_BIT ); err =remap_pfn_range (vma, va,page_to_pfn (page),PAGE_SIZE , -vm_get_page_prot (vma->vm_flags & ~VM_SHARED )); +vma_flags_to_page_prot (vma_flags));if (err)break ; }
@@ -7350,7 +7352,7 @@ static int perf_mmap_rb(struct vm_area_struct *vma, struct perf_event *event,if (!perf_mmap_calc_limits (vma, &user_extra, &extra))return -EPERM ; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) rb_flags |=RING_BUFFER_WRITABLE ; rb = rb_alloc(nr_pages,
@@ -7431,7 +7433,7 @@ static int perf_mmap_aux(struct vm_area_struct *vma, struct perf_event *event,WARN_ON (!rb && event->rb); -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) rb_flags |=RING_BUFFER_WRITABLE ; ret = rb_alloc_aux(rb, event, pgoff_start, nr_pages,
@@ -7466,7 +7468,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)if (event->cpu ==-1 && event->attr.inherit)return -EINVAL ; -if (!(vma->vm_flags &VM_SHARED )) +if (!vma_test (vma,VMA_SHARED_BIT ))return -EINVAL ; ret =security_perf_event_read (event);
@@ -9829,7 +9831,7 @@ static int perf_event_mmap_match(struct perf_event *event, {struct perf_mmap_event *mmap_event = data;struct vm_area_struct *vma = mmap_event->vma; -int executable = vma->vm_flags &VM_EXEC ; +bool executable =vma_test (vma,VMA_EXEC_BIT );return (!executable && event->attr.mmap_data) || (executable && (event->attr.mmap || event->attr.mmap2));
@@ -9862,7 +9864,7 @@ static void perf_event_mmap_output(struct perf_event *event,if (use_build_id) misc |=PERF_RECORD_MISC_MMAP_BUILD_ID ; } -if (!(mmap_event->vma->vm_flags &VM_EXEC )) +if (!vma_test (mmap_event->vma,VMA_EXEC_BIT )) misc |=PERF_RECORD_MISC_MMAP_DATA ; perf_event_header__init(&mmap_event->event_id.header, &sample,
@@ -9913,19 +9915,19 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)char *buf =NULL ;char *name =NULL ; -if (vma->vm_flags &VM_READ ) +if (vma_test (vma,VMA_READ_BIT )) prot |=PROT_READ ; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) prot |=PROT_WRITE ; -if (vma->vm_flags &VM_EXEC ) +if (vma_test (vma,VMA_EXEC_BIT )) prot |=PROT_EXEC ; -if (vma->vm_flags &VM_MAYSHARE ) +if (vma_test (vma,VMA_MAYSHARE_BIT )) flags =MAP_SHARED ;else flags =MAP_PRIVATE ; -if (vma->vm_flags &VM_LOCKED ) +if (vma_test (vma,VMA_LOCKED_BIT )) flags |=MAP_LOCKED ;if (vma_is_hugetlb (vma)) flags |=MAP_HUGETLB ;
@@ -10091,7 +10093,7 @@ static void perf_addr_filters_adjust(struct vm_area_struct *vma)* Data tracing isn't supported yet and as such there is no need * to keep track of anything that isn't related to executable code: */ -if (!(vma->vm_flags &VM_EXEC )) +if (!vma_test (vma,VMA_EXEC_BIT ))return ;rcu_read_lock ();
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 12/13] perf: convert VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the perf mmap and mmap event logic.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Re: [PATCH 12/13] perf: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the perf mmap and mmap event logic.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
Lorenzo Stoakes (ARM)
maintainerPATCH 13/13 security: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Replace use of the legacy vm_flags_t flags with vma_flags_t values in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.
No functional change intended.
--- security/apparmor/lsm.c | 2 +- security/integrity/ima/ima_main.c | 2 +- security/ipe/hooks.c | 2 +- security/selinux/hooks.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-)
security/apparmor/lsm.c +1 -1
@@ -590,7 +590,7 @@ static int apparmor_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, unsigned long prot) {return common_mmap (OP_FMPROT , vma->vm_file, prot, - !(vma->vm_flags &VM_SHARED ) ?MAP_PRIVATE :0 ); + !vma_test (vma,VMA_SHARED_BIT ) ?MAP_PRIVATE :0 ); }#ifdef CONFIG_IO_URING
security/integrity/ima/ima_main.c +1 -1
@@ -556,7 +556,7 @@ static int ima_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,/* Is mprotect making an mmap'ed file executable? */ if (!(ima_policy_flag &IMA_APPRAISE ) || !vma->vm_file || - !(prot &PROT_EXEC ) || (vma->vm_flags &VM_EXEC )) + !(prot &PROT_EXEC ) ||vma_test (vma,VMA_EXEC_BIT ))return 0 ;security_current_getlsmprop_subj (&prop);
security/ipe/hooks.c +1 -1
@@ -112,7 +112,7 @@ int ipe_file_mprotect(struct vm_area_struct *vma,struct ipe_eval_ctx ctx =IPE_EVAL_CTX_INIT ;/* Already Executable */ -if (vma->vm_flags &VM_EXEC ) +if (vma_test (vma,VMA_EXEC_BIT ))return 0 ;if (prot &PROT_EXEC ) {
security/selinux/hooks.c +7 -7
@@ -4206,16 +4206,16 @@ static int selinux_mmap_backing_file(struct vm_area_struct *vma, {unsigned long prot =0 ; -/* translate vma->vm_flags perms into PROT perms */ -if (vma->vm_flags &VM_READ ) +/* translate VMA flag perms into PROT perms */ +if (vma_test (vma,VMA_READ_BIT )) prot |=PROT_READ ; -if (vma->vm_flags &VM_WRITE ) +if (vma_test (vma,VMA_WRITE_BIT )) prot |=PROT_WRITE ; -if (vma->vm_flags &VM_EXEC ) +if (vma_test (vma,VMA_EXEC_BIT )) prot |=PROT_EXEC ;return selinux_mmap_file_common (backing_file, prot, - vma->vm_flags &VM_SHARED , +vma_test (vma,VMA_SHARED_BIT ), true); }
@@ -4229,13 +4229,13 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,u32 av;const struct file *file = vma->vm_file;bool backing_file; -bool shared = vma->vm_flags &VM_SHARED ; +bool shared =vma_test (vma,VMA_SHARED_BIT );/* check if we need to trigger the "backing files are awful" mode */ backing_file = file && (file->f_mode &FMODE_BACKING );if (default_noexec && - (prot &PROT_EXEC ) && !(vma->vm_flags &VM_EXEC )) { + (prot &PROT_EXEC ) && !vma_test (vma,VMA_EXEC_BIT )) {/* * We don't use the vma_is_initial_heap() helper as it has * a history of problems and is currently broken on systems
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 13/13] security: convert VMA flag tests to use vma_flags_t
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Paul Moore
maintainerRe: [PATCH 13/13] security: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.No functional change intended.
Quoted 7 lines
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- security/apparmor/lsm.c | 2 +- security/integrity/ima/ima_main.c | 2 +- security/ipe/hooks.c | 2 +- security/selinux/hooks.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-)
Similar to the other patchset you just posted, is there any reason why individual subsystem maintainers can't pick these patches up, or is there some reason I'm missing and they need to go through a single tree?
If they can go through multiple trees, can you split this patch up? AppArmor, Integrity/IMA, IPE, and SELinux are all maintained by different groups/people.
Signature · 1 line
paul-moore.com
Re: [PATCH 13/13] security: convert VMA flag tests to use vma_flags_t
Quoted 15 lines · Paul Moore
Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.No functional change intended.
Quoted 7 lines
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- security/apparmor/lsm.c | 2 +- security/integrity/ima/ima_main.c | 2 +- security/ipe/hooks.c | 2 +- security/selinux/hooks.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-)
Quoted 8 lines
Similar to the other patchset you just posted, is there any reason why individual subsystem maintainers can't pick these patches up, or is there some reason I'm missing and they need to go through a single tree?
If they can go through multiple trees, can you split this patch up? AppArmor, Integrity/IMA, IPE, and SELinux are all maintained by different groups/people.
Since there seems to be a desire to bypass normal procedure in favor of speed (surely that will never backfire), the SELinux changes look fine to me, but please do wait to hear from the AppArmor, IMA, and IPE maintainers before merging this patch.
Signature · 1 line
paul-moore.com
Re: [PATCH 13/13] security: convert VMA flag tests to use vma_flags_t
Quoted 25 lines · Paul Moore
Quoted 15 lines · Paul Moore
Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.No functional change intended.
Quoted 7 lines
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- security/apparmor/lsm.c | 2 +- security/integrity/ima/ima_main.c | 2 +- security/ipe/hooks.c | 2 +- security/selinux/hooks.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-)Quoted 8 lines
Similar to the other patchset you just posted, is there any reason why individual subsystem maintainers can't pick these patches up, or is there some reason I'm missing and they need to go through a single tree?
If they can go through multiple trees, can you split this patch up? AppArmor, Integrity/IMA, IPE, and SELinux are all maintained by different groups/people.
Quoted 7 lines
Since there seems to be a desire to bypass normal procedure in favor of speed (surely that will never backfire), the SELinux changes look fine to me, but please do wait to hear from the AppArmor, IMA, and IPE maintainers before merging this patch.
Acked-by Paul Moore <[email protected]>
For the IPE part:
Lorenzo Stoakes (ARM)
maintainerRe: [PATCH 13/13] security: convert VMA flag tests to use vma_flags_t
In reply to Paul MooreQuoted 15 lines · Paul Moore
Quoted 6 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.No functional change intended.
Quoted 7 lines
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>--- security/apparmor/lsm.c | 2 +- security/integrity/ima/ima_main.c | 2 +- security/ipe/hooks.c | 2 +- security/selinux/hooks.c | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-)
Quoted 8 lines
Similar to the other patchset you just posted, is there any reason why individual subsystem maintainers can't pick these patches up, or is there some reason I'm missing and they need to go through a single tree?
If they can go through multiple trees, can you split this patch up? AppArmor, Integrity/IMA, IPE, and SELinux are all maintained by different groups/people.
Sure, they're all independent so you can take the security bits through your tree, I guess fairly easy for Andrew/David to figure out which went where?
Intentionally made these easy ones given how busy the cycle is, just keeping the conversion rolling forward :)
--
Cheers, Lorenzo
Re: [PATCH 13/13] security: convert VMA flag tests to use vma_flags_t
In reply to Lorenzo Stoakes (ARM)Quoted 7 lines · Lorenzo Stoakes (ARM)
Replace use of the legacy
vm_flags_tflags withvma_flags_tvalues in the mmap and mprotect LSM hooks of SELinux, AppArmor, IMA and IPE.No functional change intended.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>---
David Hildenbrand (Arm)
maintainerQuoted 17 lines · Lorenzo Stoakes (ARM)
Continue the conversion of legacy
vm_flags_tflags to the newvma_flags_tbitmap type.Do some more core mm conversion (we really should be the first to completely move to the new scheme :), but also update some mm-adjacent and otherwise straightforward cases -
/proc/$pid/mapsand friends, the coredump VMA dump size logic, uprobes, perf and LSM mmap/mprotect hooks.This series only makes strictly mechanical changes to keep things gentle during this very busy cycle.
No functional change intended.
Build tested on x86-64 (allmodconfig, each patch individually), i386, arm64, riscv nommu and ppc64le.
Signed-off-by Lorenzo Stoakes (ARM) <[email protected]>
Quoted 16 lines
---
Lorenzo Stoakes (ARM) (13):
mm/gup: convert GUP code to usevma_flags_tmm/filemap: convert fault and readahead logic to usevma_flags_tmm/rmap: convert remaining VMA flag tests to usevma_flags_tmm/migrate: convert VMA flag tests to usevma_flags_t
mm: convert THP VMA flag tests to usevma_flags_tmm/ksm: convert VMA flag tests to usevma_flags_tmm/madvise: convertmadvise_vma_behavior()to usevma_flags_t
mm: convert miscellaneous VMA flag tests to usevma_flags_tfs/proc/task_mmu: convert VMA flag tests to usevma_flags_tfs/coredump: convertvma_dump_size()to usevma_flags_t
uprobes: convert VMA flag tests to usevma_flags_t
perf: convert VMA flag tests to usevma_flags_t
security: convert VMA flag tests to usevma_flags_t
I agree that this should be picked separately. For example, I will pick everything that falls into my realm to reduce conflicts.
Ideally, patches really only touch one component.
[PATCH 07/13] mm/madvise: convert madvise_vma_behavior() to use vma_flags_t
is all over the place :)
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerQuoted 2 lines · David Hildenbrand (Arm)
I agree that this should be picked separately. For example, I will pick everything that falls into my realm to reduce conflicts.
Hmm, generally tree-wide mechanical changes are the exception to that rule no?
It's going to make the rest of the VMA flags/mmap_prepare conversion really quite difficult if I have to chase every single driver maintainer in the kernel (literally in both cases pretty much :).
And sometimes there are dependencies which mean you really can't split it across trees unless you establish functionality in one cycle and callers in another, but that seems a little silly.
I was thinking that once the VMA tree is separate I'd put mechanical changes like this through it. Is that not the way to go?
Quoted 2 lines
Ideally, patches really only touch one component.
Right, but sometimes functions are declared in one place and called in others. It is impossible to change the signature of one without also touching the others.
Quoted 4 lines
[PATCH 07/13] mm/madvise: convert
madvise_vma_behavior()to usevma_flags_tis all over the place :)
It's not really all over the place, it's converting vm_flags_t to vma_flags_t across madvise.c, which involves changing a few function signatures, whose callers must be updated.
I could split it up into 3 patches where 1 does internal-only, one changes 1 function, and the next changes another, if that works?
But there's no way for that change to only touch madvise() given the function decl/callers.
--
Cheers, Lorenzo
David Hildenbrand (Arm)
maintainerQuoted 6 lines · Lorenzo Stoakes (ARM)
Quoted 2 lines · David Hildenbrand (Arm)
I agree that this should be picked separately. For example, I will pick everything that falls into my realm to reduce conflicts.
Hmm, generally tree-wide mechanical changes are the exception to that rule no?
I think it really depends. If changes are well standalone, I don't see why it couldn't just cleanly go through separate trees.
Anything that is more involved (like the madvise change), there is not really a way around.
Well, there is: stable topic branch and letting separate trees merge that ...
Quoted 10 lines
It's going to make the rest of the VMA flags/mmap_prepare conversion really quite difficult if I have to chase every single driver maintainer in the kernel (literally in both cases pretty much :).
Quoted 1 line
And sometimes there are dependencies which mean you really can't split it
across trees unless you establish functionality in one cycle and callers in another, but that seems a little silly.
I was thinking that once the VMA tree is separate I'd put mechanical changes like this through it. Is that not the way to go?
Maybe? We'll have to learn. Right now it immediately caused conflicts between mine and Andrew's tree.
Because of [PATCH 05/13] mm: convert THP VMA flag tests to use vma_flags_t which is THP-only, and feels like it could go straight through one of my trees, avoiding conflicts with Andrew's tree. But maybe there is more to it that I am missing.
I assume stable topic branches would fix that, but they are currently unfortunately not on the table ... :)
Quoted 7 lines
Quoted 3 lines
Ideally, patches really only touch one component.
Right, but sometimes functions are declared in one place and called in others. It is impossible to change the signature of one without also touching the others.
Yes. Something like that is unavoidable. Or if you need new APIs/
Quoted 9 lines
Quoted 5 lines
[PATCH 07/13] mm/madvise: convert
madvise_vma_behavior()to usevma_flags_tis all over the place :)
It's not really all over the place, it's converting
vm_flags_ttovma_flags_tacrossmadvise.c, which involves changing a few function signatures, whose callers must be updated.
Ah, yeah. What on earth does arch/powerpc/kvm/book3s_hv_uvmem.c do with madvise :(
Quoted 3 lines
I could split it up into 3 patches where 1 does internal-only, one changes 1 function, and the next changes another, if that works?
No, these things really have to go in as one unit, no need to split that up.
Signature · 3 lines
Cheers, David
Lorenzo Stoakes (ARM)
maintainerI think we're slightly talking across purposes, so to be clear - I am totally fine with you taking any of this through your tree or whatever works for you and Andrew to avoid merge pain :)
I was just talking more generally about how to merge series that touch a lot of subsystems and maintainers-who-may-never-reply, etc.
These are the edge cases that make things... fun :)
Anyway, I guess easiest resolution here is for you to take the bits that belong to your trees and Andrew takes the bits that belong elsewhere?
I don't think anything here has an inter-dependency.
On Sat, Nov 07, 2026 at 08:26:29PM +0100, David Hildenbrand (Arm) wrote:
[ ... ]
Quoted 5 lines
Because of [PATCH 05/13] mm: convert THP VMA flag tests to use
vma_flags_twhich is THP-only, and feels like it could go straight through one of my trees, avoiding conflicts with Andrew's tree. But maybe there is more to it that I am missing.
Sorry about that! Please take that through your tree.
Quoted 3 lines
I assume stable topic branches would fix that, but they are currently unfortunately not on the table ... :)
I guess we need everybody-on-git for this!
I guess when Liam and & I have the VMA tree we can do that at least for stuff that goes there :)
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Ideally, patches really only touch one component.
Right, but sometimes functions are declared in one place and called in others. It is impossible to change the signature of one without also touching the others.
Yes. Something like that is unavoidable. Or if you need new APIs/
Yes.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
[PATCH 07/13] mm/madvise: convert
madvise_vma_behavior()to usevma_flags_t
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
is all over the place :)
It's not really all over the place, it's converting
vm_flags_ttovma_flags_tacrossmadvise.c, which involves changing a few function signatures, whose callers must be updated.Ah, yeah. What on earth does
arch/powerpc/kvm/book3s_hv_uvmem.cdo with madvise :(
Yeah it's quite worrying that... :)
Quoted 6 lines
Quoted 4 lines
I could split it up into 3 patches where 1 does internal-only, one changes 1 function, and the next changes another, if that works?
No, these things really have to go in as one unit, no need to split that up.
Thanks, yeah, it's a pain I know but eventually 'one fine day' (probably in 2028) everything will be converted to vma_flags_t/mmap_prepare and we won't have to think about this :P
--
Cheers, Lorenzo
David Hildenbrand (Arm)
maintainerQuoted 11 lines · Lorenzo Stoakes (ARM)
I think we're slightly talking across purposes, so to be clear - I am totally fine with you taking any of this through your tree or whatever works for you and Andrew to avoid merge pain :)
I was just talking more generally about how to merge series that touch a lot of subsystems and maintainers-who-may-never-reply, etc.
These are the edge cases that make things... fun :)
Anyway, I guess easiest resolution here is for you to take the bits that belong to your trees and Andrew takes the bits that belong elsewhere?
Yes, that's what I did now, applying #1,#3,#4,#5,#6
7+8 touches some of my components, but the chance for conflicts are hopefully small.
Quoted 3 lines
I don't think anything here has an inter-dependency.
Yeah that makes it a lot easier.
Quoted 11 lines · David Hildenbrand (Arm)
[ ... ]
Quoted 5 lines
Because of [PATCH 05/13] mm: convert THP VMA flag tests to use
vma_flags_twhich is THP-only, and feels like it could go straight through one of my trees, avoiding conflicts with Andrew's tree. But maybe there is more to it that I am missing.Sorry about that! Please take that through your tree.
Not your fault, I guess we'll have to get used to merging stuff through separate trees, and dealing with conflicts that cannot be avoided :)
Quoted 8 lines
Quoted 3 lines
I assume stable topic branches would fix that, but they are currently unfortunately not on the table ... :)
I guess we need everybody-on-git for this!
I guess when Liam and & I have the VMA tree we can do that at least for stuff that goes there :)
Ack!
Quoted 25 lines
Quoted 9 lines
Quoted 7 lines
Right, but sometimes functions are declared in one place and called in others. It is impossible to change the signature of one without also touching the others.
Yes. Something like that is unavoidable. Or if you need new APIs/
Yes.
Quoted 8 lines
Quoted 6 lines
It's not really all over the place, it's converting
vm_flags_ttovma_flags_tacrossmadvise.c, which involves changing a few function signatures, whose callers must be updated.Ah, yeah. What on earth does
arch/powerpc/kvm/book3s_hv_uvmem.cdo with madvise :(Yeah it's quite worrying that... :)
Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I could split it up into 3 patches where 1 does internal-only, one changes 1 function, and the next changes another, if that works?
No, these things really have to go in as one unit, no need to split that up.
Thanks, yeah, it's a pain I know but eventually 'one fine day' (probably in 2028) everything will be converted to vma_flags_t/mmap_prepare and we won't have to think about this :P
Right! :)
Signature · 3 lines
Cheers, David
Andrew Morton
maintainerQuoted 8 lines · On Mon, 9 Nov 2026 14:40:48 +0100 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 7 lines · Lorenzo Stoakes (ARM)
I think we're slightly talking across purposes, so to be clear - I am totally fine with you taking any of this through your tree or whatever works for you and Andrew to avoid merge pain :)
I was just talking more generally about how to merge series that touch a lot of subsystems and maintainers-who-may-never-reply, etc.
Quoted 6 lines
Quoted 4 lines
These are the edge cases that make things... fun :)
Anyway, I guess easiest resolution here is for you to take the bits that belong to your trees and Andrew takes the bits that belong elsewhere?
Yes, that's what I did now, applying #1,#3,#4,#5,#6
Cool.
I'll remove the whole series from mm.git immediately for collision-avoidance reasons - let's sort things out later.
I'll get better/more accurate about this soon - I need to set up infrastructure to fetch everyone else's trees, do test merges and figure out what should be removed/fixed in mm.git. I might just base mm.git on everyone-else and always route its stuff ->david. I need to spend a bit of time on this and discuss with the mm-next peeps.
David Hildenbrand (Arm)
maintainerQuoted 15 lines · Andrew Morton
Quoted 13 lines · On Mon, 9 Nov 2026 14:40:48 +0100 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 11 lines · Lorenzo Stoakes (ARM)
I think we're slightly talking across purposes, so to be clear - I am totally fine with you taking any of this through your tree or whatever works for you and Andrew to avoid merge pain :)
I was just talking more generally about how to merge series that touch a lot of subsystems and maintainers-who-may-never-reply, etc.
These are the edge cases that make things... fun :)
Anyway, I guess easiest resolution here is for you to take the bits that belong to your trees and Andrew takes the bits that belong elsewhere?
Quoted 6 lines
Quoted 1 line
Yes, that's what I did now, applying #1,#3,#4,#5,#6
Cool.
I'll remove the whole series from mm.git immediately for collision-avoidance reasons - let's sort things out later.
The mm-next merge today still worked (minor conflict on #7 due to one unnecessary ksm.c hunk I commented on), so you could have likely just kept all but the above patches.
Quoted 6 lines
I'll get better/more accurate about this soon - I need to set up infrastructure to fetch everyone else's trees, do test merges and figure out what should be removed/fixed in mm.git. I might just base mm.git on everyone-else and always route its stuff ->david. I need to spend a bit of time on this and discuss with the mm-next peeps.
Ack!
Signature · 3 lines
Cheers, David
Andrew Morton
maintainerQuoted 18 lines · On Mon, 9 Nov 2026 18:48:07 +0100 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Mon, 9 Nov 2026 14:40:48 +0100 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 11 lines · Lorenzo Stoakes (ARM)
I think we're slightly talking across purposes, so to be clear - I am totally fine with you taking any of this through your tree or whatever works for you and Andrew to avoid merge pain :)
I was just talking more generally about how to merge series that touch a lot of subsystems and maintainers-who-may-never-reply, etc.
These are the edge cases that make things... fun :)
Anyway, I guess easiest resolution here is for you to take the bits that belong to your trees and Andrew takes the bits that belong elsewhere?
Yes, that's what I did now, applying #1,#3,#4,#5,#6
Quoted 8 lines
Quoted 4 lines
Cool.
I'll remove the whole series from mm.git immediately for collision-avoidance reasons - let's sort things out later.
The mm-next merge today still worked (minor conflict on #7 due to one unnecessary
ksm.chunk I commented on), so you could have likely just kept all but the above patches.
OK, I'll take a look at re-adding things...
Quoted 8 lines
Quoted 6 lines
I'll get better/more accurate about this soon - I need to set up infrastructure to fetch everyone else's trees, do test merges and figure out what should be removed/fixed in mm.git. I might just base mm.git on everyone-else and always route its stuff ->david. I need to spend a bit of time on this and discuss with the mm-next peeps.
Ack!
...once this is in place!