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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F114C54E76 for ; Thu, 5 Jan 2023 15:19:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94D1F8E0002; Thu, 5 Jan 2023 10:19:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FC468E0001; Thu, 5 Jan 2023 10:19:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C35D8E0002; Thu, 5 Jan 2023 10:19:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6D7518E0001 for ; Thu, 5 Jan 2023 10:19:16 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3B1701A0DBA for ; Thu, 5 Jan 2023 15:19:16 +0000 (UTC) X-FDA: 80321103912.09.200505E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf03.hostedemail.com (Postfix) with ESMTP id 1BD9D20011 for ; Thu, 5 Jan 2023 15:19:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672931954; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4sr1zUIX8YqchENZZMigHVdcEgrIXH2gvQE2eV//wHE=; b=n+sz0WVwrsMfRsXeHOHAxacA1iDJoGxBNofv4s76Lo9d9QlRHPKexuYwOntq+Tn8PDOu3Y p1nlBt1brAQDN9obeV4+6KJmaBGacCbHdg2FRQ4fFMWIaSwoCpo9S54U6O6rhukQv2ELOE cNs31pB9AKHbFW0iO4/O5tWl/aReI8w= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672931954; a=rsa-sha256; cv=none; b=G0AwCYDCwb8rgaRkvICmIVEo7hn43lNtMlaRlCBD14zlxqau9LMmI3y79VYdwAE15ceVbH WCV/HTEW/Ihbdhldi6jx9rcyR8HsIGESDWPAj3Q3+i7lAtJNRLeffxHx8Q7mml1OEBHUFD OXmC0uT73bvBdDP+1hBcK9e1QG/cQu8= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3ADFB174BD; Thu, 5 Jan 2023 15:19:07 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 157F5138DF; Thu, 5 Jan 2023 15:19:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MsyLBGvqtmO1JQAAMHmgww (envelope-from ); Thu, 05 Jan 2023 15:19:07 +0000 Message-ID: Date: Thu, 5 Jan 2023 16:19:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: A better dump_page() Content-Language: en-US To: Matthew Wilcox , David Rientjes Cc: 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 References: <202212312021.bc1efe86-oliver.sang@intel.com> <41276905-b8a5-76ae-8a17-a8ec6558e988@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 1BD9D20011 X-Stat-Signature: 6a3oqqnndpxqd7uue6xym777jwbppkso X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1672931953-171186 X-HE-Meta: U2FsdGVkX18MBUxSFXJoZ1hxJ7XDoPUJfB/rBiBMSWXzLgMaTpEL1kMsgLDP5dcQpLFgcWiwQ4msPGsDPs9l1BZHzDicK/GNfgf6st+MYadn65gtLhnbhp/htIjzl0K0/VCKjAB0mcQmvtHmRsXynw0A1SpTWdWUehFhXoWR4qKjubbE2u7IjHvsNRB1/MIVFsTDWlTA5oZrABC0Lib3gncJJ3/i+dj/Ec4xw2iBt+Q0z4s3+hoCCA8WwbddzOi2Ah6Z0EqT/aqSrP4Lcg/0RLFhsCLuncpo/FogvBwJwzW8eAoPMuwo+NNDB+ouWBEmzAjjRhrVYaON/7Cwc9KfvHNHknFKrs+doYAjrr7yLJWBVb7Bs+MMlC6kEWpbdkwFHd4CxHAl2e4x/ye7GpNfG2e5i/6DIXuzIsp/bHRshwcV9plG9OtHlHe6PxmIxei8gVDp33yiD4KxR9DCDxCFmBia9gW/u5n5kl+fvbqtbvPkuEGgU0GJ93XXDfLJ5ciWGfZwNDFt88W89BoRLK5aCASCdLBxkoudvcOglTFy6XMmDaUDgtUODGPpfRgPbhWxrCOa20RoGlyvh5PDYuQq/WNoj3Iq2e+4SJIMSIUcAY5VWrUvq6Z1d2umjOvqyZ0NizEWAX6MY+dDRUVCSwVfqgwto2AUR4t9+w8abMt/zRs/+W7rjGNXhwBDiatCCoOPLb84cqSTNOCQAsIvzMFqxHVRgIJmhsuc87zWx6ty+U3OkHocBD1xI1b+qEkEFBxRehCTUV93LKFngYc0wPKd+8jFofWok/K+UqdsPHK3Xdlgz0kgobvDhZR0RA2P9uYJnkqW/gT63N8a7GKUQnv2/fB5ED9eqhn8XGGBN7qfOZJAdMvUz0PFLJpWodtFJckvOMU1F07sPWp0JlguwFLeqqMPOyfgRaPtKQEKYeYLkyc= 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 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. I'm afraid the only way to prevent this is to make sure any helpers __dump_page() uses simply must not contain any VM_BUG/WARN_ON sanity checks, and anything treated as a pointer must be checked before dereferencing. 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.