From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61586CA9EAE for ; Tue, 29 Oct 2019 09:03:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D0C32083E for ; Tue, 29 Oct 2019 09:03:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D0C32083E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D27376B0006; Tue, 29 Oct 2019 05:03:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD81B6B0007; Tue, 29 Oct 2019 05:03:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC6FE6B0008; Tue, 29 Oct 2019 05:03:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 939256B0006 for ; Tue, 29 Oct 2019 05:03:51 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id F18354DDC for ; Tue, 29 Oct 2019 09:03:50 +0000 (UTC) X-FDA: 76096234620.24.horse82_78e18898fea61 X-HE-Tag: horse82_78e18898fea61 X-Filterd-Recvd-Size: 4135 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 09:03:50 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 32C57AE46; Tue, 29 Oct 2019 09:03:49 +0000 (UTC) Date: Tue, 29 Oct 2019 10:03:47 +0100 From: Michal Hocko To: Shakeel Butt Cc: Roman Gushchin , Johannes Weiner , Andrew Morton , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Dumazet , Greg Thelen , syzbot+13f93c99c06988391efe@syzkaller.appspotmail.com Subject: Re: [PATCH] mm: memcontrol: fix data race in mem_cgroup_select_victim_node Message-ID: <20191029090347.GG31513@dhcp22.suse.cz> References: <20191029005405.201986-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191029005405.201986-1-shakeelb@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon 28-10-19 17:54:05, Shakeel Butt wrote: > 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. I am sorry but I do not understand the problem and the fix. Why does the race happen and why does _ONCE fixes it? There is still no synchronization. Do you want to prevent from memcg->last_scanned_node reloading? > Signed-off-by: Shakeel Butt > Suggested-by: Eric Dumazet > Cc: Greg Thelen > 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 -- Michal Hocko SUSE Labs