Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp965547ybz; Wed, 22 Apr 2020 11:05:08 -0700 (PDT) X-Google-Smtp-Source: APiQypICiNi6NmIAP953dOm8XRE/lMQ0OQgPMxQ7k8+vWkKpVD1v56J9bqlw+0L/ENm8E2XQ5Fib X-Received: by 2002:a50:e8cb:: with SMTP id l11mr25538484edn.174.1587578707885; Wed, 22 Apr 2020 11:05:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587578707; cv=none; d=google.com; s=arc-20160816; b=X6oZSdHc7MvhGSSScl+4yM2i2bbBLMEZb9GX8ihMOJ4XppUo7TgdwSFgGjlIq0WO9i 05DpgwvUVZVQ0W9endQN0LWFMjSrG2M9pJ682kI00UV8B1DvvU98UbF2mwJGsETuUPsN aG5Sjd7lbT9/a4Rk7sbjaOLA5WZm25pmh1vwlzuT8FN0c5SeJLQuV+y/ye/cDgKYVrg4 lFA0E/97oKMpcs6s1kuLb5bLwTeFz3KvVFVV/aqeTEa8os1aUTUPhOTCqTFkeMe9jTOf 9OVJDU+3v3PLxoCv1nZ6mNQtL2DpM9QOcEkiWsB3ZdOs3HF/f6hEz8pfo7VE07Gje7NZ i9sQ== 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=OxPQfRGdb/9tZKOeYvx9nsO533AAnUsM72YkEAHTBCI=; b=GnhMgjLz3xqiDynnLheISxU0jnl5IGQPN/m14Ds2tVqZ3UxK8MStlxfFufw8uGTA2S P4XEXKhKJazd4R7ymwxo+0h1VvOuHKDV3KBSO8e8eYziY9RHM0/k8BLC9Ksdoi9tL/NC qbSxfQfhj/OFXjW9dXt3gkDVWOCrv/1DZfUX5yMeDFdmhP9GV8kydFJIwwyiv+nyLWLA cP4NY0IhbM3gmdJc8nPtdJyqTmw846rZB1V34sFbKVb2dy3fHgF8HtTgVcueTb9cIRFD AazCYSCQiO85aTnXyzbVskn4s6Mcs6K/4W0EKPdSrqU8shUf7WfzQsyZfve0tzz6KZ1v qD5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MtBnqEYd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id r24si3744614edm.269.2020.04.22.11.04.39; Wed, 22 Apr 2020 11:05:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MtBnqEYd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726942AbgDVSCg (ORCPT + 99 others); Wed, 22 Apr 2020 14:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726924AbgDVSCg (ORCPT ); Wed, 22 Apr 2020 14:02:36 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE41AC03C1A9 for ; Wed, 22 Apr 2020 11:02:35 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id g4so3338707ljl.2 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=TgXgWMHvRJrILc+KhVew6dHXcBkAR/+Iw5bAOrPmsMRC+B6U8Tg1qYW/TWbmhHoqVC 2TOYp9Zt+BgnXsTqnI5nhhIR7P8pApkxbivE4rgmfNd8mmy1c3KqfDl/eyNM3CLYWQ+R 0bZ6CvLA1sSBEkpyXsJdF8Nq2d3+c6PeffWCt0RcSLD8C6DYbfragJGR4fcZGS2lCmSB EYB0FX/NNhu9dTIQNu+80+2zjakxYnY+gydoDkmV+bh8xBJ12renIsZo+0PFK0WncpkZ JRu7icw54ygQ34Wlk0tqGX2kvTycvixb+rD+uh6fAWMfCKUHVR3lIyaCM1phPZuQpUPR EvrA== X-Gm-Message-State: AGi0Pub77xBPYN7WHwa8VWWrDE+y0tIdM/wBqnVenYE3XeTGhBd1y7cW jYbe3rMVtGBkm7y/t+Ox4syGdynL/VB3vNaPdiFT2w== 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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