Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp385361ybz; Tue, 21 Apr 2020 23:38:41 -0700 (PDT) X-Google-Smtp-Source: APiQypJNWJKSu6U3W7gWM2/g8do29wkHDC5zRmnkQe/XzrQz3ZAwWXFO7mZmP6XH23i56KiHHBed X-Received: by 2002:a50:f381:: with SMTP id g1mr9934779edm.219.1587537521593; Tue, 21 Apr 2020 23:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587537521; cv=none; d=google.com; s=arc-20160816; b=E8VlqWu6qqauhI6cvffSBIkyaQFKEjRmvmSGbOOvnZuZ2gGolTWF15ruN2YcxDTrKk qE6nCUo9TvUd/tXlllWNboJo4AwCc8/2yCWfaya8ynWFPpim6l4p0dl+uNQL2lZdrtI+ bxc016JdwPvs5hT3QLiVCHXBdSc2YihUUEgNmeUBdWPU1gSNmNrPoHk2W1V0HjVWzXzc 2R4Fb3N9Tcm5P5yZuop5ilCk4xjAXxyOwietckAbxDz6YPKipG+pV+fmYT5BVguy1mWl N9/ru31UbyIfoJ4V28xIXGTFz2pua78Zt8XTICi2Lr8IvIIqrnaCTkYlpsyFjF4FaP2c dz1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CZSSzJnZ1MHzcmsWtWuWxkow51PnPw2IWZgspST+uVI=; b=sBiOvbjmPOv8tf5xHAWvzwZe5wO8UGuhhLTRwWr9UjuRhTEEN5D2+mdxrA3pJ3GCJf DNueKUDtYhA7gcLlIBi1fwc7qnwEmwz5C830KE0LYr93pga07xz3UY/F10IlFyZJb2k0 EzJ8LOIqQu3Y04Kb67ZVv/afI+h/qxO0Q9AUyR1JNEdzY6AImB0r2CqrzbJmuosuTipP 1RZ5M2ZGhV5TrbM0wyiFDQSrCd4Bvw0TLRh3OMrSx1OHWFx5EedDXF/T2K7sdmOaTuVM EGL0GGRVdminlDDQOL73s7J+uKQLuypiiVn8r+q7c1e5pqSM6fHKs20KZXLY5U9Rk97p FVvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ls5QfuFX; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r15si2797271edx.362.2020.04.21.23.38.18; Tue, 21 Apr 2020 23:38:41 -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=@gmail.com header.s=20161025 header.b=ls5QfuFX; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbgDVGgX (ORCPT + 99 others); Wed, 22 Apr 2020 02:36:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgDVGgW (ORCPT ); Wed, 22 Apr 2020 02:36:22 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8DBC03C1A6; Tue, 21 Apr 2020 23:36:22 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id o185so608467pgo.3; Tue, 21 Apr 2020 23:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CZSSzJnZ1MHzcmsWtWuWxkow51PnPw2IWZgspST+uVI=; b=ls5QfuFXXFiilf45USH7v+eQmuTJ3PHmJP7NplN6QLta76WP1KbKLw2xFzg1bKPU2w 1uNvOi2bCmYUCIcqBXXs/uWK+5EQ5ffvG23l1PRQixBaa8YoNuph7ZYC0E2pKibWqQT+ Kx1AJtKpffeBMLcBkSxf1Y5sqLCxT6289uSxh3vwNepMkHKeN/ufWMIOyFlm+fgvW/ue zuCTlvXNPDYcKZVY2CRsXxlhwYiCZyuPHEPGVdAlkToo0nRZpJcrUXWw/1SSm/oQLrWg OIQ61v4WXvivJqWuxywhk+BZasO3yh5ILcO+0jnXerym2Ch9CAjEZfsfE9PKDZSNOpNY 2Qxw== 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:user-agent; bh=CZSSzJnZ1MHzcmsWtWuWxkow51PnPw2IWZgspST+uVI=; b=k9wK3UtTBGp8zzkysM4mytECpCVI7QxsulksFot7jU4SfUWg4OjquP4aUxEC+lD/ZB 0oZlHa7lZjUxFQ3Log8xvjZ+p7NDDNSDC2sgIip9g3d4emJLxgnJrFJySoJz91dzWyl8 8QFzMgYthlEtCoGK9oNOk/EnOpHPAHnd7PuJBvVuKWtmEZTa5Lu2LJHWUQkmQBkQw38E +22heCXvMuC3LUy+HALgKxMN7/qUia5bThXj2c7D/lqpDEl0swhRQWKO6dapz5tL4oYP 3aHlp4AxGzFGDK6l8VlYBzfIBmJtgnqCPRZxEPFZp4zMp43vJuH5ox98CroAoLtopjAk eq/A== X-Gm-Message-State: AGi0PubQJfIDfdbaZjNSAypuddxkOuXR8waKeEDW+8tBYwOSBL2q80va f4cl08FaSGgfYZck/b97oec= X-Received: by 2002:a63:6cc5:: with SMTP id h188mr24276969pgc.337.1587537382250; Tue, 21 Apr 2020 23:36:22 -0700 (PDT) Received: from js1304-desktop ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id e4sm4197953pjv.30.2020.04.21.23.36.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2020 23:36:21 -0700 (PDT) Date: Wed, 22 Apr 2020 15:36:16 +0900 From: Joonsoo Kim To: Johannes Weiner Cc: Alex Shi , Shakeel Butt , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 02/18] mm: memcontrol: fix theoretical race in charge moving Message-ID: <20200422063615.GB6780@js1304-desktop> 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: <20200420221126.341272-3-hannes@cmpxchg.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 20, 2020 at 06:11:10PM -0400, Johannes Weiner wrote: > The move_lock is a per-memcg lock, but the VM accounting code that > needs to acquire it comes from the page and follows page->mem_cgroup > under RCU protection. That means that the page becomes unlocked not > when we drop the move_lock, but when we update page->mem_cgroup. And > that assignment doesn't imply any memory ordering. If that pointer > write gets reordered against the reads of the page state - > page_mapped, PageDirty etc. the state may change while we rely on it > being stable and we can end up corrupting the counters. > > Place an SMP memory barrier to make sure we're done with all page > state by the time the new page->mem_cgroup becomes visible. > > Also replace the open-coded move_lock with a lock_page_memcg() to make > it more obvious what we're serializing against. > > Signed-off-by: Johannes Weiner Reviewed-by: Joonsoo Kim Thanks.