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.3 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,URIBL_BLOCKED,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 0209BC43215 for ; Thu, 21 Nov 2019 21:31:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B8234206CB for ; Thu, 21 Nov 2019 21:31:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KQXl3u2S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8234206CB 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 46C0C6B0389; Thu, 21 Nov 2019 16:31:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41CBF6B038A; Thu, 21 Nov 2019 16:31:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 332026B038B; Thu, 21 Nov 2019 16:31:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id 1E03A6B0389 for ; Thu, 21 Nov 2019 16:31:07 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 9AEA78249980 for ; Thu, 21 Nov 2019 21:31:06 +0000 (UTC) X-FDA: 76181580132.27.page61_7e075f79b8161 X-HE-Tag: page61_7e075f79b8161 X-Filterd-Recvd-Size: 4348 Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Nov 2019 21:31:05 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id v138so4603847oif.6 for ; Thu, 21 Nov 2019 13:31:05 -0800 (PST) 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=4Ih+wdf+T8QIhxXa0Z/BjR6OEVlveBg+npb+LGLRLAs=; b=KQXl3u2SVxyMz8rlN77m7iXC4ogPKT54d6c96jwtR1V+9QP6TEJSfb7qFvrb+c8sYn K1HETXSPjLCE+ngl2e3oauOhqVrEPFPM/ZhnnrzVqESA+rClKn4LlMg7AyKV4Td5W2Ef xZ/qSXNCfrpe4jEh11iqbzoHAebuFk6JndluiFnmlqwAn8qHcNvAmBcFo4YjRec62s+I GRFgKzmVkO22wLfhbM8JasOVjj3eAkjRhG06EPVSfLHi7Oxy1zwpIe9LLOjMTDraMIfi 5/lkMveIVEwgKvw90PoSaktKGc7LanP0P3AO+m//ciW9Hi25i5albVbdjQTMnkwoR8HF Truw== 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=4Ih+wdf+T8QIhxXa0Z/BjR6OEVlveBg+npb+LGLRLAs=; b=BaC+jTulUEJl0IvECR4MEYkj44suRI0sRbCSP6b2AoozLCfCxjzLWXZfMPxGI+9RSu /H45QJz8Y8jsl62YCLdaxge+xuDdMtgzvy47hm57KfdXO37Ww9M7u1gDY2XowUVrSt5K HXqL0oQcNM1gD7g9XDTsVuFqc5zciH/5jaE79Fr/091qbFMO9DuXQ/1H59jOgEHHGiQQ NrHIeZXmAVo0YVpCgC47vTMB8DxHzBB62u65MgqqwxxkVq9iL/5i36PwGOO3sGlCliUl nmyVeLl4+4ZpM0QefG6cmmfmp61eVOL/Nkg/Noxn5qrPsE35jZkebnuB8DmnYMJFjObC Abjg== X-Gm-Message-State: APjAAAVEKMAykqpoFbeQYrbWYA1C7P7e3cKA1AUrvXjvk3sqEDhhEXXn ZyDPiNnNYGQLPbpJ8E7OCniJ33GJBXecDOn4/pOFrg== X-Google-Smtp-Source: APXvYqyyYZQan3opx0rXCprghR1vY7gbbQA4CJmeQnXT2oWPmvhKt0mBKHrMonq2HYj1qOct6NiLQYx4svVuB+BfkVI= X-Received: by 2002:aca:7516:: with SMTP id q22mr9124234oic.144.1574371864860; Thu, 21 Nov 2019 13:31:04 -0800 (PST) MIME-Version: 1.0 References: <20191120165847.423540-1-hannes@cmpxchg.org> <20191121205631.GA487872@cmpxchg.org> In-Reply-To: <20191121205631.GA487872@cmpxchg.org> From: Shakeel Butt Date: Thu, 21 Nov 2019 13:30:52 -0800 Message-ID: Subject: Re: [PATCH] mm: fix unsafe page -> lruvec lookups with cgroup charge migration To: Johannes Weiner Cc: Hugh Dickins , Andrew Morton , Michal Hocko , Alex Shi , 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 Thu, Nov 21, 2019 at 12:56 PM Johannes Weiner wrote: > > On Wed, Nov 20, 2019 at 07:15:27PM -0800, Hugh Dickins wrote: > > It like the way you've rearranged isolate_lru_page() there, but I > > don't think it amounts to more than a cleanup. Very good thinking > > about the odd "lruvec->pgdat = pgdat" case tucked away inside > > mem_cgroup_page_lruvec(), but actually, what harm does it do, if > > mem_cgroup_move_account() changes page->mem_cgroup concurrently? > > > > You say use-after-free, but we have spin_lock_irq here, and the > > struct mem_cgroup (and its lruvecs) cannot be freed until an RCU > > grace period expires, which we rely upon in many places, and which > > cannot happen until after the spin_unlock_irq. > > You are correct, I missed the rcu locking implied by the > spinlock. With this, the justification for this patch is wrong. > > But all of this is way too fragile and error-prone for my taste. We're > looking up a page's lruvec in a scope that does not promise at all > that the lruvec will be the page's. Luckily we currently don't touch > the lruvec outside of the PageLRU branch, but this subtlety is > entirely non-obvious from the code. > > I will put more thought into this. Let's scrap this patch for now. What about the comment on mem_cgroup_page_lruvec()? I feel that comment is a good documentation independent of the original patch.