Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp105185ybx; Tue, 29 Oct 2019 15:07:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBQ142gGN17OFDBrf9dmVjt233VsCVEjd4dgOVYZXJGWJCxI4ugegQpTX8dzLHCrnyErdo X-Received: by 2002:a17:906:2d68:: with SMTP id f8mr5667600eji.71.1572386869638; Tue, 29 Oct 2019 15:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572386869; cv=none; d=google.com; s=arc-20160816; b=QI6xUTKri9q1Kiyv1HAmFMZVGGuKWZqBxwSpDxaiEShS2ZQqD5YzHHyReFRCYRntwR zj6pgb9XaQBU9fC33rBkqsC4MzPyIKpIz3X3GsSfD/PvERAFyZlJkJJ8pPjzx9wlBIEy 7NZ6wuEuldhfc4Hs3No58S5m88acMTgACJ1Aq+X0hd2jjMdcmW8ef3hnR+tAfcbNyBWP pTo4hbgLH5sFhmGdE0NBstb7j8mh3/nwM+yRRyrDkbsS6zSkRk/4gT2En/VY+qCNjYK6 Y8xtx2y0jbp5VGzs+K+i2GUmziHAKu1pqBHy3Gks+eTy0oB+pmJJGRIny9mK7Szgp9m0 5pUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qjPIA2E/5Fq521b+ML0SLUvafFSbqxin1BmVqwTUyt8=; b=hey0WJYvtgulY4xdLn4jQ/ui6RsvntqzoBCEYtppvVksiYms2Tm3B5KhrKYiydiWKO QWqtZZIMnlHGINznnPbTZJS9mfEEmmvZXOqThkY7T7Vt0Pgrd3o8C6bCDA0KcKt3U6ih M33bMpiZOT1WhY/VD4EcbIQ1gi8M9hDLh9OlTtCSXRzdEPAgKEgaCWDwYBn1uWFMeij/ sXML6Ab7UuDPyj1R5wrsfkfq5zZ62RVKFCjsb8EpY5O4RtgJabXBwWfl6pB8UUK01ltY Mo3ArsvQGNG8DLaPBUzGlHOQbufc/mlHwW8g3BhomIAVmm4vYs0Yx3HgmPLuBS4xKIlx NmXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GEgloQHT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w20si51926edc.397.2019.10.29.15.07.26; Tue, 29 Oct 2019 15:07:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GEgloQHT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730600AbfJ2SJl (ORCPT + 99 others); Tue, 29 Oct 2019 14:09:41 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:37329 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbfJ2SJl (ORCPT ); Tue, 29 Oct 2019 14:09:41 -0400 Received: by mail-oi1-f193.google.com with SMTP id y194so5165635oie.4 for ; Tue, 29 Oct 2019 11:09:40 -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=dRVt/y6u9QS/KpHVTX51p6oftUPC5/MXJygYjCLK4oOuaCkVZY+FwJ7svxW6qbDhGf t9n7nLpPL27nCnhZelT/jnrvpxHhanuzVYQym7rbq00vJS+tIuruizZrYOYWez5Nyilo dpshLluuxMvDjlnN7JzUQZwWRszUY9yqp02LxSbzb/mb4uAgu/KKsbmieK07LYQO+mHr h9s7TzdV/tfJlq+il9LT47MYp9dfxr01ucYLO8pniOB72TUjrk0JR//P7aRkhBjLv7Jn 2vZb52pqEM/EAKWCmQ78O9OhsU3mvuE79ZpEnPUI3EaYxMvs8jZB/XImnigWFtTPIJZp PSdQ== X-Gm-Message-State: APjAAAXO7R3iCMyPDH53Qgf2hwtZfMUjWIryBJQ/C3n6qsd01wuQtd1/ NzXZDZYsOYVKTNcxUDTN4ahsBuxeT+1icrxNzFgrfA== 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +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