From: Shakeel Butt <shakeelb@google.com>
To: Roman Gushchin <guro@fb.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org, Shakeel Butt <shakeelb@google.com>,
Eric Dumazet <edumazet@google.com>,
Greg Thelen <gthelen@google.com>,
syzbot+13f93c99c06988391efe@syzkaller.appspotmail.com
Subject: [PATCH] mm: memcontrol: fix data race in mem_cgroup_select_victim_node
Date: Mon, 28 Oct 2019 17:54:05 -0700 [thread overview]
Message-ID: <20191029005405.201986-1-shakeelb@google.com> (raw)
Syzbot reported the following bug:
BUG: KCSAN: data-race in mem_cgroup_select_victim_node / mem_cgroup_select_victim_node
write to 0xffff88809fade9b0 of 4 bytes by task 8603 on cpu 0:
mem_cgroup_select_victim_node+0xb5/0x3d0 mm/memcontrol.c:1686
try_to_free_mem_cgroup_pages+0x175/0x4c0 mm/vmscan.c:3376
reclaim_high.constprop.0+0xf7/0x140 mm/memcontrol.c:2349
mem_cgroup_handle_over_high+0x96/0x180 mm/memcontrol.c:2430
tracehook_notify_resume include/linux/tracehook.h:197 [inline]
exit_to_usermode_loop+0x20c/0x2c0 arch/x86/entry/common.c:163
prepare_exit_to_usermode+0x180/0x1a0 arch/x86/entry/common.c:194
swapgs_restore_regs_and_return_to_usermode+0x0/0x40
read to 0xffff88809fade9b0 of 4 bytes by task 7290 on cpu 1:
mem_cgroup_select_victim_node+0x92/0x3d0 mm/memcontrol.c:1675
try_to_free_mem_cgroup_pages+0x175/0x4c0 mm/vmscan.c:3376
reclaim_high.constprop.0+0xf7/0x140 mm/memcontrol.c:2349
mem_cgroup_handle_over_high+0x96/0x180 mm/memcontrol.c:2430
tracehook_notify_resume include/linux/tracehook.h:197 [inline]
exit_to_usermode_loop+0x20c/0x2c0 arch/x86/entry/common.c:163
prepare_exit_to_usermode+0x180/0x1a0 arch/x86/entry/common.c:194
swapgs_restore_regs_and_return_to_usermode+0x0/0x40
mem_cgroup_select_victim_node() can be called concurrently which reads
and modifies memcg->last_scanned_node without any synchrnonization. So,
read and modify memcg->last_scanned_node with READ_ONCE()/WRITE_ONCE()
to stop potential reordering.
Signed-off-by: Shakeel Butt <shakeelb@google.com>
Suggested-by: Eric Dumazet <edumazet@google.com>
Cc: Greg Thelen <gthelen@google.com>
Reported-by: syzbot+13f93c99c06988391efe@syzkaller.appspotmail.com
---
mm/memcontrol.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c4c555055a72..5a06739dd3e4 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1667,7 +1667,7 @@ int mem_cgroup_select_victim_node(struct mem_cgroup *memcg)
int node;
mem_cgroup_may_update_nodemask(memcg);
- node = memcg->last_scanned_node;
+ node = READ_ONCE(memcg->last_scanned_node);
node = next_node_in(node, memcg->scan_nodes);
/*
@@ -1678,7 +1678,7 @@ int mem_cgroup_select_victim_node(struct mem_cgroup *memcg)
if (unlikely(node == MAX_NUMNODES))
node = numa_node_id();
- memcg->last_scanned_node = node;
+ WRITE_ONCE(memcg->last_scanned_node, node);
return node;
}
#else
--
2.24.0.rc0.303.g954a862665-goog
next reply other threads:[~2019-10-29 0:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-29 0:54 Shakeel Butt [this message]
2019-10-29 9:03 ` [PATCH] mm: memcontrol: fix data race in mem_cgroup_select_victim_node Michal Hocko
2019-10-29 18:09 ` Shakeel Butt
2019-10-29 18:28 ` Marco Elver
2019-10-29 18:46 ` Shakeel Butt
2019-10-29 18:34 ` Johannes Weiner
2019-10-29 18:47 ` Shakeel Butt
2019-10-29 18:47 ` Michal Hocko
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=20191029005405.201986-1-shakeelb@google.com \
--to=shakeelb@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=edumazet@google.com \
--cc=gthelen@google.com \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=syzbot+13f93c99c06988391efe@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.