Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp964147ybz; Wed, 22 Apr 2020 11:03:47 -0700 (PDT) X-Google-Smtp-Source: APiQypLcGH87+cgssBW/JpK3ezC68nhDcT7idr9Wvufv+r8gLYYLz98+2OPhFcwVicH9GZLz6K6i X-Received: by 2002:aa7:db41:: with SMTP id n1mr10339500edt.314.1587578627011; Wed, 22 Apr 2020 11:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587578627; cv=none; d=google.com; s=arc-20160816; b=W5jJgawCqdrA9Yb46cejoUL3vB8v6xZwm17v8afx+JftIfJ9pB4e5XQsOvWUNHtM8i SEq2NcC62t4uag30UhEwt2SoXr2qxofmtKkrC5r7t1UDa4x8f37cDyZ8aMQeAF0mxxU2 utdauBdTas2GLFfb8/Z0cXBH6uEWtTueiGFD2GeAlp+YlnJsMjXRy+bo6ZdDsO6lYjeR 8MWdvOmkzLgG0fcWpfhZ70gVq458cf63jVkPvNkyLsb47uT0u9sgEnI+Aif4XQ1b+ZWB vLLMJwLis2WECGNP95nNnBKp3/OhnOa6hGOeBNs1QiGZ5TBJEj6/SyWXToD+9VEEec/a 02lA== 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=VeICkZcacX5o5DfIzM6geA/GUL/N+krHSEmjMqZ24Ck=; b=eUSkiS1QB4mJH+0HKyiVAub2okZXir4qPd6jPkFAjvO2+L+6orbYZ3oAGCjSm5kI/B Xch6K6Wdk0eXrAhOV55SGIUxgaEiTRfQP/HMHGH4MPVP+fOOwpHuB8zOBeXI1BH1GLPs bkRmfMJyI5A/ybY/5pNcu3n9pGMY46hsWYI8YV2zMoJmcbBBiRLL8lr+kzB8rpoZr2QJ IlFvesD/kD2/ql2gA7FqH/ou7Cg735yILKMIgLHgUMHKgjYsUc8e4Dw57yMM9KDaBaNz wRig3zNzd+A3fBbaX7qZtGrHjo59lmaWVn+7wD/1yLPDDm56q+FHEzqyHJAYfDWj4CmV 6t1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cL4XfOMR; 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 z9si2045189edi.150.2020.04.22.11.03.12; Wed, 22 Apr 2020 11:03:46 -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=cL4XfOMR; 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 S1726760AbgDVSB6 (ORCPT + 99 others); Wed, 22 Apr 2020 14:01:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726698AbgDVSB5 (ORCPT ); Wed, 22 Apr 2020 14:01:57 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6328C03C1AA for ; Wed, 22 Apr 2020 11:01:56 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id w20so3351543ljj.0 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=O/XajnzG5twb/VP4tVGFwrmfDMFGNglMbJk3OXRJ0ZMaz49RBoXoADp8z5zYrLIclw kgBoZj2Rr0NisVX5I6wgZcQVVcg8UXL0+ReOAeOp9GaeipZ4hYd9KzfYIXNKeruRAUW7 zemFNAHP19JKdeObsUM9DDLNV63MOCN/OA3HkjWH/C6hBZCtm0DLxTUSr6FbelNhVSfE SEzSnGAZ6t2VJVbCMsJgoqiLiyyb7AcQ/YqjbB7pQgkoD4tCZA7vv0v76SH6+Mm1gkYA vktNXxwxLoEhrYnx1bLacBi5S5YHD4Q3sXQfsSs45MGoEIhdtICDULlrk30PczpqOt9W bxVg== X-Gm-Message-State: AGi0PuYxhsVGb2CMarQybYUk6aNEiB0BthIvBjNLfCmlEqLU21ZB2daS pBY3xdrrxJC/XBNrnFObUUrOxzJKUQQ+eDDPzVfP/g== 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.