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 9C259C432C0 for ; Thu, 21 Nov 2019 21:31:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68E45206CB 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" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbfKUVbG (ORCPT ); Thu, 21 Nov 2019 16:31:06 -0500 Received: from mail-oi1-f195.google.com ([209.85.167.195]:38649 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfKUVbG (ORCPT ); Thu, 21 Nov 2019 16:31:06 -0500 Received: by mail-oi1-f195.google.com with SMTP id a14so4613767oid.5 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=mVi7tenEhJo13CnKgSW4nOxeU2hHzyk66eClWi4bGoWhUgtJ3gkHrMg6OvocLLULnk z7Wq6aevP6gtH7jGtOC8HhKlFP09K6KFv3m48gWK/e4HNpRXa+JjMx0rtltW3vMNCRDY xQHNMsEp/fX0jwIREVJ3XPm4WROBs2KyzriBLYFOfk/LdD9Mp4cMRis8iXqjuxH38MiJ LHKUZsS+WKHT+AY9g25xif4rlgQnx3JkOGaYbSCdv4hJkk5PdKJ72cyByqWUrd1epbmC jzRmg9a/dFH1RK+pbx0yOsIHtaOYRHFs7tMebDQy/sDqAET3v2qRxPUfzOFc78lIfJj4 TPbg== X-Gm-Message-State: APjAAAXHoYj/XU5UKHoVhUTlFdZ7QG1MgGgcezpLhwbFkAXy91sftPH0 Dj4bO8HCIc6065KTlIoNhtfdWXY7uFIQVVlJSMP0tg== 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.