From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johannes Weiner Subject: Re: [PATCH 02/18] mm: memcontrol: fix theoretical race in charge moving Date: Wed, 22 Apr 2020 13:42:29 -0400 Message-ID: <20200422174229.GD362484@cmpxchg.org> References: <20200420221126.341272-1-hannes@cmpxchg.org> <20200420221126.341272-3-hannes@cmpxchg.org> Mime-Version: 1.0 Return-path: 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== Content-Disposition: inline In-Reply-To: Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Shakeel Butt Cc: Joonsoo Kim , Alex Shi , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , Linux MM , Cgroups , LKML , Kernel Team 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.