Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12524678rwl; Tue, 3 Jan 2023 16:10:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXtbnp84y2GJjUPYp5LxnLEZlIgBxbTV0JQXBK2J+QswP5nTStJiDlr1MLbxeJgYRPOs2X0V X-Received: by 2002:a05:6a20:a690:b0:a5:418:8341 with SMTP id ba16-20020a056a20a69000b000a504188341mr60506449pzb.28.1672791017232; Tue, 03 Jan 2023 16:10:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672791017; cv=none; d=google.com; s=arc-20160816; b=w+2izl1PIL5mo0TJA0QZ9I98Xt/uM1kZKb3EcO5W514EErTOeljZtmDNp6l02Cnv/U cmGHaTFuYzGl9/PzrQYTR261IKPQLe9/0D7MgcM2EwLrc+APN1ExYQJyw2G9X9hA8JEi kSBQhVPFXMqKa/aDnNoYZAvyuMRV4grEIygbS1cMX66+Du5zBv0+1QavH5LzNDijVY/k lMH4+lgxuwccvETJ+Tkwt61oVg++GekbvDOg9iFa8W05D6weJMqgTORxbF/6yALfBwFb tVYA4JF6UiH5qPxsLnzDKi3DwZ6ZafnXGgBeX8ijUn2zOkVvHlr1hhUPXXE3cKfdi9Jw AijQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gJPqyGklqTbYMdKnqat7Qbv+pMXyAuOwKbuCLL2MIGw=; b=shKHg4Tn4wOZq5esgShVu4o4q7EDboJptmT1Gm7j/iQX1SnhWDW/1IEC9OtJB8NEXD 8/YFBipAAMwGFcr1VjLq6HbX5xtHkeEt7lUNkU2yXn0CBHzHWY372a8jO2/hwRN4Wt2t h1SbIhPOu9JmSHcYcY7Oir9kW9P8l6iOBwx828YonjqM4KP7lHmSmjw6ewWkP8PZ8w6g PATZ4ZiJW1X06hN+EVPGZHzcsSYizazI4Y6k0HGurP9wC5p2yXrQdLwAm42fiNiRMUGf 1vBmAYJShQuHENrpNwDrXHfNfpcKIiXnlWaMTUDcLrNO6nKgt4MCQjZiXk4y314Rw064 uJLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kgw2QhRf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a170902904400b00176953fee67si31578100plz.86.2023.01.03.16.10.08; Tue, 03 Jan 2023 16:10:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kgw2QhRf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234225AbjACX3z (ORCPT + 57 others); Tue, 3 Jan 2023 18:29:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjACX3x (ORCPT ); Tue, 3 Jan 2023 18:29:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AE3D2601 for ; Tue, 3 Jan 2023 15:29:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gJPqyGklqTbYMdKnqat7Qbv+pMXyAuOwKbuCLL2MIGw=; b=kgw2QhRfZdK8b99xYswM0FAnRa dSWhynhEso+r248R4juIWtqk7DJjJUjp0jhL12KxbqdpiSIrFQ8YSV3VoZFFQ3yO99t2DD70ULyf1 wM3nop/kBaR8yEWyrpbQai8qbp4lcfvIeHsju2Sky76nk/2u4JpuaBwBTW6f5ZmoIh9ACBywZefUB tBytsJdtHZYYlXWf+BK5TNHejVhq9PzgzAkt5OuDjbnMzapHMYdNAqnLoqHqPY0Qps6mu7wHxXe44 fUPitTOeDXgQy1Yk4pts9rgn8+abS24OGJzxGdjmvEzuziye1YpH3/+B++sf8+kPT2PuSlaL5E+EU uSpJ2wlw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCqiy-00EUm4-5a; Tue, 03 Jan 2023 23:29:40 +0000 Date: Tue, 3 Jan 2023 23:29:40 +0000 From: Matthew Wilcox To: David Rientjes Cc: Vlastimil Babka , kernel test robot , Hyeonggon Yoo <42.hyeyoo@gmail.com>, oe-lkp@lists.linux.dev, lkp@intel.com, Mike Rapoport , Christoph Lameter , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: A better dump_page() Message-ID: References: <202212312021.bc1efe86-oliver.sang@intel.com> <41276905-b8a5-76ae-8a17-a8ec6558e988@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 03, 2023 at 03:07:12PM -0800, David Rientjes wrote: > On Tue, 3 Jan 2023, Matthew Wilcox wrote: > > > On Tue, Jan 03, 2023 at 11:42:11AM +0100, Vlastimil Babka wrote: > > > Separately we should also make the __dump_page() more resilient. > > > > Right. It's not ideal when one of our best debugging tools obfuscates > > the problem we're trying to debug. I've seen probems like this before, > > and the problem is that somebody calls dump_page() on a page that they > > don't own a refcount on. That lets the page mutate under us in some > > fairly awkward ways (as you've seen here, it seems to be part of several > > different compound allocations at various points during the dump > > process). > > > > One possibility I thought about was taking our own refcount on the > > page at the start of dump_page(). That would kill off the possibility > > of ever passing in a const struct page, and it would confuse people. > > Also, what if somebody passes in a pointer to something that's not a > > struct page? Then we've (tried to) modify memory that's not a refcount. > > > > I think the best we can do is to snapshot the struct page and the folio > > it appears to belong to at the start of dump_page(). It'll take a > > little care (for example, folio_pfn() must be passed the original > > folio, and not the snapshot), but I think it's doable. > > > > By snapshot do you mean memcpy() of the metadata to the stack? I assume > this still leaves the opportunity for the underlying mutation of the page > but makes the window more narrow. Right. We'd need to memcpy() both the page and the folio, so around 192 bytes. It doesn't make it consistent since it could be mutated during the memcpy(), but it will be consistent throughout the execution of the function, so we won't get calls like folio_entire_mapcount() aborting due to the folio having become a tail page halfway through.