linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mempolicy: fix lock contention on mems_allowed
@ 2022-08-09 10:49 Abel Wu
  2022-08-09 12:11 ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Abel Wu @ 2022-08-09 10:49 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka, Michal Hocko, Mel Gorman, Muchun Song
  Cc: linux-mm, linux-kernel, Abel Wu

The mems_allowed field can be modified by other tasks, so it
isn't safe to access it with alloc_lock unlocked even in the
current process context.

Fixes: 78b132e9bae9 ("mm/mempolicy: remove or narrow the lock on current")
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
---
 mm/mempolicy.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index d39b01fd52fe..ae422e44affb 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -855,12 +855,14 @@ static long do_set_mempolicy(unsigned short mode, unsigned short flags,
 		goto out;
 	}
 
+	task_lock(current);
 	ret = mpol_set_nodemask(new, nodes, scratch);
 	if (ret) {
+		task_unlock(current);
 		mpol_put(new);
 		goto out;
 	}
-	task_lock(current);
+
 	old = current->mempolicy;
 	current->mempolicy = new;
 	if (new && new->mode == MPOL_INTERLEAVE)
@@ -1295,7 +1297,9 @@ static long do_mbind(unsigned long start, unsigned long len,
 		NODEMASK_SCRATCH(scratch);
 		if (scratch) {
 			mmap_write_lock(mm);
+			task_lock(current);
 			err = mpol_set_nodemask(new, nmask, scratch);
+			task_unlock(current);
 			if (err)
 				mmap_write_unlock(mm);
 		} else
-- 
2.31.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-11  9:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 10:49 [PATCH] mm/mempolicy: fix lock contention on mems_allowed Abel Wu
2022-08-09 12:11 ` Michal Hocko
2022-08-11  8:43   ` Abel Wu
2022-08-11  9:09     ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox