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=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 2FFB8C54FCB for ; Wed, 22 Apr 2020 18:01:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB6DE2082E for ; Wed, 22 Apr 2020 18:01:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cL4XfOMR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB6DE2082E 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 85E558E0005; Wed, 22 Apr 2020 14:01:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 835A18E0003; Wed, 22 Apr 2020 14:01:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74B4C8E0005; Wed, 22 Apr 2020 14:01:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 5C63F8E0003 for ; Wed, 22 Apr 2020 14:01:57 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 189228158 for ; Wed, 22 Apr 2020 18:01:57 +0000 (UTC) X-FDA: 76736259474.18.bulb94_4b34a44d0eb60 X-HE-Tag: bulb94_4b34a44d0eb60 X-Filterd-Recvd-Size: 4863 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 18:01:56 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id g4so3336361ljl.2 for ; Wed, 22 Apr 2020 11:01:56 -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=VeICkZcacX5o5DfIzM6geA/GUL/N+krHSEmjMqZ24Ck=; b=cL4XfOMRgrSEemK6NhlwLMnQug9WZa18bhIbX62Kuv//MMo/AbdFk7SezdnPca2O6j 7Z98w0ubkPO7fv98GDmkR/MoSl9cfL0Tcvs92lqyqx8RfgALPRIw7IssCtZZ3wFe9zJJ bfi4qrCpsmOag4OR1QHluehtfQE/oHErG8BFd1HmHFdhj+yVtenXBTciJQ864x6wipD6 cTzANHcDT4OXVOurM+RCx3wWYGawzR0anSa2YE4c6puLTIA9aIF8yMjgB7tmMkT+vw2J KnyQeGNi4hAiYt2r0u5LrazJnVwzSDjFXg95O4uEtTU5RRVPffX+jKrcmLxg0Y9alJJ+ WLGA== 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=VeICkZcacX5o5DfIzM6geA/GUL/N+krHSEmjMqZ24Ck=; b=TZztXCBbQ2le1ranu5GDZ/rpLjXwdhfg1IeaH9NJNuzTOnM+1JCBDfVkbngIyC0spO 70b5y041mivdPEChp/1Cv2B+UrK3aou6G5NV6RSFvrJVTRcfdui/zGQYJZSrEDiEeMiY TC5e21tp4K9ImSktCog3ndPo4DsoESDxJjHVVqtwksU9ZKqsGSJNrWZEiOu8gMFn+Kgc +hO7sn+dHTABbKm4ocLZwAESODDOqzjog0jRR7Bxae5UGtuddULKUz23TkrWeIMGIoAW jjArSFvXqHulUICREePsrhK5RWaMoomUy3OacFihgtjZk1GrZkEJeR/TmzXAa7HIfYK1 kT+g== X-Gm-Message-State: AGi0PuYZIpIqiyH9xQQrwW7bi6C8ET45r1RBsKNg3MWPZftwm51MmwuF gi10P+ARMxNj1mTR0bsEiWBrco5J/FGRU77JOjP/Zg== X-Google-Smtp-Source: APiQypKl3UYhU9fAxPl/IQhzSvDx7R/nce6w2dJxZfvNJTkneHQkG2mQu+SCu00s+rs+TxVR605HW1Re6IhK2rEh0+4= X-Received: by 2002:a2e:b6cf:: with SMTP id m15mr28214ljo.168.1587578514909; Wed, 22 Apr 2020 11:01:54 -0700 (PDT) MIME-Version: 1.0 References: <20200420221126.341272-1-hannes@cmpxchg.org> <20200420221126.341272-3-hannes@cmpxchg.org> <20200422174229.GD362484@cmpxchg.org> In-Reply-To: <20200422174229.GD362484@cmpxchg.org> From: Shakeel Butt Date: Wed, 22 Apr 2020 11:01:42 -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 Wed, Apr 22, 2020 at 10:42 AM Johannes Weiner wrote: > > 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. Thanks for the clarification. I would suggest removing "theoretical" from the subject as it undermines that a real bug is fixed by the patch.