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=-11.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 18FEAC55185 for ; Wed, 22 Apr 2020 18:02:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE8FE2076E for ; Wed, 22 Apr 2020 18:02:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MtBnqEYd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE8FE2076E 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 577CD8E0006; Wed, 22 Apr 2020 14:02:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 501488E0003; Wed, 22 Apr 2020 14:02:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C9768E0006; Wed, 22 Apr 2020 14:02:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 1F66E8E0003 for ; Wed, 22 Apr 2020 14:02:36 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D640983F1 for ; Wed, 22 Apr 2020 18:02:35 +0000 (UTC) X-FDA: 76736261070.19.wax45_50d92c298fe30 X-HE-Tag: wax45_50d92c298fe30 X-Filterd-Recvd-Size: 3915 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 18:02:35 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id w20so3353828ljj.0 for ; Wed, 22 Apr 2020 11:02:35 -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=OxPQfRGdb/9tZKOeYvx9nsO533AAnUsM72YkEAHTBCI=; b=MtBnqEYdd89iXzsWZUzdrGnwyjo111BKIiu7L3ZHWXsQEJMUCoEyKDRbJIyIbEZ0UL DV3+yaBUmM6gMxXui+ZOIe6OyD7VtRJ23975UXk+/Wj0COST+PbV9MJTROveWW0bw2T7 GtXFKn4EezlfKVlwrZaFUmoy/J+Vyg0tVlz69s+eov79IvvYBC6QTV2+OAVc8P/TxcAB A8+D4KWyIqFJwYB36BbmoTeDFQv2oa4PzTVNJUV6suxSZPhHbZMiB3N4XCK8SMiAZedT H6oGGCppXSeyYI9Pa+3Rc/6Drhivl0uuWfd0hsHATauPrPn70QbuvXx3LUDAOw5klFM8 xeuw== 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=OxPQfRGdb/9tZKOeYvx9nsO533AAnUsM72YkEAHTBCI=; b=tgK8rkQdLXcmZsUrHMuSNY8NTTV2W1GnYKPNLFYp8DfoeC5OAmCdLktmGE3CIvVLvm UoVzB33CER+Mcru7xdv362Q3qHibsVfJtmnh4gt7fxUVmhU+pAd++xGup70fei2QSufV N89axhoOCo5Q4cQn3zz9vXPd4nM1IUMBSipi9W2DQwpYl1w7qUuVbboGjAMZTlY+D3Te v+iORawBs7pP4JTu+spr50g0F+RZ4HiikaGAiezRwWFSbQL2dc13DYX5dphC3foHFB3k UTL1rzYmsBs9L9a0Q7T252MFm18c1QAtldFTAOe/wgvjzeTplEzEc8qhWlkzCgYBANPN 1aDg== X-Gm-Message-State: AGi0PuY68sjczPa6AGTfA01tHUw71Q/3WYKrMxaOFOhoh4AnRbCQ1Hu2 1RQsF8yMuJuDu3oE0qLVs9xbC4Rr/mlJJAuuwkKwAw== X-Google-Smtp-Source: APiQypKntPoBdVTS/8WRMaXpnY/jdYe0MPd3EYScD5Cm/9aT/zP0pcWdgKz8DqlIB8lwr7cYH+N/ASnro4D3GssV3l8= X-Received: by 2002:a05:651c:1209:: with SMTP id i9mr21615lja.250.1587578553958; Wed, 22 Apr 2020 11:02:33 -0700 (PDT) MIME-Version: 1.0 References: <20200420221126.341272-1-hannes@cmpxchg.org> <20200420221126.341272-3-hannes@cmpxchg.org> In-Reply-To: <20200420221126.341272-3-hannes@cmpxchg.org> From: Shakeel Butt Date: Wed, 22 Apr 2020 11:02:22 -0700 Message-ID: Subject: Re: [PATCH 02/18] mm: memcontrol: fix theoretical race in charge moving To: Johannes Weiner Cc: Joonsoo Kim , Alex Shi , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , Linux MM , Cgroups , LKML , Kernel Team 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: On Mon, Apr 20, 2020 at 3:11 PM Johannes Weiner wrote: > > The move_lock is a per-memcg lock, but the VM accounting code that > needs to acquire it comes from the page and follows page->mem_cgroup > under RCU protection. That means that the page becomes unlocked not > when we drop the move_lock, but when we update page->mem_cgroup. And > that assignment doesn't imply any memory ordering. If that pointer > write gets reordered against the reads of the page state - > page_mapped, PageDirty etc. the state may change while we rely on it > being stable and we can end up corrupting the counters. > > Place an SMP memory barrier to make sure we're done with all page > state by the time the new page->mem_cgroup becomes visible. > > Also replace the open-coded move_lock with a lock_page_memcg() to make > it more obvious what we're serializing against. > > Signed-off-by: Johannes Weiner Reviewed-by: Shakeel Butt