From: Suren Baghdasaryan <surenb@google•com>
To: akpm@linux-foundation•org
Cc: michel@lespinasse•org, joelaf@google•com, songliubraving@fb•com,
mhocko@suse•com, leewalsh@google•com, david@redhat•com,
peterz@infradead•org, bigeasy@linutronix•de, peterx@redhat•com,
dhowells@redhat•com, linux-mm@kvack•org, edumazet@google•com,
jglisse@google•com, punit.agrawal@bytedance•com, will@kernel•org,
arjunroy@google•com, dave@stgolabs•net, minchan@google•com,
x86@kernel•org, hughd@google•com, willy@infradead•org,
gurua@google•com, mingo@redhat•com,
linux-arm-kernel@lists•infradead.org, rientjes@google•com,
axelrasmussen@google•com, kernel-team@android•com,
soheil@google•com, paulmck@kernel•org, jannh@google•com,
liam.howlett@oracle•com, shakeelb@google•com, luto@kernel•org,
gthelen@google•com, ldufour@linux•ibm.com, surenb@google•com,
vbabka@suse•cz, posk@google•com, lstoakes@gmail•com,
peterjung1337@gmail•com, linuxppc-dev@lists•ozlabs.org,
kent.overstreet@linux•dev, linux-kernel@vger•kernel.org,
hannes@cmpxchg•org, tatashin@google•com,
mgorman@techsingularity•net, rp pt@kernel•org
Subject: [PATCH v4 3/7] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK
Date: Thu, 26 Jan 2023 11:37:48 -0800 [thread overview]
Message-ID: <20230126193752.297968-4-surenb@google.com> (raw)
In-Reply-To: <20230126193752.297968-1-surenb@google.com>
To simplify the usage of VM_LOCKED_CLEAR_MASK in vm_flags_clear(),
replace it with VM_LOCKED_MASK bitmask and convert all users.
Signed-off-by: Suren Baghdasaryan <surenb@google•com>
Acked-by: Michal Hocko <mhocko@suse•com>
Acked-by: Mel Gorman <mgorman@techsingularity•net>
Acked-by: Mike Rapoport (IBM) <rppt@kernel•org>
---
include/linux/mm.h | 4 ++--
kernel/fork.c | 2 +-
mm/hugetlb.c | 4 ++--
mm/mlock.c | 6 +++---
mm/mmap.c | 6 +++---
mm/mremap.c | 2 +-
6 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index abb31103d060..ad4fdb9405ba 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -421,8 +421,8 @@ extern unsigned int kobjsize(const void *objp);
/* This mask defines which mm->def_flags a process can inherit its parent */
#define VM_INIT_DEF_MASK VM_NOHUGEPAGE
-/* This mask is used to clear all the VMA flags used by mlock */
-#define VM_LOCKED_CLEAR_MASK (~(VM_LOCKED | VM_LOCKONFAULT))
+/* This mask represents all the VMA flag bits used by mlock */
+#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT)
/* Arch-specific flags to clear when updating VM flags on protection change */
#ifndef VM_ARCH_CLEAR
diff --git a/kernel/fork.c b/kernel/fork.c
index 9260f975b8f4..5e3029ea8e1e 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -659,7 +659,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
tmp->anon_vma = NULL;
} else if (anon_vma_fork(tmp, mpnt))
goto fail_nomem_anon_vma_fork;
- tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
+ vm_flags_clear(tmp, VM_LOCKED_MASK);
file = tmp->vm_file;
if (file) {
struct address_space *mapping = file->f_mapping;
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index b6cbba105ffc..3a01a9dbf445 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6970,8 +6970,8 @@ static unsigned long page_table_shareable(struct vm_area_struct *svma,
unsigned long s_end = sbase + PUD_SIZE;
/* Allow segments to share if only one is marked locked */
- unsigned long vm_flags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
- unsigned long svm_flags = svma->vm_flags & VM_LOCKED_CLEAR_MASK;
+ unsigned long vm_flags = vma->vm_flags & ~VM_LOCKED_MASK;
+ unsigned long svm_flags = svma->vm_flags & ~VM_LOCKED_MASK;
/*
* match the virtual addresses, permission and the alignment of the
diff --git a/mm/mlock.c b/mm/mlock.c
index 0336f52e03d7..5c4fff93cd6b 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -497,7 +497,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
if (vma->vm_start != tmp)
return -ENOMEM;
- newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
+ newflags = vma->vm_flags & ~VM_LOCKED_MASK;
newflags |= flags;
/* Here we know that vma->vm_start <= nstart < vma->vm_end. */
tmp = vma->vm_end;
@@ -661,7 +661,7 @@ static int apply_mlockall_flags(int flags)
struct vm_area_struct *vma, *prev = NULL;
vm_flags_t to_add = 0;
- current->mm->def_flags &= VM_LOCKED_CLEAR_MASK;
+ current->mm->def_flags &= ~VM_LOCKED_MASK;
if (flags & MCL_FUTURE) {
current->mm->def_flags |= VM_LOCKED;
@@ -681,7 +681,7 @@ static int apply_mlockall_flags(int flags)
for_each_vma(vmi, vma) {
vm_flags_t newflags;
- newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
+ newflags = vma->vm_flags & ~VM_LOCKED_MASK;
newflags |= to_add;
/* Ignore errors */
diff --git a/mm/mmap.c b/mm/mmap.c
index d4abc6feced1..fa3cbd625850 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2671,7 +2671,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) ||
is_vm_hugetlb_page(vma) ||
vma == get_gate_vma(current->mm))
- vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+ vm_flags_clear(vma, VM_LOCKED_MASK);
else
mm->locked_vm += (len >> PAGE_SHIFT);
}
@@ -3340,8 +3340,8 @@ static struct vm_area_struct *__install_special_mapping(
vma->vm_start = addr;
vma->vm_end = addr + len;
- vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
- vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+ vm_flags_init(vma, (vm_flags | mm->def_flags |
+ VM_DONTEXPAND | VM_SOFTDIRTY) & ~VM_LOCKED_MASK);
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
vma->vm_ops = ops;
diff --git a/mm/mremap.c b/mm/mremap.c
index 1b3ee02bead7..55157b990091 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -687,7 +687,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
if (unlikely(!err && (flags & MREMAP_DONTUNMAP))) {
/* We always clear VM_LOCKED[ONFAULT] on the old vma */
- vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+ vm_flags_clear(vma, VM_LOCKED_MASK);
/*
* anon_vma links of the old vma is no longer needed after its page
--
2.39.1
next prev parent reply other threads:[~2023-01-26 19:41 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 19:37 [PATCH v4 0/7] introduce vm_flags modifier functions Suren Baghdasaryan
2023-01-26 19:37 ` [PATCH v4 1/7] kernel/fork: convert vma assignment to a memcpy Suren Baghdasaryan
2023-01-26 19:40 ` Mike Rapoport
2023-01-26 19:37 ` [PATCH v4 2/7] mm: introduce vma->vm_flags wrapper functions Suren Baghdasaryan
2023-01-26 19:42 ` Mike Rapoport
2023-02-08 1:48 ` Hyeonggon Yoo
2023-01-26 19:37 ` Suren Baghdasaryan [this message]
2023-01-27 17:45 ` [PATCH v4 3/7] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK Davidlohr Bueso
2023-01-27 20:56 ` Suren Baghdasaryan
2023-01-26 19:37 ` [PATCH v4 4/7] mm: replace vma->vm_flags direct modifications with modifier calls Suren Baghdasaryan
2023-01-27 14:23 ` Liam R. Howlett
2023-01-31 8:32 ` Hyeonggon Yoo
2023-01-31 18:54 ` Suren Baghdasaryan
2023-01-31 20:53 ` Andrew Morton
2023-01-31 21:08 ` Suren Baghdasaryan
2023-01-31 23:12 ` Andrew Morton
2023-02-01 0:03 ` Suren Baghdasaryan
2023-02-01 12:23 ` Hyeonggon Yoo
2023-01-26 19:37 ` [PATCH v4 5/7] mm: replace vma->vm_flags indirect modification in ksm_madvise Suren Baghdasaryan
2023-01-26 22:45 ` Michael Ellerman
2023-02-08 1:54 ` Hyeonggon Yoo
2023-01-26 19:37 ` [PATCH v4 6/7] mm: introduce __vm_flags_mod and use it in untrack_pfn Suren Baghdasaryan
2023-01-26 19:44 ` Mike Rapoport
2023-01-26 19:37 ` [PATCH v4 7/7] mm: export dump_mm() Suren Baghdasaryan
2023-03-14 20:11 ` [PATCH v4 0/7] introduce vm_flags modifier functions Alex Williamson
2023-03-17 19:08 ` Suren Baghdasaryan
2023-03-17 22:40 ` Alex Williamson
2023-03-17 23:04 ` Suren Baghdasaryan
2023-03-22 13:48 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230126193752.297968-4-surenb@google.com \
--to=surenb@google$(echo .)com \
--cc=akpm@linux-foundation$(echo .)org \
--cc=arjunroy@google$(echo .)com \
--cc=axelrasmussen@google$(echo .)com \
--cc=bigeasy@linutronix$(echo .)de \
--cc=dave@stgolabs$(echo .)net \
--cc=david@redhat$(echo .)com \
--cc=dhowells@redhat$(echo .)com \
--cc=edumazet@google$(echo .)com \
--cc=gthelen@google$(echo .)com \
--cc=gurua@google$(echo .)com \
--cc=hannes@cmpxchg$(echo .)org \
--cc=hughd@google$(echo .)com \
--cc=jannh@google$(echo .)com \
--cc=jglisse@google$(echo .)com \
--cc=joelaf@google$(echo .)com \
--cc=kent.overstreet@linux$(echo .)dev \
--cc=kernel-team@android$(echo .)com \
--cc=ldufour@linux$(echo .)ibm.com \
--cc=leewalsh@google$(echo .)com \
--cc=liam.howlett@oracle$(echo .)com \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-mm@kvack$(echo .)org \
--cc=linuxppc-dev@lists$(echo .)ozlabs.org \
--cc=lstoakes@gmail$(echo .)com \
--cc=luto@kernel$(echo .)org \
--cc=mgorman@techsingularity$(echo .)net \
--cc=mhocko@suse$(echo .)com \
--cc=michel@lespinasse$(echo .)org \
--cc=minchan@google$(echo .)com \
--cc=mingo@redhat$(echo .)com \
--cc=paulmck@kernel$(echo .)org \
--cc=peterjung1337@gmail$(echo .)com \
--cc=peterx@redhat$(echo .)com \
--cc=peterz@infradead$(echo .)org \
--cc=posk@google$(echo .)com \
--cc=punit.agrawal@bytedance$(echo .)com \
--cc=rientjes@google$(echo .)com \
--cc=shakeelb@google$(echo .)com \
--cc=soheil@google$(echo .)com \
--cc=songliubraving@fb$(echo .)com \
--cc=tatashin@google$(echo .)com \
--cc=vbabka@suse$(echo .)cz \
--cc=will@kernel$(echo .)org \
--cc=willy@infradead$(echo .)org \
--cc=x86@kernel$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox