Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1032729rwl; Thu, 5 Jan 2023 07:53:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3sPrMgCxj8zBjX5UlD2uJZD5Kxp1ovdJeQba//aoN6QBRsS0G6q31ky6Ln9FEtS4hnI/p X-Received: by 2002:a17:906:8e91:b0:7c1:5248:4f3a with SMTP id ru17-20020a1709068e9100b007c152484f3amr40744367ejc.56.1672933984322; Thu, 05 Jan 2023 07:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672933984; cv=none; d=google.com; s=arc-20160816; b=nYR2x8i4McBpBTZSt/cHabzYQLmqxBRq1kV74XfiDnQAfnwx1TBL5bO9oFGKbsPaLL yHh8FMRjfcD9N7M+TvqXInyd3C6Q72b4GVqi3r7o+c+dq16wCo9eeKOlutV+amC9lDFM HlgVncjecdlt3cpAaJH/P/IWOjMJBeo2mfKaXL+Lqv53JpdACO8XvYjsHmoeqExalVCM 6HDw13OsqYv3vOrwhl+/GAcP92xERs2wTOC+qcSTZCN8V1iq91zhc7PrTi3fZ1QT2kUm nAiqKP5T4dGqcVlN2DECcHWeZ9batISPk+4lwypKu387RyqsKW0TVnADXZlpvxIRUgZK G+cQ== 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=gQUVnq/KRRYcYlYb/NUnN+HgkAGfxeQMSvNtoyFPIfA=; b=iH8jXW3VGcl0MOg4N4i+B0i5aPyZ/cYcNHgJmHI3TJDRhNi65qwNUTWk31T3zq4MkX k1J13zTJsqy6FECjfWFix2IEg4SaQ0tU5vO1P/Qietkh23oE2HbPzy7zI16q5KrwRSob /JhLlp07AYzNH+MIHRKcv/fkEGR0kmPIEv3xDMUmIwhi50ogKP3eo+EOr5iGKzEKBQ/F QCyyEbE/LMBRr56by0TkYvf76ETxCccYIlloj8Ka+pSZN/UkTWaqMXpOmcbzXRQRaAnS Zo28CPBD2Q0mbIAXltRTMsabDCY9r7/9XBN3bU7RGCvxOXOPqTkTKCRZOvYWJKF/mnpQ 2/aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=nVxl5SVx; 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 di21-20020a170906731500b007bea4cb61d6si34647973ejc.424.2023.01.05.07.52.51; Thu, 05 Jan 2023 07:53:04 -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=nVxl5SVx; 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 S234294AbjAEPga (ORCPT + 55 others); Thu, 5 Jan 2023 10:36:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234625AbjAEPgH (ORCPT ); Thu, 5 Jan 2023 10:36:07 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952E95C1C0 for ; Thu, 5 Jan 2023 07:36:02 -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=gQUVnq/KRRYcYlYb/NUnN+HgkAGfxeQMSvNtoyFPIfA=; b=nVxl5SVxoL53J3crMeqVtxMmpU NePoexvwH/aFyYAe2DpV5UNcUTKzQe1KqL7XHfWZu09jGQ9sv/h/jeC7UgIquWWRzin7QNnuff3l/ UxWaHhnXB5YYYOK1vq24S8u+DpanFGp2A5vHUz+D3S8LEESH2nXzH5mEH+Trpw6Dk9QflurylSbfK mpfl0wdSrT0dqKO2ANuixUeWxM4bPYIYTiy9F3r4NoWDTEgIGj5gXgHoScp0cKgSMS0r3HRd9doQ0 +yfePNNkASURsf1Auhh/0G1fx0QeVHW8wvccBYK3cHXrDIgt2+Y8IFHQyIEvMO7nQ8pleWpiK+9uc 4AUb13xg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDSHb-00GERU-DZ; Thu, 05 Jan 2023 15:35:55 +0000 Date: Thu, 5 Jan 2023 15:35:55 +0000 From: Matthew Wilcox To: Vlastimil Babka Cc: David Rientjes , 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 Thu, Jan 05, 2023 at 04:19:06PM +0100, Vlastimil Babka wrote: > On 1/4/23 00:29, Matthew Wilcox wrote: > > 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. > > I'm afraid this problem can still happen if the snapshot is inconsistent in > the first place and you e.g. snapshot the tail page as tail page, and the > supposed folio head page as not head page. Oh, there would have to be an explicit check that the head page pointed to is actually a head page, and further that it really is the head page of this page. But the advantage is that we can check that we have a consistent snapshot _once_ rather than in every helper that we use in this function. The question is what to do if we have an inconsistent snapshot. The answer we usually use (eg in filemap, gup, etc) is to try again until we get a consistent answer. But I think that's the wrong answer here; if we get an inconsistent snapshot, we should give up. Whatever information might have been gleaned from the head page is now gone, because we don't have the original head page any more. So we should just dump the page as a non-compound page. > The local copying still makes a lot of sense though, as anything checked on > the copy that determines its further evaluation can be trusted to remain > consistent without complicated piecemeal READ_ONCE()'s etc. And as you > mentioned it will allow us to proceed with constification, where the > possibility of dump_page() through VM_BUG_ON_PAGE() is IIRC a big blocker > for constifying the various flags checking helpers etc. Yes, that's a nice side-benefit ;-)