Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp947668ybz; Wed, 22 Apr 2020 10:44:47 -0700 (PDT) X-Google-Smtp-Source: APiQypK+qUKO2I+Iutka6VBHzDGE+VeBiDK8U5A66djQJ+Y9/AaNyxZmW/ceQ7qDLpSIEHIZVdyO X-Received: by 2002:a05:6402:543:: with SMTP id i3mr22816335edx.255.1587577487154; Wed, 22 Apr 2020 10:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587577487; cv=none; d=google.com; s=arc-20160816; b=oW9psS2Hj4X4zENgDifUlCeJ4zDLREotzBrtx4PJxJemqVDfldKq9MCPlSsOzQ2ep+ +vD5P0dApeZKe2sNZ5exmE8/FqGyVSHN+2wzYeCsahp1bl3Cagotp85ICRVzh+e1Szsq Fsba97zoGuuXLb2H2xja60xkQbiinfQ8lVkUXKVmxBmRdQEO4VZaWvmkgok6klhmlAlW oSZjM34ch9jFDwlrzWbmGiMvyurIEAA0dfHbUM72J9CBWJMSSK5Dm7eCS3t3wsfx5NtA IGU/+R5tOMCiv1qH+rhYi+WcyUkXghfOCpt9haUHc3IBNzoYmcUphw7a7tgf4N2ZB5Zk NywA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=cjTwD6uKqnZZSCCcyV16R+WZpCxCW7qEmnrNY09I9TU=; b=V2XINZrUJ8SZxosq4geiGFIs2xIintmN79j7BjXx/jcvzHBmHdy6+XFVUjiday2z5f 3f06OBb7zLKthodZZJictydgMmeEXSHv+kWh3M2k+NSFpFkbZ7suHLaYU7FF/KO4lpg+ UHTFIe6MukzbhxZJdm9JIbJyjMBNw+bdkT6J7qzSzGs1B/uNg30Hs91bQkn4eDnsgJI6 FmSUhb7672fSFh3z1SQVkQbEBMK1tM9dyNbHCAFMY5MIvCNgKA2VNxc/3LbLDLvY+LBc 680nVVzODt9rH1ygpsmHmLc9nZielIOHCtTO/UkSlX9z8it3nV7DJVQnO7at5pjk0hZd tb1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=SXe+TpnW; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cm6si3726567edb.71.2020.04.22.10.44.24; Wed, 22 Apr 2020 10:44:47 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=SXe+TpnW; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726335AbgDVRmc (ORCPT + 99 others); Wed, 22 Apr 2020 13:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726100AbgDVRmb (ORCPT ); Wed, 22 Apr 2020 13:42:31 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC945C03C1AA for ; Wed, 22 Apr 2020 10:42:31 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id l13so2370801qtr.7 for ; Wed, 22 Apr 2020 10:42:31 -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=rp9bqRvhG7k2POv2Wd8kVJEIPieSk56AaGViNMF2avAhZ837odxOTr9dXKcF74FKt1 Jtpl3XQNjlSW6Td/jluK24qM6fQ0pqg15IdvZiCjpiCqwRwRgqvdUtHXk/zIEozMP/Qs Q3YoBG6d+ocX9cthXJj08Yi+nmxndAlqwRt5WS3urNvtBG2GyOQZZGuG6KQnuxRNx7sA HUpc/JPyUn1FoGIYl1L5jYkitphjmNC2Z/8vmvqvF0T9xuvAcZKvdhaAtCfFlKQtPOMx duO3FhCqXuMSQ6Qci2Sq2exbJ23bxlkQ/jJk2lUdZt1MfTtwcA+YJSi/NAA2Z11jPirK Ko2g== X-Gm-Message-State: AGi0PubzCGgZdAFE/0J9xVulKDfY/ksx9GCwMzA7SAQZpNJyGrzaekHn sLIoFGoIJSgtBMN35DuyVg2Srg== 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: 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 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.