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=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 62125C5518B for ; Wed, 22 Apr 2020 17:42:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E0BA62137B for ; Wed, 22 Apr 2020 17:42:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="SXe+TpnW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0BA62137B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5D5BD8E0005; Wed, 22 Apr 2020 13:42:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AC5F8E0003; Wed, 22 Apr 2020 13:42:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C1E38E0005; Wed, 22 Apr 2020 13:42:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 353328E0003 for ; Wed, 22 Apr 2020 13:42:33 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EC3D8180AD81F for ; Wed, 22 Apr 2020 17:42:32 +0000 (UTC) X-FDA: 76736210544.14.use64_3345c8f540650 X-HE-Tag: use64_3345c8f540650 X-Filterd-Recvd-Size: 4903 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 17:42:32 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id x12so1851062qts.9 for ; Wed, 22 Apr 2020 10:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cjTwD6uKqnZZSCCcyV16R+WZpCxCW7qEmnrNY09I9TU=; b=SXe+TpnWHooh9QOLTZ6dPrc+kEXDChrdMWSwPBBvrbiuRWeGWW4hR03UNURAOWyCOp A1ivM3w+kYgYiUu+raGzagTVxzAhGDXYZcsTCw6/tsVAY3o4o96oA/5u0oHg7RjjMTq9 tgPnfshzSvCpYaPzIkCLITPjO6AAJIMqP3Wky3w89IvCWzujBOauLENhuaU/X8CuKuFB 8EledqZQwjMwAG0LDDP2CO649rhMDeXWU9lcZdD6RFJtGFZVkWheR2JO6HN7ol45mBUs vSj0lAKRCmXtbhp4BRu1PeJvtSagZIOT3/OIgRyEa/DVVTdkukHbVZO6fwxvfFVXDdCc 7YlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cjTwD6uKqnZZSCCcyV16R+WZpCxCW7qEmnrNY09I9TU=; b=LKclIUSxlwA7Oy/UgqyIFiIeSBEQ555CinNYMDpuUE8UmIeIsukWsOfk4xHublHUIc EdrAsoWhRwkDQDM0311GV19hXiPwl1lpXlgZ8FuI/LLMD05jPwn0D8mmK2TUEBbyJI94 8sxwokV7bWaJ6761xkEMmhxAX6Oa7G4Yvc3/S+06S7vYNXTrknKPlZ6yjXlTR4V//lWu oELf7XW+o0NUqkvLgVQxjlOiJuPt/u6GfGHTv+wu1X/zYs3fq3OGgAxa5qNksrFOK49f /0+0pmxKzTC0oIPO6ieSbKhP+TP1RP/VETbNz4GEGZlZz9zykWakQKs8KNafmL3zCwoJ wjzQ== X-Gm-Message-State: AGi0PuY3jlYmJMeRPCC5c8oZmwfhBgZK6xJRF9HI/YNNylRwbDRNRV2Q AfjMc427xgo9Li3lV9XNhQ0aBg== X-Google-Smtp-Source: APiQypLCRW4f/+7KFXIOLDocHwtHxj9EaXuX28tZn0XEH0wFojEsxjsXdo/ovxx6ossCISYPdzFDOQ== X-Received: by 2002:ac8:23e3:: with SMTP id r32mr28222389qtr.268.1587577350782; Wed, 22 Apr 2020 10:42:30 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::921]) by smtp.gmail.com with ESMTPSA id w42sm4577463qtj.63.2020.04.22.10.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 10:42:30 -0700 (PDT) Date: Wed, 22 Apr 2020 13:42:29 -0400 From: Johannes Weiner To: Shakeel Butt Cc: Joonsoo Kim , Alex Shi , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , Linux MM , Cgroups , LKML , Kernel Team Subject: Re: [PATCH 02/18] mm: memcontrol: fix theoretical race in charge moving Message-ID: <20200422174229.GD362484@cmpxchg.org> References: <20200420221126.341272-1-hannes@cmpxchg.org> <20200420221126.341272-3-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Apr 22, 2020 at 09:51:20AM -0700, Shakeel Butt wrote: > On Mon, Apr 20, 2020 at 3:11 PM Johannes Weiner wrote: > > @@ -5426,15 +5420,23 @@ static int mem_cgroup_move_account(struct page *page, > > } > > > > /* > > + * All state has been migrated, let's switch to the new memcg. > > + * > > * It is safe to change page->mem_cgroup here because the page > > - * is referenced, charged, and isolated - we can't race with > > - * uncharging, charging, migration, or LRU putback. > > + * is referenced, charged, isolated, and locked: we can't race > > + * with (un)charging, migration, LRU putback, or anything else > > + * that would rely on a stable page->mem_cgroup. > > + * > > + * Note that lock_page_memcg is a memcg lock, not a page lock, > > + * to save space. As soon as we switch page->mem_cgroup to a > > + * new memcg that isn't locked, the above state can change > > + * concurrently again. Make sure we're truly done with it. > > */ > > + smp_mb(); > > You said theoretical race in the subject but the above comment > convinced me that smp_mb() is required. So, why is the race still > theoretical? Sorry about the confusion. I said theoretical because I spotted it while thinking about the code. I'm not aware of any real users that suffered the consequences of this race condition. But they could exist in theory :-) I think it's a real bug that needs fixing.