From: Suren Baghdasaryan <surenb@google•com>
To: akpm@linux-foundation•org
Cc: michel@lespinasse•org, nvdimm@lists•linux.dev, heiko@sntech•de,
leewalsh@google•com, dri-devel@lists•freedesktop.org,
perex@perex•cz, jglisse@google•com, arjunroy@google•com,
m.szyprowski@samsung•com, linux-arch@vger•kernel.org,
qianweili@huawei•com, linux-samsung-soc@vger•kernel.org,
aneesh.kumar@linux•ibm.com, chenhuacai@kernel•org,
kasan-dev@googlegroups•com, linux-acpi@vger•kernel.org,
rientjes@google•com, xen-devel@lists•xenproject.org,
devel@lists•orangefs.org, robdclark@gmail•com,
minchan@google•com, robert.jarzmik@free•fr,
linux-um@lists•infradead.org, etnaviv@lists•freedesktop.org,
npiggin@gmail•com, alex.williamson@redhat•com,
viro@zeniv•linux.org.uk, luto@kernel•org, gthelen@google•com,
tglx@linutronix•de, ldufour@linux•ibm.com, surenb@google•com,
linux-sgx@vger•kernel.org, martin.petersen@oracle•com,
linux-usb@vger•kernel.org, linux-kernel@vger•kernel.org,
linux-perf-users@vger•kernel.org, linux-crypto@vger•kernel.org,
linux-fsdevel@vger•kernel.org, linux-media@vger•k ernel.org,
freedreno@lists•freedesktop.org, joelaf@google•com,
linux-aio@kvack•org, linux-fbdev@vger•kernel.org,
linux-ia64@vger•kernel.org, david@redhat•com,
dave.hansen@linux•intel.com,
virtualization@lists•linux-foundation.org, edumazet@google•com,
target-devel@vger•kernel.org, punit.agrawal@bytedance•com,
linux-s390@vger•kernel.org, dave@stgolabs•net, deller@gmx•de,
hughd@google•com, andrii@kernel•org,
patrik.r.jakobsson@gmail•com,
linux-stm32@st-md-mailman•stormreply.com,
linux-rockchip@lists•infradead.org,
linux-graphics-maintainer@vmware•com, kernel-team@android•com,
jayalk@intworks•biz, soheil@google•com, selinux@vger•kernel.org,
linux-arm-msm@vger•kernel.org, mripard@kernel•org,
shakeelb@google•com, haojian.zhuang@gmail•com,
loongarch@lists•linux.dev, linux-arm-kernel@lists•infradead.org,
tytso@mit•edu, nico@fluxnic•net, muchun.song@linux•dev,
hjc@rock-chips•com, mcoquelin.stm32@gmail•com,
tatashin@google•com, mike.kravetz@oracle•com,
songliubraving@fb•com, jasowang@redhat. com,
alsa-devel@alsa-project•org, peterx@redhat•com,
linux-tegra@vger•kernel.org, kraxel@redhat•com, will@kernel•org,
dmaengine@vger•kernel.org, bhe@redhat•com, miklos@szeredi•hu,
linux-rdma@vger•kernel.org, linux-staging@lists•linux.dev,
willy@infradead•org, gurua@google•com, dgilbert@interlog•com,
xiang@kernel•org, pabeni@redhat•com, jejb@linux•ibm.com,
quic_abhinavk@quicinc•com, bp@alien8•de, mchehab@kernel•org,
linux-ext4@vger•kernel.org, tomba@kernel•org,
hughlynch@google•com, sre@kernel•org, tfiga@chromium•org,
linux-xfs@vger•kernel.org, zhangfei.gao@linaro•org,
wangzhou1@hisilicon•com, netdev@vger•kernel.org,
bpf@vger•kernel.org, linux-erofs@lists•ozlabs.org,
davem@davemloft•net, mhocko@suse•com, kvm@vger•kernel.org,
mst@redhat•com, peterz@infradead•org, bigeasy@linutronix•de,
alexandre.torgue@foss•st.com, dhowells@redhat•com,
linux-mm@kvack•org, ray.huang@amd•com, adilger.kernel@dilger•ca,
kuba@kernel•org, sparclinux@vger•kernel.org, airlied@gmail•com,
anton.ivanov@cambridge greys.com, herbert@gondor•apana.org.au,
linux-scsi@vger•kernel.org, richard@nod•at, x86@kernel•org,
vkoul@kernel•org, mingo@redhat•com, axelrasmussen@google•com,
intel-gfx@lists•freedesktop.org, daniel@ffwll•ch,
paulmck@kernel•org, jannh@google•com, chao@kernel•org,
maarten.lankhorst@linux•intel.com, liam.howlett@oracle•com,
hdegoede@redhat•com, linux-mediatek@lists•infradead.org,
matthias.bgg@gmail•com, vbabka@suse•cz, dimitri.sivanich@hpe•com,
amd-gfx@lists•freedesktop.org, posk@google•com,
lstoakes@gmail•com, peterjung1337@gmail•com,
yoshfuji@linux-ipv6•org, linuxppc-dev@lists•ozlabs.org,
dsahern@kernel•org, kent.overstreet@linux•dev,
kexec@lists•infradead.org, tiwai@suse•com,
krzysztof.kozlowski@linaro•org, tzimmermann@suse•de,
hannes@cmpxchg•org, dmitry.baryshkov@linaro•org,
johannes@sipsolutions•net, mgorman@techsingularity•net,
linux-accelerators@lists•ozlabs.org, l.stach@pengutronix•de
Subject: [PATCH v2 1/6] mm: introduce vma->vm_flags modifier functions
Date: Wed, 25 Jan 2023 00:38:46 -0800 [thread overview]
Message-ID: <20230125083851.27759-2-surenb@google.com> (raw)
In-Reply-To: <20230125083851.27759-1-surenb@google.com>
vm_flags are among VMA attributes which affect decisions like VMA merging
and splitting. Therefore all vm_flags modifications are performed after
taking exclusive mmap_lock to prevent vm_flags updates racing with such
operations. Introduce modifier functions for vm_flags to be used whenever
flags are updated. This way we can better check and control correct
locking behavior during these updates.
Signed-off-by: Suren Baghdasaryan <surenb@google•com>
---
include/linux/mm.h | 37 +++++++++++++++++++++++++++++++++++++
include/linux/mm_types.h | 8 +++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index c2f62bdce134..b71f2809caac 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -627,6 +627,43 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
INIT_LIST_HEAD(&vma->anon_vma_chain);
}
+/* Use when VMA is not part of the VMA tree and needs no locking */
+static inline void init_vm_flags(struct vm_area_struct *vma,
+ unsigned long flags)
+{
+ vma->vm_flags = flags;
+}
+
+/* Use when VMA is part of the VMA tree and modifications need coordination */
+static inline void reset_vm_flags(struct vm_area_struct *vma,
+ unsigned long flags)
+{
+ mmap_assert_write_locked(vma->vm_mm);
+ init_vm_flags(vma, flags);
+}
+
+static inline void set_vm_flags(struct vm_area_struct *vma,
+ unsigned long flags)
+{
+ mmap_assert_write_locked(vma->vm_mm);
+ vma->vm_flags |= flags;
+}
+
+static inline void clear_vm_flags(struct vm_area_struct *vma,
+ unsigned long flags)
+{
+ mmap_assert_write_locked(vma->vm_mm);
+ vma->vm_flags &= ~flags;
+}
+
+static inline void mod_vm_flags(struct vm_area_struct *vma,
+ unsigned long set, unsigned long clear)
+{
+ mmap_assert_write_locked(vma->vm_mm);
+ vma->vm_flags |= set;
+ vma->vm_flags &= ~clear;
+}
+
static inline void vma_set_anonymous(struct vm_area_struct *vma)
{
vma->vm_ops = NULL;
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 2d6d790d9bed..6c7c70bf50dd 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -491,7 +491,13 @@ struct vm_area_struct {
* See vmf_insert_mixed_prot() for discussion.
*/
pgprot_t vm_page_prot;
- unsigned long vm_flags; /* Flags, see mm.h. */
+
+ /*
+ * Flags, see mm.h.
+ * WARNING! Do not modify directly.
+ * Use {init|reset|set|clear|mod}_vm_flags() functions instead.
+ */
+ unsigned long vm_flags;
/*
* For areas with an address space and backing store,
--
2.39.1
next prev parent reply other threads:[~2023-01-25 11:51 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-25 8:38 [PATCH v2 0/6] introduce vm_flags modifier functions Suren Baghdasaryan
2023-01-25 8:38 ` Suren Baghdasaryan [this message]
2023-01-25 8:56 ` [PATCH v2 1/6] mm: introduce vma->vm_flags " Michal Hocko
2023-01-25 9:09 ` Peter Zijlstra
2023-01-25 16:49 ` Suren Baghdasaryan
2023-01-25 18:37 ` Matthew Wilcox
2023-01-25 19:21 ` Suren Baghdasaryan
2023-01-25 18:33 ` Matthew Wilcox
2023-01-25 19:22 ` Suren Baghdasaryan
2023-01-26 9:17 ` Mike Rapoport
2023-01-26 14:50 ` Mike Rapoport
2023-01-26 15:09 ` Matthew Wilcox
2023-01-26 16:25 ` Suren Baghdasaryan
2023-01-25 8:38 ` [PATCH v2 2/6] mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK Suren Baghdasaryan
2023-01-25 9:02 ` Michal Hocko
2023-01-26 9:19 ` Mike Rapoport
2023-01-25 8:38 ` [PATCH v2 3/6] mm: replace vma->vm_flags direct modifications with modifier calls Suren Baghdasaryan
2023-01-25 9:30 ` Michal Hocko
2023-01-25 16:55 ` Suren Baghdasaryan
2023-01-26 9:21 ` Mike Rapoport
2023-01-26 17:07 ` Sebastian Reichel
2023-01-25 8:38 ` [PATCH v2 4/6] mm: replace vma->vm_flags indirect modification in ksm_madvise Suren Baghdasaryan
2023-01-25 9:38 ` Michal Hocko
2023-01-25 16:57 ` Suren Baghdasaryan
2023-01-25 17:08 ` Michal Hocko
2023-01-25 17:22 ` Suren Baghdasaryan
2023-01-26 9:26 ` Mike Rapoport
2023-01-25 8:38 ` [PATCH v2 5/6] mm: introduce mod_vm_flags_nolock and use it in untrack_pfn Suren Baghdasaryan
2023-01-25 9:42 ` Michal Hocko
2023-01-25 17:00 ` Suren Baghdasaryan
2023-01-26 9:34 ` Mike Rapoport
2023-01-25 8:38 ` [PATCH v2 6/6] mm: export dump_mm() Suren Baghdasaryan
2023-01-25 9:43 ` Michal Hocko
2023-01-26 14:48 ` Mike Rapoport
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=20230125083851.27759-2-surenb@google.com \
--to=surenb@google$(echo .)com \
--cc=akpm@linux-foundation$(echo .)org \
--cc=alex.williamson@redhat$(echo .)com \
--cc=aneesh.kumar@linux$(echo .)ibm.com \
--cc=arjunroy@google$(echo .)com \
--cc=chenhuacai@kernel$(echo .)org \
--cc=devel@lists$(echo .)orangefs.org \
--cc=dri-devel@lists$(echo .)freedesktop.org \
--cc=etnaviv@lists$(echo .)freedesktop.org \
--cc=gthelen@google$(echo .)com \
--cc=heiko@sntech$(echo .)de \
--cc=jglisse@google$(echo .)com \
--cc=kasan-dev@googlegroups$(echo .)com \
--cc=ldufour@linux$(echo .)ibm.com \
--cc=leewalsh@google$(echo .)com \
--cc=linux-acpi@vger$(echo .)kernel.org \
--cc=linux-arch@vger$(echo .)kernel.org \
--cc=linux-crypto@vger$(echo .)kernel.org \
--cc=linux-fsdevel@vger$(echo .)kernel.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-media@vger$(echo .)k \
--cc=linux-perf-users@vger$(echo .)kernel.org \
--cc=linux-samsung-soc@vger$(echo .)kernel.org \
--cc=linux-sgx@vger$(echo .)kernel.org \
--cc=linux-um@lists$(echo .)infradead.org \
--cc=linux-usb@vger$(echo .)kernel.org \
--cc=luto@kernel$(echo .)org \
--cc=m.szyprowski@samsung$(echo .)com \
--cc=martin.petersen@oracle$(echo .)com \
--cc=michel@lespinasse$(echo .)org \
--cc=minchan@google$(echo .)com \
--cc=npiggin@gmail$(echo .)com \
--cc=nvdimm@lists$(echo .)linux.dev \
--cc=perex@perex$(echo .)cz \
--cc=qianweili@huawei$(echo .)com \
--cc=rientjes@google$(echo .)com \
--cc=robdclark@gmail$(echo .)com \
--cc=robert.jarzmik@free$(echo .)fr \
--cc=tglx@linutronix$(echo .)de \
--cc=viro@zeniv$(echo .)linux.org.uk \
--cc=xen-devel@lists$(echo .)xenproject.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