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=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 8C9F0C43215 for ; Thu, 21 Nov 2019 20:56:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A5D30206CB for ; Thu, 21 Nov 2019 20:56:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="cwuJLrMB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5D30206CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 178DA6B0381; Thu, 21 Nov 2019 15:56:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 129CB6B0383; Thu, 21 Nov 2019 15:56:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03EBD6B0384; Thu, 21 Nov 2019 15:56:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id E27FB6B0381 for ; Thu, 21 Nov 2019 15:56:34 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 997CE8249980 for ; Thu, 21 Nov 2019 20:56:34 +0000 (UTC) X-FDA: 76181493108.07.drug70_738619f671a1b X-HE-Tag: drug70_738619f671a1b X-Filterd-Recvd-Size: 4420 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Nov 2019 20:56:33 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id o17so4376477qko.6 for ; Thu, 21 Nov 2019 12:56:33 -0800 (PST) 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:user-agent; bh=jo8ATEWyaSv/vLCn6HnPEaOlsTqvflPgdCXI72jAtAM=; b=cwuJLrMBZhPa5DBRo45PuWX50UB2Z5+gnbtBmxVA7l/W0adG0YbnCA+7EREee4ihMc /RtO2VS4M4autGBGzWZTC46Jv/LvU147g9Fe9ZrChLgdMY+2MhaYCoaBjmPAKML/GefK VsbDCS5rx0r5a8Yr8KgX4nvZa37JnXmMlmF9QekitglonB7f4EXFQTtRmVDQb2Zbltlx KwQpiRpPbM2LMBteWoe4r9FvgKpzKFjVlySacY13KC2eiNkTNw4bwv7DtJGh5FIwLoM2 eD8G2mK3gounHPRVqZB7S/qn3WcDBAFP289D4mndKgQmZUjv19S70bmW84IqqAvtTHWJ c2Vg== 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=jo8ATEWyaSv/vLCn6HnPEaOlsTqvflPgdCXI72jAtAM=; b=JODICy76TrbWlj4+hJtD1sA7wMGMlvKXP1FLxlERy/TyA7KNwx9rFai/pAxNgdAeDz pgKrPPnwsibGQ7Zv/fkpjuKXmMAeNxOaxOcGR4dAe1IrwgV0Gr70b9Bf3OsdLHEJ0U9w xsElv+Y9mryJGzRgDIOZkSIm9Etvd4cOD9TAQwdXTiT0DATcFqosYLG74fw1IhYx0Spn llz9qxVGQUrU5w35BjDZlqEDfsUjRCbQNPZLBvjAaDjKt2rhzEcykpE44wfwMikhymHc 8nLS+ewy9OQujq8FyWFSRg+iuxUYuiB7T7F5gY7NnurAIo6ZekvSZ1iNTKwF3yeVji16 0e8A== X-Gm-Message-State: APjAAAXZTUXTFERTF1vXzANrxuYLd4Gg2nlsZyGI0AxSEjawRGgStnVM 4PKlHB/gTxLM2Uw4LGXX+4T+Gw== X-Google-Smtp-Source: APXvYqzsNvwhS/lTU40H0qPMgE9W+CAi3eGFu6U08L2WuddkClqPGbs73rv7JHDvuvP81IsNUVvndg== X-Received: by 2002:a05:620a:1653:: with SMTP id c19mr2834381qko.482.1574369793110; Thu, 21 Nov 2019 12:56:33 -0800 (PST) Received: from localhost ([2620:10d:c091:500::1:dbed]) by smtp.gmail.com with ESMTPSA id b4sm1934576qka.75.2019.11.21.12.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 12:56:32 -0800 (PST) Date: Thu, 21 Nov 2019 15:56:31 -0500 From: Johannes Weiner To: Hugh Dickins Cc: Andrew Morton , Shakeel Butt , Michal Hocko , Alex Shi , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH] mm: fix unsafe page -> lruvec lookups with cgroup charge migration Message-ID: <20191121205631.GA487872@cmpxchg.org> References: <20191120165847.423540-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) 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 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.