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.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 F04BACA9EC4 for ; Tue, 29 Oct 2019 18:09:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A802A208E3 for ; Tue, 29 Oct 2019 18:09:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GEgloQHT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A802A208E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 550326B0006; Tue, 29 Oct 2019 14:09:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FDF36B0008; Tue, 29 Oct 2019 14:09:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ECBF6B000A; Tue, 29 Oct 2019 14:09:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 186C56B0006 for ; Tue, 29 Oct 2019 14:09:42 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id B135D6125 for ; Tue, 29 Oct 2019 18:09:41 +0000 (UTC) X-FDA: 76097610162.20.sack61_5498a140b9015 X-HE-Tag: sack61_5498a140b9015 X-Filterd-Recvd-Size: 5783 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 18:09:41 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id k2so4626701oij.12 for ; Tue, 29 Oct 2019 11:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qjPIA2E/5Fq521b+ML0SLUvafFSbqxin1BmVqwTUyt8=; b=GEgloQHTa6D4+gvI9CNAFRP6KGQEIM5wYH9xmQxYFJxfmoN/S3HWvbO9fc4WkqwO8K MG7DPxKv6o190npOhAGGHq3gCmMduti7dve9KfbZB2DfW36Cuq4+A1E7qa9lGiGGpeP9 7c3IlpH2WU+nd0YxdB7l0cCemIePL2VcRnTvilGoBfIzq/WNuOI+XckME9mhWzF6B8SQ sMHJ5zTJyG6lFU+MIp78cZLi9LgZGLJuBMm8KE6loBZqSPX+OG1Wk01Ac9awzUC9hH9s GXfrdcRAhmPUrh/5C6lfXiyTDhZd3J+C3rphT1vV0JR6Zx0HuunJMzyrHMeDp8ZScoWY sehw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qjPIA2E/5Fq521b+ML0SLUvafFSbqxin1BmVqwTUyt8=; b=C3bNwRiTkXIySoNYzZc5AYVcqvuQywWWxPd3C+Rp6veDR9xgffTiRs9fNbWwDy22sU Ecq1BCUeoCPb0WisqSCMDZ/yoS0MpdDC25ot3WKEF+OoPc3nesVsm4LLrtelEhp62RN0 Auv9Bue2Px+5rymv6+9sZyvrPF8nRcmCP24D98aAFTBxYp0pnjLn/otuLvxhTPTBDJdJ oRMa62PFruEJxVV4mW1DuYdnBh0o7WuQBGukKntOyTp3dBvB5CkSEa9KIwpmyuXo5foe /mR1f5iznCcCIo8y3cnWBw3xB/09gnAjKx5ajobI1OypDW3xSdcO/Dd72cNtg7UxnSwx 3cOw== X-Gm-Message-State: APjAAAVJBq/r83pXF50W7i8yg58rQMqQTSp6QX9K4zUupuxlaGHrn4hi ftVddIMPkG5yozDsDY2KslywB737SWbkBpuaou5KfQ== X-Google-Smtp-Source: APXvYqxf+4np1mY9GDrvb3MwI60Z5G648uXhlHqOf9rZZpiCD5i1uBsR6EE+QlrYh1JGuYcUnXUvq7Z+5wJWCE2URVE= X-Received: by 2002:aca:7516:: with SMTP id q22mr5083282oic.144.1572372580060; Tue, 29 Oct 2019 11:09:40 -0700 (PDT) MIME-Version: 1.0 References: <20191029005405.201986-1-shakeelb@google.com> <20191029090347.GG31513@dhcp22.suse.cz> In-Reply-To: <20191029090347.GG31513@dhcp22.suse.cz> From: Shakeel Butt Date: Tue, 29 Oct 2019 11:09:29 -0700 Message-ID: Subject: Re: [PATCH] mm: memcontrol: fix data race in mem_cgroup_select_victim_node To: Michal Hocko Cc: Roman Gushchin , Johannes Weiner , Andrew Morton , Linux MM , Cgroups , LKML , Eric Dumazet , Greg Thelen , syzbot+13f93c99c06988391efe@syzkaller.appspotmail.com, elver@google.com Content-Type: text/plain; charset="UTF-8" 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: +Marco On Tue, Oct 29, 2019 at 2:03 AM Michal Hocko wrote: > > 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? > The problem is memcg->last_scanned_node can read and modified concurrently. Though to me it seems like a tolerable race and not worth to add an explicit lock. My aim was to make KCSAN happy here to look elsewhere for the concurrency bugs. However I see that it might complain next on memcg->scan_nodes. Now taking a step back, I am questioning the whole motivation behind mem_cgroup_select_victim_node(). Since we pass ZONELIST_FALLBACK zonelist to the reclaimer, the shrink_node will be called for all potential nodes. Also we don't short circuit the traversal of shrink_node for all nodes on nr_reclaimed and we scan (size_on_node >> priority) for all nodes, I don't see the reason behind having round robin order of node traversal. I am thinking of removing the whole mem_cgroup_select_victim_node() heuristic. Please let me know if there are any objections. thanks, Shakeel