public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
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,
	42.hyeyoo@gmail•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@te chsingularity.net,
	rppt@kernel•org
Subject: [PATCH 1/1] mm: introduce vm_flags_reset_once to replace WRITE_ONCE vm_flags updates
Date: Tue, 31 Jan 2023 16:01:16 -0800	[thread overview]
Message-ID: <20230201000116.1333160-1-surenb@google.com> (raw)

Provide vm_flags_reset_once() and replace the vm_flags updates which used
WRITE_ONCE() to prevent compiler optimizations.

Fixes: 0cce31a0aa0e ("mm: replace vma->vm_flags direct modifications with modifier calls")
Reported-by: Hyeonggon Yoo <42.hyeyoo@gmail•com>
Signed-off-by: Suren Baghdasaryan <surenb@google•com>
---
Notes:
- The patch applies cleanly over mm-unstable
- The SHA in Fixes: line is from mm-unstable, so is... unstable

 include/linux/mm.h | 7 +++++++
 mm/mlock.c         | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 5bf0ad48faaa..23ce04f6e91e 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -648,6 +648,13 @@ static inline void vm_flags_reset(struct vm_area_struct *vma,
 	vm_flags_init(vma, flags);
 }
 
+static inline void vm_flags_reset_once(struct vm_area_struct *vma,
+				       vm_flags_t flags)
+{
+	mmap_assert_write_locked(vma->vm_mm);
+	WRITE_ONCE(ACCESS_PRIVATE(vma, __vm_flags), flags);
+}
+
 static inline void vm_flags_set(struct vm_area_struct *vma,
 				vm_flags_t flags)
 {
diff --git a/mm/mlock.c b/mm/mlock.c
index ed49459e343e..617469fce96d 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -380,7 +380,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 	 */
 	if (newflags & VM_LOCKED)
 		newflags |= VM_IO;
-	vm_flags_reset(vma, newflags);
+	vm_flags_reset_once(vma, newflags);
 
 	lru_add_drain();
 	walk_page_range(vma->vm_mm, start, end, &mlock_walk_ops, NULL);
@@ -388,7 +388,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 
 	if (newflags & VM_IO) {
 		newflags &= ~VM_IO;
-		vm_flags_reset(vma, newflags);
+		vm_flags_reset_once(vma, newflags);
 	}
 }
 
-- 
2.39.1.456.gfc5497dd1b-goog


             reply	other threads:[~2023-02-01  0:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01  0:01 Suren Baghdasaryan [this message]
2023-02-01  7:43 ` [PATCH 1/1] mm: introduce vm_flags_reset_once to replace WRITE_ONCE vm_flags updates Michal Hocko
2023-02-08  1:46 ` Hyeonggon Yoo

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=20230201000116.1333160-1-surenb@google.com \
    --to=surenb@google$(echo .)com \
    --cc=42.hyeyoo@gmail$(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@te \
    --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